-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloudify_orcestra2.py
More file actions
85 lines (74 loc) · 2.41 KB
/
Copy pathcloudify_orcestra2.py
File metadata and controls
85 lines (74 loc) · 2.41 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
from typing import Dict, Any
import glob
from pathlib import Path
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/"
TRUNK = "/work/mh0066/ICON-LAM"
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 + "/*.zarr"))
]
local_dsdict={}
for ini in tqdm(init_dates_trunks):
print(ini)
dsname = '.'.join(ini.split('/')[-1].split('.')[:-1])
chunks="auto"
if not l_dask:
chunks=None
ds, mapper_dict[ini] = open_zarr_and_mapper(
ini, storage_options=dict(cache_size=0),chunks=chunks
)
ds.attrs.update(conf_dict)
ds = adapt_for_zarr_plugin_and_stac(dsname, ds)
ds.encoding["source"]=ini
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