[docs]@dataclasses.dataclassclassCorrectorSelector:""" A dataclass containing all the information needed to build a CorrectorConfigProtocol, including the type of the CorrectorConfigProtocol and the data needed to build it. This is helpful as CorrectorSelector can be serialized and deserialized without any additional information, whereas to load a CorrectorConfigProtocol you would need to know the type of the CorrectorConfigProtocol being loaded. It is also convenient because CorrectorSelector is a single class that can be used to represent any CorrectorConfigProtocol, whereas CorrectorConfigProtocol is a protocol that can be implemented by many different classes. Parameters: type: the type of the CorrectorConfigProtocol config: data for a CorrectorConfigProtocol instance of the indicated type """type:strconfig:Mapping[str,Any]registry:ClassVar[Registry]=Registry()def__post__init(self):ifself.registryisnotRegistry():raiseValueError("CorrectorSelector.registry should not be set manually")@classmethoddefregister(cls,type_name)->Callable[[CT],CT]:returncls.registry.register(type_name)defbuild(self,gridded_operations:GriddedOperations,vertical_coordinate:HybridSigmaPressureCoordinate,timestep:datetime.timedelta,):instance=self.registry.from_dict(self.get_state())returninstance.build(gridded_operations=gridded_operations,vertical_coordinate=vertical_coordinate,timestep=timestep,)
[docs]defget_state(self)->Mapping[str,Any]:""" Get a dictionary containing all the information needed to build a CorrectorConfigProtocol. """return{"type":self.type,"config":self.config}
[docs]@classmethoddeffrom_state(cls,state:Mapping[str,Any])->"CorrectorSelector":""" Create a CorrectorSelector from a dictionary containing all the information needed to build a CorrectorConfigProtocol. """returndacite.from_dict(data_class=cls,data=state,config=dacite.Config(strict=True))
[docs]@classmethoddefget_available_types(cls):"""This class method is used to expose all available types of Correctors."""returncls(type="",config={}).registry._types.keys()