monkey_wrench.input_output.seviri package
The package providing utilities for resampling SEVIRI native files, as well as filename conversions.
- class monkey_wrench.input_output.seviri.ChimpFilesPrefix(*values)[source]
Bases:
EnumAn enum including all the allowed CHIMP-compliant file prefixes.
Examples of such prefixes are
"seviri"and"chimp", where the former marks the input files for CHIMP (e.g."seviri_20220112_22_12.nc") and the latter corresponds to CHIMP output files (e.g."chimp_20220112_22_12.nc").- chimp = 'chimp'
- seviri = 'seviri'
- class monkey_wrench.input_output.seviri.RemoteSeviriFile(*, fsspec_cache: Literal['filecache', 'blockcache'] | None = None)[source]
Bases:
FsSpecCache
- class monkey_wrench.input_output.seviri.Resampler(*, fsspec_cache: ~typing.Literal['filecache', 'blockcache'] | None = None, parent_output_directory_path: ~typing.Annotated[~pathlib.Path, ~pydantic.types.PathType(path_type=dir), ~pydantic.functional_validators.AfterValidator(func=~monkey_wrench.input_output._types.<lambda>)], datetime_format_string: str = '%Y/%m/%d', reset_child_datetime_directory: bool = False, dataset_save_options: dict[str, bool | str | int] = {'include_lonlats': False, 'writer': 'cf'}, area: ~typing.Annotated[~pathlib.Path, ~pydantic.types.PathType(path_type=file), ~pydantic.functional_validators.AfterValidator(func=~monkey_wrench.input_output._types.<lambda>)] | dict[str, ~typing.Any] | ~pyresample.geometry.AreaDefinition, output_filename_generator: ~typing.Annotated[~typing.Callable[[...], ~pathlib.Path], ~pydantic.functional_validators.BeforeValidator(func=~monkey_wrench.generic.models._function.validate_function_path, json_schema_input_type=PydanticUndefined)] | ~typing.Callable[[str], ~pathlib.Path] = <function input_filename_from_product_id>, channel_names: list[str] = ['VIS006', 'VIS008', 'IR_016', 'IR_039', 'WV_062', 'WV_073', 'IR_087', 'IR_097', 'IR_108', 'IR_120', 'IR_134', 'HRV'], radius_of_influence: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)] = 20000, remove_file_if_exists: bool = True)[source]
Bases:
Area,DatasetSaveOptions,DateTimeDirectory,RemoteSeviriFile- resample(product_id: str) None[source]
Resample the given SEVIRI native file (opened with
fsspec) using the resampler attributes.- Parameters:
product_id – The product ID to open.
- output_filename_generator: Annotated[Callable[[...], Path], BeforeValidator(func=validate_function_path, json_schema_input_type=PydanticUndefined)] | Callable[[str], Path]
The function using which an output filename will be generated from the given input filename (SEVIRI native file).
The generated filename is used to store the resampled file. The generated output filename will be prepended with
output_pathto compose a complete filepath for the output file.
- channel_names: list[str]
The list of channels to load from the file. Defaults to
satpy.readers.seviri_base.CHANNEL_NAMES.values().
- radius_of_influence: Annotated[int, Ge(ge=0)]
An integer which marks the search radius (in meters) for neighbouring data points. Defaults to
20_000.
- remove_file_if_exists: bool
A boolean to determine whether to removes the output file first if it already exists.
This might save us from some issues regrading files being overwritten and corrupted.
- monkey_wrench.input_output.seviri.datetime_to_filename(prefix: ChimpFilesPrefix, datetime_object: datetime, extension: str = '.nc') Path[source]
Generate a CHIMP-compliant filename based on the datetime object and the given prefix.
- Parameters:
prefix – A string with which the filename will start.
datetime_object – The datetime object to retrieve the timestamp string from.
extension – The file extension, Defaults to
".nc".
- Returns:
A filename with the following format
"<prefix>_<year><month><day>_<hour>_<minute><extension>".
- monkey_wrench.input_output.seviri.input_filename_from_datetime(datetime_objects: datetime | list[datetime] | set[datetime] | tuple[datetime, ...], extension: str = '.nc') Path | list[Path] | set[Path] | tuple[Path, ...][source]
Generate (a) CHIMP-compliant input filename(s) based on (a) datetime object(s).
- Parameters:
datetime_objects – Either a single datetime object, or a list/set/tuple of datetime objects.
extension – The file extension, Defaults to
".nc".
- Returns:
Depending on the input, either a single filename, or a list/set/tuple of filenames. The type of the output matches the type of the input in case of a list/set.tuple, e.g. a tuple of strings as input will result in a tuple of paths.
Example
>>> input_filename_from_datetime(datetime(2020, 1, 1, 0, 12)) PosixPath('seviri_20200101_00_12.nc')
>>> input_filename_from_datetime( ... [datetime(2020, 1, 1, 0, 12), datetime(2020, 3, 4, 2, 42)] ... ) [PosixPath('seviri_20200101_00_12.nc'), PosixPath('seviri_20200304_02_42.nc')]
- monkey_wrench.input_output.seviri.input_filename_from_product_id(product_ids: str | list[str] | set[str] | tuple[str, ...], extension: str = '.nc') Path | list[Path] | set[Path] | tuple[Path, ...][source]
Generate (a) CHIMP-compliant input filename(s) based on (a) SEVIRI product ID(s).
- Parameters:
product_ids – Either a single SEVIRI product ID, or a list/set/tuple of SEVIRI product IDs.
extension – The file extension, Defaults to
".nc".
- Returns:
Depending on the input, either a single filename, or a list/set/tuple of filenames. The type of the output matches the type of the input in case of a list/set.tuple, e.g. a tuple of strings as input will result in a tuple of paths.
Example
>>> input_filename_from_product_id( ... "MSG3-SEVI-MSG15-0100-NA-20150731221240.036000000Z-NA" ... ) PosixPath('seviri_20150731_22_12.nc')
>>> input_filename_from_product_id(( ... "MSG3-SEVI-MSG15-0100-NA-20150731221240.036000000Z-NA", ... "MSG3-SEVI-MSG15-0100-NA-20231231171242.800000000Z-NA" ... )) (PosixPath('seviri_20150731_22_12.nc'), PosixPath('seviri_20231231_17_12.nc'))
- monkey_wrench.input_output.seviri.output_filename_from_datetime(datetime_objects: datetime | list[datetime] | set[datetime] | tuple[datetime, ...], extension: str = '.nc') Path | list[Path] | set[Path] | tuple[Path, ...][source]
Generate (a) CHIMP-compliant output filename(s) based on (a) datetime object(s).
- Parameters:
datetime_objects – Either a single datetime object , or a list/set/tuple of datetime objects.
extension – The file extension, Defaults to
".nc".
- Returns:
Depending on the input, either a single filename, or a list/set/tuple of filenames. The type of the output matches the type of the input in case of a list/set.tuple, e.g. a tuple of strings as input will result in a tuple of paths.
Example
>>> output_filename_from_datetime(datetime(2020, 1, 1, 0, 12)) PosixPath('chimp_20200101_00_12.nc')
>>> output_filename_from_datetime( ... [datetime(2020, 1, 1, 0, 12), datetime(2020, 3, 4, 2, 42)] ... ) [PosixPath('chimp_20200101_00_12.nc'), PosixPath('chimp_20200304_02_42.nc')]
- monkey_wrench.input_output.seviri.output_filename_from_product_id(product_ids: str | list[str] | set[str] | tuple[str, ...], extension: str = '.nc') Path | list[Path][source]
Generate (a) CHIMP-compliant output filename(s) based on (a) SEVIRI product ID(s).
- Parameters:
product_ids – Either a single SEVIRI product ID , or a list/set/tuple of SEVIRI product IDs.
extension – The file extension, Defaults to
".nc".
- Returns:
Depending on the input, either a single filename, or a list/set/tuple of filenames. The type of the output matches the type of the input in case of a list/set.tuple, e.g. a tuple of strings as input will result in a tuple of paths.
Example
>>> output_filename_from_product_id( ... "MSG3-SEVI-MSG15-0100-NA-20150731221240.036000000Z-NA" ... ) PosixPath('chimp_20150731_22_12.nc')
>>> output_filename_from_product_id([ ... "MSG3-SEVI-MSG15-0100-NA-20150731221240.036000000Z-NA", ... "MSG3-SEVI-MSG15-0100-NA-20231231171242.800000000Z-NA" ... ]) [PosixPath('chimp_20150731_22_12.nc'), PosixPath('chimp_20231231_17_12.nc')]
- monkey_wrench.input_output.seviri.seviri_extension_context() Generator[Callable, None, None][source]
A context manager to load the SEVIRI extension.
- Yields:
A SEVIRI-aware CHIMP CLI function which can perform a retrieval.
Submodules
- monkey_wrench.input_output.seviri._common module
- monkey_wrench.input_output.seviri._extension module
- monkey_wrench.input_output.seviri._models module
DEFAULT_CHANNEL_NAMEScatch_warnings()RemoteSeviriFileResamplerResampler.output_filename_generatorResampler.channel_namesResampler.areaResampler.dataset_save_optionsResampler.datetime_format_stringResampler.reset_child_datetime_directoryResampler.parent_output_directory_pathResampler.fsspec_cacheResampler.radius_of_influenceResampler.remove_file_if_existsResampler.resample()
- monkey_wrench.input_output.seviri._types module