scmdata.filters

Helpers for filtering data in scmdata.run.ScmRun.

Based upon pyam.utils.

is_in

is_in(vals, items)[source]

Find elements of vals which are in items.

Parameters:
Returns:

numpy.ndarray of bool – Array of the same length as vals where the element is True if the corresponding element of vals is in items and False otherwise

find_depth

find_depth(meta_col, s, level, separator='|')[source]

Find all values which match given depth from a filter keyword.

Parameters:
  • meta_col (pandas.core.series.Series) – Column in which to find values which match the given depth

  • s (str) – Filter keyword, from which level should be applied

  • level (typing.Union[int, str]) – Depth of value to match as defined by the number of separator in the value name. If an int, the depth is matched exactly. If a str, then the depth can be matched as either “X-”, for all levels up to level “X”, or “X+”, for all levels above level “X”.

  • separator (str) – The string used to separate levels in s. Defaults to a pipe (“|”).

Returns:

numpy.ndarray of bool – Array where True indicates a match

Raises:

ValueError – If level cannot be understood

pattern_match

pattern_match(meta_col, values, level=None, regexp=False, separator='|')[source]

Filter data by matching metadata columns to given patterns.

Parameters:
Returns:

numpy.ndarray of bool – Array where True indicates a match

Raises:

TypeError – Filtering is performed on a string metadata column which contains numpy.nan and has_nan is False

years_match

years_match(data, years)[source]

Match years in time columns for data filtering.

Parameters:
Returns:

numpy.ndarray of bool – Array where True indicates a match

Raises:

TypeError – If years is not int or list of int

month_match

month_match(data, months)[source]

Match months in time columns for data filtering.

Parameters:
Returns:

numpy.ndarray of bool – Array where True indicates a match

day_match

day_match(data, days)[source]

Match days in time columns for data filtering.

Parameters:
Returns:

numpy.ndarray of bool – Array where True indicates a match

hour_match

hour_match(data, hours)[source]

Match hours in time columns for data filtering.

Parameters:
Returns:

numpy.ndarray of bool – Array where True indicates a match

time_match

time_match(data, times, conv_codes, strptime_attr, name)[source]

Match times by applying conversion codes to filtering list.

Parameters:
Returns:

numpy.ndarray of bool – Array where True indicates a match

Raises:

ValueError – If input times cannot be converted understood or if input strings do not lead to increasing integers (i.e. “Nov-Feb” will not work, one must use [“Nov-Dec”, “Jan-Feb”] instead)

datetime_match

datetime_match(data, dts)[source]

Match datetimes in time columns for data filtering.

Parameters:
Returns:

numpy.ndarray of bool – Array where True indicates a match

Raises:

TypeErrordts contains int