[ncl-talk] Save output as a NetCDF or tiff file

Dennis Shea shea at ucar.edu
Sun Nov 12 16:28:48 MST 2023


See copy_VarCoords

On Fri, Nov 10, 2023 at 1:39 PM Setareh Rahimi <setareh.rahimi at gmail.com>
wrote:

> Thank you so much for your help. How can I assign lat/lon to the AOD,
> please?
> I used the below lines in the script but received the following error: " fatal:(XLAT)
> is not a named dimension in variable (a2)".
>
>
>
>        system("/bin/rm -f AOD550_2D.nc")    ; remove any pre-existing file
>
>        ncdf = addfile("AOD550_2D.nc" ,"c")  ; open output netCDF file
>
>
>     ;===================================================================
>
>     ; create global attributes of the file (optional)
>
>     ;===================================================================
>
>        fAtt               = True            ; assign file attributes
>
>        fAtt at title         = "Derived AOD"
>
>        fAtt at creation_date = systemfunc ("date")
>
>
>        fileattdef( ncdf, fAtt )            ; copy file attributes
>
>
>     ;===================================================================
>
>     ; make time an UNLIMITED dimension; recommended  for most applications
>
>     ;===================================================================
>
>        filedimdef(ncdf,"time",-1,True)
>
>
>     ;===================================================================
>
>     ; output variables directly; NCL will call appropriate functions
>
>     ; to write the meta data associated with each variable
>
>     ;===================================================================
>
>        ncdf->AOD550_2D  = AOD550_2D
>
>
>       ncdf->a2  = a2(0,:,:,:)
>
>       AOD550_2D!0    = "lat"
>
>       AOD550_2D!1    = "lon"
>
>              AOD550_2D&lat  = a2&XLAT
>
> ===========================================================================================
> here is printVarSummary of "a2"
>
> Variable: a2
>
> Type: float
>
> Total Size: 144434880 bytes
>
>             36108720 values
>
> Number of Dimensions: 4
>
> Dimensions and sizes: [Time | 24] x [bottom_top | 30] x [south_north |
> 229] x [west_east | 219]
>
> Coordinates:
>
>             Time: [   0..  23]
>
> Number Of Attributes: 6
>
>   coordinates : XLONG XLAT XTIME
>
>   stagger :
>
>   units : ?
>
>   description : bin 2 layer optical thickness
>
>   MemoryOrder : XYZ
>
>   FieldType : 104
>
>
>
> On Fri, Nov 10, 2023 at 8:17 PM Dennis Shea <shea at ucar.edu> wrote:
>
>> netCDF operator  'ncks' to extract a variable from a netCDF file and copy
>> it to another
>>
>> %> ncks -v xxx Model.nc XXX.nc
>>
>> where 'xxx' is the name of the variable on the model file
>> ===============================
>>     AOD
>>
>>        *system* <https://www.ncl.ucar.edu/Document/Functions/Built-in/system.shtml>("/bin/rm -f AOD.nc")    ; remove any pre-existing file
>>        ncdf = *addfile* <https://www.ncl.ucar.edu/Document/Functions/Built-in/addfile.shtml>("AOD.nc" ,"c")  ; open output netCDF file
>>
>>     ;===================================================================
>>     ; create global attributes of the file (optional)
>>     ;===================================================================
>>        fAtt               = True            ; assign file attributes
>>        fAtt at title         = "Derived AOD"
>>        fAtt at creation_date = *systemfunc* <https://www.ncl.ucar.edu/Document/Functions/Built-in/systemfunc.shtml> ("date")
>>        *fileattdef* <https://www.ncl.ucar.edu/Document/Functions/Built-in/fileattdef.shtml>( ncdf, fAtt )            ; copy file attributes
>>
>>     ;===================================================================
>>     ; make time an UNLIMITED dimension; recommended  for most applications
>>     ;===================================================================
>>        *filedimdef* <https://www.ncl.ucar.edu/Document/Functions/Built-in/filedimdef.shtml>(ncdf,"time",-1,True)
>>
>>     ;===================================================================
>>     ; output variables directly; NCL will call appropriate functions
>>     ; to write the meta data associated with each variable
>>     ;===================================================================
>>        ncdf->AOD  = AOD
>>
>> ================================
>> See
>> *https://www.ncl.ucar.edu/Applications/method_1.shtml
>> <https://www.ncl.ucar.edu/Applications/method_1.shtml>*
>>
>> On Fri, Nov 10, 2023 at 1:02 AM Setareh Rahimi via ncl-talk <
>> ncl-talk at mailman.ucar.edu> wrote:
>>
>>> Dear all,
>>> I have calculated Aerosol Optical Depth (AOD) from WRF-Chem output using
>>> "TAUAER2" and "TAUAER3" variables (script attached). Instead of using the
>>> created AOD to plot it, I would like to save the AOD as a NetCDF or tiff
>>> file. So how can I do this, please?
>>> I have another question. How can I extract one variable from the model
>>> output and save it as a NetCDF or tiff file?
>>> Please help me with these issues.
>>> Kind regards,
>>>
>>> --
>>> S.Rahimi
>>>
>>> _______________________________________________
>>> ncl-talk mailing list
>>> ncl-talk at mailman.ucar.edu
>>> List instructions, subscriber options, unsubscribe:
>>> https://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>
>>
>
> --
> S.Rahimi
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20231112/8854b343/attachment.htm>


More information about the ncl-talk mailing list