Skip to content
Snippets Groups Projects
Commit f6c5dee0 authored by Christopher Polster's avatar Christopher Polster
Browse files

Copy template and rename for threshold identification

parent 1c78d728
No related branches found
No related tags found
1 merge request!1Single- and Double Threshold Identification and Tracking
from .identification import MultiThresholdIdentification
from ..identification import IdentificationTechnique
import xarray as xr
class MultiThresholdIdentification(IdentificationTechnique):
def __init__(self, some_parameter='', **kwargs):
# Constructor. Called from example_template.py, parameters can be passed and set here.
self.param = some_parameter
# Specify processing mode 2d or 3d: In 2d, identification will be performed on 2d levels,
# in 3d the identification will be performed per 3d block
self.processing_mode = '2d'
pass
def precompute(self, dataset: xr.Dataset, **kwargs):
# Precomputation, done once for the entire dataset.
# All work which requires or takes the entire input can be performed here, identify() later is called in
# parallel for all timesteps, ensemble members, ...
# Also data fields need to be added here in case they are needed and populated later on.
# e.g. dataset['identified_areas'] = xr.zeros_like(dataset['existing_field'], dtype=bool)
return dataset
def identify(self, dataset: xr.Dataset, **kwargs):
# Identification, here is the place for your identification algorithm.
# This is called in parallel for each spatial subset of the data, e.g., for each member and for each timestep
# Therefore, dataset contains only spatial dimensions (lat,lon) if self.processing_mode = '2d' is set,
# (see __init__), or (lat,lon,level) if '3d' is set.
# here your code ... identify objects for this subset.
# Let's say you detected 5 objects:
obj_list = []
for i in range(5):
# get an instance of a new object, can pass an ID or set in manually afterwards
obj = self.get_new_object()
# set some ID to it
obj.id = i + 1
# get properties of object and populate them (like defined in template.proto)
properties = obj.properties
properties.size = 42
properties.centroid.x = i
properties.centroid.y = 2*i
properties.centroid.z = 3*i
properties.list_of_something.append("type x")
properties.list_of_something.append("type z")
obj_list.append(obj)
# return the dataset (can be changed here), and the list of objects
return dataset, obj_list
def postprocess(self, dataset: xr.Dataset, pb2_desc, **kwargs):
# Here post process: called once after processing the whole dataset.
# If needed, the dataset or objects can be changed here.
# objects are already in finished protobuf description, cf. the JSON output.
# pb2_desc.sets is list of trackable sets, each one contains the timesteps list, where each entry is a valid time and contains a list of objects.
return dataset, pb2_desc
syntax = "proto2";
/* This file contains the feature description for an identified object.
* The "Properties" message is required and contains all the properties of an object.
*/
message MaskArray {
repeated int32 shape = 1;
required bytes data = 2;
}
message Properties {
required MaskArray masks = 1;
repeated float thresholds = 2;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment