From 978f92105bbc200c2d92badc2f78ad9f96d53081 Mon Sep 17 00:00:00 2001 From: Lauren Gallic Date: Thu, 2 Nov 2023 15:08:11 +0000 Subject: [PATCH] moved constant kerchunk variables to collection asset and kept unique ones for the item level --- .../_kerchunk_helper_functions.py | 23 +++++++++++++-- src/stactools/ecmwf_forecast/stac.py | 29 +++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/stactools/ecmwf_forecast/_kerchunk_helper_functions.py b/src/stactools/ecmwf_forecast/_kerchunk_helper_functions.py index 40345a7..74aa9a9 100644 --- a/src/stactools/ecmwf_forecast/_kerchunk_helper_functions.py +++ b/src/stactools/ecmwf_forecast/_kerchunk_helper_functions.py @@ -71,8 +71,27 @@ def get_kerchunk_indices(part): elif ((part.stream == "scwv") or (part.stream == "wave")) and (part.type == "fc"): mzz = MultiZarrToZarr(out, concat_dims=["time"]) - return convert_base64(compress_lat_lon(mzz.translate())) - + #get output, filter down and only keep the unique d['refs'] items + d = convert_base64(compress_lat_lon(mzz.translate())) + new_d = {} + new_d['refs'] = dict(filter(filter_kerchunk(d['refs'].items()))) + + return new_d + +def filter_kerchunk(pair): + wanted_keys = ['time/0', + 'mp2/0.0.0', + 'mwd/0.0.0', + 'mwp/0.0.0', + 'swh/0.0.0', + 'pp1d/0.0.0', + 'valid_time/0', + 'step/0'] + key, value = pair + if key in wanted_keys: + return True + else: + return False def convert_base64(d): for key in d['refs']: diff --git a/src/stactools/ecmwf_forecast/stac.py b/src/stactools/ecmwf_forecast/stac.py index 606452a..3be680e 100644 --- a/src/stactools/ecmwf_forecast/stac.py +++ b/src/stactools/ecmwf_forecast/stac.py @@ -211,6 +211,35 @@ def create_collection( { "type": GRIB2_MEDIA_TYPE, "roles": ["data"], + "kerchunk:indices": {'refs': {'step/0': 'base64:AAAAAAAAXkA=', + '.zattrs': '{"GRIB_centre":"ecmf","GRIB_centreDescription":"European Centre for Medium-Range Weather Forecasts","GRIB_edition":2,"GRIB_subCentre":0,"coordinates":"meanSea latitude longitude step time valid_time","institution":"European Centre for Medium-Range Weather Forecasts"}', + '.zgroup': '{"zarr_format":2}', + 'meanSea/0': 'base64:AAAAAAAAAAA=', + 'latitude/0': 'base64:AAAAAACAVkCamZmZmZlWwJqZmZmZmdm/', + 'longitude/0': 'base64:AAAAAACAZsAAAAAAAIBmQJqZmZmZmdk/', + 'mp2/.zarray': '{"chunks":[1,451,900],"compressor":null,"dtype":"