Commit 0aa946dd authored by Modellers Operational's avatar Modellers Operational
Browse files

Add file conversion for adrift

parent e40cccaa
vars_list=$(echo $VARS | tr "," "\n" | tr ";" "\n")
for v in $vars_list; do
ncatted -a _FillValue,$v,o,f,"-32768"
ncatted -a _FillValue,h,o,f,"-32768"
import numpy as np
import netCDF4 as nc
import datetime as dt
import sys
copy_var = [l for s in [this_str.split(',') for this_str in sys.argv[1].split(';')] for l in s]
out_file = ''
in_file = ''
copy_var.extend(['h', 'mask', 'lon', 'lat'])
ref_date = dt.datetime(2000,1,1)
#copy_var = ['v', 'u', 'h', 'mask', 'lon', 'lat', 'temp', 'salinity', 'ww', 'zeta']
#copy_var = ['lon', 'lat', 'mask', 'h', 'Uwind', 'Vwind']
in_nc = nc.Dataset(in_file, 'r')
out_nc = nc.Dataset(out_file, 'w')
for dimension in in_nc.dimensions.keys():
out_nc.createDimension(dimension, in_nc.dimensions[dimension].size)
for attribute in in_nc.ncattrs():
setattr(out_nc, attribute, getattr(in_nc, attribute))
for var_name in copy_var:
in_var = in_nc.variables[var_name]
var = out_nc.createVariable(var_name, format, in_var.dimensions)
if in_var.ncattrs:
for attribute in in_var.ncattrs():
if attribute not in ['_FillValue']:
setattr(var, attribute, getattr(in_var, attribute))
var[:] = in_var[:]
# time
in_time_str_raw = in_nc.variables['Times'][:]
in_time_str = np.asarray([b''.join(this_str).decode('utf-8') for this_str in in_time_str_raw])
in_time_dt = np.asarray([dt.datetime.strptime(this_str, '%Y-%m-%dT%H:%M:%S.000000') for this_str in in_time_str])
time_sec = np.asarray([(this_dt - ref_date).total_seconds() for this_dt in in_time_dt])
atts = {'units': 'seconds since 2000-01-01 00:00:00',
'long_name': 'time',
'time_zone': 'UTC'}
var = out_nc.createVariable('time', format, ('time'))
for att_name, att_val in atts.items():
setattr(var, att_name, att_val)
var[:] = time_sec
default = src_file=/${OUTPUT_DIR}/${FORECAST_DAY}/${OUTPUT_FILENAME}.nc;
cd /${PORTAL_BASEDIR}/today_forecast/
rm -f
python3 convert_time bash ${VARS};
bash ./ ${VARS};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment