Chapter 4 Create and plot timeseries

notebook filename | 05-timeseries_chl.Rmd
history | converted to R notebook from Timeseries_CHL.R

This example extracts a time-series of monthly satellite chlorophyll data for the period of 1997-present from four different monthly satellite datasets:

  • SeaWiFS, 1997-2012 (ID = erdSWchlamday)
  • MODIS, 2002-present (ID = erdMH1chlamday)
  • VIIRS, 2012-present (ID = nesdisVHNSQchlaMonthly)
  • OC-CCI, 1997-2017, a blended product that merges multiple satellite missions (ID = pmlEsaCCI31OceanColorMonthly)

The exercise demonstrates the following techniques:

  • Using xtracto_3D to extract data from a rectangular area of the ocean over time
  • Using rerddap to retrieve information about a dataset from ERDDAP
  • Comparing results from different sensors
  • Averaging data temporally and spatially
  • Producing scatter plots
  • Producing line plots
  • Drawing maps with satellite data using ggplot

4.2 Define the area boundaries

You will extract data for an area in the Southern California Bight, between -120 to -115 degrees east longitude and 31 to 34 degrees north latitude.

  • Set the longitude range: xcoord<-c(-120, -115)
  • Set the latitude range: xcoord<-c(31,34)

4.3 Extract satellite data with rxtracto_3D

For each dataset, you will extract satellite data for the entire length of the available timeseries.

  • Dates must be defined separately for each dataset. rxtracto_3D will crash if dates are entered that are not part of the timeseries.
  • The beginning (earliest) date to use in timeseries is obtained from the information returned in dataInfo.
  • To get the ending (most recent) date to use in the timeseries, you will use the last option for time.

4.3.1 Get the SeaWiFS data

To begin, examine the metadata for the SeaWiFS monthly dataset (ID = erdSWchlamday). The script below:

  • Gathers information about the dataset (metadata) using rerddap
  • Displays the information
## <ERDDAP info> erdSWchlamday 
##  Base URL: https://upwell.pfeg.noaa.gov/erddap/ 
##  Dimensions (range):  
##      time: (1997-09-16T00:00:00Z, 2010-12-16T12:00:00Z) 
##      altitude: (0.0, 0.0) 
##      latitude: (-90.0, 90.0) 
##      longitude: (0.0, 360.0) 
##  Variables:  
##      chlorophyll: 
##          Units: mg m-3

Set the arguments for and run rxtracto_3D with the script below:

  • Use the name of the chlorophyll variable that was displayed above in dataInfo: parameter <- “chlorophyll”. You can set this manually, but in this example, you will set pamameter directly from the variable returned from the rerddap::info() function (dataInfo).
  • The metadata from dataInfo also shows you that this variable has an altitude coordinate that equals zero. Set the value of the time coordinate to zero: zcoord <- 0.
  • Obtain the beginning and ending dates from the variable returned from the rerddap::info() function (dataInfo).
  • Use the “last” option for the ending date instead of the actual date in the dataInfo
## Registered S3 method overwritten by 'httr':
##   method           from  
##   print.cache_info hoardr

4.3.2 Now get MODIS data

First get the datadet metadata with “rerddap::info” by changing the dataset ID to “erdMH1chlamday”

## <ERDDAP info> erdMH1chlamday 
##  Base URL: https://upwell.pfeg.noaa.gov/erddap/ 
##  Dimensions (range):  
##      time: (2003-01-16T00:00:00Z, 2020-02-16T00:00:00Z) 
##      latitude: (-89.97918, 89.97916) 
##      longitude: (-179.9792, 179.9792) 
##  Variables:  
##      chlorophyll: 
##          Units: mg m^-3

Set the arguments for, and runs, rxtracto_3D

Since this dataset does not have an altitude dimension, remove zcoord as an argument in rxtracto_3D

4.3.3 Now get VIIRS data

First get the dataset metadata with “rerddap::info” by changeing the dataset ID to “nesdisVHNSQchlaMonthly”

Repeat the same commands but change the name of the dataset.

## <ERDDAP info> nesdisVHNSQchlaMonthly 
##  Base URL: https://upwell.pfeg.noaa.gov/erddap/ 
##  Dimensions (range):  
##      time: (2012-01-02T12:00:00Z, 2020-02-01T12:00:00Z) 
##      altitude: (0.0, 0.0) 
##      latitude: (-89.75626, 89.75625) 
##      longitude: (-179.9812, 179.9813) 
##  Variables:  
##      chlor_a: 
##          Units: mg m^-3

Set the arguments for and run rxtracto_3D

  • This dataset has an altitude dimension. Include zcoord as an argument in the rxtracto_3D function

4.6 Now add ESA OCCI Data

If you needed a single timeseries from 1997 to present, you would have to use the plot above to devise some method to reconcile the difference in values where two datasets overlap. Alternatively, you could use the ESA OC-CCI (ocean color climate change initiative) dataset, which blends data from many satellite missions into a single dataset. Next we will add the ESA OC-CCI dataset to the plot above to see how it compares with data from the individual satellite missions.

  • Change the dataset ID to “pmlEsaCCI31OceanColorMonthly” in the rerddap::info function.
  • There are over 60 variables in this dataset, so the dataInfo is not displayed (feel free to examine the dataInfo variable on your own).
  • This dataset has no altitude dimension. Do not include zcoord as an argument in the rxtracto_3D function.

Add ESA OCCI data to the plot

4.7 Make maps of the average chlorophyll for each satellite mission

The average chlorophyll was saved earlier as the chl avgmap variable

## Warning in f(...): Raster pixels are placed at uneven horizontal intervals and
## will be shifted. Consider using geom_tile() instead.
## Warning in f(...): Raster pixels are placed at uneven vertical intervals and
## will be shifted. Consider using geom_tile() instead.
## Warning in f(...): Raster pixels are placed at uneven horizontal intervals and
## will be shifted. Consider using geom_tile() instead.
## Warning in f(...): Raster pixels are placed at uneven vertical intervals and
## will be shifted. Consider using geom_tile() instead.
## Warning in f(...): Raster pixels are placed at uneven horizontal intervals and
## will be shifted. Consider using geom_tile() instead.
## Warning in f(...): Raster pixels are placed at uneven vertical intervals and
## will be shifted. Consider using geom_tile() instead.

logo