cal_nc package¶
Submodules¶
cal_nc.nc_conf module¶
Functions for parsing of configuration files.
-
cal_nc.nc_conf.read_config(cfg_file, de_str=True)[source]¶ Read in configuration file and return entries in dictionary.
ConfigParser options used are;
allow_no_value=True
- Parameters
cfg_file (
strorpathlib) – Configuration path/filename with the required format.de_str (
bool) – If True [default] then attempt to de-string string entries.
- Returns
- Dictionary with sub-dictionaries for each section or None if
cfg_filecannot be found.
-
cal_nc.nc_conf.extract_specials(cfg_dict, specials=[], overwrite=False)[source]¶ Extracts special configuration keys from dictionary and returns them.
- Parameters
cfg_dict (
dict) – Configuration dictionaryspecials (
list) – list of special strings to extract if they are present incfg_dict. Default isdefault_special_str. Any special strings given are appended todefault_special_strrather than replacing it as long asoverwriteis False.overwrite (
bool) – If False [default] then any strings given inspecialsare appended todefault_special_str. If True then only those strings included inspecialsare searched for.
- Returns
- Tuple of two dictionaries. Dictionary of specials found in
cfg_dict with keys of the special strings. Dictionary of
cfg_dictwith special items removed. If no specials found thenspecials_dictwill be {}.
- Tuple of two dictionaries. Dictionary of specials found in
cal_nc.nc_func module¶
Functions for reading, writing, and manipulating netCDF files.
-
cal_nc.nc_func.read_nc(master, aux=[])[source]¶ Function for reading netCDF calibration files into DataSets.
Note
All nc files are left open so that the Datasets associated with each file can be operated on/with in the rest of the program. This is required whether or not the file was opened as read-only. Thus all Datasets should be explicitly closed when they are finished with.
- Parameters
master (
strorpathlib) – ‘master’ netCDF filename that is opened for read/write.aux (
list) – List of any additional netCDF filenames that are to be added/concatenated with master nc file. Auxillary nc files are opened as read only. Default is [], ie no auxillary files.
- Returns
Tuple of dataset from master netCDF and list of any auxillary Datasets.
-
cal_nc.nc_func.process_nc(master_nc, aux_nc=[], anc_files=[], out_nc=None, instr=None, updates={})[source]¶ Processes all netCDF and auxillary files.
The master netCDF is copied to a temporary file which is opened for read/ write while any auxilary files are opened as read-only datasets. Modifications, concatenations, etc are done on the temporary dataset and once complete it is closed and moved to the output file which may be either the master file or out_nc.
Updates are applied to the master dataset after any concatenation etc.
- Parameters
master_nc (
str) – Filename string of ‘master’ netCDF file.aux_nc (
list, optional) – List of any additional filename/s of netCDF files that are to be added/concatenated with master nc file. Default is [], ie no auxillary files.anc_files (
list, optional) – List of any ancillary files that are not netCDF and so need to be parsed before being injested into the dataset. Default is [], ie no ancillary files.out_nc (
str, optional) – Filename string of netCDF to be written. If None (default) or the same as master_nc, master_nc is overwritten.instr (
str, optional) – Identifying string of instrument which determines processor class. If None (default) then instrument is identified from master_nc.updates (
dict, optional) – All other updates to be applied to the final dataset. Default is {}.
-
cal_nc.nc_func.run_ncgen(fin, fout, nc_fmt=3)[source]¶ Create netCDF file from input cdl by calling external program, ncgen.
- Parameters
fin (
strorpathlib) – Filename of cdl file.fout (
str) – Filename of output netCDF file.nc_fmt (
int) –Integer specifying the format of the netCDF created, default is 3 for netCDF-4. Options are;
netcdf classic file format, netcdf-3 type model
netcdf 64 bit classic file format, netcdf-3 type model
netcdf-4 file format, netcdf-4 type model
netcdf-4 file format, netcdf-3 type model
Note that using a netcdf-3 format will break group features and thus the entire cal-nc structure.
cal_nc.utils module¶
General utility functions. Primarily for file manipulation etc
-
cal_nc.utils.filepath(f, paths=['.'])[source]¶ Finds path where file, f, exists from selection of paths.
Single filename is given and the complete path for this file is found from a list of possible locations. If does not exist then return f. Note that if the file exists in two locations then the paths list carries with it the order of priority, only a single file is returned.
- Parameters
f (
strorpathlib) – Complete or part filename.paths (
list) – List of path strings to search. Default isdefault_file_dir. –
- Returns
If valid file is found the complete path/filename is returned. If no valid path is found then f is returned.
Module contents¶
Calibration netCDF general functions