Skip to content

Commit

Permalink
Merge branch 'hydroffice:master' into mean_speed_column
Browse files Browse the repository at this point in the history
  • Loading branch information
eriffon authored Dec 4, 2024
2 parents c89ef67 + 8e56673 commit 11362cc
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions scripts/reduce_netcdf_woa23.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import logging
import os

from netCDF4 import Dataset

from hyo2.ssm2.app.gui.soundspeedmanager import AppInfo

logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)

input_path = r"C:\Users\gmasetti\AppData\Local\HydrOffice\Sound Speed\atlases\woa23_orig"
output_path = r"C:\Users\gmasetti\AppData\Local\HydrOffice\Sound Speed\atlases\woa23"

# """ USED TO REDUCE THE SIZE OF THE FULL WOA13 DATABASE """

# temp annual
file = "woa18_decav_t00_04.nc"
i_path = os.path.join(input_path, "temp", file)
i = Dataset(i_path, mode='r')
o_path = os.path.join(output_path, "temp", file)
if os.path.exists(o_path):
os.remove(o_path)
o = Dataset(o_path, mode='w')

for name, dim in i.dimensions.items():
o.createDimension(name, len(dim) if not dim.isunlimited() else None)

for name, var_i in i.variables.items():

if name in ['lat', 'lon', 'depth', 't_an']:
# create variable
var_o = o.createVariable(name, var_i.datatype, var_i.dimensions)
# copy attributes
var_o.setncatts({k: var_i.getncattr(k) for k in var_i.ncattrs()})
# copy data
var_o[:] = var_i[:]

# temp monthly/seasonal
for id in range(1, 17):
file = "woa18_decav_t%02d_04.nc" % id
i_path = os.path.join(input_path, "temp", file)
i = Dataset(i_path, mode='r')
o_path = os.path.join(output_path, "temp", file)
if os.path.exists(o_path):
os.remove(o_path)
o = Dataset(o_path, mode='w')

for name, dim in i.dimensions.items():
o.createDimension(name, len(dim) if not dim.isunlimited() else None)

for name, var_i in i.variables.items():

if name in ['lon', 'lat', 't_an', 's_an', 't_sd', 's_sd', 'depth']:
# create variable
var_o = o.createVariable(name, var_i.datatype, var_i.dimensions)
# copy attributes
var_o.setncatts({k: var_i.getncattr(k) for k in var_i.ncattrs()})
# copy data
var_o[:] = var_i[:]

# temp monthly/seasonal
for id in range(1, 17):
file = "woa18_decav_s%02d_04.nc" % id
i_path = os.path.join(input_path, "sal", file)
i = Dataset(i_path, mode='r')
o_path = os.path.join(output_path, "sal", file)
if os.path.exists(o_path):
os.remove(o_path)
o = Dataset(o_path, mode='w')

for name, dim in i.dimensions.items():
o.createDimension(name, len(dim) if not dim.isunlimited() else None)

for name, var_i in i.variables.items():

if name in ['lon', 'lat', 't_an', 's_an', 't_sd', 's_sd', 'depth']:
# create variable
var_o = o.createVariable(name, var_i.datatype, var_i.dimensions)
# copy attributes
var_o.setncatts({k: var_i.getncattr(k) for k in var_i.ncattrs()})
# copy data
var_o[:] = var_i[:]

0 comments on commit 11362cc

Please sign in to comment.