JuliaGeo / CommonDataModel.jl

CommonDataModel.jl is a module that defines types common to NetCDF and GRIB data
MIT License
11 stars 4 forks source link

Build Status codecov documentation stable documentation dev

This package contains abstracts type definition for loading and manipulating GRIB, NetCDF, geoTiff and Zarr files. This package aims to follow the Common Data Model and the CF (climate and forecast models) Metadata Conventions.

Format Package read support write support
NetCDF NCDatasets
OPeNDAP NCDatasets -
GRIB GRIBDatasets -
geoTIFF TIFFDatasets -
Zarr ZarrDatasets

Features include:

Here is minimal example for loading files using CommonDataModel:

import CommonDataModel as CDM
import SomeDatasets # where SomeDatasets is either GRIBDatasets, NCDatasets, ZarrDatasets,...

ds = SomeDatasets.Dataset("file_name")

# ntime is the number of time instances
ntime = ds.dim["time"] # or CDM.dims(ds)["time"]

# create an array-like structure v corresponding to variable temperature
v = ds["temperature"]

# load a subset
subdata = v[10:30,30:5:end]

# load all data
data = v[:,:]

# load a global attribute
title = ds.attrib["title"]  # or CDM.attribs(ds)["title"]
close(ds)

Most users would typically import GRIBDatasets, NCDatasets... directly and not CommonDataModel.

File conversions

By implementing a common interface, files can be converted from one format to another using the write function. For example GRIB files can be converted to NetCDF (or Zarr) files:

using NCDatasets # or ZarrDatasets
using GRIBDatasets
using Downloads: download

grib_file = download("https://github.com/JuliaGeo/GRIBDatasets.jl/raw/98356af026ea39a5ec0b5e64e4289105492321f8/test/sample-data/era5-levels-members.grib")
netcdf_file = "test.nc"
NCDataset(netcdf_file,"c") do ds
   write(ds,GRIBDataset(grib_file))
end