Skip to content

Commit

Permalink
Merge pull request #2 from gantian127/release-0.1.2
Browse files Browse the repository at this point in the history
Release 0.1.2
  • Loading branch information
gantian127 authored Mar 9, 2021
2 parents 98bcde3 + 1555996 commit d0d6842
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 35 deletions.
17 changes: 9 additions & 8 deletions notebooks/config_file.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
service_id: phh2o
coverage_id: phh2o_0-5cm_mean
crs: urn:ogc:def:crs:EPSG::152160
west: -1784000
south: 1356000
east: -1140000
north: 1863000
output: test.tif
bmi-soilgrids:
service_id: phh2o
coverage_id: phh2o_0-5cm_mean
crs: urn:ogc:def:crs:EPSG::152160
west: -1784000
south: 1356000
east: -1140000
north: 1863000
output: test.tif
21 changes: 11 additions & 10 deletions notebooks/config_file2.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
service_id: phh2o
coverage_id: phh2o_0-5cm_mean
crs: urn:ogc:def:crs:EPSG::4326
west: -105.38
south: 39.45
east: -104.5
north: 40.07
width: 316
height: 275
output: test.tif
bmi-soilgrids:
service_id: phh2o
coverage_id: phh2o_0-5cm_mean
crs: urn:ogc:def:crs:EPSG::4326
west: -105.38
south: 39.45
east: -104.5
north: 40.07
width: 316
height: 275
output: test2.tif
46 changes: 29 additions & 17 deletions soilgrids/bmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ def finalize(self) -> None:
loop. This typically includes deallocating memory, closing files and
printing reports.
"""
self._time_index = 0.0
self._var = {}
self._grid = {}
self._input_var_names = ()
self._output_var_names = ()
self._dataset = None


def get_component_name(self) -> str:
"""Name of the component.
Expand All @@ -49,7 +54,7 @@ def get_current_time(self) -> float:
float
The current model time.
"""
return self._time_index
return 0.0

def get_end_time(self) -> float:
"""End time of the model.
Expand All @@ -58,7 +63,7 @@ def get_end_time(self) -> float:
float
The maximum model time.
"""
return 9999.0
return 0.0

def get_grid_face_edges(self, grid: int, face_edges: numpy.ndarray) -> numpy.ndarray:
"""Get the face-edge connectivity.
Expand Down Expand Up @@ -200,7 +205,7 @@ def get_grid_rank(self, grid: int) -> int:
int
Rank of the grid.
"""
return 2
return len(self._grid[grid].shape)

def get_grid_shape(self, grid: int, shape: numpy.ndarray) -> numpy.ndarray:
"""Get dimensions of the computational grid.
Expand Down Expand Up @@ -276,7 +281,8 @@ def get_grid_x(self, grid: int, x: numpy.ndarray) -> numpy.ndarray:
ndarray of float
The input numpy array that holds the grid's column x-coordinates.
"""
raise NotImplementedError("get_grid_x")
x[:] = self._dataset.x.values
return x

def get_grid_y(self, grid: int, y: numpy.ndarray) -> numpy.ndarray:
"""Get coordinates of grid nodes in the y direction.
Expand All @@ -291,7 +297,8 @@ def get_grid_y(self, grid: int, y: numpy.ndarray) -> numpy.ndarray:
ndarray of float
The input numpy array that holds the grid's row y-coordinates.
"""
raise NotImplementedError("get_grid_y")
y[:] = self._dataset.y.values
return y

def get_grid_z(self, grid: int, z: numpy.ndarray) -> numpy.ndarray:
"""Get coordinates of grid nodes in the z direction.
Expand Down Expand Up @@ -334,7 +341,7 @@ def get_input_item_count(self) -> int:
int
The number of input variables.
"""
return 0
return len(self._input_var_names)

def get_output_var_names(self) -> Tuple[str]:
"""List of a model's output variables.
Expand All @@ -355,7 +362,7 @@ def get_output_item_count(self) -> int:
int
The number of output variables.
"""
return 1
return len(self._output_var_names)

def get_start_time(self) -> float:
"""Start time of the model.
Expand All @@ -375,7 +382,7 @@ def get_time_step(self) -> float:
float
The time step used in model.
"""
return 1.0
return 0.0

def get_time_units(self) -> str:
"""Time units of the model.
Expand All @@ -387,7 +394,7 @@ def get_time_units(self) -> str:
-----
CSDMS uses the UDUNITS standard from Unidata.
"""
return 'none'
return "1"

def get_value(self, name: str, dest: numpy.ndarray) -> numpy.ndarray:
"""Get a copy of values of the given variable.
Expand All @@ -406,7 +413,7 @@ def get_value(self, name: str, dest: numpy.ndarray) -> numpy.ndarray:
The same numpy array that was passed as an input buffer.
"""
# return all the value at current time step, for scalar it is just one value
dest[:] = self._dataset[0].values.reshape(-1).copy()
dest[:] = self.get_value_ptr(name).reshape(-1).copy()
return dest

def get_value_at_indices(
Expand All @@ -427,7 +434,7 @@ def get_value_at_indices(
Value of the model variable at the given location.
"""
# return the value at current time step with given index in 1D or 2D grid. when it is scalar no need for ind
dest[:] = self._dataset[0].values.reshape(-1)[inds]
dest[:] = self.get_value_ptr(name).reshape(-1)[inds]
return dest

def get_value_ptr(self, name: str) -> numpy.ndarray:
Expand Down Expand Up @@ -575,17 +582,22 @@ def initialize(self, config_file: str) -> None:
"""
if config_file:
with open(config_file, "r") as fp:
conf = yaml.safe_load(fp)
conf = yaml.safe_load(fp).get('bmi-soilgrids', {})
else:
conf = {}
conf = {'service_id': 'phh2o',
'coverage_id': 'phh2o_0-5cm_mean',
'crs': 'urn:ogc:def:crs:EPSG::152160',
'west': -1784000,
'south': 1356000,
'east': -1140000,
'north': 1863000,
'output': 'test.tif'}

soilgrids = SoilGrids()
self._dataset = soilgrids.get_coverage_data(**conf)

self._output_var_names = tuple([soilgrids.metadata['variable_name']])

self._time_index = 0.0

array = self._dataset[0].values
self._grid = {
0: BmiGridUniformRectilinear(
Expand Down Expand Up @@ -644,7 +656,7 @@ def update(self) -> None:
then they can be computed by the :func:`initialize` method and this
method can return with no action.
"""
self._time_index += 1.0
raise NotImplementedError("update")

def update_until(self, time: float) -> None:
"""Advance model state until the given time.
Expand Down

0 comments on commit d0d6842

Please sign in to comment.