Skip to content

Commit

Permalink
fix silent zero fill when DEM are missing (#890)
Browse files Browse the repository at this point in the history
* fix silent zero fill when DEM are missing

* some more refactoring

* whats new
  • Loading branch information
fmaussion committed Oct 30, 2019
1 parent f9defc6 commit dadc8d1
Show file tree
Hide file tree
Showing 7 changed files with 295 additions and 322 deletions.
5 changes: 5 additions & 0 deletions docs/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ Enhancements
Bug fixes
~~~~~~~~~

- Small bugs in DEM processing fixed - internal refactoring followed,
hopefully for the good (:pull:`890` and :pull:`886`).
By `Fabien Maussion <https://github.com/fmaussion>`_ and
`Matthias Dusch <https://github.com/matthiasdusch>`_.


v1.1.2 (12.09.2019)
-------------------
Expand Down
9 changes: 3 additions & 6 deletions oggm/cli/prepro_levels.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
import argparse
import time
import logging
import rasterio
import numpy as np
import geopandas as gpd

# Locals
import oggm.cfg as cfg
from oggm import utils, workflow, tasks
from oggm.core import gis
from oggm.exceptions import InvalidParamsError

# Module logger
Expand All @@ -37,17 +37,14 @@ def _rename_dem_folder(gdir, source=''):
# open tif-file to check if it's worth it
dem_f = gdir.get_filepath('dem')
try:
with rasterio.open(dem_f, 'r', driver='GTiff') as dem_ds:
dem = dem_ds.read(1).astype(rasterio.float32)
dem = gis.read_geotiff_dem(gdir)
except IOError:
# No file, no problem - still, delete the file if needed
# Error reading file, no problem - still, delete the file if needed
if os.path.exists(dem_f):
os.remove(dem_f)
return

# Check the DEM
min_z = -999.
dem[dem <= min_z] = np.NaN
isfinite = np.isfinite(dem)
if np.all(~isfinite) or (np.min(dem) == np.max(dem)):
# Remove the file and return
Expand Down
Loading

0 comments on commit dadc8d1

Please sign in to comment.