Skip to content

Commit

Permalink
Fix issue when soilcode is a float
Browse files Browse the repository at this point in the history
  • Loading branch information
johanvdw committed Apr 17, 2024
1 parent 123c5da commit 9ee94fa
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions niche_vlaanderen/niche.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,15 +439,19 @@ def _check_input_files(self, full_model):
):
band = band.astype("float32")

# convert old soil codes to new soil codes
if f == "soil_code" and np.all(band[band != nodata] >= 10000):
band[band != nodata] = np.round(band[band != nodata] / 10000)

# create a mask for no-data values, taking into account data-types
if band.dtype == "float32" and nodata is not None:
band[np.isclose(band, nodata)] = np.nan
band[np.isclose(nodata, band)] = np.nan
else:
band[band == nodata] = -99

# convert old soil codes to new soil codes
if f == "soil_code" and np.all((band >= 10000)|(band==-99)|np.isnan(band)):
band[band>=10000] = np.round(band[band>=10000] / 10000)

if f == "soil_code" and band.dtype == "float32":
band[np.isnan(band)] = -99
band = band.astype(int)

inputarray[f] = band

Expand Down

0 comments on commit 9ee94fa

Please sign in to comment.