acept.dwd_try_data_handling

Module for handling DWD TRY data.

Use this module to:
  • read DWD TRY data as a Xarray Dataset

  • preprocess DWD TRY data

  • combine multiple DWD TRY datasets (temperature, direct radiation, and global radiation) into a single Xarray Dataset for use in acept

  • uncompress DWD TRY data to make file reading faster

  • check if DWD TRY data is available in the correct subdirectory of acept.acept_constants.DWD_TRY_PATH

raises ValueOutsideRangeError:

if years are outside the allowed range (see acept.dwd_try_data_handling.DWD_MAX_RANGE)

raises ValueError:

if an unknown DWD feature is requested

Note

To set up the DWD TRY data, use the module acept.dwd_try_data_setup

Module Contents

Functions

read_dwd_netcdf_file(→ xarray.Dataset)

Read a DWD netCDF file and return the data as a Xarray Dataset.

preprocess_dwd_try_dataset(→ xarray.Dataset)

Preprocess the DWD TRY dataset to make it ready for use.

preprocess_combined_dwd_try_dataset(→ xarray.Dataset)

Preprocess the combined DWD TRY dataset to make it ready for use.

combine_dwd_try_data_and_save([year_start, year_end, ...])

Combine the DWD TRY data files (of 'temperature', 'rad_direct', 'rad_global') for Bavaria and save them as netCDF

combine_dwd_try_data_and_save_single_year(...[, ...])

Combine the DWD TRY data files (of 'temperature', 'rad_direct', 'rad_global') for Bavaria and save them as netCDF

check_for_un_compressed_dwd_try_data(→ bool)

Whether the combined DWD TRY data is downloaded in the correct directory for the given years. If not, return False.

check_for_dwd_try_data_year(→ bool)

Whether DWD TRY data was downloaded in the correct directory for the given year. If not, return False.

path_to_dwd_file(→ str)

Path to the DWD TRY data file for the given feature, year, and month.

Attributes

DWD_MIN_YEAR

Minimum year of DWD TRY data available to download.

DWD_MAX_YEAR

Maximum year of DWD TRY data.

DWD_MAX_RANGE

1995-2012.

acept.dwd_try_data_handling.DWD_MIN_YEAR = 1995[source]

Minimum year of DWD TRY data available to download.

acept.dwd_try_data_handling.DWD_MAX_YEAR = 2012[source]

Maximum year of DWD TRY data.

acept.dwd_try_data_handling.DWD_MAX_RANGE[source]

1995-2012.

Type:

Maximum range of years of DWD TRY data available to download as a python range object

acept.dwd_try_data_handling.read_dwd_netcdf_file(dwd_feature: str, year, month, debug: bool = True) xarray.Dataset[source]

Read a DWD netCDF file and return the data as a Xarray Dataset.

Parameters:
  • dwd_feature (str) – The DWD feature to read. Valid options are “temperature”, “rad_direct”, and “rad_global” or “combined_try” for all three features in the same file.

  • year – The year of the data.

  • month – The month of the data.

  • debug (bool) – (optional) Whether to print debug information. Defaults to True.

Returns:

The data read from the netCDF file.

Return type:

xarray.Dataset

acept.dwd_try_data_handling.preprocess_dwd_try_dataset(wd_data: xarray.Dataset, dwd_feature: str, debug: bool = True) xarray.Dataset[source]

Preprocess the DWD TRY dataset to make it ready for use.

Use this function to preprocess the DWD TRY dataset for use in ACEPT. This is the same as preprocess_combined_dwd_try_dataset but for the individual DWD TRY datasets. This step is necessary to use to read the individual DWD TRY datasets.

Parameters:
  • wd_data (xarray.Dataset) – The Xarray Dataset to preprocess.

  • dwd_feature (str) – The DWD feature to read. Valid options are “temperature”, “rad_direct”, and “rad_global” or “combined_try” for all three features in the same file.

  • debug (bool) – (optional) Whether to print debug information. Defaults to True.

Returns:

The preprocessed Xarray Dataset.

Return type:

xarray.Dataset

acept.dwd_try_data_handling.preprocess_combined_dwd_try_dataset(wd_data: xarray.Dataset, debug: bool = True) xarray.Dataset[source]

Preprocess the combined DWD TRY dataset to make it ready for use.

Use this function to preprocess the combined DWD TRY dataset for use in ACEPT. This is the same as preprocess_dwd_try_dataset but for the combined DWD TRY dataset. This step is necessary to use to read the combined DWD TRY dataset.

Parameters:
  • wd_data (xarray.Dataset) – The Xarray Dataset to preprocess.

  • debug (bool) – Whether to print debug information. Defaults to True.

Returns:

The preprocessed Xarray Dataset.

Return type:

xarray.Dataset

acept.dwd_try_data_handling.combine_dwd_try_data_and_save(year_start: int = DWD_MIN_YEAR, year_end: int = DWD_MAX_YEAR, debug: bool = True, uncompressed_years: None | list[int] = None)[source]

Combine the DWD TRY data files (of ‘temperature’, ‘rad_direct’, ‘rad_global’) for Bavaria and save them as netCDF files.

Included features: temperature, direct and global radiation. Combine the data for these features for Bavaria for the given years and the monthly files. This makes using the TRY data easier and more efficient. Store the data in uncompressed netCDF files to speed up reading the data.

Parameters:
  • year_start (int) – start year of the data set to be combined

  • year_end (int) – end year of the data set to be combined

  • debug (bool) – if True, print debug information

  • uncompressed_years (None | list[int]) – optional list of years to be combined and saved without compression

Raises:

ValueOutsideRangeError – if year_start or year_end is outside the allowed range (see acept.dwd_try_data_handling.DWD_MAX_RANGE)

acept.dwd_try_data_handling.combine_dwd_try_data_and_save_single_year(bavaria_shape: geopandas.GeoDataFrame, year_spec: int, debug: bool = True, uncompressed_years: None | list[int] = None)[source]

Combine the DWD TRY data files (of ‘temperature’, ‘rad_direct’, ‘rad_global’) for Bavaria and save them as netCDF files. Included features: temperature, direct and global radiation. Combine the data for these features for Bavaria for the given year and the monthly files.

Parameters:
  • bavaria_shape (geopandas.GeoDataFrame) – shape of Bavaria

  • year_spec (int) – year of the data set to be combined

  • debug (bool) – if True, print debug information

  • uncompressed_years (None | list[int]) – optional list of years to be combined and saved without compression. Defaults to None.

Raises:

ValueOutsideRangeError – if year_spec is outside the allowed range (see acept.dwd_try_data_handling.DWD_MAX_RANGE)

acept.dwd_try_data_handling.check_for_un_compressed_dwd_try_data(compressed=True, year_start: int = DWD_MIN_YEAR, year_end: int = DWD_MAX_YEAR) bool[source]

Whether the combined DWD TRY data is downloaded in the correct directory for the given years. If not, return False. If yes, return True.

Parameters:
  • compressed – whether the combined DWD TRY data is available in the correct directory

  • year_start (int) – start year of the data set to be checked

  • year_end (int) – end year of the data set to be checked

Raises:

ValueOutsideRangeError – if year_start or year_end is outside the allowed range (see acept.dwd_try_data_handling.DWD_MAX_RANGE)

Returns:

whether the combined DWD TRY data is there

Return type:

bool

acept.dwd_try_data_handling.check_for_dwd_try_data_year(year: int, types_to_check: list[str] = ['temperature', 'rad_direct', 'rad_global']) bool[source]

Whether DWD TRY data was downloaded in the correct directory for the given year. If not, return False. If yes, return True.

Parameters:
  • year (int) – year of the data set to be checked

  • types_to_check (list[str]) – list of types of data to be checked, allowed values are ‘temperature’, ‘rad_direct’, ‘rad_global’, ‘combined_try’, ‘combined_try_uncompressed’

Raises:

ValueOutsideRangeError – if year is outside the allowed range (see acept.dwd_try_data_handling.DWD_MAX_RANGE)

Returns:

whether the specified DWD TRY data is there

Return type:

bool

acept.dwd_try_data_handling.path_to_dwd_file(feature: str, year: int, month: int) str[source]

Path to the DWD TRY data file for the given feature, year, and month.

Parameters:
  • feature (str) – The DWD feature to read. Valid options are “temperature”, “rad_direct”, “rad_global”, “combined_try”, or “combined_try_uncompressed”.

  • year (int) – The year of the data.

  • month (int) – The month of the data.

Raises:

ValueError – If the feature is not valid.

Returns:

The path to the DWD file.

Return type:

str