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 = 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 = 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 = 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 = 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. This function works even if the path doesn’t point to anything.
No normalization is done, i.e. all ‘.’ and ‘..’ will be kept along. Use resolve() to get the canonical path to a file.
- classmethod cwd()[source]#
Return a new path pointing to the current working directory (as returned by os.getcwd()).
- 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.
- hardlink_to(target)[source]#
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_file()[source]#
Whether this path is a regular file (also True for symlinks pointing to regular files).
- 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.
- link_to(target)[source]#
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.
- 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.
- read_text(encoding=None, errors=None)[source]#
Open the file in text mode, read it, and close the file.
- 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 (for example turning slashes into backslashes under Windows).
- rglob(pattern)[source]#
Recursively yield all existing files (of any kind, including directories) matching the given relative pattern, anywhere in this subtree.
- 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.
- symlink_to(target, target_is_directory=False)[source]#
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.
- 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