netcdf4_interface#

ioapps.netcdf4_interface.nccheck(ncfile, ncfrmt=None)[source]#

DESCRIPTION:

This function checks whether a given file path is a netCDF-formatted file and returns a boolean valued variable specifying such.

Parameters:
ncfile: str

A Python string specifying the netCDF-formatted file to be read.

Keywords:
ncfrmt: str, optional

A Python string specifying the format of the netCDF-formatted file(to be created); available options are NETCDF4, NETCDF4_CLASSIC, NETCDF3_CLASSIC, NETCDF3_64BIT_OFFSET, or NETCDF3_64BIT_DATA; if not specified, NETCDF4_CLASSIC is assumed.

Returns:
is_ncfile: bool

A Python boolean valued variable specifying whether the specified input file is a netCDF-formatted file.

Return type:

bool

ioapps.netcdf4_interface.ncconcat(ncfilelist, ncfile, ncdim, ncfrmt=None)[source]#

DESCRIPTION:

This function concatenates a list of netCDF-formatted files, provided in ncfilelist, into a single file (ncfile); the concatenation is performed along a single specified dimension (ncdim); optional arguments enable the format of the concatenated file to be specified.

Parameters:
ncfilelist: List

A Python string containing the list of netCDF files to be concatenated.

ncfile: str

A Python string specifying the netCDF file(to be created) containing the concatenated values collected from each of the files to be concatenated.

ncdim: str

A Python string specifying the netCDF variable dimension along which to concatenated the respective netCDF files list.

Keywords:
ncfrmt: str, optional

A Python string specifying the format of the netCDF file containing the concatenated values collected from each of the files to be concatenated; available options are NETCDF4, NETCDF4_CLASSIC, NETCDF3_CLASSIC, NETCDF3_64BIT_OFFSET, or NETCDF3_64BIT_DATA; if not specified, NETCDF4_CLASSIC is assumed.

Return type:

None

ioapps.netcdf4_interface.nccopy(ncfilein, ncfileout, ncfrmtout, ncfrmtin=None, ncvarlist=None, ncunlimval=None, use_nccopy=False)[source]#

DESCRIPTION:

This function performs a direct copy of an input netCDF-formattedfile to a specified output netCDF-formatted file of a specified format.

Parameters:
ncfilein: str

A Python string specifying the input netCDF-formatted file to be copied.

ncfileout: str

A Python string specifying the netCDF file(to be created) containing the contents of the input netCDF file.

ncfrmtout: str

A Python string specifying the format of the netCDF file to be created; available options are NETCDF4, NETCDF4_CLASSIC, NETCDF3_CLASSIC, NETCDF3_64BIT_OFFSET, or NETCDF3_64BIT_DATA.

Keywords:
ncfrmtin: str, optional

A Python string specifying the format of the input netCDF-formatted file; available options are NETCDF4, NETCDF4_CLASSIC, NETCDF3_CLASSIC, NETCDF3_64BIT_OFFSET, or NETCDF3_64BIT_DATA; if not specified, NETCDF4_CLASSIC is assumed.

ncvarlist: List, optional

A Python list of variable name strings; if NoneType, the variables within the list will be the only variables written to the destination netCDF-formatted file.

ncunlimval: int, optional

A Python integer value specifying the unlimited dimension size; if NoneType, the dimension size will be 0.

use_nccopy: bool, optional

A Python boolean valued variable specifying whether to use the netCDF nccopy utility to produce a direct copy of the netCDF-formatted file specified upon entry.

Raises:
NetCDF4InterfaceError:
  • raised if the netCDF nccopy application output file form is not supported.

Return type:

None

ioapps.netcdf4_interface.nccopyvar(ncfilein, ncfileout, ncvarname, ncvar, ncout_mode, ncfrmtin=None, ncfrmtout=None)[source]#

DESCRIPTION:

This function performs a direct copy of a specified variable from a specified input file to a specified output file.

Parameters:
ncfilein: str

A Python string specifying the input(source) netCDF-formatted file.

ncfileout: str

A Python string specifying the output(destination) netCDF-formatted file.

ncvarname: str

A Python string specifying the netCDF variable to be copied.

ncvar: numpy.array

A Python array containing the values for the respective netCDF variable.

ncout_mode: str

A Python string specifying the write-mode for the output netCDF-formatted file; this should typically be either ‘w’ for a new netCDF-formatted file write(this will clobber any previous existence of ncfileout) or ‘a’ to append to an existing netCDF-formatted file.

Keywords:
ncfrmtin: str, optional

A Python string specifying the format of the netCDF-formatted input file; available options are NETCDF4, NETCDF4_CLASSIC, NETCDF3_CLASSIC, NETCDF3_64BIT_OFFSET, or NETCDF3_64BIT_DATA.

ncfrmtout: str, optional

A Python string specifying the format of the netCDF file to be written to; available options are NETCDF4, NETCDF4_CLASSIC, NETCDF3_CLASSIC, NETCDF3_64BIT_OFFSET, or NETCDF3_64BIT_DATA.

Return type:

None

ioapps.netcdf4_interface.ncnumvar(ncfile, ncfrmt=None)[source]#

DESCRIPTION:

This function parses a netCDF-formatted file to determine the total number of variable arrays within the respective file.

Parameters:
ncfile: str

A Python string specifying the netCDF-formatted file to be read.

Keywords:
ncfrmt: str, optional

A Python string specifying the format of the netCDF-formatted file (to be created); available options are NETCDF4, NETCDF4_CLASSIC, NETCDF3_CLASSIC, NETCDF3_64BIT_OFFSET, or NETCDF3_64BIT_DATA; if not specified, NETCDF4_CLASSIC is assumed.

Returns:
numvar: int

A Python integer specifying the total number of variable arrays within the respective netCDF-formatted input file.

Return type:

int

ioapps.netcdf4_interface.ncreaddim(ncfile, ncdimname, ncfrmt=None)[source]#

DESCRIPTION:

This function parses a netCDF-formatted file to collect and return the dimension size for the specified dimension variable name.

Parameters:
ncfile: str

A Python string specifying the netCDF-formatted file to be read.

ncdimname: str

A Python string specifying the netCDF dimension to be retrieved and returned.

Keywords:
ncfrmt: str, optional

A Python string specifying the format of the netCDF-formatted file (to be created); available options are NETCDF4, NETCDF4_CLASSIC, NETCDF3_CLASSIC, NETCDF3_64BIT_OFFSET, or NETCDF3_64BIT_DATA; if not specified, NETCDF4_CLASSIC is assumed.

Returns:
ncdim: int

A Python integer specifying the value for the specified dimension variable.

Return type:

int

ioapps.netcdf4_interface.ncreadattr(ncfile, ncattrname, ncvarname=None, ncfrmt=None)[source]#

DESCRIPTION:

This function parses a netCDF-formatted file to collect the specified netCDF attribute value(s)

Parameters:
ncfile: str

A Python string specifying the netCDF-formatted file to be read.

ncattrname: str

A Python string specifying the netCDF attribute to collect and return.

Keywords:
ncvarname: str, optional

A Python string specifying the netCDF variable from which to retrieve the specified netCDF attribute; a value of NoneType implies a global attribute is to be retrieved.

ncfrmt: str, optional

A Python string specifying the format of the netCDF-formatted file (to be created); available options are NETCDF4, NETCDF4_CLASSIC, NETCDF3_CLASSIC, NETCDF3_64BIT_OFFSET, or NETCDF3_64BIT_DATA; if not specified, NETCDF4_CLASSIC is assumed.

Returns:
ncattr: Union[str, float, int, Tuple]

A Python type containing the value(s) for the specified netCDF attribute.

Return type:

Union[str, float, int, Tuple]

ioapps.netcdf4_interface.ncvarexist(ncfile, ncvarname, ncfrmt=None)[source]#

DESCRIPTION:

This function reads a netCDF-formatted file and queries the variable list for the existence of a specified variable name (ncvarname); it returns a boolean values indicating whether the variable name has been found.

Parameters:
ncfile: str

A Python string specifying the netCDF-formatted file to be read.

ncvarname: str

A Python string specifying the netCDF variable to be queried.

Keywords:
ncfrmt: str, optional

A Python string specifying the format of the netCDF-formatted file (to be created); available options are NETCDF4, NETCDF4_CLASSIC, NETCDF3_CLASSIC, NETCDF3_64BIT_OFFSET, or NETCDF3_64BIT_DATA; if not specified, NETCDF4_CLASSIC is assumed.

Returns:
ncvarexist: bool

A Python boolean variable indicating whether the queried variable exists within the respective netCDF file.

Return type:

bool

ioapps.netcdf4_interface.ncvarlist(ncfile, ncfrmt=None)[source]#

DESCRIPTION:

This function reads and returns a list of variables within the netCDF-formatted file specified upon entry.

Parameters:
ncfile: str

A Python string specifying the netCDF-formatted file to be read.

Keywords:
ncfrmt: str, optional

A Python string specifying the format of the netCDF-formatted file (to be created); available options are NETCDF4, NETCDF4_CLASSIC, NETCDF3_CLASSIC, NETCDF3_64BIT_OFFSET, or NETCDF3_64BIT_DATA; if not specified, NETCDF4_CLASSIC is assumed.

Returns:
varlist: List

A Python list of variables within the netCDF-formatted file specified upon entry.

Return type:

List

ioapps.netcdf4_interface.ncwrite(ncfile, ncdim_obj, ncvar_obj, ncfrmt=None, glbattrs_dict=None)[source]#

DESCRIPTION:

This function writes a netCDF-formatted file, containing the specified dimensions, variables, and (optional) attributes.

Parameters:
ncfile: str

A Python string specifying the netCDF-formatted file (to be created).

ncdim_obj: object

A Python object containing the dimension variable attributes for the netCDF-formatted file (to be created).

ncvar_obj: object

A Python object containing the variable attributes for the netCDF-formatted file (to be created).

Keywords:
ncfrmt: str, optional

A Python string specifying the format of the netCDF-formatted file (to be created); available options are NETCDF4, NETCDF4_CLASSIC, NETCDF3_CLASSIC, NETCDF3_64BIT_OFFSET, or NETCDF3_64BIT_DATA; if not specified, NETCDF4_CLASSIC is assumed.

glbattrs_dict: Dict, optional

A Python dictionary containing global attribute values; the dictionary keys are the global attribute names while the dictionary values are the corresponding key values.

Return type:

None

ioapps.netcdf4_interface.ncwritevar(ncfile, ncvarname, ncvar, ncfrmt=None)[source]#

DESCRIPTION:

This function opens a netCDF-formatted file and writes the array (ncvar) values for the specified variable to the respective (open) netCDF-formatted file.

Parameters:
ncfile: str

A Python string specifying the netCDF-formatted file to be written to.

ncvarname: str

A Python string specifying the netCDF variable to be written/updated.

ncvar: numpy.array

A Python array containing the values for the specified netCDF variable.

Keywords:
ncfrmt: str, optional

A Python string specifying the format of the netCDF-formatted file (to be created); available options are NETCDF4, NETCDF4_CLASSIC, NETCDF3_CLASSIC, NETCDF3_64BIT_OFFSET, or NETCDF3_64BIT_DATA; if not specified, NETCDF4_CLASSIC is assumed.

Return type:

None