Reading MERRA data#

This Example show how to read the MERRA atmospheric data and to show the structure of the MERRA data

Workflow:

  1. Initialize MERRA data file

  2. Take a look at the variables

  3. Preload data in the region

  4. Get timeseries for a specific location

  5. Introduction of standard loaders

import reskit as rk

Initialize a MERRA data file#

  • In this case, rk._TEST_DATA_[“weather_data”] points to a netCDF4 file on your machine with climate model weather datasets

  • If rk._TEST_DATA_[“weather_data”] points to a folder, all netCDF4 files in that folder will be scanned

print(rk.TEST_DATA["merra-like"])
/home/docs/checkouts/readthedocs.org/user_builds/ethos-reskit/checkouts/latest/reskit/_test/data/merra-like
# The 'bounds' input limits the spatial domain of the weath data which is loaded into memory
#  - given as: [low-lat, low-lon, high-lat, high-lon]

# The files scanned will be listed, unless verbose=False is specified

src = rk.weather.MerraSource(rk.TEST_DATA["merra-like"], bounds=[5, 49, 7, 52])
/home/docs/checkouts/readthedocs.org/user_builds/ethos-reskit/checkouts/latest/reskit/_test/data/merra-like/MERRA_tavg1_2d.2015.Europe.PS.nc4
/home/docs/checkouts/readthedocs.org/user_builds/ethos-reskit/checkouts/latest/reskit/_test/data/merra-like/MERRA_tavg1_2d.2015.Europe.SWGDN.nc4
/home/docs/checkouts/readthedocs.org/user_builds/ethos-reskit/checkouts/latest/reskit/_test/data/merra-like/MERRA_tavg1_2d.2015.Europe.T10M.nc4
/home/docs/checkouts/readthedocs.org/user_builds/ethos-reskit/checkouts/latest/reskit/_test/data/merra-like/MERRA_tavg1_2d.2015.Europe.T2M.nc4
/home/docs/checkouts/readthedocs.org/user_builds/ethos-reskit/checkouts/latest/reskit/_test/data/merra-like/MERRA_tavg1_2d.2015.Europe.T2MDEW.nc4
/home/docs/checkouts/readthedocs.org/user_builds/ethos-reskit/checkouts/latest/reskit/_test/data/merra-like/MERRA_tavg1_2d.2015.Europe.U10M.nc4
/home/docs/checkouts/readthedocs.org/user_builds/ethos-reskit/checkouts/latest/reskit/_test/data/merra-like/MERRA_tavg1_2d.2015.Europe.U2M.nc4
/home/docs/checkouts/readthedocs.org/user_builds/ethos-reskit/checkouts/latest/reskit/_test/data/merra-like/MERRA_tavg1_2d.2015.Europe.U50M.nc4
/home/docs/checkouts/readthedocs.org/user_builds/ethos-reskit/checkouts/latest/reskit/_test/data/merra-like/MERRA_tavg1_2d.2015.Europe.V10M.nc4
/home/docs/checkouts/readthedocs.org/user_builds/ethos-reskit/checkouts/latest/reskit/_test/data/merra-like/MERRA_tavg1_2d.2015.Europe.V2M.nc4
/home/docs/checkouts/readthedocs.org/user_builds/ethos-reskit/checkouts/latest/reskit/_test/data/merra-like/MERRA_tavg1_2d.2015.Europe.V50M.nc4
# See all of the variables in this file...
src.variables
name units path shape
time time minutes since 2015-01-01 00:30:00 /home/docs/checkouts/readthedocs.org/user_buil... (71,)
lon longitude degrees_east /home/docs/checkouts/readthedocs.org/user_buil... (5,)
lat latitude degrees_north /home/docs/checkouts/readthedocs.org/user_buil... (7,)
PS surface_pressure Pa /home/docs/checkouts/readthedocs.org/user_buil... (71, 7, 5)
SWGDN surface_incoming_shortwave_flux W m-2 /home/docs/checkouts/readthedocs.org/user_buil... (71, 7, 5)
T10M 10-meter_air_temperature K /home/docs/checkouts/readthedocs.org/user_buil... (71, 7, 5)
T2M 2-meter_air_temperature K /home/docs/checkouts/readthedocs.org/user_buil... (71, 7, 5)
T2MDEW dew_point_temperature_at_2_m K /home/docs/checkouts/readthedocs.org/user_buil... (71, 7, 5)
U10M 10-meter_eastward_wind m s-1 /home/docs/checkouts/readthedocs.org/user_buil... (71, 7, 5)
U2M 2-meter_eastward_wind m s-1 /home/docs/checkouts/readthedocs.org/user_buil... (71, 7, 5)
U50M eastward_wind_at_50_meters m s-1 /home/docs/checkouts/readthedocs.org/user_buil... (71, 7, 5)
V10M 10-meter_northward_wind m s-1 /home/docs/checkouts/readthedocs.org/user_buil... (71, 7, 5)
V2M 2-meter_northward_wind m s-1 /home/docs/checkouts/readthedocs.org/user_buil... (71, 7, 5)
V50M northward_wind_at_50_meters m s-1 /home/docs/checkouts/readthedocs.org/user_buil... (71, 7, 5)

Preload the data in this region#

# Load a specific variable
src.load("U50M", name="wind_speed")

Get the time series for a specific location#

# Get a time series for a single location
# Locations are given as (Lon, lat)
t = src.get("wind_speed", locations=(6.0, 50.0))

t.head()
2015-01-01 00:30:00+00:00    3.564828
2015-01-01 01:30:00+00:00    3.401189
2015-01-01 02:30:00+00:00    3.127785
2015-01-01 03:30:00+00:00    2.838547
2015-01-01 04:30:00+00:00    2.414742
Name: (6.0, 50.0), dtype: float32
# Get a time series for multiple locations
t = src.get("wind_speed", locations=[(5.5, 50.0), (6.0, 50.0), (6.7, 50.0)])

t.head()
(5.5, 50.0) (6.0, 50.0) (6.7, 50.0)
2015-01-01 00:30:00+00:00 2.886117 3.564828 3.810922
2015-01-01 01:30:00+00:00 2.529118 3.401189 3.825017
2015-01-01 02:30:00+00:00 2.138527 3.127785 3.693214
2015-01-01 03:30:00+00:00 1.761887 2.838547 3.489914
2015-01-01 04:30:00+00:00 1.258858 2.414742 3.195015
# Get a time series for a single location, but interpolate the surrounding MERRA points the specified location(s)
# Options are:
#  'bilinear' -> Uses linear interpolation. Requires the surrounding 4 index points
#  'cubic' -> Uses cubic interpolation. Requires the surrounding 16 index points
t = src.get("wind_speed", (6.0, 50.0), interpolation="bilinear")

t.head()
2015-01-01 00:30:00+00:00    3.293344
2015-01-01 01:30:00+00:00    3.052360
2015-01-01 02:30:00+00:00    2.732082
2015-01-01 03:30:00+00:00    2.407883
2015-01-01 04:30:00+00:00    1.952389
Name: (6.0, 50.0), dtype: float64

Standard Loaders#

Many weather sources have similar (but nevertheless slightly different) variables which often need to be transformed into a standard unit. Therefore RESKit configures each weather source with numerous available ‘standard loader’ functions

src.list_standard_variables()
sload_elevated_wind_direction
sload_elevated_wind_speed
sload_global_horizontal_irradiance
sload_surface_air_temperature
sload_surface_dew_temperature
sload_surface_pressure
sload_surface_wind_direction
sload_surface_wind_speed
sload_wind_direction_at_10m
sload_wind_direction_at_2m
sload_wind_direction_at_50m
sload_wind_speed_at_10m
sload_wind_speed_at_2m
sload_wind_speed_at_50m
# Load, for example, "surface air temperature", which will always be output in degrees-Celcius
src.sload_surface_air_temperature()
# Access the data using the same name
t = src.get("surface_air_temperature", (6.0, 50.0), interpolation="bilinear")

t.head()
2015-01-01 00:30:00+00:00   -2.400848
2015-01-01 01:30:00+00:00   -2.561975
2015-01-01 02:30:00+00:00   -2.745178
2015-01-01 03:30:00+00:00   -2.974139
2015-01-01 04:30:00+00:00   -3.179675
Name: (6.0, 50.0), dtype: float64