Skip to content
Thomas Nipen edited this page Oct 16, 2022 · 4 revisions

To get ready for the examples in the next sections, run the code below to set up necessary variables (you will also need the test datasets). This retrieves air temperature and precipitation from the observation, analysis, and forecast files as well as metadata about the grids.

import gridpp
import netCDF4
import numpy as np

# Input data
with netCDF4.Dataset('analysis.nc', 'r') as file:
    ilats = file.variables['latitude'][:]
    ilons = file.variables['longitude'][:]
    igrid = gridpp.Grid(ilats, ilons)
    temp_analysis = np.moveaxis(np.squeeze(file.variables['air_temperature_2m'][:]), 0, 2)
    precip_analysis = np.moveaxis(np.squeeze(file.variables['air_temperature_2m'][:]), 0, 2)

with netCDF4.Dataset('forecast.nc', 'r') as file:
    temp_forecast = np.squeeze(file.variables['air_temperature_2m'][:])
    precip_forecast = np.squeeze(file.variables['air_temperature_2m'][:])

# Output grid
with netCDF4.Dataset('output.nc', 'r') as file:
    olats = file.variables['latitude'][:]
    olons = file.variables['longitude'][:]
    ogrid = gridpp.Grid(olats, olons)

# Observations
with netCDF4.Dataset('obs.nc', 'r') as file:
    plats = file.variables['latitude'][:]
    plons = file.variables['longitude'][:]
    points = gridpp.Points(plats, plons)
    temp_obs = file.variables['air_temperature_2m'][:, 0]
    precip_obs = file.variables['precipitation_amount'][:, 0]
Clone this wiki locally