Skip to main content

NetCDF4 Variable Appender

NetCDF4 Variable Appender Script

A new basic script, written by Paolo Veglio, called edit_netcdf.py is now available.  It is written in Python 3 and could be used as a programming template to give guidance on how to add a new post-processed computed variable (e.g.: Median) to an existing defined Group (e.g.: Aerosol_Optical_Depth_Land) inside a fully-populated NetCDF4 file (*.nc).   Also provided, at the end of this script, is the syntax for attaching new local attributes to this newly added variable (e.g.:  FillValue, units, & title).  This script can be used as a template on how to create more complex code that could modify production NetCDF4 files (before they are distributed to the public) in order to add new more complex variables, which somewhat static L3 processing tools like Yori cannot easily compute in real-time due to its chained-aggregation design. 

To run this simple example script, one would invoke the following command from a terminal window, with Python 3 available, and NetCDF4 and NumPy modules installed (see required installed libraries below):

     python   edit_netcdf.py   <existing_netcdf_file>   <group_in_file>   <new_variable_name>

Obviously, the newly computed variable needs to be defined correctly somewhere in the code, and the dimensions must match other simple variables already defined (e.g.: Mean or Standard_Deviation).  Coded currently in this script is a basic sample variable containing all 0's.  Some comments are included in the template script provided to help clarify each step of the logic.  It should be noted this is not fancy or super flexible code as currently written, but should give a good basic starting point to improve upon.

 

Sample Code:

The template python 3 script, which you can build upon, is offered below:

edit_netcdf.py (Python 3 Code)

 

Required Installed Libraries: 

Note that this sample python script provided above requires: