carpet_concentrations.time

Time handling

MONTHS_PER_YEAR

MONTHS_PER_YEAR: int = 12

Months per year

NonUniqueYearMonths

class NonUniqueYearMonths(unique_vals, counts)[source]

Bases: ValueError

Raised when the user tries to convert to year-month with non-unique values

This happens when the datetime values lead to year-month values that are not unique

CftimeConverter

class CftimeConverter(*args, **kwargs)[source]

Bases: Protocol

Callable that supports converting stacked time co-ordinates to cftime.datetime

convert_year_month_to_time

convert_year_month_to_time(inp, day=1, **kwargs)[source]

Convert year and month co-ordinates into a time axis

This is a facade to convert_to_time()

Parameters
Returns

xarray.core.dataset.Dataset – Data with time axis

convert_to_time

convert_to_time(inp, time_coords, cftime_converter)[source]

Convert some co-ordinates representing time into a time axis

Parameters
Returns

xarray.core.dataset.Dataset – Data with time axis

split_time_to_year_month

split_time_to_year_month(inp, time_axis='time')[source]

Convert the time dimension to year and month without stacking

This means there is still a single time dimension in the output, but there is now also accompanying year and month information

Parameters

inp (xarray.core.dataset.Dataset) – Data to convert

Returns

xarray.core.dataset.Dataset – Data with year and month information for the time axis

Raises

NonUniqueYearMonths – The years and months are not unique

convert_time_to_year_month

convert_time_to_year_month(inp, time_axis='time')[source]

Convert the time dimension to year and month co-ordinates

Parameters

inp (xarray.core.dataset.Dataset) – Data to convert

Returns

xarray.core.dataset.Dataset – Data with year and month co-ordinates

get_start_of_next_month

get_start_of_next_month(y, m)[source]

Get start of next month

Parameters
  • y (int) – Year

  • m (int) – Month

Returns

cftime._cftime.datetime – Start of next month