Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getvar returns ['GSW' is not a valid variable name]; extract_vars returns [got multiple values for argument 'timeidx'] #238

Open
phalucy opened this issue Apr 28, 2024 · 3 comments

Comments

@phalucy
Copy link

phalucy commented Apr 28, 2024

Dear all,

I'm now working on an issue that needs the net heat flux at surface.
To calculate it, I need the variables including GSW, GLW, TSK, EMISS, GRDFLX, HFX, and LH.
The others are easily obtainded by wrf.getvar function, but I failed in getting the variable GSW, and the error message is here:

gsw = wrf.getvar(wrflist, "GSW", timeidx=t,  @method="cat")
  File "/Users/abc/anaconda3/envs/pygmt/lib/python3.10/site-packages/wrf/ro
utines.py", line 352, in getvar
    raise ValueError("'{}' is not a valid variable name".format(varname))
ValueError: 'GSW' is not a valid variable name

I checked the wrfout file and confirmed there is a variable named 'GSW' (I could also plot it):

float GSW(Time, south_north, west_east) ;
		GSW:FieldType = 104 ;
		GSW:MemoryOrder = "XY " ;
		GSW:description = "NET SHORT WAVE FLUX AT GROUND SURFACE" ;
		GSW:units = "W m-2" ;
		GSW:stagger = "" ;
		GSW:coordinates = "XLONG XLAT XTIME" ;

After that, I tried to use wrf.extract_vars to get the variables that originally embedded in the wrfout file, but I also got error

gsw = wrf.extract_vars(wrflist, "GSW", timeidx=t, method="cat")
TypeError: extract_vars() got multiple values for argument 'timeidx'

The argument 'timeidx=t' works fine in other variables such as GLW, etc.

Is this a bug or I need special way to extract GSW? For now, I could only get 'SWDOWN' and 'ALBEDO' seperately and calculate GSW by myself.

@phalucy phalucy changed the title 'GSW' is not a valid variable name]; extract_vars returns [got multiple values for argument 'timeidx'] getvar returns ['GSW' is not a valid variable name]; extract_vars returns [got multiple values for argument 'timeidx'] Apr 28, 2024
@kafitzgerald
Copy link
Collaborator

kafitzgerald commented Apr 29, 2024

Hi @phalucy, thanks for the question.

You'll need to use wrf.extract_vars since "GSW" is a variable in the file rather than one of the supported diagnostics.

I'm not quite sure offhand what's going on with the TypeError from wrf.extract_vars. Do you have a short example to reproduce this?

@phalucy
Copy link
Author

phalucy commented May 2, 2024

Hi @kafitzgerald, thank you for your reply, but I'm sorry I don't have an smaller-enough example that could be uploaded.
Now I'm OK by calculating GSW based on SWDOWN and ALBEDO.

Meanwhile, I wish to know why some variables (such as GLW, ALBEDO, SWDOWN, etc.) were obtained successfully by the 'getvar' function, which are also not supported diagnostics.

@kafitzgerald
Copy link
Collaborator

My apologies, I misspoke about wrf.getvar vs wrf.extract_vars. You should be able to just use wrf.getvar. However, I'm still not quite sure why you're seeing the ValueError with wrf.getvar and haven't been able to replicate it.

I think you may be able to get wrf.extract_vars to work by specifying the variable name as a keyword argument vs. a positional argument (see below) or swapping the order so the arguments align with what's expected. Interestingly the varnames and timeidx are specified in a different order from getvar.

gsw = wrf.extract_vars(wrflist, varnames=["GSW"], timeidx=t, method="cat")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants