miranda.eccc package#

Environment and Climate Change Canada specialized conversion module.

miranda.eccc.aggregate_stations(source_files: str | PathLike | None = None, output_folder: str | PathLike | None = None, time_step: str = None, variables: str | int | list[str | int] | None = None, include_flags: bool = True, groupings: int | None = None, mf_dataset_freq: str | None = None, temp_directory: str | PathLike | None = None, n_workers: int = 1) None[source]#
Parameters:
  • source_files (str or Path)

  • output_folder (str or Path)

  • variables (str or int or list of str or int, optional)

  • time_step ({“hourly”, “daily”})

  • include_flags (bool)

  • groupings (int) – The number of files in each group used for converting to multi-file Datasets.

  • mf_dataset_freq (str, optional) – Resampling frequency for creating output multi-file Datasets. E.g. ‘YS’: 1 year per file, ‘5YS’: 5 years per file.

  • temp_directory (str or Path, optional) – Use another temporary directory location in case default location is not spacious enough.

  • n_workers (int)

Returns:

None

miranda.eccc.convert_ahccd(data_source: str | Path, output_dir: str | Path, variable: str, generation: int | None = None) None[source]#

Convert Adjusted and Homogenized Canadian Climate Dataset files.

Parameters:
  • data_source (str or Path)

  • output_dir (str or Path)

  • variable (str)

  • generation (int, optional)

Returns:

None

miranda.eccc.convert_ahccd_fwf_files(ff: Path | str, metadata: DataFrame, variable: str, generation: int = None, cols_specs: list[tuple[int, int]] | None = None, attrs: dict | None = None) Dataset[source]#

Convert AHCCD fixed-width files.

Parameters:
  • ff (str or Path)

  • metadata (pandas.DataFrame)

  • variable (str)

  • generation

  • cols_specs

  • attrs

Returns:

xarray.Dataset

miranda.eccc.convert_flat_files(source_files: str | PathLike, output_folder: str | PathLike | list[str | int], variables: str | int | list[str | int], mode: str = 'hourly', n_workers: int = 4) None[source]#
Parameters:
  • source_files (str or Path)

  • output_folder (str or Path)

  • variables (str or List[str])

  • mode ({“hourly”, “daily”})

  • n_workers (int)

Returns:

None

miranda.eccc.daily_summaries_to_netcdf(station: dict, path_output: Path | str) None[source]#

Convert daily climate summaries to NetCDF files.

Uses xarray to transform the ‘station’ from find_and_extract_dly into a CF-Convention netCDF file

Parameters:
  • station (dict) – dict created by using find_and_extract_dly

  • path_output (str or Path) – Output path.

Returns:

None

miranda.eccc.extract_daily_summaries(path_station: Path | str, rm_flags: bool = False, file_suffix: str = '.csv') dict[source]#

Extract daily climate summaries from ECCC CSV files.

Parameters:
  • path_station (str or Path) – PathLike or str to the station’s folder containing the csv files.

  • rm_flags (bool) – Removes the ‘Flag’ and ‘Quality’ columns of the ECCC files.

  • file_suffix (str) – File suffixes used by the tabular data. Default: “.csv”.

Returns:

dict – dict containing the station metadata, as well as the data stored within a pandas Dataframe.

miranda.eccc.merge_converted_variables(source_files: str | PathLike, output_folder: str | PathLike, variables: str | int | list[str | int] | None = None, station_metadata: str | PathLike | None = None, overwrite: bool = False, n_workers: int = 1) None[source]#
Parameters:
  • source_files (str, Path)

  • output_folder (str, Path)

  • variables (str or int or list of str or int, optional)

  • station_metadata (str or Path, optional)

  • overwrite (bool)

  • n_workers (int)

Returns:

None

Submodules#

miranda.eccc._homogenized module#

Adjusted and Homogenized Canadian Clime Data module.

miranda.eccc._homogenized.convert_ahccd(data_source: str | Path, output_dir: str | Path, variable: str, generation: int | None = None) None[source]#

Convert Adjusted and Homogenized Canadian Climate Dataset files.

Parameters:
  • data_source (str or Path)

  • output_dir (str or Path)

  • variable (str)

  • generation (int, optional)

Returns:

None

miranda.eccc._homogenized.convert_ahccd_fwf_files(ff: Path | str, metadata: DataFrame, variable: str, generation: int = None, cols_specs: list[tuple[int, int]] | None = None, attrs: dict | None = None) Dataset[source]#

Convert AHCCD fixed-width files.

Parameters:
  • ff (str or Path)

  • metadata (pandas.DataFrame)

  • variable (str)

  • generation

  • cols_specs

  • attrs

Returns:

xarray.Dataset

miranda.eccc._raw module#

miranda.eccc._raw.aggregate_stations(source_files: str | PathLike | None = None, output_folder: str | PathLike | None = None, time_step: str = None, variables: str | int | list[str | int] | None = None, include_flags: bool = True, groupings: int | None = None, mf_dataset_freq: str | None = None, temp_directory: str | PathLike | None = None, n_workers: int = 1) None[source]#
Parameters:
  • source_files (str or Path)

  • output_folder (str or Path)

  • variables (str or int or list of str or int, optional)

  • time_step ({“hourly”, “daily”})

  • include_flags (bool)

  • groupings (int) – The number of files in each group used for converting to multi-file Datasets.

  • mf_dataset_freq (str, optional) – Resampling frequency for creating output multi-file Datasets. E.g. ‘YS’: 1 year per file, ‘5YS’: 5 years per file.

  • temp_directory (str or Path, optional) – Use another temporary directory location in case default location is not spacious enough.

  • n_workers (int)

Returns:

None

miranda.eccc._raw.convert_flat_files(source_files: str | PathLike, output_folder: str | PathLike | list[str | int], variables: str | int | list[str | int], mode: str = 'hourly', n_workers: int = 4) None[source]#
Parameters:
  • source_files (str or Path)

  • output_folder (str or Path)

  • variables (str or List[str])

  • mode ({“hourly”, “daily”})

  • n_workers (int)

Returns:

None

miranda.eccc._raw.merge_converted_variables(source_files: str | PathLike, output_folder: str | PathLike, variables: str | int | list[str | int] | None = None, station_metadata: str | PathLike | None = None, overwrite: bool = False, n_workers: int = 1) None[source]#
Parameters:
  • source_files (str, Path)

  • output_folder (str, Path)

  • variables (str or int or list of str or int, optional)

  • station_metadata (str or Path, optional)

  • overwrite (bool)

  • n_workers (int)

Returns:

None

miranda.eccc._summaries module#

miranda.eccc._summaries.daily_summaries_to_netcdf(station: dict, path_output: Path | str) None[source]#

Convert daily climate summaries to NetCDF files.

Uses xarray to transform the ‘station’ from find_and_extract_dly into a CF-Convention netCDF file

Parameters:
  • station (dict) – dict created by using find_and_extract_dly

  • path_output (str or Path) – Output path.

Returns:

None

miranda.eccc._summaries.extract_daily_summaries(path_station: Path | str, rm_flags: bool = False, file_suffix: str = '.csv') dict[source]#

Extract daily climate summaries from ECCC CSV files.

Parameters:
  • path_station (str or Path) – PathLike or str to the station’s folder containing the csv files.

  • rm_flags (bool) – Removes the ‘Flag’ and ‘Quality’ columns of the ECCC files.

  • file_suffix (str) – File suffixes used by the tabular data. Default: “.csv”.

Returns:

dict – dict containing the station metadata, as well as the data stored within a pandas Dataframe.

miranda.eccc._support_rvt module#

class miranda.eccc._support_rvt.Path(*args, **kwargs)[source]#

Bases: PurePath

PurePath subclass that can make system calls.

Path represents a filesystem path but unlike PurePath, also offers methods to do system calls on path objects. Depending on your system, instantiating a Path will return either a PosixPath or a WindowsPath object. You can also instantiate a PosixPath or WindowsPath directly, but cannot instantiate a WindowsPath on a POSIX system or vice versa.

absolute()[source]#

Return an absolute version of this path by prepending the current working directory. No normalization or symlink resolution is performed.

Use resolve() to get the canonical path to a file.

chmod(mode, *, follow_symlinks=True)[source]#

Change the permissions of the path, like os.chmod().

classmethod cwd()[source]#

Return a new path pointing to the current working directory (as returned by os.getcwd()).

exists()[source]#

Whether this path exists.

expanduser()[source]#

Return a new path with expanded ~ and ~user constructs (as returned by os.path.expanduser)

glob(pattern)[source]#

Iterate over this subtree and yield all existing files (of any kind, including directories) matching the given relative pattern.

group()[source]#

Return the group name of the file gid.

Make this path a hard link pointing to the same file as target.

Note the order of arguments (self, target) is the reverse of os.link’s.

classmethod home()[source]#

Return a new path pointing to the user’s home directory (as returned by os.path.expanduser(‘~’)).

is_block_device()[source]#

Whether this path is a block device.

is_char_device()[source]#

Whether this path is a character device.

is_dir()[source]#

Whether this path is a directory.

is_fifo()[source]#

Whether this path is a FIFO.

is_file()[source]#

Whether this path is a regular file (also True for symlinks pointing to regular files).

is_mount()[source]#

Check if this path is a POSIX mount point

is_socket()[source]#

Whether this path is a socket.

Whether this path is a symbolic link.

iterdir()[source]#

Iterate over the files in this directory. Does not yield any result for the special paths ‘.’ and ‘..’.

lchmod(mode)[source]#

Like chmod(), except if the path points to a symlink, the symlink’s permissions are changed, rather than its target’s.

Make the target path a hard link pointing to this path.

Note this function does not make this path a hard link to target, despite the implication of the function and argument names. The order of arguments (target, link) is the reverse of Path.symlink_to, but matches that of os.link.

Deprecated since Python 3.10 and scheduled for removal in Python 3.12. Use hardlink_to() instead.

lstat()[source]#

Like stat(), except if the path points to a symlink, the symlink’s status information is returned, rather than its target’s.

mkdir(mode=511, parents=False, exist_ok=False)[source]#

Create a new directory at this given path.

open(mode='r', buffering=-1, encoding=None, errors=None, newline=None)[source]#

Open the file pointed by this path and return a file object, as the built-in open() function does.

owner()[source]#

Return the login name of the file owner.

read_bytes()[source]#

Open the file in bytes mode, read it, and close the file.

read_text(encoding=None, errors=None)[source]#

Open the file in text mode, read it, and close the file.

Return the path to which the symbolic link points.

rename(target)[source]#

Rename this path to the target path.

The target path may be absolute or relative. Relative paths are interpreted relative to the current working directory, not the directory of the Path object.

Returns the new Path instance pointing to the target path.

replace(target)[source]#

Rename this path to the target path, overwriting if that path exists.

The target path may be absolute or relative. Relative paths are interpreted relative to the current working directory, not the directory of the Path object.

Returns the new Path instance pointing to the target path.

resolve(strict=False)[source]#

Make the path absolute, resolving all symlinks on the way and also normalizing it.

rglob(pattern)[source]#

Recursively yield all existing files (of any kind, including directories) matching the given relative pattern, anywhere in this subtree.

rmdir()[source]#

Remove this directory. The directory must be empty.

samefile(other_path)[source]#

Return whether other_path is the same or not as this file (as returned by os.path.samefile()).

stat(*, follow_symlinks=True)[source]#

Return the result of the stat() system call on this path, like os.stat() does.

Make this path a symlink pointing to the target path. Note the order of arguments (link, target) is the reverse of os.symlink.

touch(mode=438, exist_ok=True)[source]#

Create this file with the given access mode, if it doesn’t exist.

Remove this file or link. If the path is a directory, use rmdir() instead.

write_bytes(data)[source]#

Open the file in bytes mode, write to it, and close the file.

write_text(data, encoding=None, errors=None, newline=None)[source]#

Open the file in text mode, write to it, and close the file.

miranda.eccc._support_rvt.gather_eccc_stations(timestep: str, start_date: datetime | str | None = None, end_date: datetime | str | None = None, climate_id: str | None = None) DataFrame[source]#

Collect ECCC station data from the Environment and Climate Change Canada API.

Parameters:
  • timestep (str)

  • start_date (datetime.datetime or str, optional)

  • end_date (datetime.datetime or str, optional)

  • climate_id (str, optional)

Returns:

pandas.DataFrame

miranda.eccc._utils module#

miranda.eccc._utils.cf_ahccd_metadata(code: str, gen: int)[source]#
Parameters:
  • code ({“dx”, “dn”, “dm”, “dt”, “ds”, “dr”})

  • gen ({1, 2, 3})

Returns:

dict[str, int or str or float], dict, list[tuple[int, int]], int

miranda.eccc._utils.cf_station_metadata(variable_code: int | str) Mapping[str, int | float | str][source]#
Parameters:

variable_code (int or str)

Returns:

dict