Closed halima1993 closed 4 years ago
Hi Halima,
Yeah, I am fine. I hope you are also keeping well.
You are looking for the function aggregateSubannual(). It works very similarly for the aggregateYears() function that you used above. In particular is also takes a "method" argument, I guess you will want "sum" in this case although "mean" is also an option. It also takes a "target" argument, which defaults to "Year", so obviously since this is what you want you don't need to specify it.
Does that answer your question?
Hey yes thank you so much. I would like to know if I am using the aggregateSubannual()
properly in my code. My current code is:
field1<- getField(source =cfluxnee,
first =2000, last =2010, var = "mgpp", verbose = TRUE, spatial.extent = mountains, spatial.extent.id = "SEA") #mainfile
years15<-selectYears(x = field1, first =2000, last = 2010)
aggregate1<-aggregateSubannual(years15, method = "sum", target = "Year",
verbose = FALSE)
rastermpi15<-promoteToRaster(aggregate1, layers = "all", tolerance = 0.01,
grid.topology = NULL)
After aggregateSubannual, I convert it to raster, is the usage of aggregateSubannual()
done properly in my code above? The output raster shows a raster showing gpp from 2000-2010 right?
Yeah sure. It sums the 12 monthly values of mgpp and gives one value per year. But in the code above you are not aggregating the years, just the months. Your resulting raster will have 11 layers, total gpp for each year from 2000-2010.
If you want to average the years, you need to put back in the aggregateYears() call that you had in your first example:
aggregatempi15<-aggregateYears(years15, method="mean")
I think the point is that you can call aggregateYears() or aggregateSubannual() or both. I think you want to call both.
Alright, so is this code fine :
aggregatempi15<-aggregateYears(years15,method="sum")
aggregate1<-aggregateSubannual(years15, method = "sum", target = "Year",
verbose = FALSE)
rastermpi15<-promoteToRaster(aggregate1, layers = "all", tolerance = 0.01,
grid.topology = NULL)
(Actually I am comparing satellite data with LPJ-DGVM. The satellite data raster (2000-2010) is ranging from 0-6 kgC m-2, however the LPJ data is ranging from 0-2 kgC m-2), hence through this above code does my aggregation code for my LPJ data is correct for the comparison? shall I insert "mean" in both aggregateYears and aggregateSubannual?
Well not quite. But you need to think through what you are doing.
From I can tell you want the mean year of the annual sum. So you need to call aggregateYears() with "mean" and aggregateSubannual() with "sum". Something like
field1<- getField(source =cfluxnee,
first =2000, last =2010, var = "mgpp", verbose = TRUE, spatial.extent = mountains, spatial.extent.id = "SEA") #mainfile
years15<-selectYears(x = field1, first =2000, last = 2010)
years15.meanyear <- aggregateYears(years15, "mean")
years15.meanyear.annualsum <- aggregateSubannualyears15.meanyear5, "sum")
rastermpi15<- promoteToRaster(years15.meanyear.annualsum, layers = "all", tolerance = 0.01,
grid.topology = NULL)
But maybe you actually want annual values for each year from 2000 to 2010? I am not sure... It depends if you added or averaged your years of satellite data.
ok thank you so much! Yes I did get a lot of clarification through your answer. You may close this issue. Stay safe and take care!
A pleasure. You take care too!
Hey Matthew, hope you are well and safe. I want to ask you that I have mgpp out file, and I would like to convert it into yearly mgpp.
my code is
I would like to aggregate months by mean and show a raster file showing Yearly mgpp from 2000-2010. How can I achieve this in DGVMTools in R?