-
Notifications
You must be signed in to change notification settings - Fork 0
Glacier Mass Change Algorithm
In order to get snowfall data for a specific glacier, we send a call to the GPM API with the date, latitude and longitude of the glacier, and type of precipitation (in this case, precip_30mn_frozen). This gives us snowfall in millimeters for a certain area over the past 30 minutes. Data is returned in the form of a JSON file, from which we can extract a GeoTIFF file that contains the precipitation accumulation visualized within the area.
GeoTIFF files are an extension of TIFF files (which stands for Tagged Image File Format). Like TIFF, GeoTIFF is a raster graphic file type, only GeoTIFF makes use of TIFF layers in order to store geological metadata alongside the raw data. As a result, GeoTIFF files tend to be large, but they’re an effectively “lossless” way of compressing and sending data, and all information is contained within one file.
requests.get(link, params=query) to call API
- Query is a dictionary that matches different query parameters with values to request specifically
- convert API response to a JSON file (using .json() function)
- open JSON response file as a dictionary in Python
- parse dictionary to find the GeoTIFF file representation of the precipitation data
The GeoTIFF graphing code is modeled off of the National Snow and Ice Data Center’s GeoTIFF Analysis in Python (See here for more information. This link also includes code to open API data in IDL and MATLAB).
- Rasterio: package to open, interpret, and create raster files (such as GeoTIFF), has a dependency on GDAL (must have both installed)
- Affine: package to perform affine transformations on data (preserve shape without spatial awareness), transforms raster layers into information that Matplotlib can understand
- Matplotlib: package to create high-quality graphs in Python
- This code is written in the api_call_python_only.py file on the Precipitation API Call Branch.
- The get_geotiff function calls the API and parses the response to return a GeoTIFF file that contains the precipitation data for a specific latitude and longitude.
- Rasterio is used to open the GeoTIFF as a raster object
- The data is transformed using Affine
- The data is scaled to make it more visually appealing
- Matplotlib is used to create “color buckets” for raster layers
- Finally, the graph is created and shown on the screen ** There are also some aesthetic changes made in this portion of the code
Postman is an API platform that allows us to access and visualize Nasa’s GPM Data. In Postman, you can create a collection to store the commands/requests you have made to the API. In your collection, there is a bar which allows you to insert the API link and interact with the API. We are using the “get” command to retrieve data from the GPM API. Postman also allows you to input query parameters to specify the data you are asking the API for. In regards to the GPM API data, we use the parameters:
- q = precip_30mn
- lat = [insert value here]
- long = [insert value here]
- startTime = [insert date here]
- endTime = [insert date here] For more information on these parameters, see the GPM API Documentation page.
From Postman, the GPM API gives us a JSON file, which contains links to the precipitation data in several forms under the “items” section. We are interested in the link for the GeoTIFF file format.
HTTR is a package for R that allows us to access data from the http protocol in R. HTTR can be used for “get” requests to API, similar to “get” requests in Postman. Potential requests in R using HTTR can be visualized in Postman.
dat <- GET (“https:[insert API access link here]”, query = list ([insert query parameters here]))
The API access link can be found in the API’s documentation. For the GPM API, we use "https://pmmpublisher.pps.eosdis.nasa.gov/opensearch". The query parameters specify the data you are requesting from the API. See the Postman Wiki information above for more information.
- warn_for_status(dat)
- stop_for_status(dat)
Warn for status will throw a warning that the request was not successful. Stop for status will terminate the program if the request was not successful.
str(content(dat, "parsed"))
content(dat)
GDAL is a package for multiple programming languages that can interpret GeoTIFF files. Currently, we are using GDAL in R to open GeoTIFF files and show its content. GDAL also contains methods to interpret and analyze GeoTIFF data.
install(“rgdal”)