Wranglers API

Functions used to ‘wrangle’ netCDF-SCM netCDF files into other formats

netcdf_scm.wranglers.convert_scmdf_to_tuningstruc(scmdf, outdir, prefix=None, force=False)[source]

Convert an scmdata.ScmRun to a matlab tuningstruc

One tuningstruc file will be created for each unique [“model”, “scenario”, “variable”, “region”, “unit”] combination in the input scmdata.ScmRun.

Parameters
  • scmdf (scmdata.ScmRun) – scmdata.ScmRun to convert to a tuningstruc

  • outdir (str) – Directory in which to save the tuningstruc

  • prefix (str) – Prefix for the filename. The rest of the filename is generated from the metadata. .mat is also appended automatically. If None, no prefix is used.

  • force (bool) – If True, overwrite any existing files

Returns

List of files which were not re-written as they already exist

Return type

list

Raises

AssertionError – If timeseries are not unique for a given [“climate_model”, “model”, “scenario”, “variable”, “region”, “unit”] combination.

netcdf_scm.wranglers.convert_tuningstruc_to_scmdf(filepath, variable=None, region=None, unit=None, scenario=None, model=None)[source]

Convert a matlab tuningstruc to an scmdata.ScmRun

Parameters
  • filepath (str) – Filepath from which to load the data

  • variable (str) – Name of the variable contained in the tuningstruc. If None, convert_tuningstruc_to_scmdf will attempt to determine it from the input file.

  • region (str) – Region to which the data in the tuningstruc applies. If None, convert_tuningstruc_to_scmdf will attempt to determine it from the input file.

  • unit (str) – Units of the data in the tuningstruc. If None, convert_tuningstruc_to_scmdf will attempt to determine it from the input file.

  • scenario (str) – Scenario to which the data in the tuningstruc applies. If None, convert_tuningstruc_to_scmdf will attempt to determine it from the input file.

  • model (str) – The (integrated assessment) model which generated the emissions scenario associated with the data in the tuningstruc. If None, convert_tuningstruc_to_scmdf will attempt to determine it from the input file and if it cannot, it will be set to “unspecified”.

Raises

KeyError – If a metadata variable is not supplied and it cannot be determined from the tuningstruc.

Returns

scmdata.ScmRun with the tuningstruc data

Return type

scmdata.ScmRun

netcdf_scm.wranglers.get_tuningstruc_name_from_df(df, outdir, prefix)[source]

Get the name of a tuningstruc from a pd.DataFrame

Parameters
  • df (pd.DataFrame) – pandas DataFrame to convert to a tuningstruc

  • outdir (str) – Base path on which to append the metadata and .mat.

  • prefix (str) – Prefix to prepend to the name. If None, no prefix is prepended.

Returns

tuningstruc name

Return type

str

Raises

ValueError – A name cannot be determined because e.g. more than one scenario is contained in the dataframe