-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wrote a simple consolidator script for the chunked outputs
the script is very inefficient, and I recall NetCDF having an in-built function for this, but anyway, it works, and I can wait...
- Loading branch information
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# %% | ||
import numpy as np | ||
from tqdm import tqdm | ||
|
||
from pycsam.src import io, var | ||
from pycsam.inputs.icon_global_run import params | ||
|
||
chunk_start = 0 | ||
n_cells = 20480 | ||
chunk_sz = 100 | ||
|
||
dat_path = params.path_output + "global_dataset/chunks/" | ||
out_path = params.path_output + "global_dataset/" | ||
out_fn = 'icon_global_R2B4' | ||
|
||
global_dat = np.zeros((n_cells), dtype='object') | ||
|
||
cnt = 0 | ||
for chunk in tqdm(range(chunk_start, n_cells, chunk_sz)): | ||
|
||
sfx = "_" + str(chunk+chunk_sz) | ||
fn = params.fn_output + sfx + '.nc' | ||
|
||
writer = io.nc_writer(params, sfx) | ||
|
||
if chunk+chunk_sz > n_cells: | ||
chunk_end = n_cells | ||
else: | ||
chunk_end = chunk+chunk_sz | ||
|
||
for ii in range(chunk, chunk_end): | ||
struct = var.obj() | ||
res = writer.read_dat(dat_path, fn, ii, struct) | ||
global_dat[cnt] = struct | ||
# print(cnt) | ||
del struct | ||
|
||
cnt += 1 | ||
|
||
# print(cnt, chunk_end) | ||
print("\n==========") | ||
print("Collection done; writing output...") | ||
print("==========\n") | ||
assert (cnt) == chunk_end | ||
|
||
params.path_output = out_path | ||
global_writer = io.nc_writer(params, '') | ||
|
||
for cnt, item in tqdm(enumerate(global_dat)): | ||
global_writer.duplicate(cnt, item) | ||
|
||
# %% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters