Utilities for Mocking Geophysical Data (pyzome.mock_data)
Provides some simple utilities for generating mock geophysical data. These include the automatic generation of coordinates such as latitudes and longitudes. These utilities are used internally for tests, but are also exposed publicly in case they are useful for users.
Functions
- pyzome.mock_data.lat_coord(resolution: float | int, name: str = 'lat', left_lim: float | int = -90.0, right_lim: float | int = 90.0, inclusive: bool = True) DataArray
Generate a regularly spaced latitude-like coordinate
- Parameters:
resolution (float | int) – The spacing between latitudes in degrees
name (str, optional) – The name of the coordinate, defaults to “lat”
left_lim (float | int, optional) – The left latitude limit, which defaults to -90
right_lim (float | int, optional) – The right latitude limit, which defaults to 90
inclusive (bool, optional) – Whether to include the right latitude limit, which defaults to True
- Returns:
latitudes – Regularly spaced latitudes with the given resolution (and name/limits, if given)
- Return type:
xarray.DataArray
- pyzome.mock_data.lon_coord(resolution: float | int, name: str = 'lon', left_lim: float | int = 0.0, right_lim: float | int = 360.0, inclusive: bool = False) DataArray
Generate a regularly spaced longitude-like coordinate
- Parameters:
resolution (float | int) – The spacing between longitudes in degrees
name (str, optional) – The name of the coordinate, defaults to “lon”
left_lim (float | int, optional) – The left longitude limit, which defaults to 0
right_lim (float | int, optional) – The right longitude limit, which defaults to 360
inclusive (bool, optional) – Whether to include the right longitude limit, which defaults to False
- Returns:
longitudes – Regularly spaced longitudes with the given resolution (and name/limits, if given)
- Return type:
xarray.DataArray
- pyzome.mock_data.plev_coord(levels_per_decade: int, left_lim_exponent: int = 3, right_lim_exponent: int = 0, name: str = 'plev', units: str = 'hPa') DataArray
Generate a pressure-like vertical coordinate with logarithmic spacing
- Parameters:
levels_per_decade (int) – The number of levels per decade (i.e., between 10^3 and 10^2, 10^2 and 10^1, etc.)
left_lim_exponent (int, optional) – The base-10 exponent for the left-most pressure level, which defaults to 3 (for 1000 hPa)
right_lim_exponent (int, optional) – The base-10 exponent for the right-most pressure level, which defaults to 0 (for 1 hPa)
name (str, optional) – The name of the coordinate, which defaults to “lev”
units (str, optional) – The units of the coordinate, which defaults to “hPa”
- Returns:
pressures – Pressure-like coordinate with logarithmic spacing having the given number of levels per decade (and name/limits/units, if given)
- Return type:
xarray.DataArray
- pyzome.mock_data.time_coord(start: str = '2000-01-01', end: str = '2001-01-01', freq: str = 'M') DataArray
Generate a time-like coordinate
- Parameters:
start (str, optional) – The start date, which defaults to “2000-01-01”
end (str, optional) – The end date, which defaults to “2001-01-01”
freq (str, optional) – The frequency of the time coordinate, which defaults to “M” (monthly). See https://numpy.org/doc/stable/reference/arrays.datetime.html#basic-datetimes for more information.
- Returns:
times – Time-like coordinate with the given start/end dates and frequency
- Return type:
xarray.DataArray
- pyzome.mock_data.create_dummy_geo_field(lons: None | DataArray = None, lats: None | DataArray = None, levs: None | DataArray = None, times: None | DataArray = None, name: str = 'dummy', attrs: dict = {}) DataArray
Mock a geophysical field with random data
- Parameters:
lons (
xarray.DataArray) – The longitudes of the data. Defaults to None (longitudes excluded)lats (
xarray.DataArray) – The latitudes of the data. Defaults to None (latitudes excluded)levs (
xarray.DataArray, optional) – The vertical levels of the data. Defaults to None (vertical levels excluded)times (
xarray.DataArray, optional) – The times of the data. Defaults to None (times excluded)name (str, optional) – The name of the data. Defaults to “dummy”
attrs (dict, optional) – The attributes of the data. Defaults to an empty dictionary.
- Returns:
dummy_data – Random data with corresponding geophysical coordinates
- Return type:
xarray.DataArray
- pyzome.mock_data.create_dummy_geo_dataset(field_names: list[str], lons: None | DataArray = None, lats: None | DataArray = None, levs: None | DataArray = None, times: None | DataArray = None, field_attrs: None | dict = None) Dataset
Mock a dataset of geophysical fields with random data
- Parameters:
field_names (list[str]) – The names of the fields
lons (
xarray.DataArray) – The longitudes of the datalats (
xarray.DataArray) – The latitudes of the datalevs (
xarray.DataArray, optional) – The vertical levels of the data. Defaults to None (vertical levels excluded)times (
xarray.DataArray, optional) – The times of the data. Defaults to None (times excluded)field_attrs (dict, optional) – The attributes of the data. Defaults to None. If provided, this should be a nested dictionary with the outer keys corresponding to the field names, and inner keys/dicts corresponding to the attributes for each field.
- Returns:
dummy_dataset – Dataset with fields having random data matching the given geophysical coordinates
- Return type:
xarray.Dataset