grass icon indicating copy to clipboard operation
grass copied to clipboard

Adjustments to t.rast.aggregate - temporally weighted aggregation

Open fkroeber opened this issue 3 years ago • 8 comments

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.

fkroeber avatar Aug 16 '21 16:08 fkroeber

This addition sounds really cool :) Would you mind providing a reproducible example to test it?

veroandreo avatar Aug 16 '21 22:08 veroandreo

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.

neteler avatar Nov 30 '21 19:11 neteler

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!

griembauer avatar Dec 06 '21 06:12 griembauer

Binder link for anyone who wants to test this.

wenzeslaus avatar Mar 16 '22 02:03 wenzeslaus

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?

veroandreo avatar Mar 19 '22 20:03 veroandreo

Maybe a more intuitive example with r.mapcalc and maps having a single integer value?

Anyone willing to propose an example here?

neteler avatar Feb 18 '23 10:02 neteler

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?

veroandreo avatar Feb 20 '23 20:02 veroandreo