grass
grass copied to clipboard
Adjustments to t.rast.aggregate - temporally weighted aggregation
Until now, t.rast.aggregate provides diffrent sampling methods to select rasters for each time interval which subsequently are aggregated to the specified granularity using the specified method (in turn being handed over to r.series internally). Unfortunately, the present range of sampling methods only allow for complete in-/exclusion of single rasters during the aggregation procedure. This PR aims at enhancing t.rast.aggregate in a way that allows for weighted aggregations based on weighting factors representing the temporal overlap between the input rasters and the output rasters (see below). Therefore, a new sampling method called "relates" is introduced and a weighting flag (w) defined.
This addition sounds really cool :) Would you mind providing a reproducible example to test it?
To be fixed:
Run flake8 --count --statistics --show-source --jobs=$(nproc) .
./python/grass/temporal/aggregation.py:326:13: E722 do not use bare 'except'
except:
^
./python/grass/temporal/aggregation.py:331:13: E722 do not use bare 'except'
except:
^
./python/grass/temporal/aggregation.py:336:13: E722 do not use bare 'except'
except:
^
./python/grass/temporal/aggregation.py:341:13: E722 do not use bare 'except'
except:
^
./python/grass/temporal/aggregation.py:346:13: E722 do not use bare 'except'
except:
^
5 E722 do not use bare 'except'
5
Error: Process completed with exit code 1.
Hi @wenzeslaus, we finally implemented the requested changes (some code restructuring & commenting, an example in the .html, added a test). Could you re-review? Thanks!
Binder link for anyone who wants to test this.
Binder link for anyone who wants to test this.
After the merge with main, the link does not work. Use this one instead: https://mybinder.org/v2/gh/fkroeber/grass/t.rast.aggregate?urlpath=lab%2Ftree%2Fdoc%2Fnotebooks%2Fbasic_example.ipynb
I tested by adapting the example in the html:
gs.parse_command("g.region", raster="elevation", flags="pg")
for map in range(12):
gs.run_command("r.surf.random", output="map"+"_"+str(map))
gs.run_command("t.create", type="strds", temporaltype="absolute", output="temperature_weekly", title="Weekly Temperature", description="Test dataset with weekly temperature")
gs.run_command("t.register", flags="i", type="raster", input="temperature_weekly", maps="map_0,map_1,map_2,map_3,map_4,map_5,map_6,map_7,map_8,map_9,map_10,map_11", start="2021-05-01", increment="1 weeks")
gs.parse_command("t.rast.list", input="temperature_weekly", columns="name,start_time,end_time,min,max")
gs.run_command("t.rast.aggregate", input="temperature_weekly", output="temperature_10daily_weighted", basename="tendaily_temp_weighted", method="average", granularity="10 days", sampling="related", flags="w")
gs.parse_command("t.rast.list", input="temperature_10daily_weighted", columns="name,start_time,end_time,min,max")
the aggregation seems to work fine, but it's difficult to say if the weighting also works... Maybe a more intuitive example with r.mapcalc and maps having a single integer value?
Maybe a more intuitive example with r.mapcalc and maps having a single integer value?
Anyone willing to propose an example here?
Maybe a more intuitive example with r.mapcalc and maps having a single integer value?
Anyone willing to propose an example here?
See my suggestions. What do you think?