Era5ZarrSource
¶
Classes:
-
Era5ZarrSource–ERA5 source backed by a regular lat/lon Zarr dataset.
Era5ZarrSource
¶
Era5ZarrSource(
source,
bounds=None,
index_pad=5,
time_index_from=None,
time_slice=None,
chunks=None,
consolidated=True,
storage_options=None,
verbose=True,
forward_fill=True,
**kwargs,
)
Bases: Era5Source
ERA5 source backed by a regular lat/lon Zarr dataset.
A drop-in alternative to Era5Source for weather data which is not available as a directory of netCDF4 files, but as a Zarr store -- either on a local disk or in the cloud, e.g. the Earth Data Hub ERA5 single-level dataset. All simulation-facing behaviour (the 'sload_*' loaders, the clear variable names, the constants and the long-run-average rasters) is inherited from Era5Source, so that workflows do not have to know which of the two storage formats they are reading from.
The differences to Era5Source arise from the storage format: * The dataset is opened with xarray instead of netCDF4 and is kept in '_dataset', therefore 'load' and 'get' are reimplemented here * The store may use either 'valid_time' or 'time' as its temporal dimension, see _normalise_time_axis * A store which only contains the raw accumulated solar radiation is supplemented with the processed variants on the fly, see _derive_solar_variables * Longitudes may be given on a [0, 360) grid, which is handled transparently in 'get' so that placements can always be given on a [-180, 180) grid * The time span to read can be restricted with 'time_slice', which matters for multi-year cloud stores where reading everything is prohibitively slow
Note
Only regular latitude/longitude grids are supported. Stores using a flattened 'values' dimension (as e.g. published for reduced Gaussian grids) are rejected.
See Also
Era5Source reskit.weather.NCSource
Initialize an ERA5 source from a regular latitude/longitude Zarr store.
Compared to Era5Source, the data is not read from netCDF4 files but from a local or cloud hosted Zarr store, e.g. the Earth Data Hub ERA5 single-level dataset. Flattened 'values' grids as used by some stores are not supported.
Stores which only provide the raw accumulated solar radiation ('ssrd', 'fdir') are supplemented with the processed variants ('ssrd_t_adj', 'fdir_t_adj') on the fly, see _derive_solar_variables. The RESKit ERA5 time convention (TIME_OFFSET) is applied to the timestamps of the store, so that 'time_slice' and 'time_index' share one convention.
Parameters:
-
(source¶str or Dataset) –The Zarr store to read, either as an already opened dataset or as a path/URL. * Cloud stores are recognized by their protocol, i.e. 'https://' or 'gs://' * 'https://' stores are read with the credentials of '~/.netrc', which is where the credentials of the Earth Data Hub have to be saved
-
(bounds¶Anything acceptable to geokit.Extent.load(), default:None) –The boundaries of the data which is needed * Usage of this will help with memory management * If None, the full spatial extent of the store is used
-
(index_pad¶int, default:5) –The padding to apply to the boundaries * Useful in case of interpolation
-
(time_index_from¶str, default:None) –The variable which has to exist in the store, given either as an ERA5 name or as one of the clear names of Era5Source, e.g. 'elevated_wind_speed'. * Only validates the store, the time convention is independent of this variable
-
(time_slice¶slice, default:None) –Limit the time span which is loaded from the store, given in the time convention of RESKit, i.e. at half hours. Strongly recommended for multi-year cloud stores. * The first requested timestep of derived solar variables still uses the accumulation preceding it in the store
-
(chunks¶dict, default:None) –The chunk sizes to load the store with, e.g. {"valid_time": 48}. Passed on to xarray.open_dataset(), by default the chunking of the store is used.
-
(consolidated¶bool, default:True) –If True, the consolidated metadata of the store is used, by default True
-
(storage_options¶dict, default:None) –Additional options for the storage backend, passed on to xarray.open_dataset(). Only needed to overwrite the defaults for the recognized cloud protocols.
-
(verbose¶bool, default:True) –If True, then status outputs are printed when reading weather data
-
(forward_fill¶bool, default:True) –If True, then a single missing time step at the end of the data is forward-filled
See Also
Era5Source
Methods:
-
get–Extract the data of a loaded variable at the given locations.
-
load–Read a variable from the store into the data library '.data'.
-
raw_passthrough_variables–Return the NC short names that are used raw from the ERA5 download — i.e. the
-
sload_boundary_layer_height–Standard loader function for the variable 'boundary_layer_height' in meters
-
sload_direct_horizontal_irradiance–Standard loader function for the variable 'direct_horizontal_irradiance' in W/m²
-
sload_direct_horizontal_irradiance_archive–Standard loader function for the variable 'direct_horizontal_irradiance'
-
sload_elevated_wind_direction–Standard loader function for the variable 'elevated_wind_direction'
-
sload_elevated_wind_speed–Standard loader function for the variable 'elevated_wind_speed'
-
sload_global_horizontal_irradiance–Standard loader function for the variable 'global_horizontal_irradiance' in W/m²
-
sload_global_horizontal_irradiance_archive–Archive loader function for the variable 'global_horizontal_irradiance. Uses non corrected solar inputs.
-
sload_snow_albedo–Standard loader function for the variable 'snow_albedo'
-
sload_snow_density–Standard loader function for the variable 'snow_density'
-
sload_snow_depth_water_equivalent–Standard loader function for the variable 'snow_depth_water_equivalent'
-
sload_snowfall_water_equivalent–Standard loader function for the variable 'snowfall_water_equivalent'
-
sload_surface_air_temperature–Standard loader function for the variable 'surface_air_temperature'
-
sload_surface_dew_temperature–Standard loader function for the variable 'surface_dew_temperature'
-
sload_surface_pressure–Standard loader function for the variable 'surface_pressure'
-
sload_surface_wind_speed–Standard loader function for the variable 'surface_wind_speed'
-
sload_wind_speed_at_100m–Standard loader function for the variable 'wind_speed_at_100m'
-
sload_wind_speed_at_10m–Standard loader function for the variable 'wind_speed_at_10m'
-
var_info–Print the xarray representation of a variable of the store.
Source code in reskit/weather/Era5Source/Era5ZarrSource.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | |
get
¶
get(
variable,
locations,
interpolation="near",
force_as_data_frame=False,
outside_okay=False,
_indices=None,
)
Extract the data of a loaded variable at the given locations.
Behaves like NCSource.get(), except that locations are additionally wrapped onto the longitude convention of the store. Placements can therefore always be given on a [-180, 180) grid, no matter whether the store uses [-180, 180) or [0, 360).
Parameters:
-
(variable¶str) –The name of the variable in the data library '.data'
-
(locations¶Anything acceptable to geokit.LocationSet) –The locations to extract data for, with longitudes on a [-180, 180) grid
-
(interpolation¶str, default:'near') –The interpolation mode, e.g. 'near', 'bilinear' or 'cubic', by default 'near'
-
(force_as_data_frame¶bool, default:False) –If True, a pandas DataFrame is returned even for a single location, by default False
-
(outside_okay¶bool, default:False) –If True, locations outside the extent of the source give NaN instead of raising, by default False
-
(_indices¶optional, default:None) –Precomputed location indices, see NCSource.get()
Returns:
-
Series or DataFrame–The time series of the variable at each location, labelled with the original (unwrapped) coordinates
Source code in reskit/weather/Era5Source/Era5ZarrSource.py
load
¶
load(
variable,
name=None,
height_idx=None,
processor=None,
overwrite=False,
)
Read a variable from the store into the data library '.data'.
The Zarr counterpart of NCSource.load(). The data is read for the configured spatial subset only, is oriented to match '.lats' and '.lons', and is stored as a plain numpy array of the shape (time, latitude, longitude).
Parameters:
-
(variable¶str) –The ERA5 name of the variable to read, as listed in '.variables'
-
(name¶str, default:None) –The key to store the data under in '.data', by default the variable name itself
-
(height_idx¶int, default:None) –The index to select along the height dimension, for variables which have one
-
(processor¶callable, default:None) –A function applied to the raw numpy array before it is stored, e.g. for a unit conversion. Must preserve the shape of the array.
-
(overwrite¶bool, default:False) –If False, a variable which is already in '.data' under 'name' is not read again, by default False
Raises:
-
ResError–If the variable does not exist in the store, if it does not have the expected dimensions, or if its length along the time axis does not match the time index (and cannot be repaired by forward-filling a single missing last step)
Source code in reskit/weather/Era5Source/Era5ZarrSource.py
raw_passthrough_variables
classmethod
¶
raw_passthrough_variables(cds_variables)
Return the NC short names that are used raw from the ERA5 download — i.e. the
variables that survive preprocessing unchanged, with the ones that get replaced by
a preprocessed/derived output (see PREPROCESSED_NC_NAMES) removed.
Parameters:
-
(cds_variables¶iterable of str) –The ERA5 CDS API variable names a workflow requires (e.g.
["2m_temperature", "surface_pressure", "100m_u_component_of_wind"]).
Returns:
-
list of str–The corresponding NC short names that pass through unmodified.
Source code in reskit/weather/Era5Source/Era5Source.py
sload_boundary_layer_height
¶
Standard loader function for the variable 'boundary_layer_height' in meters from the surface
Reads 'blh', or 'boundary_layer_height' for stores which use the long name.
Source code in reskit/weather/Era5Source/Era5ZarrSource.py
sload_direct_horizontal_irradiance
¶
Standard loader function for the variable 'direct_horizontal_irradiance' in W/m²
Reads the processed 'fdir_t_adj' if the store provides it, and otherwise falls back on the variant derived from the raw accumulated 'fdir', see _derive_solar_variables.
Source code in reskit/weather/Era5Source/Era5ZarrSource.py
sload_direct_horizontal_irradiance_archive
¶
Standard loader function for the variable 'direct_horizontal_irradiance'
Automatically reads the variable "fdir" from the given ERA5 source and saves it as the variable 'direct_horizontal_irradiance' in the data library
Source code in reskit/weather/Era5Source/Era5Source.py
sload_elevated_wind_direction
¶
Standard loader function for the variable 'elevated_wind_direction'
Automatically reads the variables "wd
Where 'Era5Source.ELEVATED_WIND_SPEED_HEIGHT
The "wd
TODO: Update function to also be able to handle raw ERA5 inputs for u & v
Source code in reskit/weather/Era5Source/Era5Source.py
sload_elevated_wind_speed
¶
Standard loader function for the variable 'elevated_wind_speed'
sload_global_horizontal_irradiance
¶
Standard loader function for the variable 'global_horizontal_irradiance' in W/m²
Reads the processed 'ssrd_t_adj' if the store provides it, and otherwise falls back on the variant derived from the raw accumulated 'ssrd', see _derive_solar_variables.
Source code in reskit/weather/Era5Source/Era5ZarrSource.py
sload_global_horizontal_irradiance_archive
¶
Archive loader function for the variable 'global_horizontal_irradiance. Uses non corrected solar inputs. Use only for reproduceability purposes'
Automatically reads the variable "ssrd" from the given ERA5 source and saves it as the variable 'global_horizontal_irradiance' in the data library
Source code in reskit/weather/Era5Source/Era5Source.py
sload_snow_albedo
¶
Standard loader function for the variable 'snow_albedo'
unit: dimensionless, instantaneous
Automatically reads the variable "asn" from the given ERA5 source and saves it as the variable 'snow_albedo' in the data library
Source code in reskit/weather/Era5Source/Era5Source.py
sload_snow_density
¶
Standard loader function for the variable 'snow_density'
unit: kg/m^3, instantaneous
Automatically reads the variable "rsn" from the given ERA5 source and saves it as the variable 'snow_density' in the data library
Source code in reskit/weather/Era5Source/Era5Source.py
sload_snow_depth_water_equivalent
¶
Standard loader function for the variable 'snow_depth_water_equivalent'
unit: meters, instantaneous
Automatically reads the variable "sd" from the given ERA5 source and saves it as the variable 'snow_depth_water_equivalent' in the data library
Source code in reskit/weather/Era5Source/Era5Source.py
sload_snowfall_water_equivalent
¶
Standard loader function for the variable 'snowfall_water_equivalent'
unit: meters per time step, accumulation
Automatically reads the variable "sf" from the given ERA5 source and saves it as the variable 'snowfall_water_equivalent' in the data library
Source code in reskit/weather/Era5Source/Era5Source.py
sload_surface_air_temperature
¶
Standard loader function for the variable 'surface_air_temperature'
Automatically reads the variable "t2m" from the given ERA5 source and saves it as the variable 'surface_air_temperature' in the data library
Temperature values are also converted from kelvin to degrees celsius
Source code in reskit/weather/Era5Source/Era5Source.py
sload_surface_dew_temperature
¶
Standard loader function for the variable 'surface_dew_temperature'
Automatically reads the variable "d2m" from the given ERA5 source and saves it as the variable 'surface_dew_temperature' in the data library
Temperature values are also converted from kelvin to degrees celsius
Source code in reskit/weather/Era5Source/Era5Source.py
sload_surface_pressure
¶
Standard loader function for the variable 'surface_pressure'
Automatically reads the variable "sp" from the given ERA5 source and saves it as the variable 'surface_pressure' in the data library
Source code in reskit/weather/Era5Source/Era5Source.py
sload_surface_wind_speed
¶
Standard loader function for the variable 'surface_wind_speed'
sload_wind_speed_at_100m
¶
Standard loader function for the variable 'wind_speed_at_100m'
sload_wind_speed_at_10m
¶
Standard loader function for the variable 'wind_speed_at_10m'