Eratos Xarray Access Functions
This page details the implementation of Xarray, which is the easiest way to get started accessing data on Eratos.
An interactive tutorial covering this content and its applications can be found here .
Using Eratos Xarray
First, make sure you have installed the required packages and are importing them into your workspace, either locally or on the Colab.
# Import requred packages
#Credentials packages
from eratos.creds import AccessTokenCreds
from eratos.adapter import Adapter
#Processing packages
import xarray as xr
import eratos_xarray
import numpy as np
import matplotlib.pyplot as plt
First, authenticate, find the dataset ERN and open the dataset. This is also a good chance to have a look at the datasets metadata.
Some useful resources:
#Printing the dataset once opened will print its metadata
dataset = xr.open_dataset(found_ern, eratos_auth=ecreds)
print(dataset)
Get Timeseries Data at a Point (1 Dimensional)
To get a 1 dimensional subset of a dataset, i.e. a value at a point across time, use this .sel() approach:
Example inputs:
lat: -17.93, long: 145.92
start_time: "2024-02-22", end_time: "2024-02-27"
lat_point = #<PUT LAT HERE>
lon_point = #<PUT LON HERE>
start_time = #<PUT START HERE> in ""
end_time = #<PUT END HERE> in ""
#The .sel function expects a range, so we will create a range around the point. You may need to change resolution depending on the resolution of your dataset so that you only get one lat and lon value each.
resolution = 0.02
lat_range = (lat_point - resolution, lat_point + resolution)
lon_range = (lon_point - resolution, lon_point + resolution)
#Extract the data
bars_point = dataset.sel(lat=slice(*lat_range), lon=slice(*lon_range), time=slice(start_time, end_time))
# Load the subset bars
bars_point.load()
print(bars_point)
Get Geospatial Data Across an Area (2 Dimensional)
To get a 2 dimensional subset of a dataset, i.e. a value across an area at a point in time, use this .sel() approach:
lat_range = #<PUT LAT Tuple HERE>
long_range = #<PUT Long Tuple HERE>
time_point = #<PUT TIME HERE> in ""
#Extract the data
bars_region = dataset.sel(lat=slice(*lat_range), lon=slice(*long_range),time=slice(time_point, time_point))
#Load the subset bars
bars_region.load()
print(bars_region)
Get a 3D Space+Time Subset
To get a 3 dimensional subset of a dataset, i.e. a value across an area across time, use this .sel() approach:
lat_range = #<PUT LAT Tuple HERE>
long_range = #<PUT Long Tuple HERE>
time_start = #<PUT TIME HERE> in ""
time_end = #<PUT TIME HERE> in ""
bars_region_over_time = dataset.sel(lat=slice(*lat_range), lon=slice(*long_range),time=slice(time_start, time_end))
#Load the subset bars
bars_region_over_time.load()
print(bars_region_over_time)
Visualise and Apply the Data
Now you have extracted the data, you may want to visualise it, or use it in a model. Check out these pages for info on how to do this:
Updated 8 days ago