remove_empty_variables

Functions for removal of empty product-specific variables. As a variable cannot be removed from a netCDF file, a new file has to be created, with the option of removing the old one.

ncas_amof_netcdf_template.remove_empty_variables.get_json_from_github(url: str) dict[str, dict[str, dict[str, Union[str, float]]]][source]

Returns desired json file from https://github.com/ncasuk/AMF_CVs/tree/main/AMF_CVs URL should be in form https://raw.githubusercontent.com/ncasuk/AMF_CVs/main/AMF_CVs/___.json, otherwise a JSONDecodeError will be returned by the r.json() call

Parameters:

url (str) – URL of json file

Returns:

JSON data from URL

Return type:

dict

ncas_amof_netcdf_template.remove_empty_variables.get_product_variables_metadata(product: str, skip_check: bool = False, tag: str = 'latest') tuple[list[str], dict[str, dict[str, Union[str, float]]]][source]

Get variables and their metadata associated with a product. product should be in https://github.com/ncasuk/AMF_CVs/blob/main/AMF_CVs/AMF_product.json

Parameters:
  • product (str) – Product describing the data from the instrument for the netCDF file.

  • skip_check (bool) – Skips checking if product in the product json file. Default False.

  • tag (str) – Tagged release version of AMF_CVs to check

Returns:

All product-specific variables. dict: Dictionary of variables and their attributes.

Return type:

list

ncas_amof_netcdf_template.remove_empty_variables.main(infile: str, outfile: Optional[str] = None, overwrite: bool = True, verbose: int = 0, tag: str = 'latest', skip_check: bool = False) None[source]

If a product-specific variable is empty, we want to remove it. However, removing a variable from a netcdf file is not possible, so we have to create a new one, and just not copy over the empty variable.

Parameters:
  • infile (str) – File path and name of current netCDF file.

  • outfile (str) – Name of temporary netCDF file to create (or not so temporary, see overwrite). If None, then an file with tmp appended to start of infile filename will be created. Default None.

  • overwrite (any) – Optional. If truthy, outfile overwrites infile. If falsy, both outfile and infile remain. Default True.

  • verbose (any) – Optional. If truthy, prints variables that are being removed from infile. Default 0.

  • tag (str) – Optional. Tag release version of AMF_CVs being used. Passed to get_product_variables_metadata function. Default “latest”.

  • skip_check (bool) – Optional. Skip checking for product in AMF_CVs product json file. Passed to get_product_variables_metadata function. Default False.