-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcnaps_keepbits.py
More file actions
80 lines (39 loc) · 1.78 KB
/
cnaps_keepbits.py
File metadata and controls
80 lines (39 loc) · 1.78 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
#!/usr/bin/env python
# coding: utf-8
# # Calculate keepbits for CNAPSv2 daily average files with 99.9% info
# snip out a piece of water only and determine keepbits for CNAPS vars using xinfo, using a water only subset
# In[1]:
import xarray as xr
import xbitinfo as xb
import fsspec
from pathlib import Path
# In[2]:
fs = fsspec.filesystem('file')
# In[3]:
flist = fs.glob('/storage/cnapsv2/useast_avg_*.nc')
# In[4]:
ds = xr.open_dataset(flist[0], chunks={'ocean_time':1}, drop_variables=['dstart'])
# In[5]:
# calculate keepbits on a section with water cells only, and only for first 10 time steps
# In[6]:
ds2 = ds[['temp','salt','omega','zeta']].isel(ocean_time=slice(0,10), s_rho=-1, s_w=-4,
eta_rho=slice(500,700), xi_rho=slice(800,1000))
bitinfo = xb.get_bitinformation(ds2, dim="xi_rho", implementation='python')
keepbits1 = xb.get_keepbits(bitinfo, inflevel=0.999) # get number of mantissa bits to keep for 99% real information
keepbits1.values
# In[7]:
ds2 = ds[['v','vbar']].isel(ocean_time=slice(0,100), s_rho=-1,
eta_v=slice(500,700), xi_v=slice(800,1000))
bitinfo = xb.get_bitinformation(ds2, dim="xi_v", implementation='python')
keepbits2 = xb.get_keepbits(bitinfo, inflevel=0.999) # get number of mantissa bits to keep for 99% real information
keepbits2.values
# In[8]:
ds2 = ds[['u','ubar']].isel(ocean_time=slice(0,100), s_rho=-1,
eta_u=slice(500,700), xi_u=slice(800,1000))
bitinfo = xb.get_bitinformation(ds2, dim="xi_u", implementation='python')
keepbits3 = xb.get_keepbits(bitinfo, inflevel=0.999) # get number of mantissa bits to keep for 99% real information
keepbits3.values
# In[9]:
keepbits = xr.merge([keepbits1, keepbits2, keepbits3], compat='override')
# In[10]:
keepbits.to_netcdf('keepbits.nc', mode='w')