ghislainv / deforisk-qgis-plugin

📦 🐍 🌎 deforisk QGis plugin for creating and comparing risk maps of deforestation in the tropics
https://deforisk-qgis-plugin.org
GNU General Public License v3.0
1 stars 0 forks source link

Running on PERU aoi: time analysis + issues #5

Open thomasarsouze opened 3 weeks ago

thomasarsouze commented 3 weeks ago

I've been running deforisk on the PERU aoi:

Traceback (most recent call last): File "/Users/arsouze/miniconda3/envs/deforisk/lib/python3.12/site-packages/riskmapjnr/dist_edge_threshold.py", line 346, in dist_edge_threshold index_thresh = np.nonzero(res_df["perc"].values > defor_threshold)[0][0]


IndexError: index 0 is out of bounds for axis 0 with size 0

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/arsouze/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/deforisk-qgis-plugin-main/rmj_functions/bm_calibrate.py", line 286, in finished
    raise self.exception
  File "/Users/arsouze/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/deforisk-qgis-plugin-main/rmj_functions/bm_calibrate.py", line 124, in run
    dist_thresh = rmj.dist_edge_threshold(
                  ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/arsouze/miniconda3/envs/deforisk/lib/python3.12/site-packages/riskmapjnr/dist_edge_threshold.py", line 348, in dist_edge_threshold
    raise ValueError("Increase maximal distance "
ValueError: Increase maximal distance defined in argument 'dist_bins'.
```

If I modify `max dist = 6000` then it runs fine (crashed at 5000)

  - For forecast / validation, I ran into the following bug after ~15mn:
```
ValueError: Length of values (477) does not match length of index (471) 
Traceback (most recent call last):
  File "/Users/arsouze/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/deforisk-qgis-plugin-main/rmj_functions/bm_predict.py", line 259, in finished
    raise self.exception
  File "/Users/arsouze/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/deforisk-qgis-plugin-main/rmj_functions/bm_predict.py", line 178, in run
    rmj.benchmark.defrate_per_class(
  File "/Users/arsouze/miniconda3/envs/deforisk/lib/python3.12/site-packages/riskmapjnr/benchmark/defrate_per_class.py", line 136, in defrate_per_class
    df["rate_mod"] = (df_mod["ndefor"] / df_mod["nfor"]).values
    ~~^^^^^^^^^^^^
  File "/Users/arsouze/miniconda3/envs/deforisk/lib/python3.12/site-packages/pandas/core/frame.py", line 4311, in __setitem__
    self._set_item(key, value)
  File "/Users/arsouze/miniconda3/envs/deforisk/lib/python3.12/site-packages/pandas/core/frame.py", line 4524, in _set_item
    value, refs = self._sanitize_column(value)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/arsouze/miniconda3/envs/deforisk/lib/python3.12/site-packages/pandas/core/frame.py", line 5266, in _sanitize_column
    com.require_length_match(value, self.index)
  File "/Users/arsouze/miniconda3/envs/deforisk/lib/python3.12/site-packages/pandas/core/common.py", line 573, in require_length_match
    raise ValueError(
ValueError: Length of values (477) does not match length of index (471)
```

- FAR models:
The Fit model to data run crashes for historical period with :
```
              File "/Users/arsouze/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/deforisk-qgis-plugin-main/far_functions/far_calibrate.py", line 373, in finished
              raise self.exception
              File "/Users/arsouze/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/deforisk-qgis-plugin-main/far_functions/far_calibrate.py", line 96, in run
              dataset = pd.read_csv(dataset_file)
              ^^^^^^^^^^^^^^^^^^^^^^^^^
              File "/Users/arsouze/miniconda3/envs/deforisk/lib/python3.12/site-packages/pandas/io/parsers/readers.py", line 1026, in read_csv
              return _read(filepath_or_buffer, kwds)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
              File "/Users/arsouze/miniconda3/envs/deforisk/lib/python3.12/site-packages/pandas/io/parsers/readers.py", line 626, in _read
              return parser.read(nrows)
              ^^^^^^^^^^^^^^^^^^
              File "/Users/arsouze/miniconda3/envs/deforisk/lib/python3.12/site-packages/pandas/io/parsers/readers.py", line 1923, in read
              ) = self._engine.read( # type: ignore[attr-defined]
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
              File "/Users/arsouze/miniconda3/envs/deforisk/lib/python3.12/site-packages/pandas/io/parsers/c_parser_wrapper.py", line 234, in read
              chunks = self._reader.read_low_memory(nrows)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
              File "parsers.pyx", line 838, in pandas._libs.parsers.TextReader.read_low_memory
              File "parsers.pyx", line 905, in pandas._libs.parsers.TextReader._read_rows
              File "parsers.pyx", line 874, in pandas._libs.parsers.TextReader._tokenize_rows
              File "parsers.pyx", line 891, in pandas._libs.parsers.TextReader._check_tokenize_status
              File "parsers.pyx", line 2061, in pandas._libs.parsers.raise_parser_error
             pandas.errors.ParserError: Error tokenizing data. C error: Expected 11 fields in line 1001, saw 15
```

Next steps are ongoing... but it takes a lot of time.
ghislainv commented 3 weeks ago

Hi @thomasarsouze . Thanks for the feedback. I am not surprised it takes time for the computation. Could you prepare a zip file for data on Peru that I could download will the following folders:

Thanks.

thomasarsouze commented 3 weeks ago

Sure... sending link by mail.

ghislainv commented 3 weeks ago

Thanks @thomasarsouze .

First error: Yes, for big countries and long time-periods, it might be necessary to increase maximal distance defined in argument 'dist_bins'. We should indicate this in the documentation.

Second error: thanks to your feedback I corrected a bug in the riskmapjnr.benchmark.defrate_per_class() function (see commit db79e71). Indeed some risk classes might not exist in the future as forest is disappearing. I had the same problem while running the plugin on Guatemala. Now it should be OK.

Third error for fitting FAR models on the historical period. I am not able to reproduce the error yet. Note that for large model, spatial cell size in sample should be set at 10km resolution to avoid estimating too many parameters. Maybe that's why you got some problems for calibrating the model for Peru with the default plugin parameters used in the Get Started tuto.

I do not close until we change doc for error 1 and fix the issue for error 3.