lizzieinvancouver / decsens

0 stars 0 forks source link

working on sliding windows ... #18

Open lizzieinvancouver opened 3 years ago

lizzieinvancouver commented 3 years ago

@cchambe12 I am playing around with a randomized leafout date, but want to make sure I understand the output from run_SW f(x) correctly. So for example:

> swapre_stat
  X           x
1 1  74.0000000
2 2   8.0000000
3 3   1.0000000
4 4 127.3557718
5 5  -3.4619482
6 6   0.1636611
7 7   0.4116864

So my questions: (1) How do I interpret the window close and open? Are they DOY or relative to something. If they are DOY then does it mean the window opens on day 74 of the year before leafout and closes in January the next year or what? (2) What is the aggregate statistic number? (3) What is row 6? (4) Are my other assumptions about the rows (slope, intercept etc.) correct?

Thanks for any help!

lizzieinvancouver commented 3 years ago

@cchambe12 For comparison, here's the results when I randomize leafout date:

> swapre_statrand 
  X           x
1 1 311.0000000
2 2 127.0000000
3 3   1.0000000
4 4 143.1103655
5 5  -2.8707274
6 6   0.3039285
7 7   0.1214731
lizzieinvancouver commented 3 years ago

@cchambe12 Okay! I think I have figured it out:

  1. window open date relative to refday
  2. WindowClose (relative to refday)
  3. which statistic (1-4, see below)
  4. model intercept
  5. model slope
  6. error of slope (I believe)
  7. adj R squared

Best model is selected of the one's climwin says are best across 4 'aggregate statistics.' Taken from Simmons et al. 2019, "The aggregate statistic used in this method is typically a sum, mean (e.g. of the daily mean, minimum, or maximum temperature), minimum (e.g. the minimum mean daily temperature reached in a focal window) or maximum (e.g. the max- imum mean daily temperature reached in a focal window) envi- ronmental value, or the slope of environmental change across the window (the gradient of a linear model of daily mean temperature against date within the focal window).") They are referenced this way in the climwin package:

  # 1 = mean
  # 2 = max
  # 3 = min
  # 4 = slope
lizzieinvancouver commented 3 years ago

Some useful to me vignettes are Advanced climwin and just climwin

cchambe12 commented 3 years ago

@lizzieinvancouver Nice! Yes this all looks correct to me, sorry I was late to the party!

lizzieinvancouver commented 3 years ago

@cchambe12 No apologies! It was holidays and you should be taking time off.

I worked on the randomization of leafout date, and on trying the simulated climate data (see sims_sw.R and sims_runsw.R). Sort of tackily I did not write the sims_sw.R to be very automated but it's the parameters in there now, and I either set fstaradjforchill to 0 or 3 depending on whether there was chill. I ran it with 50 years but interestingly I could not get it to find windows for most of those sims.

Here's a few things I could use help with:

  1. Can you check my work especially on how I plotted the simulated data results (sims_runsw.R). I really need a head-check on how to plot the windows -- am I actually plotting the correct windows? It's hard with refday.
  2. Can we adjust the slidingwindow command so that we also ask it to fit a SUM window? That's what the model is so I would be interested to see if a sum works. Here's and example from here:
MassWin <- slidingwin(xvar = list(Temp = MassClimate$Temp),
                      cdate = MassClimate$Date,
                      bdate = Mass$Date,
                      baseline = lm(Mass ~ 1, data = Mass),
                      cinterval = "day",
                      range = c(150, 0),
                      upper = 0, binary = TRUE,
                      type = "absolute", refday = c(20, 05),
                      stat = "sum",
                      func = "lin")

Critical next things to do are:

  1. Can we pull REAL climate data from a latitudinal gradient (a big one, like Germany to middle or norther Sweden) say ... 10 locations and simulate a LEAFOUT date based on simple GDD (see what makes sense for a leafout in the spring and apply it across all latitudes) then see how the slidingwindow works?
  2. It would be cool to then test what warming does (add 1-3 degrees to the real climate data) versus what changing GDD does to the selected best models.

I can help with these, especially putting them on midge so we can free up R space.

Less critical but would be good to do:

  1. Can we get it to work with 'spatial'? I could not get that to work. This is not so critical but would be good to do.
  2. Check out the XXXwchill_0deg_50yrs.csv or wchill_2deg_50yrs.csv sliding windows and see why no models are returned? I will push the RDS files just now so you don't have to run the models.

Also, it would be nice to fill in the missing climate data ourselves (it's the leap years I think) though not so critical.

Other ideas I have that seem less important now are better fake climate data via a sine curve or such.

lizzieinvancouver commented 3 years ago

From Cat on 10 Dec 2020

I was able to run the sliding windows and---very quick glance---everything looks okay. I split the windows into two: 1950-1983 and 1984-2016 like in the Europe paper. Let me know if you'd like something different!

You can find all of this code in: descend/analyses/pep_analyses/simmonds_slidingwin/

"betpen_climate_slidingwin.R" preps the climate code "bp_sw_simmonds.R" runs the sliding windows

output/results_swapre_bp_mayref.csv: are the results years and mean climate data from the sliding window for the pre cc dataset using May 1 as a reference point output/sumstats_swapre_bp_mayref.csv: are the sliding window summaries for the pre cc dataset using May 1 as a reference point output/results_swapost_bp_mayref.csv: are the results years and mean climate data from the sliding window for the post cc dataset using May 1 as a reference point output/sumstats_swapost_bp_mayref.csv: are the sliding window summaries for the post cc dataset using May 1 as a reference point