-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloudify_orcestra.py
More file actions
105 lines (93 loc) · 3.27 KB
/
Copy pathcloudify_orcestra.py
File metadata and controls
105 lines (93 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
from typing import Dict, Any
import glob
from tqdm import tqdm
import xarray as xr
from cloudify.utils.datasethelper import (
#reset_encoding_get_mapper,
open_zarr_and_mapper,
adapt_for_zarr_plugin_and_stac,
set_compression,
)
from cloudify.utils.statistics import (
build_summary_df,
summarize_overall,
print_summary
)
# Configuration constants
TRUNK = "/work/mh0492/m301067/orcestra/healpix/"
DIMS = ["2d", "3d"]
# ORCESTRA dataset configuration
conf_dict = dict(
source_id="ICON-LAM",
institution_id="MPI-M",
project_id="ORCESTRA",
activity_id="ORCESTRA",
experiment_id="orcestra_1250m",
authors="Romain Fiévet",
contact="romain.fievetATmpimet.mpg.de",
description="https://orcestra-campaign.org/lam.html",
)
def add_orcestra(
mapper_dict: Dict[str, Any],
dsdict: Dict[str, xr.Dataset],
l_dask: bool = True
) -> tuple[Dict[str, Any], Dict[str, xr.Dataset]]:
"""
Add ORCESTRA datasets to the mapper dictionary and dataset dictionary.
This function processes ORCESTRA healpix datasets from the specified trunk directory,
handling both 2D and 3D dimensions, and preparing them for Zarr storage.
Args:
mapper_dict: Dictionary mapping dataset IDs to storage mappers
dsdict: Dictionary mapping dataset IDs to xarray Datasets
Returns:
tuple[Dict[str, Any], Dict[str, xr.Dataset]]: Updated mapper_dict and dsdict
Raises:
ValueError: If required trunk directory or datasets are not accessible
"""
# Find all initial date directories
init_dates_trunks = [
a
for a in sorted(glob.glob(TRUNK + "/*"))
#if a.split("/")[-1][0] == "0"
#if not "-rerun" in a
if "-rerun" in a
]
dsone = None
local_dsdict={}
for ini in tqdm(init_dates_trunks):
#if not "0819" in ini:
# continue
init_date = ini.split("/")[-1]
for dim in DIMS:
dstrunk = f'{ini}/{conf_dict["experiment_id"]}_{init_date}_{dim}_hpz12.zarr'
dsname = f'{conf_dict["project_id"].lower()}.{conf_dict["source_id"]}.s2024-{init_date[0:2]}-{init_date[2:4]}_{dim}_PT10M_12'
if dim == "3d":
dsname = dsname.replace("PT10M", "PT4H")
chunks="auto"
if not l_dask:
chunks=None
opts=dict(
consolidated=True,
chunks=chunks,
)
ds, mapper_dict[dstrunk] = open_zarr_and_mapper(
dstrunk, storage_options=dict(cache_size=0),**opts
)
if not dsone:
dsone = ds.copy()
ds["cell"] = dsone["cell"]
ds.attrs.update(conf_dict)
#print(ds.encoding["source"])
print(dsname)
#mapper_dict, ds = reset_encoding_get_mapper(mapper_dict, dsname, ds, l_dask=l_dask)
ds = adapt_for_zarr_plugin_and_stac(dsname, ds)
ds = set_compression(ds)
ds.encoding["source"]=dstrunk
dsdict[dsname] = ds
local_dsdict[dsname] = ds
df=build_summary_df(local_dsdict)
df.to_csv("/tmp/orcestra_datasets.csv")
su=summarize_overall(df)
print(print_summary(su))
del local_dsdict
return mapper_dict, dsdict