inbo / niche_vlaanderen

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

Output Niche model: split category "not present" into 2 categories #263

Closed cecileherr closed 1 year ago

cecileherr commented 4 years ago

Niche Python Package feature request: add an extra category to the results of a (full or simple) NICHE model (model_Vxx.tif):

It would be useful to split the category "not present" into 2 categories:

DriesAdriaens commented 4 years ago

Additionally, it would be fine if we could explicitely choose to have a more detailed legend for the output of a full/simple NICHE model by specifying an extra parameter (e.g. legend = extended) in the plot, write or zonal.stats statements.

For a simple model (i.e. only checking against reference values for soil type and groundwater levels; parameter full_model = false), the current value 0 "not present" should indeed be split up into "soil type unsuitable" and "groundwater levels unsuitable". For a full model, the value 0 "not present" should be split up into "soil type unsuitable" and "any other abiotic input unsuitable" since besides the soil type and groundwater levels also nutrient_level or acidity, and eventually management and inundation regime could be limiting site suitability for a vegetation type.

johanvdw commented 4 years ago

I think you would need 5 types rather than 4. Here is a suggestion:

-99 no data 1: present -1: soil type unsuitable -2: groundwater unsuitable -3: both unsuitable

For backwards compatibility, I would keep using 1 for presence.

johanvdw commented 4 years ago

full model: split out also nutrient_level and acidity

johanvdw commented 4 years ago

Given the way niche works, it is impossible that both soil type and groundwater are unsuitable. So internally I would store this as:

-99 no data 0 not present 1 soil suitable 2 groundwater & soil suitable 4: nutrient_level suitable (only possible if soil&groundwater are suitable) 8: acidity suitable (only possible if soil&groundwater are suitable) 16: management suitable (only possible if soil&groundwater are suitable) 32: flooding suitable (only possible if soil&groundwater are suitable)

That way we can filter out places where everything is suitable by checking they match 1+2+4+8+16+32=63 .

This also allows us checking out the individual options using binary operators.

johanvdw commented 4 years ago

I have now added the above functionality. full.plot_detail(11) (instead of full.plot) you get:

image

This shows when vegetation is possible, given the different contstraints.

johanvdw commented 4 years ago

todo: add 'suitable' to the legend where appropriate

johanvdw commented 4 years ago

todo: always show all possible options in legend

johanvdw commented 2 years ago

This is what I currently have: image image

Not sure what the best colorscheme would be.

cecileherr commented 2 years ago

@johanvdw Could you please check what goes wrong with the legend in the example below? I noticed that the legend is not always in agreement with the map (until now only when I use inundation_vegetation/management_vegetation --- UPDATE 9/11: no, the problem seems to be present in simple models too. I found an example with code 1 in simple legend = code 3 in detailed legend + a wrong legend ("soil suitable" instead of "soil+gxg suitable"). ---

Example with testcase zwarte_beek:

import niche_vlaanderen as nv

full = nv.Niche()
path = "testcase/zwarte_beek/input/" 
full.set_input("mhw", path + "mhw.asc")
full.set_input("mlw", path + "mlw.asc")
full.set_input("msw", path + "msw.asc")
full.set_input("soil_code",path + "soil_code.asc")
full.set_input("nitrogen_animal", 0)
full.set_input("nitrogen_fertilizer", 0)
full.set_input("management", path + "management.asc")
full.set_input("nitrogen_atmospheric", path + "nitrogen_atmospheric.asc")
full.set_input("inundation_acidity", 0)
full.set_input("inundation_nutrient", 0)
full.set_input("rainwater", 0) 
full.set_input("seepage", 0)
full.set_input("minerality", path + "minerality.asc")
full.set_input("management_vegetation", path + "management.asc")
full.set_input("inundation_vegetation", 2)
full.run(strict_checks=False)
full

%matplotlib inline
import matplotlib.pyplot as plt
ax = full.plot_detail(14, limit_legend=True) #problem: 4 categories in map and legend, but mismatch

#and compare this to the exported file for type 14: contains 5 categories: 1, 7, 15, 23, 31
full.write("output", overwrite_files=True,  detailed_files=True)
cecileherr commented 2 years ago

And a request regarding the legend:

cecileherr commented 2 years ago

A minor problem concerning the log file produced with simple.write(detailed_files=True):

The file mentions:

files_written:
  1: output\V01.tif
(...)
01_detail: output\V01_detail.tif
(..)

But as far as I can see, there is no V01_detail.tif exported: only V01.tif with detailed categories (which is OK). The log file should probably be corrected by dropping:

01_detail: output\V01_detail.tif
(..)
cecileherr commented 1 year ago

Could you please also check the symbology for the simple version of the plot (e.g. mymodel.plot(00))? I have the impression that the color scale gets expanded (and gives more than 2 shades)

Here is an example:

Too_many_shades_instead_of_01

And when I export the result for vegetation 22 I get this:

Export_22