Skip to content

Commit

Permalink
Remove checks that are no longer needed and remove duplicate definiti…
Browse files Browse the repository at this point in the history
…on of raster_columns
  • Loading branch information
margrietpalm committed Jan 3, 2025
1 parent 37394e2 commit 2382deb
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 112 deletions.
26 changes: 0 additions & 26 deletions threedi_modelchecker/checks/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,32 +141,6 @@ def description(self):
return f"The file in {self.column_name} has multiple or no bands."


class RasterHasProjectionCheck(BaseRasterCheck):
"""Check whether a raster has a projected coordinate system."""

def is_valid(self, path: str, interface_cls: Type[RasterInterface]):
with interface_cls(path) as raster:
if not raster.is_valid_geotiff:
return True
return raster.has_projection

def description(self):
return f"The file in {self.column_name} has no CRS."


class RasterIsProjectedCheck(BaseRasterCheck):
"""Check whether a raster has a projected coordinate system."""

def is_valid(self, path: str, interface_cls: Type[RasterInterface]):
with interface_cls(path) as raster:
if not raster.is_valid_geotiff or not raster.has_projection:
return True
return not raster.is_geographic

def description(self):
return f"The file in {self.column_name} does not use a projected CRS."


class RasterHasMatchingEPSGCheck(BaseRasterCheck):
"""Check whether a raster's EPSG code matches the EPSG code in the global settings for the SQLite."""

Expand Down
38 changes: 1 addition & 37 deletions threedi_modelchecker/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@
RasterExistsCheck,
RasterGridSizeCheck,
RasterHasOneBandCheck,
RasterHasProjectionCheck,
RasterIsProjectedCheck,
RasterIsValidCheck,
RasterPixelCountCheck,
RasterRangeCheck,
Expand Down Expand Up @@ -2363,17 +2361,6 @@ def is_none_or_empty(col):
for i, column in enumerate(RASTER_COLUMNS)
]
CHECKS += [
RasterHasProjectionCheck(
error_code=761 + i,
column=column,
)
for i, column in enumerate(RASTER_COLUMNS)
]
CHECKS += [
RasterIsProjectedCheck(
error_code=779,
column=models.ModelSettings.dem_file,
),
RasterSquareCellsCheck(
error_code=780,
column=models.ModelSettings.dem_file,
Expand Down Expand Up @@ -3471,29 +3458,6 @@ def is_none_or_empty(col):

unique_columns = [models.BoundaryCondition1D.connection_node_id]

raster_columns = [
models.ModelSettings.dem_file,
models.GroundWater.equilibrium_infiltration_rate_file,
models.ModelSettings.friction_coefficient_file,
models.InitialConditions.initial_groundwater_level_file,
models.InitialConditions.initial_water_level_file,
models.GroundWater.groundwater_hydraulic_conductivity_file,
models.GroundWater.groundwater_impervious_layer_level_file,
models.GroundWater.infiltration_decay_period_file,
models.GroundWater.initial_infiltration_rate_file,
models.GroundWater.leakage_file,
models.GroundWater.phreatic_storage_capacity_file,
models.Interflow.hydraulic_conductivity_file,
models.Interflow.porosity_file,
models.SimpleInfiltration.infiltration_rate_file,
models.SimpleInfiltration.max_infiltration_volume_file,
models.Interception.interception_file,
models.VegetationDrag.vegetation_height_file,
models.VegetationDrag.vegetation_stem_count_file,
models.VegetationDrag.vegetation_stem_diameter_file,
models.VegetationDrag.vegetation_drag_coefficient_file,
]


class Config:
"""Collection of checks
Expand Down Expand Up @@ -3558,7 +3522,7 @@ def generate_checks(self):
]
self.checks += generate_epsg_geom_checks(model.__table__, error_code=9)
self.checks += generate_epsg_raster_checks(
model.__table__, raster_columns, error_code=10
model.__table__, RASTER_COLUMNS, error_code=10
)

self.checks += CHECKS
Expand Down
4 changes: 2 additions & 2 deletions threedi_modelchecker/model_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from .checks.base import BaseCheck, CheckLevel
from .checks.raster import LocalContext, ServerContext
from .config import Config, raster_columns
from .config import Config, RASTER_COLUMNS

__all__ = ["ThreediModelChecker"]

Expand All @@ -27,7 +27,7 @@ def get_epsg_data(session) -> Tuple[int, str]:
raster_interface = context.raster_interface if context is not None else None
if raster_interface is None:
return None, ""
for raster in raster_columns:
for raster in RASTER_COLUMNS:
raster_files = (
session.query(raster).filter(raster != None, raster != "").first()
)
Expand Down
47 changes: 0 additions & 47 deletions threedi_modelchecker/tests/test_checks_raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
RasterGridSizeCheck,
RasterHasMatchingEPSGCheck,
RasterHasOneBandCheck,
RasterHasProjectionCheck,
RasterIsProjectedCheck,
RasterIsValidCheck,
RasterPixelCountCheck,
RasterRangeCheck,
Expand Down Expand Up @@ -230,23 +228,6 @@ def test_one_band_err(tmp_path, interface_cls):
assert not check.is_valid(path, interface_cls)


@pytest.mark.parametrize(
"interface_cls", [GDALRasterInterface, RasterIORasterInterface]
)
def test_has_projection_ok(valid_geotiff, interface_cls):
check = RasterHasProjectionCheck(column=models.ModelSettings.dem_file)
assert check.is_valid(valid_geotiff, interface_cls)


@pytest.mark.parametrize(
"interface_cls", [GDALRasterInterface, RasterIORasterInterface]
)
def test_has_projection_err(tmp_path, interface_cls):
path = create_geotiff(tmp_path / "raster.tiff", epsg=None)
check = RasterHasProjectionCheck(column=models.ModelSettings.dem_file)
assert not check.is_valid(path, interface_cls)


NULL_EPSG_CODE = (
'PROJCS["unnamed",GEOGCS["GRS 1980(IUGG, 1980)"'
+ ',DATUM["unknown",SPHEROID["GRS80",6378137,298.257222101]],'
Expand Down Expand Up @@ -277,32 +258,6 @@ def test_has_epsg(tmp_path, interface_cls, raster_epsg, sqlite_epsg, validity):
assert check.is_valid(path, interface_cls) == validity


@pytest.mark.parametrize(
"interface_cls", [GDALRasterInterface, RasterIORasterInterface]
)
def test_is_projected_ok(valid_geotiff, interface_cls):
check = RasterIsProjectedCheck(column=models.ModelSettings.dem_file)
assert check.is_valid(valid_geotiff, interface_cls)


@pytest.mark.parametrize(
"interface_cls", [GDALRasterInterface, RasterIORasterInterface]
)
def test_is_projected_err(tmp_path, interface_cls):
path = create_geotiff(tmp_path / "raster.tiff", epsg=4326)
check = RasterIsProjectedCheck(column=models.ModelSettings.dem_file)
assert not check.is_valid(path, interface_cls)


@pytest.mark.parametrize(
"interface_cls", [GDALRasterInterface, RasterIORasterInterface]
)
def test_is_projected_no_projection(tmp_path, interface_cls):
path = create_geotiff(tmp_path / "raster.tiff", epsg=None)
check = RasterIsProjectedCheck(column=models.ModelSettings.dem_file)
assert check.is_valid(path, interface_cls)


@pytest.mark.parametrize(
"interface_cls", [GDALRasterInterface, RasterIORasterInterface]
)
Expand Down Expand Up @@ -426,9 +381,7 @@ def test_raster_range_no_data(tmp_path, interface_cls):
"check",
[
RasterHasOneBandCheck(column=models.ModelSettings.dem_file),
RasterHasProjectionCheck(column=models.ModelSettings.dem_file),
RasterHasMatchingEPSGCheck(column=models.ModelSettings.dem_file),
RasterIsProjectedCheck(column=models.ModelSettings.dem_file),
RasterSquareCellsCheck(column=models.ModelSettings.dem_file),
RasterGridSizeCheck(column=models.ModelSettings.dem_file),
RasterRangeCheck(column=models.ModelSettings.dem_file, min_value=0),
Expand Down

0 comments on commit 2382deb

Please sign in to comment.