Chapter 8 Mapping projected datasets

notebook filename | 08_projected_dataset.Rmd
history | created August 2019 | updated March 2020

This example demonstrates the following techniques for working with sea ice data served in polar projected coordinates:

  • Finding and previewing sea ice data in ERDDAP
  • Creating URL requests to download projected data from ERDDAP
  • Using the latitude/longitude grids associated with a projected dataset
  • Making maps of projected data with ggplot

This example works with data provided in ERDDAP with projected coordinates (polar stereographic). For an example of reprojecting data onto maps for datasets having latitude and longitude geographic coordinates, see the Mapping projected datasets section of the course book.

8.2 Find and explore the ice datasets online in ERDDAP

In this example, we will use the NSIDC Sea Ice Concentration Climate Data Record (CDR) as our demonstration projected dataset. This dataset is in a polar stereographic projection, where the coordinates are given as meters from a central point (the north pole) instead of as latitude and longitude. Corresponding latitude and longitude grids enable easily moving between projected coordinates and latitude/longitude.

Search for the NSIDC CDR sea ice datasets

Use a web browser to go to the PolarWatch ERDDAP at https://polarwatch.noaa.gov/erddap/

In the search box type NSIDC CDR and click the Search button

A list of datasets will load, including:

  • Near-real-time data from the Northern and Southern Hemispheres
  • Science quality data from the Northern and Southern Hemispheres
  • The latitude and longitude grid for the Arctic

We will use the monthly science quality dataset for the Northern Hemisphere (ERDDAP ID = nsidcCDRiceSQnhmday) and the associated lat-lon grid dataset for the Arctic (ERDDAP ID = nsidcCDRice_nh_grid).

The dataset listing from a search for ‘NSIDC CDR’

The dataset listing from a search for ‘NSIDC CDR’

Preview the dat

From the dataset listing, click on the graph link to the left of the dataset title. Using the selectors on the left you can quickly preview maps of the data for your times of interest.

You can generate a URL for a netCDF download of the data for the previewed image by setting the file type to .nc which will display a download URL which can be used in a script.

A preview of the NSIDC Sea Ice Concentration dataset in the PolarWatch ERDDAP

A preview of the NSIDC Sea Ice Concentration dataset in the PolarWatch ERDDAP

View Detailed Inf

From the dataset listing, click on the M link to the right of the dataset title. This page will show details about the dataset including the projection. We can see that this is a polar stereographic projection with EPSG code 3411 and also the proj4 string for the dataset. In this case the projection is NSIDC Polar Stereographic North.

The metadata page provides important information about the dataset such as projection details.

The metadata page provides important information about the dataset such as projection details.

Generate a URL as a starting point for scripting

From the dataset listing, click on the data link to the left of the dataset title. We can use the data page to generate a generic url for a netCDF file download. Copy and paste the generated URL into your script, we will use the url as a starting point for forming a data request in R.

Below is an example of data request URL from the ERDDAP data access form

https://polarwatch.noaa.gov/erddap/griddap/nsidcCDRiceSQnhmday.nc?
seaice_conc_monthly_cdr
[(2017-12-16T00:00:00Z):1:(2017-12-16T00:00:00Z)] [(5837500.0):1:(-5337500.0)][(-3837500.0):1:(3737500.0)],
goddard_merged_seaice_conc_monthly
[(2017-12-16T00:00:00Z):1:(2017-12-16T00:00:00Z)] [(5837500.0):1:(-5337500.0)][(-3837500.0):1:(3737500.0)]

Obtain a URL for a data download from the ERDDAP data access web page

Obtain a URL for a data download from the ERDDAP data access web page

8.3 Download the sea ice concentration data

We will now use R and the ERDDAP API to generate a sea ice data request. Subsetting data from a projected dataset requires a few more steps than most ERDDAP datasets. Projected datasets served in the PolarWatch ERDDAP are also served with a corresponding lat-lon grid. In this section, we will demonstrate using the lat-lon grid to make a data request for the projected ice data with the following steps:

  • Download a netCDF file of the lat/lon grid from ERDDAP

  • Use the grid to find the x and y indices that correspond with your area of interest

  • Request the sea ice concentration dataset using the selected indices from the lat/lon grid

  • Read the downloaded netCDF data file and load the ice data into R variables

Download a netCDF file of the lat-lon grid from ERDDAP

First, we form a request for the full lat-lon grid using the dataset id nsidcCDRice_nh_grid and the default axis extent values. As demostrated previously, we can use a download URL from the lat-lon grid data access page as a template for data requests in R. Then we’ll download the data and read the netCDF file variables into R.

Find the x and y indices that correspond with your area of interest

Next we will get the indices of our area of interest. We will use these indices later to make subsetted data requests. For this example we are interested in all data north of 75°. We will find all coordinate values greater than or equal to 75°N. To subset by longitude you can add a longitude query. The range is an extent that covers all data north of 75° so we will be requesting the smallest box of data that covers our desired latitude range. Note that our returned request will include points south of 75°N to accomplish this.

Request the sea ice dataset using the selected indices from the lat/lon grid

Request data from the monthly science quality dataset for the Northern Hemisphere (nsidcCDRiceSQnhmday). There are four different sea ice variables in this dataset. Downloading each of them requires adding the name of each variable and the date and coordinate constraints. Here we download two of the variables. If you need a refresher on the structure of the URL call, go to the ERDDAP “Data Access Form” for a dataset and use the ‘generate the URL’ button.

Read the downloaded netCDF file and load the ice data into R variables

8.4 Make maps of the ice data

The exercise will demonstrate four different ways to map the data, because with R there is always more than one way to do things! The first three methods will use the latitude and longitude coordinates while the fourth method uses the projected coordinates. All methods use ggplot.

Prepare to make the maps

We now have the ice data in R, but there are a few things we need to do before we can make the map plots:

  • Generate the subsetted latitude and longitude grids that correspond to our ice data request. We will use these grids in the first three examples.

  • Choose the date that we want to plot

  • Reformat our data into a dataframe for plotting

Choose a date to use for the map and determine the index value for the date

Make a long-format dataframe for that time period to use with ggplot

This dataset has a fill value of 2.54 which represents a land mask. Replace that with NA before plotting.

Map with a geographical grid

See how ggplot plots the dataset as a standard geographical lat/lon plot.

Map with a polar view

Follow the example at https://stackoverflow.com/questions/48816773/polar-stereographic-map-in-r

Map with a clipped polar view

Follow the example given at https://www.r-bloggers.com/drawing-polar-centered-spatial-maps-using-ggplot2/ Note the opts function has been deprecated, and theme is now used instead.

## Warning: Removed 22908 rows containing missing values (geom_point).

Map using projected coordinates

Finally, if you don’t need to work with lat/lon coordinates you can plot the data in projected coordinates using the xgrid and ygrid variables.

## Related Materials

Projected Datasets R Notebook - Access and make projected plots of traditional lat-lon datasets from ERDDAP

ERDDAP Training Course Book - Using the features of ERDDAP