-
-
Notifications
You must be signed in to change notification settings - Fork 307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
t.rast.aggregate: Adjustments to temporally weighted aggregation #1799
base: main
Are you sure you want to change the base?
Changes from all commits
98ff93e
801b29e
1ec77c4
013ae4d
b776ef5
a256684
b8caa7b
2c093c2
4e4136c
ff88f1a
be16ac6
776d99e
1701031
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -193,6 +193,41 @@ <h4>Yearly aggregation</h4> | |||||||||||||||||||||||||||||||||||||
yearly_avg_temp_2004|climate|2004-01-01 00:00:00|2005-01-01 00:00:00 | ||||||||||||||||||||||||||||||||||||||
</pre></div> | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
<h4>Weighted aggregation</h4> | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
In this example, we create a STRDS of fictional temperature values for | ||||||||||||||||||||||||||||||||||||||
a weekly interval: | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
<div class="code"><pre> | ||||||||||||||||||||||||||||||||||||||
MAPS="map_1 map_2 map_3 map_4 map_5 map_6 map_7 map_8 map_9 map_10" | ||||||||||||||||||||||||||||||||||||||
for map in ${MAPS} ; do | ||||||||||||||||||||||||||||||||||||||
r.surf.random output=${map} min=278 max=298 | ||||||||||||||||||||||||||||||||||||||
echo ${map} >> map_list.txt | ||||||||||||||||||||||||||||||||||||||
done | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
t.create type=strds temporaltype=absolute \ | ||||||||||||||||||||||||||||||||||||||
output=temperature_weekly \ | ||||||||||||||||||||||||||||||||||||||
title="Weekly Temperature" \ | ||||||||||||||||||||||||||||||||||||||
description="Test dataset with weekly temperature" | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
t.register -i type=raster input=temperature_weekly \ | ||||||||||||||||||||||||||||||||||||||
file=map_list.txt start="2021-05-01" increment="1 weeks" | ||||||||||||||||||||||||||||||||||||||
</pre></div> | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
We can now use the <b>-w</b> flag and the <b>sampling=related</b> option | ||||||||||||||||||||||||||||||||||||||
to calculate the 10-daily average temperature. The values of each 10-days | ||||||||||||||||||||||||||||||||||||||
granule are calculated weighted by relative temporal coverage of the input | ||||||||||||||||||||||||||||||||||||||
granules. | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
<div class="code"><pre> | ||||||||||||||||||||||||||||||||||||||
t.rast.aggregate input=temperature_weekly output=temperature_10daily_weighted \ | ||||||||||||||||||||||||||||||||||||||
basename=tendaily_temp_weighted method=average granularity="10 days" \ | ||||||||||||||||||||||||||||||||||||||
sampling=related -w | ||||||||||||||||||||||||||||||||||||||
</pre></div> | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||
This is especially useful when harmonizing STRDS with granules that are not | ||||||||||||||||||||||||||||||||||||||
integer multiplications of each other. | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
<h2>SEE ALSO</h2> | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
<em> | ||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,11 +57,11 @@ def setUpClass(cls): | |
def tearDownClass(cls): | ||
"""Remove the temporary region""" | ||
cls.del_temp_region() | ||
cls.runModule("t.remove", flags="df", type="strds", inputs="A") | ||
cls.runModule("t.remove", flags="rf", type="strds", inputs="A") | ||
|
||
def tearDown(self): | ||
"""Remove generated data""" | ||
self.runModule("t.remove", flags="df", type="strds", inputs="B") | ||
self.runModule("t.remove", flags="rf", type="strds", inputs="B") | ||
|
||
def test_disaggregation(self): | ||
"""Disaggregation with empty maps""" | ||
|
@@ -238,6 +238,43 @@ def test_aggregation_3months(self): | |
maps = "b_101" + os.linesep | ||
self.assertEqual(maps, lister.outputs.stdout) | ||
|
||
def test_weighted_aggregation(self): | ||
"""Weighted aggregation to 3 weeks""" | ||
self.assertModule( | ||
"t.rast.aggregate", | ||
input="A", | ||
output="B", | ||
basename="b", | ||
granularity="3 weeks", | ||
method="average", | ||
sampling=["related"], | ||
file_limit=0, | ||
suffix="num%03", | ||
flags="w", | ||
) | ||
# assert that there are 5 rasters | ||
t_rast_list = SimpleModule("t.rast.list", input="B", flags="u").run() | ||
rasters = [ | ||
item | ||
for item in t_rast_list.outputs.stdout.split(os.linesep) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is splitlines for these cases (which actually behaves as expected unlike os.linesep here). (For future reference, see #2258, hopefully more straightforward.) |
||
if item.startswith("b_") | ||
] | ||
self.assertEqual( | ||
5, | ||
len(rasters), | ||
("Output STRDS does not contain the correct number of rasters."), | ||
) | ||
|
||
# assert that the granularity is correct and the whole time range is | ||
# covered | ||
info = SimpleModule("t.info", flags="g", input="B") | ||
ref_dict = { | ||
"start_time": "'2001-01-15 00:00:00'", | ||
"end_time": "'2001-04-30 00:00:00'", | ||
"granularity": "'21 days'", | ||
} | ||
self.assertModuleKeyValue(module=info, reference=ref_dict, precision=2, sep="=") | ||
|
||
|
||
if __name__ == "__main__": | ||
from grass.gunittest.main import test | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This example makes it much easier to understand what the weight really does as values in input maps are known and constant integer values