forked from hydroffice/hyo2_soundspeed
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'hydroffice:master' into mean_speed_column
- Loading branch information
Showing
1 changed file
with
82 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,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[:] |