Skip to content

JuliaGeo/ZarrDatasets.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ZarrDatasets

Build Status codecov.io documentation dev

ZarrDatasets.jl is a julia package to read Zarr datasets based on the native julia implementation Zarr.jl using the CommonDataModel.jl interface.

In the following example, data from Copernicus Marine Service is loaded using ZarrDatasets and a subset is saved as a NetCDF file:

using CommonDataModel: @select
using Dates
using NCDatasets
using STAC
using ZarrDatasets

# get the data set URL from product_id and dataset_id and the STAC catalog
function copernicus_marine_catalog(product_id,dataset_id,
    stac_url = "https://stac.marine.copernicus.eu/metadata/catalog.stac.json",
    asset = "timeChunked")

    cat = STAC.Catalog(stac_url);
    item_canditates = filter(startswith(dataset_id),keys(cat[product_id].items))
    # use last version per default
    dataset_version_id = sort(item_canditates)[end]
    item = cat[product_id].items[dataset_version_id]
    return href(item.assets[asset])
end

product_id = "MEDSEA_MULTIYEAR_PHY_006_004"
dataset_id = "med-cmcc-ssh-rean-d"

url = copernicus_marine_catalog(product_id,dataset_id)
ds = ZarrDataset(url);

# longitude, latitude and time are the coordinate variables defined in the
# zarr dataset
ds_sub = @select(ds, time == DateTime(2001,1,1)
    && 7 <= longitude <= 11
    && 42.3 <= latitude <= 44.5)

# save selection as a NetCDF file
NCDataset("$(dataset_id)_selection.nc","c") do ds_nc
    write(ds_nc,ds_sub)
end