nens / threedi-api-qgis-client

3Di Models & Simulations plugin
https://plugins.lizard.net/
Other
2 stars 0 forks source link

Simulation Wizard: rainfall netcdf timeseries is cleared before attempting to read it (TOPDESK 2310 0176) #510

Closed PySjon closed 7 months ago

PySjon commented 9 months ago

When uploading a rainfall netcdf in the 3Di simulation wizard, for example the timeseries_example.nc from the 3Di docs (https://api.3di.live/v3.0/docs/netcdf_specification/), the wizard checks to see if the time series intervals are even.

It then gives an IndexError right away: IndexError: list index out of range

Press Simulate in 3Di modeller interface, and add custom rainfall based on a NETCDF. Then when loading it in, it gives the error.

I expected for the .nc file to be proparly read, instead it gives an error.

The maximum size for files is 25MB and the maximum size for images is 10MB. timeseries_example.zip

2023-11-08T09:17:14     WARNING    Traceback (most recent call last):
              File "C:\Users\sjon.vandijk\AppData\Roaming\3Di\QGIS3\profiles\3Di/python/plugins\threedi_models_and_simulations\widgets\simulation_wizard.py", line 1297, in set_custom_time_series
              if not intervals_are_even(time_series):
              File "C:\Users\sjon.vandijk\AppData\Roaming\3Di\QGIS3\profiles\3Di/python/plugins\threedi_models_and_simulations\utils.py", line 254, in intervals_are_even
              expected_interval = time_series[1][0] - time_series[0][0]
             IndexError: list index out of range

simulation_wizard.py (line 1285) clears the time_series variable, before checking for it to have even intervals:

time_series = []
        simulation = self.dd_simulation.currentText()
        if from_csv:
            with open(filename, encoding="utf-8-sig") as rain_file:
                rain_reader = csv.reader(rain_file)
                units_multiplier = self.SECONDS_MULTIPLIERS["mins"]
                for rtime, rain in rain_reader:
                    # We are assuming that timestep is in minutes, so we are converting it to seconds on the fly.
                    try:
                        time_series.append([float(rtime) * units_multiplier, float(rain)])
                    except ValueError:
                        continue
        if not intervals_are_even(time_series):
PySjon commented 9 months ago

Servicedesk: 2310 0176

leendertvanwolfswinkel commented 8 months ago

@ldebek please merge