inbo / niche_vlaanderen

Python package to run the NICHE Vlaanderen model
https://inbo.github.io/niche_vlaanderen/
MIT License
5 stars 0 forks source link

Use rasters with a different extent - problem with Float32 tifs #335

Closed cecileherr closed 2 months ago

cecileherr commented 1 year ago

Expected behaviour: if there is a NoData in any input raster for a given pixel, the output should be NoData

This works (nodata in any input raster gives nodata in output)

standard_path = "../testcase/zwarte_beek/input/"
simple = nv.Niche()
simple.set_input("mhw", standard_path + "mhw.asc")
simple.set_input("mlw", standard_path + "mlw.asc")
simple.set_input("soil_code", standard_path + "soil_smallerextent.tif") #Signed integer 32 bit with NoData = -2147483647
simple.run(strict_checks=False, full_model=False)
simple

ax = simple.plot(14)

This doesn't work (NoData in soil map becomes no potential)

standard_path = "../testcase/zwarte_beek/input/"
simple = nv.Niche()
simple.set_input("mhw", standard_path + "mhw.asc")
simple.set_input("mlw", standard_path  + "mlw.asc")
simple.set_input("soil_code", standard_path + "soil_smallerextent_float.tif") #Float32 
simple.run(strict_checks=False, full_model=False)
simple

ax = simple.plot(14)

soil_smallerextent.zip

Is there something we can do about it? Or should we add a warning (avoid Float), at least in the documentation?

cecileherr commented 1 year ago

FYI: for most of the input layers, we should be able to work with Int format. Seepage and nitrogen_atmospheric are layers that as Float could come

johanvdw commented 1 year ago

I can not reproduce this locally. Can you show which versions of rasterio and gdal you use. If you just type simple after running the code above, this should be reported. Eg:

# Niche Vlaanderen version: 1.2b1
# Newer niche_vlaanderen  1.2b2 available
# Run at: 2023-03-08 12:40:22.688925

package_versions:
  pandas: 1.4.0
  numpy: 1.22.1
  rasterio: 1.3.4
  gdal: 3.5.3
  python: '3.9.2 (default, Feb 28 2021, 17:03:44) 
[GCC 10.2.1 20210110]'

model_options:
  deviation: false
  full_model: false
  name: ''
  strict_checks: false

model_properties:
  model_extent: ((216590.0, 198380.0), (216905.0, 198170.0))

input_layers:
  mhw: ../testcase/zwarte_beek/input/mhw.asc
  mlw: ../testcase/zwarte_beek/input/mlw.asc
  soil_code: ../testcase/zwarte_beek/input/soil_smallerextent.tif
  # Model run completed
cecileherr commented 1 year ago

Running conda list in my niche environment gives me this: gdal 3.5.2 py39h34c8707_1 conda-forge rasterio 1.3.2 py39h223f425_0 conda-forge

johanvdw commented 2 months ago

Some additional testing on windows/linux show the error. No data is correctly parsed on the input layer, but not after calculations.

image

image

stijnvanhoey commented 2 months ago

Fixed by https://github.com/inbo/niche_vlaanderen/pull/371