Interactive examples with MARS/GRIB input#
[1]:
%%javascript
// leave this in to disable autoscroll in Jupyter notebook
IPython.OutputArea.prototype._should_scroll = function(lines) {
return false;
}
Imports#
[2]:
import os
from pathlib import Path
import json
import fcpy
Load data#
[3]:
if (Path().home() / ".ecmwfapirc").exists():
fpath = "../samples/cases/hplp_ml_q.json"
request = json.load(open(fpath))["mars"]
ds = fcpy.fetch_mars_dataset(request)
else:
ds = fcpy.open_dataset("../data/mars.grib")
ds = ds.isel(hybrid=[0, 1])
ds
In , overriding the default value (cache=True) with cache=False is not recommended.
[3]:
<xarray.Dataset> Dimensions: (time: 1, step: 1, hybrid: 2, values: 654400) Coordinates: * time (time) datetime64[ns] 2020-07-21 * step (step) timedelta64[ns] 00:00:00 * hybrid (hybrid) float64 1.0 2.0 latitude (values) float64 ... longitude (values) float64 ... valid_time (time, step) datetime64[ns] ... Dimensions without coordinates: values Data variables: q (time, step, hybrid, values) float64 ... Attributes: GRIB_edition: 2 GRIB_centre: ecmf GRIB_centreDescription: European Centre for Medium-Range Weather Forecasts GRIB_subCentre: 0 Conventions: CF-1.7 institution: European Centre for Medium-Range Weather Forecasts history: 2023-05-08T17:57 GRIB to CDM+CF via cfgrib-0.9.1... path: ../data/mars.grib
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, 20)),
)
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 [00:54<00:00, 54.75s/it]
54.75771713256836 s
Lineplot: evaluate the effect of bits#
[5]:
suite.nblineplot()
Spatial plots: evaluate the spatial distribution of errors#
[6]:
if not os.getenv("SPHINX_BUILD"):
fcpy.nbspatialplot(
ds,
baseline=fcpy.Float(bits=32),
compressor=fcpy.LinQuantization(bits=12),
third_dim="hybrid",
)
[ ]: