Skip to content

Commit

Permalink
Make pretty
Browse files Browse the repository at this point in the history
  • Loading branch information
mdpiper committed Nov 10, 2024
1 parent e389b00 commit 2d96eff
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 45 deletions.
10 changes: 3 additions & 7 deletions examples/debug.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
# import matplotlib.pyplot as plt
from gridmet_bmi import BmiGridmet
import numpy as np
import numpy.testing as npt
import tempfile
import yaml
import datetime


def print_times(x):
Expand All @@ -20,7 +16,7 @@ def print_times(x):
x.initialize()
print(x.get_input_var_names())
print(x.get_output_var_names())
grid_id = x.get_var_grid('daily_maximum_temperature')
grid_id = x.get_var_grid("daily_maximum_temperature")
size = x.get_grid_size(grid_id)
shape = np.empty(2, dtype=int)
origin = np.empty(2, dtype=float)
Expand All @@ -32,7 +28,7 @@ def print_times(x):
tmp2 = np.array([585, 1386])
npt.assert_almost_equal(shape, np.array([585, 1386]))
vals = np.zeros(size)
x.get_value('daily_maximum_temperature', vals)
x.get_value("daily_maximum_temperature", vals)
print(np.nanmin(vals))
print(np.nanmax(vals))
print_times(x)
Expand All @@ -46,4 +42,4 @@ def print_times(x):
# fp.write((yaml.dump(yamldict, sort_keys=False)))
# name = fp.name

# print(name)
# print(name)
9 changes: 4 additions & 5 deletions examples/debug2.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import matplotlib.pyplot as plt
from gridmet_bmi import BmiGridmet, Gridmet
import numpy as np
from gridmet_bmi import Gridmet

gridmet = Gridmet(start_date='2019-03-15', end_date='2019-03-21', lazy=True)

gridmet = Gridmet(start_date="2019-03-15", end_date="2019-03-21", lazy=True)
# assert len(getattr(gridmet, 'tmax')) == 1
print(len(gridmet.tmax), type(gridmet.tmax))
tmp = 0
tmp = 0
78 changes: 45 additions & 33 deletions gridmet_bmi/bmi_gridmet.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@


class BmiGridmet(Bmi):
_name = 'Gridmet_BMI'
_input_var_names = ('')
_output_var_names = ('daily_maximum_temperature', 'daily_minimum_temperature', 'precipitation_amount')
_name = "Gridmet_BMI"
_input_var_names = ""
_output_var_names = (
"daily_maximum_temperature",
"daily_minimum_temperature",
"precipitation_amount",
)

def __init__(self):
self._model = None
Expand Down Expand Up @@ -84,7 +88,7 @@ def get_grid_edge_count(self, grid: int) -> int:
raise NotImplementedError("get_grid_edge_count")

def get_grid_edge_nodes(
self, grid: int, edge_nodes: numpy.ndarray
self, grid: int, edge_nodes: numpy.ndarray
) -> numpy.ndarray:
"""Get the edge-node connectivity.
Expand Down Expand Up @@ -120,7 +124,7 @@ def get_grid_face_count(self, grid: int) -> int:
raise NotImplementedError("get_grid_face_count")

def get_grid_face_edges(
self, grid: int, face_edges: numpy.ndarray
self, grid: int, face_edges: numpy.ndarray
) -> numpy.ndarray:
"""Get the face-edge connectivity.
Expand All @@ -139,7 +143,7 @@ def get_grid_face_edges(
raise NotImplementedError("get_grid_face_edges")

def get_grid_face_nodes(
self, grid: int, face_nodes: numpy.ndarray
self, grid: int, face_nodes: numpy.ndarray
) -> numpy.ndarray:
"""Get the face-node connectivity.
Expand Down Expand Up @@ -175,7 +179,7 @@ def get_grid_node_count(self, grid: int) -> int:
raise NotImplementedError("get_grid_node_count")

def get_grid_nodes_per_face(
self, grid: int, nodes_per_face: numpy.ndarray
self, grid: int, nodes_per_face: numpy.ndarray
) -> numpy.ndarray:
"""Get the number of nodes for each face.
Expand Down Expand Up @@ -465,11 +469,15 @@ def get_value(self, name: str, dest: numpy.ndarray) -> numpy.ndarray:
# max = numpy.nanmax(tmp[int(self._day),:,:])
# min = numpy.nanmin(tmp[int(self._day),:,:])
# to make consistent with BMI origin lower left, Gridmet origin is upper left
dest[:] = numpy.flipud(self._data[name].values[int(self._day), :, :]).reshape(-1).copy()
dest[:] = (
numpy.flipud(self._data[name].values[int(self._day), :, :])
.reshape(-1)
.copy()
)
return dest

def get_value_at_indices(
self, name: str, dest: numpy.ndarray, inds: numpy.ndarray
self, name: str, dest: numpy.ndarray, inds: numpy.ndarray
) -> numpy.ndarray:
"""Get values at particular indices.
Expand Down Expand Up @@ -544,36 +552,40 @@ def get_var_itemsize(self, name: str) -> int:
def get_var_location(self, name: str) -> str:
"""Get the grid element type that the a given variable is defined on.
The grid topology can be composed of *nodes*, *edges*, and *faces*.
The grid topology can be composed of *nodes*, *edges*, and *faces*.
*node*
A point that has a coordinate pair or triplet: the most
basic element of the topology.
*node*
A point that has a coordinate pair or triplet: the most
basic element of the topology.
*edge*
A line or curve bounded by two *nodes*.
*edge*
A line or curve bounded by two *nodes*.
*face*
A plane or surface enclosed by a set of edges. In a 2D
horizontal application one may consider the word polygon,
but in the hierarchy of elements the word face is most common.
*face*
A plane or surface enclosed by a set of edges. In a 2D
horizontal application one may consider the word
polygon
,
but in the hierarchy of elements the word
face
is most common.
Parameters
----------
name : str
An input or output variable name, a CSDMS Standard Name.
Parameters
----------
name : str
An input or output variable name, a CSDMS Standard Name.
Returns
-------
str
The grid location on which the variable is defined. Must be one of
`"node"`, `"edge"`, or `"face"`.
Returns
-------
str
The grid location on which the variable is defined. Must be one of
`"node"`, `"edge"`, or `"face"`.
Notes
-----
CSDMS uses the `ugrid conventions`_ to define unstructured grids.
Notes
-----
CSDMS uses the `ugrid conventions`_ to define unstructured grids.
.. _ugrid conventions: http://ugrid-conventions.github.io/ugrid-conventions
.. _ugrid conventions: http://ugrid-conventions.github.io/ugrid-conventions
"""
return "node"

Expand Down Expand Up @@ -708,7 +720,7 @@ def set_value(self, name: str, values: numpy.ndarray) -> None:
raise NotImplementedError("set_value")

def set_value_at_indices(
self, name: str, inds: numpy.ndarray, src: numpy.ndarray
self, name: str, inds: numpy.ndarray, src: numpy.ndarray
) -> None:
"""Specify a new value for a model variable at particular indices.
Expand Down

0 comments on commit 2d96eff

Please sign in to comment.