|
| 1 | +import logging |
| 2 | +import os |
| 3 | + |
| 4 | +from netCDF4 import Dataset |
| 5 | + |
| 6 | +from hyo2.ssm2.app.gui.soundspeedmanager import AppInfo |
| 7 | + |
| 8 | +logging.basicConfig(level=logging.DEBUG) |
| 9 | +logger = logging.getLogger(__name__) |
| 10 | + |
| 11 | +input_path = r"C:\Users\gmasetti\AppData\Local\HydrOffice\Sound Speed\atlases\woa23_orig" |
| 12 | +output_path = r"C:\Users\gmasetti\AppData\Local\HydrOffice\Sound Speed\atlases\woa23" |
| 13 | + |
| 14 | +# """ USED TO REDUCE THE SIZE OF THE FULL WOA13 DATABASE """ |
| 15 | + |
| 16 | +# temp annual |
| 17 | +file = "woa18_decav_t00_04.nc" |
| 18 | +i_path = os.path.join(input_path, "temp", file) |
| 19 | +i = Dataset(i_path, mode='r') |
| 20 | +o_path = os.path.join(output_path, "temp", file) |
| 21 | +if os.path.exists(o_path): |
| 22 | + os.remove(o_path) |
| 23 | +o = Dataset(o_path, mode='w') |
| 24 | + |
| 25 | +for name, dim in i.dimensions.items(): |
| 26 | + o.createDimension(name, len(dim) if not dim.isunlimited() else None) |
| 27 | + |
| 28 | +for name, var_i in i.variables.items(): |
| 29 | + |
| 30 | + if name in ['lat', 'lon', 'depth', 't_an']: |
| 31 | + # create variable |
| 32 | + var_o = o.createVariable(name, var_i.datatype, var_i.dimensions) |
| 33 | + # copy attributes |
| 34 | + var_o.setncatts({k: var_i.getncattr(k) for k in var_i.ncattrs()}) |
| 35 | + # copy data |
| 36 | + var_o[:] = var_i[:] |
| 37 | + |
| 38 | +# temp monthly/seasonal |
| 39 | +for id in range(1, 17): |
| 40 | + file = "woa18_decav_t%02d_04.nc" % id |
| 41 | + i_path = os.path.join(input_path, "temp", file) |
| 42 | + i = Dataset(i_path, mode='r') |
| 43 | + o_path = os.path.join(output_path, "temp", file) |
| 44 | + if os.path.exists(o_path): |
| 45 | + os.remove(o_path) |
| 46 | + o = Dataset(o_path, mode='w') |
| 47 | + |
| 48 | + for name, dim in i.dimensions.items(): |
| 49 | + o.createDimension(name, len(dim) if not dim.isunlimited() else None) |
| 50 | + |
| 51 | + for name, var_i in i.variables.items(): |
| 52 | + |
| 53 | + if name in ['lon', 'lat', 't_an', 's_an', 't_sd', 's_sd', 'depth']: |
| 54 | + # create variable |
| 55 | + var_o = o.createVariable(name, var_i.datatype, var_i.dimensions) |
| 56 | + # copy attributes |
| 57 | + var_o.setncatts({k: var_i.getncattr(k) for k in var_i.ncattrs()}) |
| 58 | + # copy data |
| 59 | + var_o[:] = var_i[:] |
| 60 | + |
| 61 | +# temp monthly/seasonal |
| 62 | +for id in range(1, 17): |
| 63 | + file = "woa18_decav_s%02d_04.nc" % id |
| 64 | + i_path = os.path.join(input_path, "sal", file) |
| 65 | + i = Dataset(i_path, mode='r') |
| 66 | + o_path = os.path.join(output_path, "sal", file) |
| 67 | + if os.path.exists(o_path): |
| 68 | + os.remove(o_path) |
| 69 | + o = Dataset(o_path, mode='w') |
| 70 | + |
| 71 | + for name, dim in i.dimensions.items(): |
| 72 | + o.createDimension(name, len(dim) if not dim.isunlimited() else None) |
| 73 | + |
| 74 | + for name, var_i in i.variables.items(): |
| 75 | + |
| 76 | + if name in ['lon', 'lat', 't_an', 's_an', 't_sd', 's_sd', 'depth']: |
| 77 | + # create variable |
| 78 | + var_o = o.createVariable(name, var_i.datatype, var_i.dimensions) |
| 79 | + # copy attributes |
| 80 | + var_o.setncatts({k: var_i.getncattr(k) for k in var_i.ncattrs()}) |
| 81 | + # copy data |
| 82 | + var_o[:] = var_i[:] |
0 commit comments