logan-berner / LandsatTS

LandsatTS is an R package to facilitate retrieval, cleaning, cross-calibration, and phenological modeling of Landsat time-series data.
Other
27 stars 3 forks source link

Possibility to display all sample sites and fit different curves #47

Closed llechler closed 8 months ago

llechler commented 8 months ago

Hi,

More a question of possibility rather than an open issue, but I was wondering a) whether it is possible to have the curve fitting of the splines displayed for all sample locations, rather than just nine random sample locations when calling and b) does the package give the option to fit curves other than cubic splines? I could not find documentation to either question online.

Many thanks, Lia

logan-berner commented 8 months ago

Hi Lia, Good questions:

a) Currently, there is not a built-in way to display the splines for all sample locations (when n > 9). However, you can write all of the spline fits out to a CSV file by setting the parameter "spl.fit.outfile" to a path/file.csv when running lsat_fit_phenological_curves(). You can then read that csv file back into R and plot the splines and observed values for each sample location. You could grab the code for creating that figure from the function (also pasted below) and probably modify it to fit your need. Sorry there is not an easier approach.

b) At this point, the only option is to fit cubic splines for the phenological curves.

Hopefully the package is generally working out well for you! -Logan

ggplot2::ggplot(example.obs.dt, ggplot2::aes(doy, si)) + ggplot2::labs(y=paste0('Landsat ', toupper(si)), x='Day of Year') + ggplot2::ggtitle('Nine random sample locations') + ggplot2::facet_wrap(~sample.id, nrow = 3, ncol = 3, scales = 'free_y') + ggplot2::geom_point(ggplot2::aes(fill = year), pch=21, color = 'black', size = 2) + ggplot2::scale_fill_gradientn(name = 'Observation', colours = c('blue','red','gold')) + ggplot2::geom_line(data = example.curves.dt, mapping = ggplot2::aes(doy, spl.fit, group = focal.yr, color = focal.yr), alpha = 0.75) + ggplot2::scale_color_gradientn(name = 'Curve', colours = c('blue','red','gold')) + ggplot2::theme_bw() + ggplot2::theme(legend.position = 'right', legend.text=ggplot2::element_text(size=12), legend.title=ggplot2::element_text(size=12), axis.text=ggplot2::element_text(size=12), axis.title=ggplot2::element_text(size=14), plot.title=ggplot2::element_text(hjust = 0.5), strip.background = ggplot2::element_rect(fill="black"), strip.text = ggplot2::element_text(color = "white", size = 12)) + ggplot2::guides(colour = ggplot2::guide_colourbar(title.position="top", title.hjust = 0.5))

llechler commented 8 months ago

Hi Logan,

Thanks for the quick reply. I managed to plot the curves for all my locations following your advice - greatly appreciated. Really enjoying the package, it is very useful for processing Landsat 8 ndvi timeseries for many different locations. May I briefly ask for your reasoning to fit cubic splines, over e.g., double logistic curves? It was not entirely clear to me from the package documentations.

All the best, Lia

logan-berner commented 8 months ago

Glad that worked for you! As you noted, there are various ways to model vegetation phenology. When initially devising the approach around 2018, I came across several papers focused on modeling forest phenology using Landsat data, including Melass et al. (2016) who had explored both splines and logistic curves. The found, "... instead of using logistic functions fit to time series of EVI, we used cubic splines to model the mean annual phenology of EVI at each pixel. We find that cubic splines provide a more flexible basis for modeling mean annual phenology and reduce bias in estimated SOS and EOS dates that can be caused by asymmetric growth or decay in EVI, which is both common and not captured by logistic functions...". Among other reasons (e.g., my background in using splines as part of dendroecology), this prompted me along the path of using splines over logistic curves.

Melaas, E. K., D. Sulla-Menashe, J. M. Gray, T. A. Black, T. H. Morin, A. D. Richardson, and M. A. Friedl. 2016. Multisite analysis of land surface phenology in North American temperate and boreal deciduous forests from Landsat. Remote Sensing of Environment 186:452-464.