Write NetCDF
- class mwr_raw2l1.write_netcdf.Writer(data_in, filename, conf_nc, conf_inst, nc_format='NETCDF4', copy_data=False)[source]
Bases:
objectClass for writing data (Dataset) to NetCDF according to the format definition in conf_file
- Parameters:
data_in –
xarray.DatasetorDataArraycontaining data to write to file. Some support is also provided if data_in is a dictionary, but this option is deprecated.filename – name and path of output NetCDF file
conf_nc – configuration dict of yaml file defining the format and contents of the output NetCDF file
conf_inst – configuration dict of yaml file with instrument specifications (contains global attrs for NetCDF)
nc_format – NetCDF format type of the output file. Default is NETCDF4
copy_data (bool) – In case of False, the dataset might experience in-place modifications which is suitable when the dataset is not used in its original form after calling the write function, for True a copy is modified. Defaults to False.
- add_history_attr()[source]
add global attribute ‘history’ with date and version of mwr_raw2l1 code run
- add_title_attr()[source]
add global attribute ‘title’ recombining info from other previously set global attributes
- append_qc_thresholds()[source]
append quality control thresholds to comment attribute of quality_flag if not refused by ‘conf_nc’
- check_dims(var, specs)[source]
check dims of var (retain order of config specs, but order of dims returned by xarray Dataset is arbitrary)
- Parameters:
var (str) – the name of the variable of whom the dimension shall be checked
specs – specifications for this variable from config. Must contain the key ‘dim’ with a list of dimensions.
- global_attrs_from_conf(conf, attr_key)[source]
add global attributes from configuration dictionary
- Parameters:
conf – configuration dictionary with global attributes under the key given by attr_key
attr_key – string specifying the key under which attributes are stored in conf dict. Usually ‘attributes’ or ‘nc_attributes’
- prepare_datavars()[source]
prepare data variables
xarray.Datasetfor writing to file standard specified in ‘conf_nc’
- prepare_time()[source]
workaround for correctly setting units and calendar of time variable (use encoding instead of attrs)
- remove_vars()[source]
remove undesired variables and dimensions from data (all that are not in the conf_nc)
- rename_vars()[source]
set variable and dimension names to the ones set in conf_nc (CARE: must be last operation before save!)
- run()[source]
write Dataset to NetCDF according to the format definition in conf_file by using the
xarraymodule
- set_fillvalue(var, specs)[source]
set the fill value of var by taking care not to remove any fill value for dimensions for CF compliance
- Parameters:
var (str) – the name of the variable of whom the dimension shall be checked
specs – specifications for this variable from config. Must contain the key ‘dim’ with a list of dimensions.