Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a geospatial extension #31

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions heat/bmi_geo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from __future__ import annotations

from abc import ABC
from abc import abstractmethod

import numpy as np
from numpy.typing import NDArray


class BmiGeo(ABC):

@abstractmethod
def initialize(self, filename: str=None) -> None:
...

@abstractmethod
def get_grid_coordinate_names(self, grid: int) -> tuple[str, ...]:
...

@abstractmethod
def get_grid_coordinate_units(self, grid: int) -> tuple[str, ...]:
...

@abstractmethod
def get_grid_coordinate(self, grid: int, coordinate: str, values: NDArray[np.float64]) -> None:
...

@abstractmethod
def get_grid_crs(self, grid: int) -> str:
...
3 changes: 3 additions & 0 deletions heat/bmi_heat.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class BmiHeat(Bmi):
_input_var_names = ("plate_surface__temperature",)
_output_var_names = ("plate_surface__temperature",)

def get_extensions(self):
return ("[email protected]_heat_geo:BmiHeatGeo",)

def __init__(self):
"""Create a BmiHeat model that is ready for initialization."""
self._model = None
Expand Down
41 changes: 41 additions & 0 deletions heat/bmi_heat_geo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from __future__ import annotations

import numpy as np
from numpy.typing import NDArray

from heat.bmi_geo import BmiGeo
from heat.bmi_heat import BmiHeat


class BmiHeatGeo(BmiGeo):
def __init__(self, bmi_heat: BmiHeat):
self._bmi_heat = bmi_heat

def initialize(self, filename: str = None) -> None:
pass

def get_grid_coordinate_names(self, grid: int) -> tuple[str, ...]:
return ("y", "x")

def get_grid_coordinate_units(self, grid: int) -> tuple[str, ...]:
return ("m", "m")

def get_grid_coordinate(
self, grid: int, coordinate: str, values: NDArray[np.float64]
) -> None:
coords = np.meshgrid(
range(self._bmi_heat._model.shape[0]),
range(self._bmi_heat._model.shape[1]),
indexing="ij"
)
if coordinate == "y":
dim = 0
elif coordinate == "x":
dim = 1
else:
raise RuntimeError(f"{coordinate}: unknown coordinate")

values[:] = coords[dim].reshape(-1) * self._bmi_heat._model.spacing[dim] + self._bmi_heat._model.origin[dim]

def get_grid_crs(self, grid: int) -> str:
return "none"