barronh / pseudonetcdf

PseudoNetCDF like NetCDF except for many scientific format backends
GNU Lesser General Public License v3.0
75 stars 35 forks source link

pncmap.py - Can I sum linearly combine multiple input variables? #32

Closed jaegunjung closed 6 years ago

jaegunjung commented 6 years ago

pncmap.py is very useful to do QA CAMx output files.

I want to plot PM2.5 but do not know how to combine multiple variables. Can you show an example?

Thanks - Jaegun

barronh commented 6 years ago

@jaegunjung

Sure, this is easy to do. You can do it inline or with a file.

Note that I use -- to force the evaluation order. I define PM25 first and then I use -v to select and plot it.

Note that both examples have an ellipsis (...) that needs to be replaced with the definition your are using. Please post your definition for the record.

Inline

pncmap.py -v PM25 -- -f uamiv --expr='PM25=...' inpath figroot

or

As a script

cat "PM25=..." > /path/to/pm25.pncexpr
pncmap.py -v PM25 -- -f uamiv --exprscript=/path/to/pm25.pncexpr inpath figroot

*If future readers are working on windows, replace the ' with " around the expression.

jaegunjung commented 6 years ago

Hi Barron,

When I used --expr='PM25=PNO3', I got the following error messages,

IOAPI_ISPH is assumed to be 6370000.; consistent with WRF **PNC:/disk41/jjung_linux/util/python/anaconda3/lib/python3.5/site-packages/PseudoNetCDF/core/_functions.py:80:UserWarning: Skipping PM25 Traceback (most recent call last): File "/usr/people/jjung/util/python/anaconda3/bin/pncmap.py", line 11, in

main() File "/usr/people/jjung/util/python/anaconda3/bin/pncmap.py", line 6, in main ifiles, args = pncparse(has_ofile = True, plot_options = True, interactive = True, parser = parser) File "/disk41/jjung_linux/util/python/anaconda3/lib/python3.5/site-packages/PseudoNetCDF/pncparse.py", line 442, in pncparse out = pncprep(args) File "/disk41/jjung_linux/util/python/anaconda3/lib/python3.5/site-packages/PseudoNetCDF/pncparse.py", line 599, in pncprep fs = [pncexpr(expr, f) for f in fs] File "/disk41/jjung_linux/util/python/anaconda3/lib/python3.5/site-packages/PseudoNetCDF/pncparse.py", line 599, in fs = [pncexpr(expr, f) for f in fs] File "/disk41/jjung_linux/util/python/anaconda3/lib/python3.5/site-packages/PseudoNetCDF/core/_functions.py", line 699, in pncexpr exec(comp, None, vardict) File "none", line 1, in NameError: name 'PNO3' is not defined Can you show me an example? Thanks - Jaegun
barronh commented 6 years ago

@jaegunjung - The two examples in the first post work. I just tested it with the test case outputs from day 20020603.avrg.grd01 with the definition that you used and with the following definition. Both can be pasted into my example and produce the expected figure.

PM25=SOA2 + SOA3 + PNO3 + SOA1 + POA + CCRS + PEC + SOA4 + PNH4 + CPRM + FCRS + PSO4 + FPRM

In the future if something doesn't work, don't just post the error. Paste the exact command that failed. Right now, I am guessing a little bit because all I see is your error.

Your error states that PNO3 isn't available. That could be for two reasons. First, the variable could not be in your output. Easily checkable with pncdump -f uamiv. Second, you might not have included the extra -- in between the -v option and and the --expr option.

It is really, really important that you include the -- before the --expr (e.g., pncmap.py -v PM25 -- --expr='PM25=PNO3' inpath outpath). Without the -- in between, it filters the species for only PM25. Since PM25 isn't there, no variables are kept. Then there are no variables available to define PM25. As stated in the initial post, the extra -- forces order of operations.

jaegunjung commented 6 years ago

Hi Barron,

Thanks for pointing "--". As you expected, I did not use "--" in the argument list. I will post the command I used in the next time so that you can understand better what happened.

I just want to note that the order of argument matters. When I tried,

pncmap.py -v PM25 --from-conv=ioapi --format=uamiv -- --expr='PM25=PNO3_1+PSO4_1+PNH4_1+POA_1+SOA1_1+SOA2_1+SOA3_1+SOA4_1+SOPA_1+SOPB_1+PEC_1+CRST_1+NA_1+PCL_1' $infile $outpath/$outfile -s LAY,0 -r TSTEP,max --states --norm="Normalize(vmin=0,vmax=20.0)"

pncmap cannot recognize "--states" argument. But, when I put the argument before the "-- --expr=..." as follows, it worked.

pncmap.py -v PM25 --from-conv=ioapi --format=uamiv -s LAY,0 -r TSTEP,max --states --norm="Normalize(vmin=0,vmax=20.0)" -- --expr='PM25=PNO3_1+PSO4_1+PNH4_1+POA_1+SOA1_1+SOA2_1+SOA3_1+SOA4_1+SOPA_1+SOPB_1+PEC_1+CRST_1+NA_1+PCL_1' $infile $outpath/$outfile

Thank you for your instruction. I appreciate it.

Jaegun