Skip to content

heiplanet_data.inout module⚓︎

heiplanet_data.inout ⚓︎

Functions:

download_data ⚓︎

download_data(output_file, dataset, request)

Download data from Copernicus's CDS using the cdsapi.

Parameters:

  • output_file (Path) –

    The path to the output file where data will be saved.

  • dataset (str) –

    The name of the dataset to download.

  • request (Dict[str, Any]) –

    A dictionary containing the request parameters.

download_total_precipitation_from_hourly_era5_land ⚓︎

download_total_precipitation_from_hourly_era5_land(start_date, end_date, area=None, out_dir=Path('.'), base_name='era5_data', data_format='netcdf', ds_name='reanalysis-era5-land', coord_name='valid_time', var_name='total_precipitation', clean_tmp_files=False)

Download total precipitation data from hourly ERA5-Land dataset. Due to the nature of this dataset, value at 00:00 is total precipitation of the previous day. Therefore, to get total precipitation for the given range, We need to download data for the given range shifted by 1 day forward, then shift the time value back by 1 day after downloading.

Parameters:

  • start_date (str) –

    Start date in "YYYY-MM-DD" format.

  • end_date (str) –

    End date in "YYYY-MM-DD" format.

  • area (List[float] | None, default: None ) –

    Geographical area [North, West, South, East]. Default is None (global).

  • out_dir (Path, default: Path('.') ) –

    Output directory to save the downloaded file. Default is current directory.

  • base_name (str, default: 'era5_data' ) –

    Base name for the file. Default is "era5_data".

  • data_format (str, default: 'netcdf' ) –

    Data format (e.g., "netcdf", "grib"). Default is "netcdf".

  • ds_name (str, default: 'reanalysis-era5-land' ) –

    Dataset name. Default is "reanalysis-era5-land". Only modify this if CDS changes the name of the dataset.

  • coord_name (str, default: 'valid_time' ) –

    Name of the time coordinate in the dataset. Default is "valid_time". Only modify this if CDS changes the name of the coordinate.

  • var_name (str, default: 'total_precipitation' ) –

    Name of the data variable. Default is "total_precipitation". Only modify this if CDS changes the name of the variable.

  • clean_tmp_files (bool, default: False ) –

    Flag to indicate if temporary files should be deleted after processing. Default is False.

Returns:

  • str ( str ) –

    The path to the downloaded file.

get_filename ⚓︎

get_filename(ds_name, data_format, years, months, days=None, times=None, has_area=False, base_name='era5_data', variables=['2m_temperature'])

Get file name based on dataset name, base name, years, months and area.

Parameters:

  • ds_name (str) –

    Dataset name.

  • data_format (str) –

    Data format (e.g., "netcdf", "grib").

  • years (List[str] | None) –

    List of years.

  • months (List[str] | None) –

    List of months.

  • days (List[str] | None, default: None ) –

    List of days.

  • times (List[str] | None, default: None ) –

    List of times.

  • has_area (bool, default: False ) –

    Flag indicating if area is included.

  • base_name (str, default: 'era5_data' ) –

    Base name for the file. Default is "era5_data".

  • variables (List[str], default: ['2m_temperature'] ) –

    List of variables. Default is ["2m_temperature"].

Returns:

  • str ( str ) –

    Generated file name.

save_to_netcdf ⚓︎

save_to_netcdf(data, filename, encoding=None)

Save data to a NetCDF file.

Parameters:

  • data (DataArray) –

    Data to be saved.

  • filename (str) –

    The name of the output NetCDF file.

  • encoding (Dict, default: None ) –

    Encoding options for the NetCDF file.