You can implement custom diagnostics by subclassing earth2mip.diagnostic.base.DiagnosticBase and ensuring it meets the functional requirements of earth2mip.geo_operator.GeoOperator.
A custom diagnostic must implement the following properties and methods:
in_channel_names: A list of input channel names (e.g., ['t2m']).out_channel_names: A list of output channel names (e.g., ['t2m_c']).in_grid: The input grid.LatLonGrid.out_grid: The output grid.LatLonGrid.__call__(x: torch.Tensor) -> torch.Tensor: The logic to transform the input tensor.load_diagnostic: A class method to instantiate the diagnostic (often used for registry patterns).
Note: Diagnostics must operate on grids and use channels consistent with the weather model they are attached to.
class Kelvin2Celcius(DiagnosticBase):
def __init__(self, grid: grid.LatLonGrid):
super().__init__()
self.grid = grid
@property
def in_channel_names(self) -> list[str]:
return ['t2m']
@property
def out_channel_names(self) -> list[str]:
return ['t2m_c']
@property
def in_grid(self) -> grid.LatLonGrid:
return self.grid
@property
def out_grid(self) -> grid.LatLonGrid:
return self.grid
def __call__(self, x: torch.Tensor) -> torch.Tensor:
return x - 273.15
@classmethod
def load_diagnostic(cls):
pass
@classmethod
def load_diagnostic(
cls, package: Optional[Package], grid: grid.LatLonGrid
):
return cls(grid)