-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added nhi_chloride_concentration v1.0.0
- Loading branch information
Showing
3 changed files
with
47 additions
and
2 deletions.
There are no files selected for viewing
Binary file added
BIN
+30.6 MB
src/nhflodata/data/mockup/nhi_chloride_concentration/v1.0.0/chloride_p50.nc
Binary file not shown.
28 changes: 28 additions & 0 deletions
28
src/nhflodata/data/mockup/nhi_chloride_concentration/v1.0.0/reduce_filesize_concentration.py
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,28 @@ | ||
import os | ||
import nlmod | ||
import xarray as xr | ||
|
||
nhflo_data_dir = "/Users/bdestombe/Downloads" | ||
fp_cl = os.path.join(nhflo_data_dir, "3dchloride_result.nc") | ||
assert os.path.isfile(fp_cl), f"file {fp_cl} not found" | ||
cl = xr.open_dataset(fp_cl) | ||
|
||
for p in cl.percentile.values: | ||
conc = cl["3d-chloride"].sel(percentile=p).rename("chloride_{p}") | ||
vmin, vmax = conc.min().item(), conc.max().item() | ||
encoding = { | ||
"zlib": True, | ||
"complevel": 5, | ||
"fletcher32": True, # Store checksums to detect corruption | ||
} | ||
dval_max = 5. | ||
assert nlmod.dims.attributes_encodings.is_int16_allowed(vmin, vmax, dval_max), "Store as float instead" | ||
scale_factor, add_offset = nlmod.dims.attributes_encodings.compute_scale_and_offset(vmin, vmax) | ||
encoding["dtype"] = "int16" | ||
encoding["scale_factor"] = scale_factor | ||
encoding["add_offset"] = add_offset | ||
encoding["_FillValue"] = -32767 # default for NC_SHORT | ||
|
||
fp_out = os.path.join(nhflo_data_dir, f"chloride_{p}.nc") | ||
conc.to_netcdf(fp_out, encoding={"chloride_{p}": encoding}) | ||
|
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