Interactive example with NetCDF input#
[1]:
%%javascript
// leave this in to disable autoscroll in Jupyter notebook
IPython.OutputArea.prototype._should_scroll = function(lines) {
return false;
}
Imports#
[2]:
import fcpy
Load data#
[3]:
# the `load_dataset' option is currently unavalable due to data handling system move.
# ds = fcpy.load_dataset(model='atmospheric-model', var_names=['2t', 'q', 'sst'], levels=list(range(1, 10)))
# The `data` folder contains two sample NetCDF files.
# Here we load specific humidity from CAMS at 32 bits
fpath = "../data/cams_q_20191201_v3.nc"
ds = fcpy.open_dataset(fpath)
ds = ds[["q"]] # Select only q as this dataset contains more vars...
ds
[3]:
<xarray.Dataset> Dimensions: (time: 1, lev: 137, lat: 451, lon: 900) Coordinates: * time (time) datetime64[ns] 2019-12-01T12:00:00 * lon (lon) float64 0.0 0.4 0.8 1.2 1.6 ... 358.0 358.4 358.8 359.2 359.6 * lat (lat) float64 -90.0 -89.6 -89.2 -88.8 -88.4 ... 88.8 89.2 89.6 90.0 * lev (lev) float64 1.0 2.0 3.0 4.0 5.0 ... 133.0 134.0 135.0 136.0 137.0 Data variables: q (time, lev, lat, lon) float32 dask.array<chunksize=(1, 137, 451, 900), meta=np.ndarray> Attributes: CDI: Climate Data Interface version 1.9.8 (https://mpimet.mpg.de... Conventions: CF-1.6 history: Mon Feb 15 18:37:28 2021: cdo -f nc4 copy tmp.grib data/mil... institution: European Centre for Medium-Range Weather Forecasts CDO: Climate Data Operators version 1.9.8 (https://mpimet.mpg.de...
Define and run experiment#
[4]:
suite = fcpy.Suite(
ds,
baseline=fcpy.Float(bits=32),
compressors=[fcpy.LinQuantization(), fcpy.Round()],
metrics=[fcpy.Difference, fcpy.AbsoluteError],
bits=list(range(12, 23)),
)
0%| | 0/1.0 [00:00<?, ?it/s] Activating project at `~/work/field-compression/field-compression`
WARNING: method definition for == at /usr/share/miniconda/envs/fcpy/share/julia/packages/ChainRulesCore/ctmSK/src/tangent_types/tangent.jl:68 declares type variable T but does not use it.
WARNING: method definition for getindex at /usr/share/miniconda/envs/fcpy/share/julia/packages/ChainRulesCore/ctmSK/src/tangent_types/tangent.jl:120 declares type variable T but does not use it.
WARNING: method definition for getindex at /usr/share/miniconda/envs/fcpy/share/julia/packages/ChainRulesCore/ctmSK/src/tangent_types/tangent.jl:120 declares type variable P but does not use it.
WARNING: method definition for canonicalize at /usr/share/miniconda/envs/fcpy/share/julia/packages/ChainRulesCore/ctmSK/src/tangent_types/tangent.jl:240 declares type variable L but does not use it.
WARNING: method definition for canonicalize at /usr/share/miniconda/envs/fcpy/share/julia/packages/ChainRulesCore/ctmSK/src/tangent_types/tangent.jl:241 declares type variable L but does not use it.
100%|██████████| 1/1.0 [02:03<00:00, 123.25s/it]
123.2505989074707 s
Lineplot: evaluate the effect of bits#
[5]:
suite.nblineplot()
Spatial plots: evaluate the spatial distribution of errors#
[6]:
fcpy.nbspatialplot(
ds,
baseline=fcpy.Float(bits=32),
compressor=fcpy.LinQuantization(bits=12),
third_dim="lev",
)
[ ]: