Skip to content

Commit

Permalink
Merge pull request #154 from LabSid-USP/112-check-the-need-to-have-th…
Browse files Browse the repository at this point in the history
…e-dem-raster-in-two-formats-pcraster-map-and-geotiff

Remove DEM raster (GeoTIFF) from simulation configuration and model report
  • Loading branch information
soaressgabriel authored Feb 26, 2024
2 parents 4bd7ee8 + 223bfb1 commit b6a6f33
Show file tree
Hide file tree
Showing 16 changed files with 98 additions and 170 deletions.
19 changes: 0 additions & 19 deletions doc/source/fileformats.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,6 @@ This file is the result of pre-processing the corresponding TIFF/GeoTIFF raster
- Columns = :ref:`clone columns<fileformats:Mask of Catchment (Clone) raster>`;
- Cell Size = :ref:`clone cell size<fileformats:Mask of Catchment (Clone) raster>`.

Digital Elevation Map (DEM) raster (TIFF)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

- Filetype: TIFF :file:`*.tif` raster file.
- Unit: `Meters Above Sea Level (MASL) <https://wiki.gis.com/wiki/index.php/Meters_above_sea_level>`_
- Valid Range: :math:`[-100.0, 10000.0]`
- Restrictions:

- ``PCRASTER_VALUESCALE`` = ``VS_SCALAR``;
- None of the pixels in the raster must contain ``NO_DATA`` value;
- Raster pixels cannot consist entirely of ``1.0`` values;
- Raster pixels cannot consist entirely of ``0.0`` values.

- Dimensions:

- Rows = :ref:`clone rows <fileformats:Mask of Catchment (Clone) raster>`;
- Columns = :ref:`clone columns<fileformats:Mask of Catchment (Clone) raster>`;
- Cell Size = :ref:`clone cell size<fileformats:Mask of Catchment (Clone) raster>`.


Local Drain Direction (LDD) raster
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
6 changes: 0 additions & 6 deletions doc/source/tutorials.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ In the part ``Grid`` set 500.000 m as size value and in the part Simulation Peri
[RASTERS]
dem = /Iguazu/input/maps/dem/dem.map
demtif = /Iguazu/input/maps/dem/dem.tif
clone = /Iguazu/input/maps/clone/clone.map
samples = /Iguazu/maps/stations/samples.map
Expand Down Expand Up @@ -109,7 +108,6 @@ Set the following values for ``Initial Soil Conditions`` fields:
[RASTERS]
dem = /Iguazu/input/maps/dem/dem.map
demtif = /Iguazu/input/maps/dem/dem.tif
clone = /Iguazu/input/maps/clone/clone.map
samples = /Iguazu/maps/stations/samples.map
soil = /Iguazu/input/maps/soil/soil.map
Expand Down Expand Up @@ -174,7 +172,6 @@ Use the default values for ``FPAR``, ``LAI`` and ``Impervious Area Interception`
[RASTERS]
dem = /Iguazu/input/maps/dem/dem.map
demtif = /Iguazu/input/maps/dem/dem.tif
clone = /Iguazu/input/maps/clone/clone.map
samples = /Iguazu/maps/stations/samples.map
soil = /Iguazu/input/maps/soil/soil.map
Expand Down Expand Up @@ -243,7 +240,6 @@ In the ``Climate`` section define the appropriate map-series from :file:`/input/
[RASTERS]
dem = /Iguazu/input/maps/dem/dem.map
demtif = /Iguazu/input/maps/dem/dem.tif
clone = /Iguazu/input/maps/clone/clone.map
samples = /Iguazu/maps/stations/samples.map
soil = /Iguazu/input/maps/soil/soil.map
Expand Down Expand Up @@ -335,7 +331,6 @@ Values in this tab correspond to calibrated parameters in the basin. For the dat
[RASTERS]
dem = /Iguazu/input/maps/dem/dem.map
demtif = /Iguazu/input/maps/dem/dem.tif
clone = /Iguazu/input/maps/clone/clone.map
samples = /Iguazu/maps/stations/samples.map
soil = /Iguazu/input/maps/soil/soil.map
Expand Down Expand Up @@ -420,7 +415,6 @@ The complete project configuration file should look like this:
[RASTERS]
dem = /Iguazu/input/maps/dem/dem.map
demtif = /Iguazu/input/maps/dem/dem.tif
clone = /Iguazu/input/maps/clone/clone.map
samples = /Iguazu/maps/stations/samples.map
soil = /Iguazu/input/maps/soil/soil.map
Expand Down
14 changes: 1 addition & 13 deletions doc/source/userguide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,13 @@ Mandatory path to the output folder. Must be a valid path to an existing **empty
Digital Elevation Map (DEM)
```````````````````````````

Mandatory path to Digital Elevation Map (DEM) file `[masl] <https://wiki.gis.com/wiki/index.php/Meters_above_sea_level>`_ in:

* **PCRaster map format** :file:`*.map`: this map contains topographic ground elevation in meters. Must be a valid file path to a PCRaster map format :file:`*.map` file. :ref:`See more. <fileformats:Digital Elevation Map (DEM) raster>`
Mandatory path to Digital Elevation Map (DEM) file `[masl] <https://wiki.gis.com/wiki/index.php/Meters_above_sea_level>`_ in PCRaster map format :file:`*.map`: this map contains topographic ground elevation in meters. Must be a valid file path to a PCRaster map format :file:`*.map` file. :ref:`See more. <fileformats:Digital Elevation Map (DEM) raster>`

.. code-block:: dosini
[RASTERS]
dem = /Dataset/UIGCRB/input/maps/dem/dem.map
-------

* **TIF format** :file:`*.tif`: this map contains topographic ground elevation in meters. Must be a valid file path to a TIF :file:`*.tif` raster file. :ref:`See more. <fileformats:Digital Elevation Map (DEM) raster (TIFF)>`

.. code-block:: dosini
[RASTERS]
demtif = /Dataset/UIGCRB/input/maps/dem/dem.tif
Mask of Catchment (Clone)
``````````````````````````

Expand Down Expand Up @@ -808,7 +797,6 @@ Configuration File Template
[RASTERS]
dem = /Dataset/UIRB/input/maps/dem/dem.map
demtif = /Dataset/UIRB/input/maps/dem/dem.tif
clone = /Dataset/UIRB/input/maps/clone/clone.map
ndvi_max = /Dataset/UIRB/input/maps/ndvi/ndvi_max.map
ndvi_min = /Dataset/UIRB/input/maps/ndvi/ndvi_min.map
Expand Down
27 changes: 8 additions & 19 deletions rubem/_dynamic_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,6 @@ def __init__(self, config: ModelConfiguration):
self.logger.info("Obtaining grid cell area...")
self.A = self.config.grid.area

self.logger.debug("Reading DEM reference file...")
try:
self.ref = getRefInfo(self.config.raster_files.demtif)
except RuntimeError:
self.logger.error(
"Error reading Digital Elevation Model (DEM) file at '%s'",
self.config.raster_files.demtif,
)
raise

self.__getEnabledOutputVars()

def __getEnabledOutputVars(self):
Expand Down Expand Up @@ -80,19 +70,18 @@ def __stepReport(self):

# Export TIFF raster series
if self.config.output_variables.file_format is OutputFileFormat.GEOTIFF:
reportTIFFSeries(
self,
self.ref,
self.outputVarsDict.get(outputVar),
outputVar,
self.config.output_directory.path,
self.currentStep,
dyn=True,
report(
variable=self.outputVarsDict.get(outputVar),
name=outputVar,
timestep=self.currentStep,
outpath=self.config.output_directory.path,
format=OutputFileFormat.GEOTIFF,
base_raster_info=self.config.output_raster_base,
)

# Export PCRaster map format raster series
if self.config.output_variables.file_format is OutputFileFormat.PCRASTER:
self.report(self.outputVarsDict.get(outputVar), outputVar)
self.report(variable=self.outputVarsDict.get(outputVar), name=outputVar)

# Check if we have to export the time series of the selected
# variable (fileName)
Expand Down
13 changes: 0 additions & 13 deletions rubem/configuration/input_raster_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ class InputRasterFiles:
:param dem: Path to the DEM file (*.map format).
:type dem: Union[str, bytes, os.PathLike]
:param demtif: Path to the DEM file (*.tif format).
:type demtif: Union[str, bytes, os.PathLike]
:param clone: Path to the mask of catchment (clone) file.
:type clone: Union[str, bytes, os.PathLike]
Expand Down Expand Up @@ -46,7 +43,6 @@ class InputRasterFiles:
def __init__(
self,
dem: Union[str, bytes, os.PathLike],
demtif: Union[str, bytes, os.PathLike],
clone: Union[str, bytes, os.PathLike],
ndvi_max: Union[str, bytes, os.PathLike],
ndvi_min: Union[str, bytes, os.PathLike],
Expand All @@ -59,7 +55,6 @@ def __init__(
self.__ranges = DataRangesSettings()

self.dem = dem
self.demtif = demtif
self.clone = clone
self.ndvi_max = ndvi_max
self.ndvi_min = ndvi_min
Expand All @@ -81,13 +76,6 @@ def __validate_files(self) -> None:
| RasterDataRules.FORBID_ALL_ZEROES
| RasterDataRules.FORBID_ALL_ONES,
),
(
self.demtif,
self.__ranges.rasters["dem"],
RasterDataRules.FORBID_NO_DATA
| RasterDataRules.FORBID_ALL_ZEROES
| RasterDataRules.FORBID_ALL_ONES,
),
(self.clone, self.__ranges.rasters["clone"], RasterDataRules.FORBID_ALL_ZEROES),
(self.ndvi_max, self.__ranges.rasters["ndvi"], RasterDataRules.FORBID_NO_DATA),
(self.ndvi_min, self.__ranges.rasters["ndvi"], RasterDataRules.FORBID_NO_DATA),
Expand Down Expand Up @@ -131,7 +119,6 @@ def __validate_files(self) -> None:
def __str__(self) -> str:
return (
f"DEM (PCRaster Map): {self.dem}\n"
f"DEM (GeoTIFF Map): {self.demtif}\n"
f"Mask of Catchment (Clone): {self.clone}\n"
f"Local Drain Direction (LDD): {self.ldd if self.ldd else 'Not specified.'}\n"
f"NDVI Max.: {self.ndvi_max}\n"
Expand Down
3 changes: 2 additions & 1 deletion rubem/configuration/model_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from rubem.configuration.model_constants import ModelConstants
from rubem.configuration.output_data_directory import OutputDataDirectory
from rubem.configuration.output_format import OutputFileFormat
from rubem.configuration.output_raster_base import OutputRasterBase
from rubem.configuration.output_variables import OutputVariables
from rubem.configuration.raster_grid_area import RasterGrid
from rubem.configuration.simulation_period import SimulationPeriod
Expand Down Expand Up @@ -134,7 +135,6 @@ def __init__(
)
self.raster_files = InputRasterFiles(
dem=self.__get_setting("RASTERS", "dem"),
demtif=self.__get_setting("RASTERS", "demtif"),
clone=self.__get_setting("RASTERS", "clone"),
ndvi_max=self.__get_setting("RASTERS", "ndvi_max"),
ndvi_min=self.__get_setting("RASTERS", "ndvi_min"),
Expand All @@ -160,6 +160,7 @@ def __init__(
kc_max=self.__get_setting("TABLES", "k_c_max"),
validate_input=validate_input,
)
self.output_raster_base = OutputRasterBase(base_raster_path=self.raster_files.dem)
except Exception as e:
self.logger.error("Failed to load configuration: %s", e)
raise
Expand Down
15 changes: 15 additions & 0 deletions rubem/configuration/output_raster_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import logging
import os
from typing import Union

from rubem.configuration.raster_map import RasterMap


class OutputRasterBase:
def __init__(self, base_raster_path: Union[str, bytes, os.PathLike]):
self.logger = logging.getLogger(__name__)
base_raster = RasterMap(base_raster_path)
self.cols = base_raster.raster.RasterXSize
self.rows = base_raster.raster.RasterYSize
self.transformation = base_raster.raster.GetGeoTransform()
base_raster = None
Loading

0 comments on commit b6a6f33

Please sign in to comment.