radar_api package#
Subpackages#
Submodules#
radar_api.checks module#
This module provides functions to check RADAR-API arguments.
- radar_api.checks.check_date(date)[source][source]#
Ensure the returned object is a
datetime.dateobject.
- radar_api.checks.check_download_protocol(protocol)[source][source]#
Check protocol validity for download.
- radar_api.checks.check_start_end_time(start_time, end_time)[source][source]#
Check start_time and end_time validity.
- radar_api.checks.check_time(time)[source][source]#
Check time validity.
It returns a
datetime.datetimeobject to seconds precision.- Parameters:
time (datetime.datetime, datetime.date, numpy.datetime64 or str) – Time object. Accepted types:
datetime.datetime,datetime.date,numpy.datetime64orstr. If string type, it expects the isoformatYYYY-MM-DD hh:mm:ss.- Returns:
time
- Return type:
radar_api.configs module#
RADAR-API configurations settings.
- radar_api.configs.define_configs(base_dir: str | None = None)[source][source]#
Defines the RADAR-API configuration file with the given credentials and base directory.
- Parameters:
base_dir (str) – The base directory where radar data are stored.
Notes
This function writes a YAML file to the user’s home directory at ~/.config_radar_api.yaml with the given RADAR-API credentials and base directory. The configuration file can be used for authentication when making RADAR-API requests.
- radar_api.configs.read_configs() dict[str, str][source][source]#
Reads the RADAR-API configuration file and returns a dictionary with the configuration settings.
- Returns:
A dictionary containing the configuration settings for the RADAR-API.
- Return type:
- Raises:
ValueError – If the configuration file has not been defined yet. Use radar_api.define_configs() to specify the configuration file path and settings.
Notes
This function reads the YAML configuration file located at ~/.config_radar_api.yaml, which should contain the RADAR-API credentials and base directory specified by radar_api.define_configs().
radar_api.download module#
Define download functions.
- radar_api.download.create_local_directories(fpaths, exist_ok=True)[source][source]#
Create recursively local directories for the provided filepaths.
- radar_api.download.define_local_filepath(filename, network, radar, base_dir=None)[source][source]#
Define filepath where to save file locally on disk.
- radar_api.download.get_list_daily_time_blocks(start_time, end_time)[source][source]#
Return a list of (start_time, end_time) tuple of daily length.
- radar_api.download.remove_corrupted_files(local_fpaths, bucket_fpaths, fs, return_corrupted_fpaths=True)[source][source]#
Check and remove files from local disk which are corrupted.
Corruption is evaluated by comparing the size of data on local storage against size of data located in the cloud bucket.
- Parameters:
local_fpaths (list) – List of filepaths on local storage.
bucket_fpaths (list) – List of filepaths on cloud bucket.
fs (fsspec.FileSystem) – fsspec filesystem instance. It must be cohrenet with the cloud bucket address of bucket_fpaths.
return_corrupted_fpaths (bool, optional) – If True, it returns the list of corrupted files. If False, it returns the list of valid files. The default is True.
- Returns:
(list_local_filepaths, list_bucket_filepaths)
- Return type:
radar_api.filter module#
This module provides files filtering functions.
- radar_api.filter.filter_file(fpath, network, start_time, end_time)[source][source]#
Utility function to select a file is matching the specified time periods.
radar_api.info module#
This module provides tools to extract information from radar filenames.
- radar_api.info.get_end_time_from_filepaths(filepaths, network, ignore_errors=False)[source][source]#
Infer files
end_timefrom filenames.
- radar_api.info.get_info_from_filename(filename, network, ignore_errors=False)[source][source]#
Retrieve file information dictionary from filename.
- radar_api.info.get_info_from_filepath(filepath, network, ignore_errors=False)[source][source]#
Retrieve file information dictionary from filepath.
- radar_api.info.get_key_from_filepath(filepath, key, network, ignore_errors=False)[source][source]#
Extract specific key information from a list of filepaths.
- radar_api.info.get_key_from_filepaths(filepaths, key, network, ignore_errors=False)[source][source]#
Extract specific key information from a list of filepaths.
- radar_api.info.get_season(time)[source][source]#
Get season from datetime.datetime or datetime.date object.
- radar_api.info.get_start_end_time_from_filepaths(filepaths, network, ignore_errors=False)[source][source]#
Infer files
start_timeandend_timefrom filenames.
- radar_api.info.get_start_time_from_filepaths(filepaths, network, ignore_errors=False)[source][source]#
Infer files
start_timefrom filenames.
- radar_api.info.get_time_component(time, component)[source][source]#
Get time component from datetime.datetime object.
- radar_api.info.get_version_from_filepath(filepath, network, integer=True)[source][source]#
Infer file
versionfrom filenames.
- radar_api.info.get_version_from_filepaths(filepaths, network, integer=True)[source][source]#
Infer files
versionfrom filenames.
- radar_api.info.group_filepaths(filepaths, network, groups=None)[source][source]#
Group filepaths in a dictionary if groups are specified.
- Parameters:
filepaths (list) – List of filepaths.
groups (list or str) – The group keys by which to group the filepaths. Valid group keys are
start_time,end_time,version,volume_identifier,radar_acronym,extension,year,month,day,doy,dow,hour,minute,second,month_name,quarter,season. The time components are extracted fromstart_time! If groups isNonereturns the input filepaths list. The default isNone.
- Returns:
Either a dictionary of format
{<group_value>: <list_filepaths>}. or the original input filepaths (ifgroups=None)- Return type:
radar_api.io module#
Define filesystems, buckets, connection types and directory structures.
- radar_api.io.available_radars(network=None, start_time=None, end_time=None)[source][source]#
Get list of available radars.
- radar_api.io.get_filesystem(protocol, fs_args=None)[source][source]#
Define fsspec filesystem.
- protocolstr
String specifying the cloud bucket storage from which to retrieve the data. It must be specified if not searching data on local storage. Use goes_api.available_protocols() to retrieve available protocols.
- fs_argsdict, optional
Dictionary specifying optional settings to initiate the fsspec.filesystem. The default is an empty dictionary. Anonymous connection is set by default.
- radar_api.io.get_network_config_filepath(network)[source][source]#
Get filepath of the network configuration file.
- radar_api.io.get_network_config_path()[source][source]#
Get directory path with the network configuration files.
- radar_api.io.get_network_radars_config_path(network)[source][source]#
Get directory path with the radar configuration files of a given network.
- radar_api.io.get_radar_config_filepath(network, radar)[source][source]#
Get filepath of the radar configuration file.
- radar_api.io.get_radar_start_time(network, radar)[source][source]#
Get first timestep with radar data.
- radar_api.io.get_radar_time_coverage(network, radar)[source][source]#
Get first and last timestep with radar data.
- radar_api.io.is_radar_available(network, radar, start_time=None, end_time=None)[source][source]#
Check if a radar was existing within the specified time period.
If
start_timeandend_timeareNone, does not perform any check.- Parameters:
start_time (datetime.datetime, datetime.date, numpy.datetime64 or str) – Start time. Accepted types:
datetime.datetime,datetime.date,numpy.datetime64orstrIf string type, it expects the isoformatYYYY-MM-DD hh:mm:ss.end_time (datetime.datetime, datetime.date, numpy.datetime64 or str) – Start time. Accepted types:
datetime.datetime,datetime.date,numpy.datetime64orstrIf string type, it expects the isoformatYYYY-MM-DD hh:mm:ss. IfNone, assume current UTC time.
radar_api.readers module#
This module defines file readers.
- radar_api.readers.check_software_availability(software, conda_package)[source][source]#
A decorator to ensure that a software package is installed.
- radar_api.readers.get_xradar_datatree_reader(network)[source][source]#
Return the xradar datatree reader.
- radar_api.readers.open_dataset(filepath, network, sweep, **kwargs)[source][source]#
Open a file into an xarray Dataset object using xradar.
radar_api.search module#
This module provides functions for searching files on local disk and cloud buckets.
- radar_api.search.find_files(radar, network, start_time, end_time, base_dir=None, protocol='s3', fs_args={}, verbose=False)[source][source]#
Retrieve files from local or cloud bucket storage.
- Parameters:
base_dir (str, optional) – This argument must be specified only if searching files on the local storage when protocol=”file”. It represents the path to the local directory where to search for radar data. If protocol=”file” and base_dir is None, base_dir is retrieved from the RADAR-API config file. The default is None.
protocol (str (optional)) – String specifying the location where to search for the data. If protocol=”file”, it searches on local storage (indicated by base_dir). Otherwise, protocol refers to a specific cloud bucket storage. Use radar_api.available_protocols() to check the available protocols. The default is “s3”.
fs_args (dict, optional) – Dictionary specifying optional settings to initiate the fsspec.filesystem. The default is an empty dictionary. Anonymous connection is set by default.
radar (str) – The name of the radar. Use radar_api.available_radars() to retrieve the available satellites.
network (str) – The name of the radar network. See radar_api.available_network() for available radar networks.
start_time (datetime.datetime) – The start (inclusive) time of the interval period for retrieving the filepaths.
end_time (datetime.datetime) – The end (exclusive) time of the interval period for retrieving the filepaths.
verbose (bool, optional) – If True, it print some information concerning the file search. The default is False.
- radar_api.search.get_directories_paths(start_time, end_time, network, radar, protocol, base_dir)[source][source]#
Returns a list of the directory paths to scan.
Module contents#
RADAR-API Package.
- radar_api.available_radars(network=None, start_time=None, end_time=None)[source][source]#
Get list of available radars.
- radar_api.define_configs(base_dir: str | None = None)[source][source]#
Defines the RADAR-API configuration file with the given credentials and base directory.
- Parameters:
base_dir (str) – The base directory where radar data are stored.
Notes
This function writes a YAML file to the user’s home directory at ~/.config_radar_api.yaml with the given RADAR-API credentials and base directory. The configuration file can be used for authentication when making RADAR-API requests.
- radar_api.find_files(radar, network, start_time, end_time, base_dir=None, protocol='s3', fs_args={}, verbose=False)[source][source]#
Retrieve files from local or cloud bucket storage.
- Parameters:
base_dir (str, optional) – This argument must be specified only if searching files on the local storage when protocol=”file”. It represents the path to the local directory where to search for radar data. If protocol=”file” and base_dir is None, base_dir is retrieved from the RADAR-API config file. The default is None.
protocol (str (optional)) – String specifying the location where to search for the data. If protocol=”file”, it searches on local storage (indicated by base_dir). Otherwise, protocol refers to a specific cloud bucket storage. Use radar_api.available_protocols() to check the available protocols. The default is “s3”.
fs_args (dict, optional) – Dictionary specifying optional settings to initiate the fsspec.filesystem. The default is an empty dictionary. Anonymous connection is set by default.
radar (str) – The name of the radar. Use radar_api.available_radars() to retrieve the available satellites.
network (str) – The name of the radar network. See radar_api.available_network() for available radar networks.
start_time (datetime.datetime) – The start (inclusive) time of the interval period for retrieving the filepaths.
end_time (datetime.datetime) – The end (exclusive) time of the interval period for retrieving the filepaths.
verbose (bool, optional) – If True, it print some information concerning the file search. The default is False.
- radar_api.group_filepaths(filepaths, network, groups=None)[source][source]#
Group filepaths in a dictionary if groups are specified.
- Parameters:
filepaths (list) – List of filepaths.
groups (list or str) – The group keys by which to group the filepaths. Valid group keys are
start_time,end_time,version,volume_identifier,radar_acronym,extension,year,month,day,doy,dow,hour,minute,second,month_name,quarter,season. The time components are extracted fromstart_time! If groups isNonereturns the input filepaths list. The default isNone.
- Returns:
Either a dictionary of format
{<group_value>: <list_filepaths>}. or the original input filepaths (ifgroups=None)- Return type:
- radar_api.open_dataset(filepath, network, sweep, **kwargs)[source][source]#
Open a file into an xarray Dataset object using xradar.
- radar_api.open_datatree(filepath, network, **kwargs)[source][source]#
Open a file into an xarray DataTree object using xradar.
- radar_api.read_configs() dict[str, str][source][source]#
Reads the RADAR-API configuration file and returns a dictionary with the configuration settings.
- Returns:
A dictionary containing the configuration settings for the RADAR-API.
- Return type:
- Raises:
ValueError – If the configuration file has not been defined yet. Use radar_api.define_configs() to specify the configuration file path and settings.
Notes
This function reads the YAML configuration file located at ~/.config_radar_api.yaml, which should contain the RADAR-API credentials and base directory specified by radar_api.define_configs().