Commit 3eb6c46f authored by ARCHER's avatar ARCHER 💬
Browse files

cast dtype to keep NETCF4_CLASSIC format

parent 59768810
...@@ -197,8 +197,13 @@ def writeLight(fname,data,date,meta=None): ...@@ -197,8 +197,13 @@ def writeLight(fname,data,date,meta=None):
meta_not_implemented = { meta_not_implemented = {
#'wind_streaks_orientation_stddev' : None #'wind_streaks_orientation_stddev' : None
} }
# translate dtype is only relevant for NETCDF4_CLASSIC
translate_dtype = {
np.dtype(np.uint8) : np.dtype(np.int16)
}
x,y = data['owiLon'].T.shape x,y = data['owiLon'].T.shape
nc=netCDF4.Dataset(fname, 'w', format='NETCDF4') nc=netCDF4.Dataset(fname, 'w', format='NETCDF4_CLASSIC')
nc.createDimension('time',1) nc.createDimension('time',1)
nc.createDimension('y',y) nc.createDimension('y',y)
nc.createDimension('x',x) nc.createDimension('x',x)
...@@ -213,7 +218,7 @@ def writeLight(fname,data,date,meta=None): ...@@ -213,7 +218,7 @@ def writeLight(fname,data,date,meta=None):
setattr(nc, global_attr, meta[global_attr]) setattr(nc, global_attr, meta[global_attr])
except: except:
logger.warning('skipping missing attr %s' % global_attr) logger.warning('skipping missing attr %s' % global_attr)
time = nc.createVariable('time',np.int64,dimensions=('time')) time = nc.createVariable('time',np.int32,dimensions=('time')) # np.int32 induce 2038 bug, but is compatible with nc3
time.standard_name = 'time' time.standard_name = 'time'
epoch = datetime.datetime(1970, 1, 1) epoch = datetime.datetime(1970, 1, 1)
time.units = "seconds since %s" % epoch.strftime("%Y-%m-%d %H:%M:%S") time.units = "seconds since %s" % epoch.strftime("%Y-%m-%d %H:%M:%S")
...@@ -229,7 +234,10 @@ def writeLight(fname,data,date,meta=None): ...@@ -229,7 +234,10 @@ def writeLight(fname,data,date,meta=None):
except: except:
fill_value=None fill_value=None
# transpose dims for correct netcdf ordering # transpose dims for correct netcdf ordering
ncvar = nc.createVariable(out_name,value.dtype,dimensions=('time','y','x'),fill_value=fill_value) dtype = value.dtype
if dtype in translate_dtype:
dtype = translate_dtype[dtype]
ncvar = nc.createVariable(out_name,dtype,dimensions=('time','y','x'),fill_value=fill_value)
for _attr in attrs: for _attr in attrs:
try: try:
...@@ -401,7 +409,7 @@ def nclight2gridded(filein,fileout): ...@@ -401,7 +409,7 @@ def nclight2gridded(filein,fileout):
ds_gd.rio.set_spatial_dims('x','y', inplace=True) ds_gd.rio.set_spatial_dims('x','y', inplace=True)
ds_gd.rio.write_crs(crs, inplace=True) ds_gd.rio.write_crs(crs, inplace=True)
ds_gd.to_netcdf(fileout,format='NETCDF4') ds_gd.to_netcdf(fileout,format='NETCDF4_CLASSIC')
def getAttribute(fname, attr): def getAttribute(fname, attr):
try: try:
......
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