Commit 89908115 authored by Antoine Grouazel's avatar Antoine Grouazel

fix a problem in ncfile.py with fillvalue=None and data in int32 for netcdf4 files

parent 80a99b25
......@@ -15,7 +15,7 @@ Model class for the image feature
import logging
import collections
import copy
import datetime
import numpy
from .abstractfeature import AbstractFeature
......@@ -117,6 +117,7 @@ class Image(AbstractFeature):
elif slices:
if len(slices) != 2:
raise Exception ("slices for the two spatial dimensions of the image must be provided")
logging.debug('image.py | slices %s',slices)
subimage = Image(latitudes=self.extract_field('lat', slices=slices),
longitudes=self.extract_field('lon', slices=slices),
times=self.extract_field('time', slices=slices),
......@@ -307,6 +308,10 @@ class Image(AbstractFeature):
#globalattr['geospatial_lon_resolution'] = self.get_lon()[1] - self.get_lon()[0]
time0 = self.get_datetimes()[0]
time1 = self.get_datetimes()[0]
if not isinstance(time0,datetime.datetime):
# if time0.size!=1:
time0 = time0[0]
time1 = time1[0]
if not 'time_coverage_start' in globalattr:
globalattr['time_coverage_start'] = \
min(time0, time1).strftime('%Y%m%dT%H%M%S')
......
......@@ -177,12 +177,13 @@ class HY2ANSOASHDFFile(HDF5File):
)
dims = self.get_dimensions(fieldname)
#gotchas trick to avoid inheritance from last call to Field
toto = Field(variable=None,datatype=None,dimensions=None,attributes=None, units=None, valid_min=None, valid_max=None)
toto.units='rara'
# toto = Field(variable=None,datatype=None,dimensions=None,attributes=None, units=None, valid_min=None, valid_max=None)
# toto.units='rara'
rec = Field(
variable,
dims,
datatype=numpy.dtype('float64')#float#'float64'
datatype=numpy.dtype('float64'),#float#'float64'
fillvalue=-9999999
)
rec.attach_storage(self.get_field_handler(fieldname))
# MetaData
......@@ -201,11 +202,12 @@ class HY2ANSOASHDFFile(HDF5File):
)
dims = self.get_dimensions('/wind_speed_selection')
#gotchas trick to avoid inheritance from last call to Field
toto = Field(variable=None,datatype=None,dimensions=None,attributes=None, units=None, valid_min=None, valid_max=None)
# toto = Field(variable=None,datatype=None,dimensions=None,attributes=None, units=None, valid_min=None, valid_max=None)
roc = Field(
variable,
dims,
datatype=numpy.dtype('float64')#float#'float64'
datatype=numpy.dtype('float64'),#float#'float64'
fillvalue=-9999999
)
aatrs = self.read_field_attributes('/wind_speed_selection')
......@@ -224,11 +226,12 @@ class HY2ANSOASHDFFile(HDF5File):
)
dims=self.get_dimensions('/wind_dir_selection')
#gotchas trick to avoid inheritance from last call to Field
toto=Field(variable=None,datatype=None,dimensions=None,attributes=None, units=None, valid_min=None, valid_max=None)
# toto=Field(variable=None,datatype=None,dimensions=None,attributes=None, units=None, valid_min=None, valid_max=None)
roc = Field(
variable,
dims,
datatype=numpy.dtype('float64')#float#'float64'
datatype=numpy.dtype('float64'),#float#'float64'
fillvalue=-9999999
)
aatrs = self.read_field_attributes('/wind_dir_selection')
......@@ -305,7 +308,7 @@ class HY2ANSOASHDFFile(HDF5File):
else:
if native[0]!='/':
native = '/'+native
print 'native trasnformed',native
# print 'native trasnformed',native
res = super(HY2ANSOASHDFFile, self).read_values(native)
res = numpy.ma.masked_array(res)
if '_selection' in native:
......
......@@ -669,7 +669,8 @@ class NCFile(AbstractMapper):
# cast from int32 to int64 or the file appeared corrupted
# later (bug in netcdf library?).
if datatype == 'int32':
datatype = 'int64'
datatype = numpy.dtype('int64')
fillvalue = self.get_netcdf_fillvalue(datatype)
fillvalue = numpy.int64(fillvalue)
if datatype == str:
......@@ -789,35 +790,35 @@ class NCFile(AbstractMapper):
# if time is two-dimensional (ex: L3 with regridded passes)
# then the time coordinate variable can not have multiple
# dimensions. We need two variables.
if feature == 'Grid':
# single dimension time variable. We use start sensing
# time as reference, by convention.
self._create_field(varname, datatype, ('time',),
fillvalue, comp, field)
# and an offset 'dtime' variable, in seconds
var = Variable(
'dtime',
description='time difference from reference time',
)
comment = 'time plus sst_dtime gives pixel time'
dims = field.dimensions
if 'time' not in dims:
dims = collections.OrderedDict([('time', 1)])
for dim in field.dimensions:
dims[dim] = field.dimensions[dim]
units = field.units.split('since')[0].strip()
dtimefield = Field(
var,
dimensions=dims,
units=units,
attributes={'comment': comment}
)
self._create_field(
'dtime', datatype,
('time', 'lat', 'lon',),
self.get_netcdf_fillvalue(datatype),
dtimefield, dtimefield)
return
# if feature == 'Grid':
# # single dimension time variable. We use start sensing
# # time as reference, by convention.
# self._create_field(varname, datatype, ('time',),
# fillvalue, comp, field)
# # and an offset 'dtime' variable, in seconds
# var = Variable(
# 'dtime',
# description='time difference from reference time',
# )
# comment = 'time plus sst_dtime gives pixel time'
# dims = field.dimensions
# if 'time' not in dims:
# dims = collections.OrderedDict([('time', 1)])
# for dim in field.dimensions:
# dims[dim] = field.dimensions[dim]
# units = field.units.split('since')[0].strip()
# dtimefield = Field(
# var,
# dimensions=dims,
# units=units,
# attributes={'comment': comment}
# )
# self._create_field(
# 'dtime', datatype,
# ('time', 'lat', 'lon',),
# self.get_netcdf_fillvalue(datatype),
# dtimefield, dtimefield)
# return
# add a dummy time dimension for grids (CF convention) to all
# fields except lat/lon
......@@ -1040,6 +1041,7 @@ class NCFile(AbstractMapper):
'dtime' in self.get_handler().variables):
ncvar = self.get_handler().variables['time']
# start time is set as reference by convention
logging.debug('ahahahh ncfile.py %s',self.get_handler().variables)
ncvar[0] = values.min()
ncvar = self.get_handler().variables['dtime']
ncvar[0, ...] = values - values.min()
......
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