[ncl-talk] _FillValue directly from a file variable

Mateus da Silva Teixeira mateusstex at gmail.com
Tue Sep 11 14:42:24 MDT 2018


Thank you Dennis,

Yes, should be the same. In my script, if file variable haven’t this attribute, I want to define according file variable type.

Best regards,

Mateus


> Em 11 de set de 2018, à(s) 11:06, Dennis Shea <shea at ucar.edu> escreveu:
> 
> The type of  the _FillValue attribute should be the same as the variable eith which it is associated.
> 
> ???
> 
> 
> typeVarGrib = getfilevartypes( f, varGrib )
> if ( isfilevaratt( f, varGrib, "_FillValue" ) ) then
>         fill = f->$varGrib$@_FillValue
> else
>         fill = default_fillvalue( typeVarGrib  )   ; <=====
> end if
> 
> http://www.ncl.ucar.edu/Document/Functions/Built-in/default_fillvalue.shtml <http://www.ncl.ucar.edu/Document/Functions/Built-in/default_fillvalue.shtml>
> 
> On Tue, Sep 11, 2018 at 6:28 AM, Mateus da Silva Teixeira <mateusstex at gmail.com <mailto:mateusstex at gmail.com>> wrote:
> Thank you Dennis and Toni for support.
> 
> I had forgotten I could use "attValue = f->$varname$@$attname$", directly, without load variable previously.
> 
> So, with this tip, I write:
> 
> typeVarGrib = getfilevartypes( f, varGrib )
> if ( isfilevaratt( f, varGrib, "_FillValue" ) ) then
>         fill = f->$varGrib$@_FillValue
> else
>         fill = default_fillvalue( typeof( typeVarGrib ) )
> end if
> 
> It works ok if _FillValue exist, but if it doesn't, I can't pass the type of grib file variable obtained with getfilevartypes, even using $ with typeVarGrib variable.
> 
> Is there a way to pass the content of typeVarGrib to typeof function?
> 
> Thanks,
> 
> Mateus
> 
> 
> 
> 
> 
> Em seg, 10 de set de 2018 às 20:03, Dennis Shea <shea at ucar.edu <mailto:shea at ucar.edu>> escreveu:
> Maybe, the following is what you want?
> 
> load "./getvaratt_value"   ; attached
> 
> ;---- TEST ----
>   f = addfile("FOO.nc", "r")
> 
>   fill = getfilevaratt_value(f, "phooey", "_FillValue")
>   print(fill)
> 
>   g = addfile("FOO.grb", "r")
>   FILL = getfilevaratt_value(g, "PHOOEY, "_FillValue")
>   print(FILL)
> 
> ====================
> You don't 'need' a function but I'd suggest it for error checking and, in some sense, clarity.
> 
> You could do it directly .... IF the variable and IF the attribute exist
> 
> attValue = f->$varname$@$attname$
> 
> 
> On Mon, Sep 10, 2018 at 3:08 PM, Toni Klemm <toni-klemm at tamu.edu <mailto:toni-klemm at tamu.edu>> wrote:
> Hm, I’m not familiar with GRIB files. But generally, don’t you *have* to load the content from all files if you want to aggregate content from multiple files into one? Or are the files too large to load them all at once?
> 
> Toni
> 
> 
> Toni Klemm, Ph.D.
> Postdoctoral Research Associate
> Department of Ecosystem Science and Management
> College of Agriculture and Life Sciences
> Texas A&M University, College Station, TX
> Contributor to the Early Career Climate Forum <http://www.eccforum.org/>
> www.toni-klemm.de <http://www.toni-klemm.de/> | @toniklemm <http://twitter.com/toniklemm>
> 
> 
> 
> 
> 
> 
> 
> 
>> On Sep 10, 2018, at 4:01 PM, Mateus da Silva Teixeira <mateusstex at gmail.com <mailto:mateusstex at gmail.com>> wrote:
>> 
>> Sorry about grammatical error: ... not be more specific.
>> 
>> Best regards,
>> 
>> Mateus
>> 
>> 
>> Em seg, 10 de set de 2018 às 17:57, Mateus da Silva Teixeira <mateusstex at gmail.com <mailto:mateusstex at gmail.com>> escreveu:
>> Hi Toni,
>> 
>> Thank you for your reply.
>> 
>> Sorry for not being more specific. Actually, I have more than 30 GRIB 1/2 files and I would like to define a single variable (with new function) to hold data from all files. Part of these files are in GRIB 1 format and other part is in GRIB 2. Also, variable name changes from GRIB 1 to GRIB 2 format, even the files coming from same source (GFS ANL). So, I want, after working with these differences, to put all data into the same array.
>> 
>> Thanks,
>> 
>> mateus
>> 
>> 
>> Em seg, 10 de set de 2018 às 17:47, Toni Klemm <toni-klemm at tamu.edu <mailto:toni-klemm at tamu.edu>> escreveu:
>> Hi Mateus,
>> 
>> I imagine there are more elegant ways, but if you don’t have too many files (or if they have the same variable type (int, float, …), you can run the command 
>> 
>> ncdump -h file/path/and/filename.nc <https://urldefense.proofpoint.com/v2/url?u=http-3A__filename.nc&d=DwMFaQ&c=ODFT-G5SujMiGrKuoJJjVg&r=WsLJ5ywbW3XnTzqo_ETV62H6s1a5bcGgnrpl7xPRfic&m=QNHQY-Rg2SD7O4tjt83KFOLSP78h3Xsi7Gp8DZC4XjQ&s=nGgX5SBhjflILx1upQjtPTbXH-SW2BKF3RylaoX5oeM&e=>
>> 
>> which will give you the metadata to each variable, and copy-paste the _FillValue value of your variable directly into your NCL script. Another way is to view the file in a viewer like Panoply and get the _FillValue that way.
>> 
>> Hope that helps,
>> Toni
>> 
>> 
>> Toni Klemm, Ph.D.
>> Postdoctoral Research Associate
>> Department of Ecosystem Science and Management
>> College of Agriculture and Life Sciences
>> Texas A&M University, College Station, TX
>> Contributor to the Early Career Climate Forum <https://urldefense.proofpoint.com/v2/url?u=http-3A__www.eccforum.org&d=DwMFaQ&c=ODFT-G5SujMiGrKuoJJjVg&r=WsLJ5ywbW3XnTzqo_ETV62H6s1a5bcGgnrpl7xPRfic&m=QNHQY-Rg2SD7O4tjt83KFOLSP78h3Xsi7Gp8DZC4XjQ&s=QUEh_u_3pzFgPJlCLTXhCDGj-D3g91zg-BqeSy81OCs&e=>
>> www.toni-klemm.de <https://urldefense.proofpoint.com/v2/url?u=http-3A__www.toni-2Dklemm.de&d=DwMFaQ&c=ODFT-G5SujMiGrKuoJJjVg&r=WsLJ5ywbW3XnTzqo_ETV62H6s1a5bcGgnrpl7xPRfic&m=QNHQY-Rg2SD7O4tjt83KFOLSP78h3Xsi7Gp8DZC4XjQ&s=VU_wO4xhSNGiMrxkh2cdBDlVDCFdstJTeeISiPDr1zs&e=> | @toniklemm <https://urldefense.proofpoint.com/v2/url?u=http-3A__twitter.com_toniklemm&d=DwMFaQ&c=ODFT-G5SujMiGrKuoJJjVg&r=WsLJ5ywbW3XnTzqo_ETV62H6s1a5bcGgnrpl7xPRfic&m=QNHQY-Rg2SD7O4tjt83KFOLSP78h3Xsi7Gp8DZC4XjQ&s=vCNxBBWrfi20WfSVT8WwtxB8Z5Y1OLH3Am8YgLAefPs&e=>
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>>> On Sep 10, 2018, at 3:34 PM, Mateus da Silva Teixeira <mateusstex at gmail.com <mailto:mateusstex at gmail.com>> wrote:
>>> 
>>> Hi,
>>> 
>>> Is there a way to get _FillValue attribute from a file variable without loading that variable?
>>> 
>>> I found getFillValue function, but I think it won't work like I expect. Also, function getfilevaratts only gives a list of the attributes. I would like to directly access the content of this attribute.
>>> 
>>> Thanks,
>>> 
>>> Mateus
>>> 
>>> _______________________________________________
>>> ncl-talk mailing list
>>> ncl-talk at ucar.edu <mailto:ncl-talk at ucar.edu>
>>> List instructions, subscriber options, unsubscribe:
>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk <https://urldefense.proofpoint.com/v2/url?u=http-3A__mailman.ucar.edu_mailman_listinfo_ncl-2Dtalk&d=DwMFaQ&c=ODFT-G5SujMiGrKuoJJjVg&r=WsLJ5ywbW3XnTzqo_ETV62H6s1a5bcGgnrpl7xPRfic&m=QNHQY-Rg2SD7O4tjt83KFOLSP78h3Xsi7Gp8DZC4XjQ&s=hVrZrwQef20v6y6LLb2lxqeSgfcc8A3CzN-mfZ61YyY&e=>
>> 
> 
> 
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu <mailto:ncl-talk at ucar.edu>
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk <http://mailman.ucar.edu/mailman/listinfo/ncl-talk>
> 
> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180911/ec9d4e74/attachment.html>


More information about the ncl-talk mailing list