veriflow.scores.categorical#

Categorical scores, based on a 2x2 contingency table.

For verification of non-probabilistic forecasts, and historical simulations of discrete variables.

For references, see: https://scores.readthedocs.io/en/stable/included.html#categorical.

Functions

create_binary_array(data, threshold_array, ...)

Given data and thresholds, compute the binary events.

Classes

CategoricalScores(config)

Categorical scores, based on the 2x2 contingency table.

CategoricalScoresConfig(*[, reduce_dims, ...])

Config to compute categorical scores, based on an event definition.

class veriflow.scores.categorical.CategoricalScores(config)[source]#

Categorical scores, based on the 2x2 contingency table.

For reference: https://scores.readthedocs.io/en/stable/included.html#categorical

Parameters:

config (CategoricalScoresConfig)

kind: str = 'categorical_scores'#
config_class#

alias of CategoricalScoresConfig

supported_data_specs: ClassVar[set[tuple[DataType, SpatialType]]] = {(DataType.simulated_forecast_single, SpatialType.point)}#
config: CategoricalScoresConfig#
compute_score_for_single_event(obs, sim, threshold_array, event)[source]#

Compute any number of categorical scores for a single event.

Parameters:
Return type:

Dataset | DataArray

classmethod from_config(raw_config)#

Initialize class from config dict.

Parameters:

raw_config (dict[str, Any])

Return type:

Self

validate_and_compute(obs, sim, thresholds)#

Validate and compute.

Parameters:
Return type:

DataArray | Dataset

class veriflow.scores.categorical.CategoricalScoresConfig(*, reduce_dims=<factory>, score_adapter, general, crs=None, verification_pair_ids=[], events, scores, return_contingency_table=True, **extra_data)[source]#

Config to compute categorical scores, based on an event definition.

Parameters:
  • reduce_dims (list[Literal[StandardDim.station, StandardDim.forecast_reference_time, StandardDim.lead_time, StandardDim.time, StandardDim.x, StandardDim.y]])

  • score_adapter (Literal[ScoreKind.categorical_scores])

  • general (Annotated[GeneralInfoConfig, SkipJsonSchema()])

  • crs (Annotated[str, FieldInfo(annotation=NoneType, required=True, description="A coordinate reference system as a string compatible with pyproj.CRS.from_string, i.e. a PROJ string, a CRS WKT string, or an authority string such as 'EPSG:4326'. The string is not parsed at configuration time so that pyproj remains an optional dependency; it is only parsed when an actual coordinate transformation is required.", metadata=[MinLen(min_length=1)])] | None)

  • verification_pair_ids (list[str])

  • events (list[ThresholdEvent])

  • scores (list[SupportedCategoricalScores])

  • return_contingency_table (bool)

  • extra_data (Any)

score_adapter: Literal[ScoreKind.categorical_scores]#
scores: Annotated[list[SupportedCategoricalScores], FieldInfo(annotation=NoneType, required=True, description='For reference, see: https://scores.readthedocs.io/en/stable/api.html#module-scores.categorical.')]#
events: Annotated[list[ThresholdEvent], FieldInfo(annotation=NoneType, required=True, description="A list of threshold event definitions. For each event, a categorical score will be computed. A threshold event is defined by a threshold and an operator. The threshold is a string that corresponds to a threshold id defined in the configuration. The operator defines how the threshold is applied to the data to create the event. For example, if the threshold is '10' and the operator is 'greater_than', the event will be created by applying the operator to the data and the threshold, i.e. data > 10. ")]#
return_contingency_table: Annotated[bool, FieldInfo(annotation=NoneType, required=True, description='Whether to return the contingency table in the output.')]#
property lead_times: LeadTimes | None#
validate_spatial_dims()#

Validate that x, y and station are never configured together.

Return type:

ReduceDims

verification_pair_ids_valid()#

Check provided filter for verification pairs contains valid ids.

Return type:

Self

property verification_pairs: list[VerificationPair]#

The configured variable pairs.

If the verification_pairs element is configured for the score, filter only these ids from the verification_pairs defined in general config.

general#
crs#
verification_pair_ids#
reduce_dims#
veriflow.scores.categorical.create_binary_array(data, threshold_array, operator)[source]#

Given data and thresholds, compute the binary events.

Parameters:
Return type:

DataArray