Skip to content

Commit

Permalink
Merge branch 'maintenance/0.5.x' into fix-flow-distances
Browse files Browse the repository at this point in the history
  • Loading branch information
inoelloc authored Jul 12, 2023
2 parents b5d3205 + 7deb380 commit ce96802
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
14 changes: 14 additions & 0 deletions doc/source/release/0.5.0-notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,17 @@ Catchment flow distances on adjacent non-nested catchments
There is a bug when calculating flow distances when two adjacent catchments are considered in the mesh but non-nested. During calculation, a flag is set around the 8 adjacent cells of each upstream cell and not on the upstream cell in particular. As a result, a gauge stuck to a cell of another catchment will not be considered as a non-nested gauge and will be filled with -99. The bug has been solved by flagging only the upstream cell and not the 8 adjacent cells.

See issue `#38 <https://github.com/DassHydro-dev/smash/issues/38>`__.

Correctly handle Nodata value during the spatial disaggregation of the rainfall
*******************************************************************************

A crash occured during the disaggregation of the rainfall. The creation of a GDAL virtual-destination failed when the parent geotiff file has its Nodata value unset (None type). When this is the case, the Nodata value of the disaggregation rainfall is automatically set to -99.

See issue `#40 <https://github.com/DassHydro-dev/smash/issues/40>`__.

Stop the execution of smash when ``start_time`` is equal to ``end_time``
************************************************************************

When ``start_time`` is equal to ``end_time``, the code crashes during the data reading with no obvious reason. Now just stop the code execution and return an error when this case occurs.

See issue `#41 <https://github.com/DassHydro-dev/smash/issues/41>`__.
4 changes: 2 additions & 2 deletions smash/core/_build_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ def _standardize_setup(setup: SetupDT):
except:
raise ValueError("argument end_time is not a valid date")

if (et - st).total_seconds() < 0:
if (et - st).total_seconds() <= 0:
raise ValueError(
"argument end_time corresponds to an earlier date than start_time"
"argument end_time is a date earlier to or equal to argument start_time"
)

if setup.read_qobs and setup.qobs_directory == "...":
Expand Down
18 changes: 11 additions & 7 deletions smash/tools/raster_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def gdal_raster_open(filename):
--------
dataset = gdal_raster_open("filename")
"""

if os.path.isfile(filename):
dataset = gdal.Open(filename)
else:
Expand Down Expand Up @@ -146,10 +146,14 @@ def gdal_reproject_raster(dataset, xres, yres):
# Workaround for gdal bug which initialise array to 0 instead as the No_Data value
# Here we initialise the band manually with the nodata_value
nodata = dataset.GetRasterBand(1).GetNoDataValue()
if not isinstance(nodata, float):
nodata = -99.0

band = virtual_destination.GetRasterBand(
1
) # Notice that band is a pointer to virtual_destination
band.SetNoDataValue(nodata)
band.SetNoDataValue(nodata) # nodata argument of type 'double'

nodataarray = np.ndarray(shape=(new_y_size, new_x_size))
nodataarray.fill(nodata)
band.WriteArray(nodataarray)
Expand Down Expand Up @@ -391,7 +395,7 @@ def union_bbox(bbox1, bbox2):
----------
bbox1: dict containin the first bbox informations
bbox2 : dict containin the second bbox informations
returns
-------
dic containing the bbox union
Expand Down Expand Up @@ -419,7 +423,7 @@ def get_bbox(dataset):
Parameters
----------
dataset: gdal object
returns
-------
dic containing the bbox of the dataset
Expand Down Expand Up @@ -447,7 +451,7 @@ def get_bbox_from_window(dataset, window):
----------
dataset: gdal object
window : dict with ncol, nrow, col offset and row offset
returns
-------
dic containing the computed bbox
Expand Down Expand Up @@ -478,7 +482,7 @@ def get_window_from_bbox(dataset, bbox):
----------
dataset: gdal object
bbox : dict containing the bbox
returns
-------
dic containing the computed windows
Expand Down Expand Up @@ -521,7 +525,7 @@ def crop_array(array, window):
----------
array: numpy array
window : dict containg the window to crop
returns
-------
crop_array: the cropped numpy array, shape of the defined window
Expand Down

0 comments on commit ce96802

Please sign in to comment.