External climatology class¶
- class marine_qc.Climatology(data, time_axis=None, lat_axis=None, lon_axis=None, source_units=None, target_units=None, valid_ntime=None)[source]¶
Class for dealing with climatologies, reading, extracting values etc.
Automatically detects if this is a single field, pentad or daily climatology.
- Parameters:
data (
xr.DataArray) – Climatology data.time_axis (
str, optional) – Name of time axis. Set if time axis in data is not CF compatible.lat_axis (
str, optional) – Name of latitude axis. Set if latitude axis in data is not CF compatible.lon_axis (
str, optional) – Name of longitude axis. Set if longitude axis in data is not CF compatible.source_units (
str, optional) – Name of units in data. Set if units are not defined in data.target_units (
str, optional) – Name of target units to which units must conform.valid_ntime (
intorlist, default:[1,73,365]) – Number of valid time steps: - 1: single field climatology - 73: pentad climatology - 365: daily climatology
- convert_units_to(target_units, source_units=None)[source]¶
Convert units to user-specific units.
- Parameters:
target_units (
str) – Target units to which units must conform.source_units (
str, optional) – Source units if not specified inClimatology.
- Return type:
Notes
For more information see:
xclim.core.units.convert_units_to()
- static get_t_index(month, day, ntime)[source]¶
Convert arrays of months and days to an array of indices for the grid.
- get_value(lat, lon, date=None, month=None, day=None)[source]¶
Get the value from a climatology at the give position and time.
- Parameters:
lat (
SequenceNumberType, optional) – Latitude of location to extract value from in degrees.lon (
SequenceNumberType, optional) – Longitude of location to extract value from in degrees.date (
SequenceDatetimeType, optional) – Date for which the value is required.month (
SequenceIntType, optional) – Month for which the value is required.day (
SequenceIntType, optional) – Day for which the value is required.
- Return type:
- Returns:
ndarrayorpd.Series– Climatology value at specified location and time.
Notes
Use only exact matches for selecting time and nearest valid index value for selecting location.
- get_value_fast(lat, lon, date=None, month=None, day=None)[source]¶
Get the value from a climatology at the give position and time.
- Parameters:
lat (
SequenceNumberType, optional) – Latitude of location to extract value from in degrees.lon (
SequenceNumberType, optional) – Longitude of location to extract value from in degrees.date (
SequenceDatetimeType, optional) – Date for which the value is required.month (
SequenceIntType, optional) – Month for which the value is required.day (
SequenceIntType, optional) – Day for which the value is required.
- Return type:
- Returns:
ndarrayorpd.Series– Climatology value at specified location and time.
Notes
Assumes that the grid is a regular latitude longitude grid. The alternative method get_value works with non-regular grids.
- static get_x_index(lon_arr, lon_axis)[source]¶
Convert an array of longitudes to an array of indices for the grid.
- Parameters:
lon_arr (
ndarray) – Array of longitudes.lon_axis (
ndarray) – Array containing the longitude axis.
- Return type:
- Returns:
ndarray– Array of indices.
- static get_y_index(lat_arr, lat_axis)[source]¶
Convert an array of latitudes to an array of indices for the grid.
- Parameters:
lat_arr (
np.ndarray) – Array of latitudes.lat_axis (
np.ndarray) – Array containing the latitude axis.
- Return type:
- Returns:
np.ndarray– Array of indices.
- classmethod open_netcdf_file(file_name, clim_name, **kwargs)[source]¶
Open a NetCDF climatology file and construct a Climatology instance.
- Parameters:
- Return type:
- Returns:
Climatology– A Climatology instance constructed from the specified variable in the NetCDF file. If the file cannot be opened, an empty climatology object is returned.
External climatology functions¶
- marine_qc.external_clim.get_climatological_value(climatology, **kwargs)[source]
Get the value from a climatology.
- Parameters:
climatology (
Climatology) – Climatology class.**kwargs (
dict) – Pass keyword-arguments to :py:func:~Climatology.get_value`.
- Return type:
- Returns:
ndarray– Climatology value at specified location and time.
- marine_qc.external_clim.open_xrdataset(files, use_cftime=True, decode_cf=False, decode_times=False, parallel=False, data_vars='minimal', chunks='default', coords='minimal', compat='override', combine='by_coords', **kwargs)[source]
Optimized function for opening large CF-compliant datasets with xarray.
This implementation follows guidance from: https://github.com/pydata/xarray/issues/1385#issuecomment-561920115
decode_timedelta=Falseis added to leave variables and coordinates with time units in {“days”, “hours”, “minutes”, “seconds”, “milliseconds”, “microseconds”} encoded as numbers.- Parameters:
files (
strorlistofstrorpath-like) – See the documentation forxarray.open_mfdataset().use_cftime (
bool, default:True) – See the documentation forxarray.decode_cf().decode_cf (
bool, default:True) – See the documentation forxarray.decode_cf().decode_times (
bool, default:False) – See the documentation forxarray.decode_cf().parallel (
bool, default:False) – See the documentation forxarray.open_mfdataset().data_vars (
{"minimal", "different", "all"}orlistofstr, default:"minimal") – See the documentation forxarray.open_mfdataset().chunks (
int,dict,"auto"orNone, optional, default:"default") – Ifchunksis"default", chunks are set to{"time": 1}. See the documentation forxarray.open_mfdataset().coords (
{"minimal", "different", "all"}orlistofstr, optional, default:"minimal") – See the documentation forxarray.open_mfdataset().compat (
{"identical", "equals", "broadcast_equals", "no_conflicts", "override", "minimal"},) – default: “override” See the documentation forxarray.open_mfdataset().combine (
{"by_coords", "nested"}, optional, default:"by_coords") – See the documentation forxarray.open_mfdataset().**kwargs (
dict) – Additional keyword arguments passed toxarray.open_mfdataset().
- Return type:
- Returns:
xarray.Dataset– Opened xarray Dataset, optimized for large CF datasets.