onehealth_db.inout module⚓︎
onehealth_db.inout
⚓︎
Functions:
-
adjust_longitude_360_to_180
–Adjust longitude from 0-360 to -180-180.
-
convert_360_to_180
–Convert longitude from 0-360 to -180-180.
-
convert_to_celsius
–Convert temperature from Kelvin to Celsius.
-
convert_to_celsius_with_attributes
–Convert temperature from Kelvin to Celsius and keep attributes.
-
download_data
–Download data from Copernicus's CDS using the cdsapi.
-
get_filename
–Get file name based on dataset name, base name, years, months and area.
-
save_to_netcdf
–Save data to a NetCDF file.
Attributes:
-
T
– -
celsius_file_name
– -
data_folder
– -
data_format
– -
dataset
– -
ds
– -
encoding
– -
file_name
– -
output_celsius_file
– -
output_file
– -
raw_file_name
– -
request
–
ds
module-attribute
⚓︎
ds = convert_to_celsius_with_attributes(ds, limited_area='area' in request, inplace=True)
encoding
module-attribute
⚓︎
file_name
module-attribute
⚓︎
file_name = get_filename(dataset, data_format, request['year'], request['month'], 'area' in request, 'era5_data', request['variable'])
request
module-attribute
⚓︎
request = {'product_type': ['monthly_averaged_reanalysis'], 'variable': ['2m_temperature', 'total_precipitation'], 'year': ['2024'], 'month': ['01', '02', '03'], 'time': ['00:00'], 'data_format': data_format, 'download_format': 'unarchived'}
adjust_longitude_360_to_180
⚓︎
Adjust longitude from 0-360 to -180-180.
Parameters:
-
dataset
(Dataset
) –Dataset with longitude in 0-360 range.
-
inplace
(bool
, default:True
) –If True, modify the original dataset. If False, return a new dataset. Default is True.
Returns:
-
Dataset
–xr.Dataset: Dataset with longitude adjusted to -180-180 range.
convert_360_to_180
⚓︎
convert_to_celsius
⚓︎
Convert temperature from Kelvin to Celsius.
Parameters:
-
temperature_kelvin
(DataArray
) –Temperature in Kelvin, accessed through t2m variable in the dataset.
Returns:
-
DataArray
–xr.DataArray: Temperature in Celsius.
convert_to_celsius_with_attributes
⚓︎
Convert temperature from Kelvin to Celsius and keep attributes.
Parameters:
-
dataset
(Dataset
) –Dataset containing temperature in Kelvin.
-
limited_area
(bool
, default:True
) –Flag indicating if the dataset is a limited area. Default is True.
-
inplace
(bool
, default:True
) –If True, modify the original dataset. If False, return a new dataset. Default is True.
Returns:
-
Dataset
–xr.Dataset: Dataset with temperature converted to Celsius.
download_data
⚓︎
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
) –A dictionary containing the request parameters.
get_filename
⚓︎
get_filename(ds_name, data_format, years, months, has_area, base_name='era5_data', variable=['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
) –List of years.
-
months
(list
) –List of months.
-
has_area
(bool
) –Flag indicating if area is included.
-
base_name
(str
, default:'era5_data'
) –Base name for the file. Default is "era5_data".
-
variable
(list
, default:['2m_temperature']
) –List of variables. Default is ["2m_temperature"].
Returns:
-
str
(str
) –Generated file name.
save_to_netcdf
⚓︎
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.