vector-from-raster

In general, the msdrought Package works best when the data from a specific point in a raster is pulled, converted into an xts object, and then analyzed. This vignette will show an alternative approach, when an entire raster is analyzed for its duration and intensity values, then a single specific point and its corresponding data is extracted to a vector. The process for both duration and intensity (as well as any other given parameter for the msdStats function) is identical.

Now we have our raster data loaded in as “infile”. Using the terra::app command, we can apply a function to each cell of the data. Begin by finding the range of dates for the raster data, as these values are needed for the package to understand the statistics. Data processing begins by filtering the data using a bartlett noise filter, then apply the msdStats function to the data.

The “intensityPlots” and “durationPlots” rasters contain the intensity and duration values for every geographical location for both of the years of data contained in the original dataset. Now that we have all the intensity and duration values, we will extract a single point’s data from the new rasters.

Now we have converted the “intensityPlots” and “durationPlots” rasters to numeric objects called “locationIntensity” and “locationDuration”, which represent the intensity and duration values for the provided coordinates across both years of data. If a different location’s data were desired, all we would need to do is swap out the lon and lat values we provided and run the previous chunk of code again. For ease of comparison to the “Sample-Walkthrough” vignette, we’ll combine the two objects together. If we had repeated the process for all 5 msdStats parameters (“duration”, “intensity”, “firstMaxValue”, “secondMaxValue”, or “min”), we could achieve the same output as the “Sample-Walkthrough” vignette.

The output now closely resembles the output format that would be achieved if the location was extracted prior to analysis. Pulling the remaining stats (“firstMaxValue”, “secondMaxValue”, and “min”) and combining those as well would result in an identical result.