netCDF specificities¶
[1]:
%matplotlib inline
# for figures in notebook
# import & initialize epygram
import epygram
epygram.init_env()
import os
INPUTS_DIR = os.path.join('..', 'inputs')
[2]:
r = epygram.formats.resource(os.path.join(INPUTS_DIR, 'aladin.197901.nc'), 'r')
[3]:
# Equivalent of `ncdump -h`
r.what()
### FORMAT: netCDF
NetCDF Global Attributes:
name: 'test_phys'
description: 'Created by xios'
title: 'Created by xios'
Conventions: 'CF-1.5'
production: 'An IPSL model'
timeStamp: '2016-Apr-15 13:09:53 CEST'
NetCDF dimension information:
Name: axis_nbounds
size: 2
Name: x
size: 49
Name: y
size: 39
Name: time_counter
size: 12
NetCDF variable information:
Name: nav_lat
dimensions: ('y', 'x')
size: 1911
type: dtype('float32')
standard_name: 'latitude'
long_name: 'Latitude'
units: 'degrees_north'
nav_model: 'FULL'
Name: nav_lon
dimensions: ('y', 'x')
size: 1911
type: dtype('float32')
standard_name: 'longitude'
long_name: 'Longitude'
units: 'degrees_east'
nav_model: 'FULL'
Name: psl
dimensions: ('time_counter', 'y', 'x')
size: 22932
type: dtype('float32')
long_name: 'air_pressure_at_sea_level (Pa)'
units: 'Pa'
online_operation: 'instant'
interval_operation: '1 h'
interval_write: '2 h'
cell_methods: 'time: point (interval: 1 h)'
_FillValue: 1e+20
missing_value: 1e+20
coordinates: 'time_instant nav_lat nav_lon'
Name: time_instant
dimensions: ('time_counter',)
size: 12
type: dtype('float64')
standard_name: 'time'
long_name: 'Time axis'
calendar: 'gregorian'
units: 'seconds since 1979-01-01 00:00:00'
time_origin: '1979-01-01 00:00:00'
bounds: 'time_instant_bounds'
Name: time_instant_bounds
dimensions: ('time_counter', 'axis_nbounds')
size: 24
type: dtype('float64')
Name: time_counter
dimensions: ('time_counter',)
size: 12
type: dtype('float64')
axis: 'T'
standard_name: 'time'
long_name: 'Time axis'
calendar: 'gregorian'
units: 'seconds since 1979-01-01 00:00:00'
time_origin: '1979-01-01 00:00:00'
bounds: 'time_counter_bounds'
Name: time_counter_bounds
dimensions: ('time_counter', 'axis_nbounds')
size: 24
type: dtype('float64')
Specify non-trivial variables for grid¶
Genuinely, this line:
r.readfield('psl')
would result in the following error:
# [2021/01/19-18:59:55][epygram.formats.netCDF][find_grid_in_variables:0459][ERROR]: unable to find X_grid in variables. Please specify with readfield() argument adhoc_behaviour={'X_grid':'name_of_the_variable'} for instance or my_resource.behave(X_grid='name_of_the_variable')
[4]:
# Hence we need to specify grids
# just for this read
f = r.readfield('psl', adhoc_behaviour={'X_grid':'nav_lon', 'Y_grid':'nav_lat'})
# or for the whole runtime
r.behave(X_grid='nav_lon', Y_grid='nav_lat')
f = r.readfield('psl')
[5]:
print(f.validity)
<List of FieldValidity which date/time are:
1979-01-01 01:00:00
1979-01-01 03:00:00
1979-01-01 05:00:00
1979-01-01 07:00:00
1979-01-01 09:00:00
1979-01-01 11:00:00
1979-01-01 13:00:00
1979-01-01 15:00:00
1979-01-01 17:00:00
1979-01-01 19:00:00
1979-01-01 21:00:00
1979-01-01 23:00:00
>
Read only a single index of the data¶
[6]:
f = r.readfield('psl', only={'time_counter':0})
[7]:
print(f.validity)
<List of FieldValidity which date/time are:
1979-01-01 01:00:00
>
[ ]: