<jupyter_start><jupyter_text>Table of Contents1&nbsp;&nbsp;Purpose2&nbsp;&nbsp;Requirements2.1&nbsp;&nbsp;Abstract Stakeholder2.2&nbsp;&nbsp;Actual Stakeholder3&nbsp;&nbsp;Dependencies3.1&nbsp;&nbsp;R installation3.2&nbsp;&nbsp;An R kernel for Jupyter notebooks3.3&nbsp;&nbsp;Load R libraries for the analyses4&nbsp;&nbsp;Analyses4.1&nbsp;&nbsp;First Leaf4.1.1&nbsp;&nbsp;Inputs4.1.2&nbsp;&nbsp;Outputs4.1.2.1&nbsp;&nbsp;Histogram4.1.2.2&nbsp;&nbsp;Boxplots4.1.2.3&nbsp;&nbsp;Ridgeline Plots4.2&nbsp;&nbsp;First Bloom5&nbsp;&nbsp;Code6&nbsp;&nbsp;Provenance7&nbsp;&nbsp;Citations  PurposeThis [biogeographical analysis package](https://github.com/usgs-bis/nbmdocs/blob/master/docs/baps.rst) (BAP) uses the [USA National Phenology Network](https://www.usanpn.org/usa-national-phenology-network) (USA-NPN)'s modeled information on phenological changes to inform and support management decisions on the timing and coordination of season-specific activities within the boundaries of a user-specified management unit. While various categories of phenological information are applicable to the seasonal allocation of resources, this package focuses on one of those, USA-NPN's modeled spring indices of first leaf and first bloom. The use case for design and development of the BAP was that of a resource manager using this analysis package and USA-NPN's Extended Spring Indices to guide the timing and location of treaments within their protected area.   Requirements  Abstract StakeholderStakeholders for the information produced by this analysis package are people making decisions based on the timing of seasonal events at a specific location. Examples include resource managers, health professionals, and recreationalists. Note: For more on the concept of "Abstract Stakeholder" please see this [reference](https://github.com/usgs-bis/nbmdocs/blob/master/docs/baps.rstabstract-stakeholder).  Actual StakeholderTo be determinedNote: For more on the concept of "Actual Stakeholder" see this [reference](https://github.com/usgs-bis/nbmdocs/blob/master/docs/baps.rstactual-stakeholder).  DependenciesThis notebook was developed using the R software environment. Several R software packages are required to run this scientific code in a Jupyter notebook. An R kernel for Jupyter notebooks is also required.  R installationGuidance on installing the R software environment is available at the [R Project](https://www.r-project.org). Several R libraries, listed below, are used for the analyses and visualizations in this notebook. General instructions for finding and installing libraries are also provided at the [R Project](https://www.r-project.org) website.    An R kernel for Jupyter notebooksThis notebook uses [IRkernel](https://irkernel.github.io). At the time of this writing (2018-05-06), <NAME> provides excellent guidance on installing the IRkernel and running R in a Jupyter notebook in her article entitled ["Jupyter And R Markdown: Notebooks With R"](https://www.datacamp.com/community/blog/jupyter-notebook-rmarkdown)    Load R libraries for the analyses<jupyter_code>library(tidyverse)
library(ggplot2)
library(ggridges)
library(jsonlite)
library(viridis)<jupyter_output><empty_output><jupyter_text>AnalysesAn understanding of the USA National Phenology Network's suite of [models and maps](https://www.usanpn.org/data/maps) is required to properly use this analysis package and to assess the results. The Extended Spring Indices, the model used to estimate the timing of "first leaf" and "first bloom" events for early spring indicator species at a specific location, are detailed on this [page](https://www.usanpn.org/data/spring_indices) of the USA-NPN website. Note both indices are based on the 2013 version of the underlying predictive model (Schwartz et al. 2013). The current model and its antecedents are described on the USA-NPN site and in peer-reviewed literatire (Ault et al. 2015, Schwartz 1997, Schwartz et al. 2006, Schwartz et al. 2013). Crimmins et al. (2017) documents the USA National Phenology Network gridded data products used in this analysis package. USA-NPN also provides an assessment of Spring Index uncertainty and error with their [Spring Index and Plausibility Dashboard](https://www.usanpn.org/data/si-x_plausibility).  First LeafThis analysis looks at the timing of First Leaf or leaf out for a specific location as predicted by the USA-NPN Extended Spring Indices models (https://www.usanpn.org/data/spring_indices, accessed 2018-01-27). The variable *average_leaf_prism* which is based on [PRISM](http://www.prism.oregonstate.edu) temperature data was used for this analysis.   InputsThe operational BAP prototype retrieves data in real-time from the [USA National Phenology Network](https://www.usanpn.org)'s Web Processing Service (WPS) using a developer key issued by USA-NPN. Their WPS allows a key holder to request and retrieve model output values for a specified model, area of interest and time period. Model output for the variable *average_leaf_prism* was retrieved 2018-01-27. The area of interest, Yellowstone National Park, was analyzed using information from the [Spatial Feature Registry](https://github.com/usgs-bis/nbmdocs/blob/master/docs/bis.rst). The specified time period was 1981 to 2016. This notebook provides a lightly processsed version of that retrieval, [YellowstoneNP-1981-2016-processed-numbers.json](./YellowstoneNP-1981-2016-processed-numbers.json), for those who do not have a personal developer key.<jupyter_code># transform the BIS emitted JSON into something ggplot2 can work with
yell <- read_json("YellowstoneNP-1981-2016-processed-numbers.json", simplifyDataFrame = TRUE, simplifyVector = TRUE, flatten = TRUE)
yelldf <- as_tibble(yell)
yellt <- gather(yelldf, Year, DOY)<jupyter_output><empty_output><jupyter_text>Outputs  HistogramProduce a histogram of modeled results for Yellowstone National Park for all years within the specified period of interest (1981 to 2016). The visualization allows the user to assess the range and distribution of all the modeled values for the user-selected area for the entire, user-specified time period. Here, the modeled Leaf Spring Index values for each of the grid that fall within the boundary of Yellowstone National Park are binned by Day of Year for the entire period of interest. The period of interest is 1981 to 2016 inclusive. Dotted vertical lines indicating the minimum (green), mean (red), and maximum (green) values of the dataset are also shown.<jupyter_code># produce a histogram for all years
ggplot(yellt, aes(DOY)) +
  geom_histogram(binwidth = 1, color = "grey", fill = "lightblue") +
  ggtitle("Histogram of First Leaf Spring Index, Yellowstone National Park (1981 - 2016)") +
  geom_vline(aes(xintercept=mean(DOY, na.rm=T)), color = "red", linetype = "dotted", size = 0.5) +
  geom_vline(aes(xintercept = min(DOY, na.rm=T)), color = "green", linetype = "dotted", size = 0.5) +
  geom_vline(aes(xintercept = max(DOY, na.rm=T)), color = "green", linetype = "dotted", size = 0.5)<jupyter_output><empty_output><jupyter_text>This notebook uses the [ggplot2](https://ggplot2.tidyverse.org/index.html) R library to produce the above histogram. Operationalized, online versions of this visualization should be based on the guidance provided by the ggplot2 developers. See their section entitled [*Histograms and frequency polygons*](https://ggplot2.tidyverse.org/reference/geom_histogram.html) for details and approaches. The webpage provides links to their source code. Also, note the modeled grid cell values are discrete and should be portrayed as such in an operationalized graphic.  Boxplots Produce a multiple boxplot display of the modeled results for Yellowstone National Park for each year within the specified time period. Each individual boxplot portrays that year's median, hinges, whiskers and "outliers". The multiple boxplot display allows the user to explore the distribution of modeled spring index values through time.<jupyter_code># Produce a mulitple boxplot display with a boxplot for each year
ggplot(yellt, aes(y = DOY, x = Year, group = Year)) +
  geom_boxplot() +
  geom_hline(aes(yintercept = median(DOY, na.rm=T)), color = "blue", linetype = "dotted", size = 0.5) +
  ggtitle("DRAFT: Boxplot of Spring Index, Yellowstone National Park (1981 to 2016)")<jupyter_output><empty_output><jupyter_text>This notebook uses the [ggplot2](https://ggplot2.tidyverse.org/index.html) R library to produce the multiple boxplot above. Base any operationalized, online versions of this visualization on the guidance provided by the ggplot2 developers. See their section entitled [*A box and whiskers plot (in the style of Tukey)*](https://ggplot2.tidyverse.org/reference/geom_boxplot.html) for details and approaches. Links to their source code are available at that web location.    Ridgeline PlotsProduce ridgeline plots for each year to better visualize changes in the distributions over time.<jupyter_code># ridgeline plot with gradient coloring based on day of year for each available year
ggplot(yellt, aes(x = DOY, y = Year, group = Year, fill = ..x..)) +
  geom_density_ridges_gradient(scale = 3, rel_min_height = 0.01, gradient_lwd = 1.0, from = 80, to = 180) +
  scale_x_continuous(expand = c(0.01, 0)) +
  scale_y_continuous(expand = c(0.01, 0)) +
  scale_fill_viridis(name = "Day of\nYear", option = "D", direction = -1) +
  labs(title = 'DRAFT: Spring Index, Yellowstone National Park',
       subtitle = 'Annual Spring Index by Year for the Period 1981 to 2016\nModel Results from the USA National Phenology Network',
       y = 'Year',
       x = 'Spring Index (Day of Year)',
       caption = "(model results retrieved 2018-01-26)") +
  theme_ridges(font_size = 12, grid = TRUE) +
  geom_vline(aes(xintercept = mean(DOY, na.rm=T)), color = "red", linetype = "dotted", size = 0.5) +
  geom_vline(aes(xintercept = min(DOY, na.rm=T)), color = "green", linetype = "dotted", size = 0.5) +
  geom_vline(aes(xintercept = max(DOY, na.rm=T)), color = "green", linetype = "dotted", size = 0.5)<jupyter_output>Picking joint bandwidth of 1.06
{'fraction_non_alphanumeric': 0.08681863230921705, 'fraction_numerical': 0.021902874132804756, 'mean_word_length': 5.382669196710943, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 21, 'https://': 18, 'lorem ipsum': 0, 'www.': 10, 'xml': 0}, 'pii_count': 3, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '6475', 'license': 'Unlicense', 'n_tokens_mistral': 3085, 'n_tokens_neox': 2805, 'n_words': 1143, 'path': 'annual-indices-of-spring.ipynb', 'repo_name': 'usgs-bcb/phenology-baps', 'size': '10099'}