Commit 23acc2aa authored by Jeff Piolle's avatar Jeff Piolle
Browse files

Merge remote-tracking branch 'origin/develop' into develop

parents b6055079 5153704c
......@@ -3,7 +3,7 @@
cerbere.mapper.ascatifrncfile
============================
Mapper class for IFREMER ASCAT netcdf files (converted from BUFR)
Mapper class for IFREMER ASCAT / OSCAT netcdf files (converted from BUFR)
:copyright: Copyright 2013 Ifremer / Cersat.
:license: Released under GPL v3 license, see :ref:`license`.
......@@ -15,7 +15,7 @@ from datetime import datetime
from collections import OrderedDict
import numpy
from .. import READ_ONLY, WRITE_NEW
from .ncfile import NCFile
from ..datamodel.field import Field
from ..datamodel.variable import Variable
......@@ -23,10 +23,10 @@ from ..datamodel.variable import Variable
VIRTUALFIELD_DESCR = {'wind_speed_selection': 'speed',
'wind_dir_selection': 'direction'
}
VIRTUALFIELD_MATCHING = {
'wind_speed_selection': 'Wind_speed_at_10_m_%d',
'wind_dir_selection': 'Wind_direction_at_10_m_%d'
}
#VIRTUALFIELD_MATCHING = {
#'wind_speed_selection': 'Wind_speed_at_10_m_%d',
#'wind_dir_selection': 'Wind_direction_at_10_m_%d'
#}
VIRTUALFIELD_UNITS = {
'wind_speed_selection': 'm s-1',
'wind_dir_selection': 'degrees'
......@@ -41,6 +41,20 @@ class AscatIFRNCFile(NCFile):
variable. Last, it adds virtual variables to provide the best
wind speed and direction solutions.
"""
def __init__(self, url=None, mode=READ_ONLY,ncformat='NETCDF4_CLASSIC', **kwargs):
super(AscatIFRNCFile,self).__init__(url=url,mode=mode,ncformat=ncformat,**kwargs)
if 'OSCAT' in url:
self.VIRTUALFIELD_MATCHING={
'wind_speed_selection': 'Wind_speed_at_10_m__%d',
'wind_dir_selection': 'Wind_direction_at_10_m__%d'
}
else:
self.VIRTUALFIELD_MATCHING={
'wind_speed_selection': 'Wind_speed_at_10_m_%d',
'wind_dir_selection': 'Wind_direction_at_10_m_%d'
}
return
def get_geolocation_field(self, fieldname):
matching = {'time': 'time',
'lon': 'Longitude',
......@@ -153,7 +167,7 @@ class AscatIFRNCFile(NCFile):
idx = self.get_handler().variables[idxname][slices]
else:
idx = self.get_handler().variables[idxname][:]
varname = VIRTUALFIELD_MATCHING[fieldname]
varname = self.VIRTUALFIELD_MATCHING[fieldname]
solutions = []
for sol in range(4):
solname = varname % sol
......
# -*- coding: utf-8 -*-
"""
cerbere.mapper.oscatifrncfile
============================
Mapper class for IFREMER OSCAT netcdf files (converted from BUFR)
:copyright: Copyright 2014 Ifremer / Cersat.
:license: Released under GPL v3 license, see :ref:`license`.
.. sectionauthor:: agrouaze
.. codeauthor:: agrouaze
"""
from datetime import datetime
from collections import OrderedDict
import numpy
import logging
from .ncfile import NCFile
from ..datamodel.field import Field
from ..datamodel.variable import Variable
from cerbere.mapper.ascatifrncfile import AscatIFRNCFile
#VIRTUALFIELD_DESCR = {'wind_speed_selection': 'speed',
#'wind_dir_selection': 'direction'
#}
VIRTUALFIELD_MATCHING = {
'wind_speed_selection': 'Wind_speed_at_10_m__%d',
'wind_dir_selection': 'Wind_direction_at_10_m__%d'
}
#VIRTUALFIELD_UNITS = {
#'wind_speed_selection': 'm s-1',
#'wind_dir_selection': 'degrees'
#}
#class OscatIFRNCFile(NCFile):
class OscatIFRNCFile(AscatIFRNCFile):
#print 'usage of the oscatmapper'
"""Mapper class for IFREMER OSCAT netcdf files (converted from BUFR)
The IFREMER OSCAT files are in netCDF format but not cf compliant
(for instance for time). This class is inherited from the
:class:`NCFile` mapper but extended to mimic the presence of a `time`
variable. Last, it adds virtual variables to provide the best
wind speed and direction solutions.
"""
#def get_geolocation_field(self, fieldname):
#matching = {'time': 'time',
#'lon': 'Longitude',
#'lat': 'Latitude'}
#if fieldname in matching:
#return matching[fieldname]
#else:
#return None
#def get_matching_dimname(self, geodimname):
#matching = {'time':'time',
#'row': 'measurement',
#'cell': 'swath'}
#if geodimname in matching:
#return matching[geodimname]
#else:
#return None
#def get_standard_dimname(self, geodimname):
#matching = {'time':'time',
#'measurement': 'row',
#'swath': 'cell'}
#if geodimname in matching:
#return matching[geodimname]
#else:
#return None
#def get_fieldnames(self):
#"""Returns the list of geophysical fields stored for the feature"""
#fieldnames = super(OscatIFRNCFile, self).get_fieldnames()
## add virtual variables for best wind speed and direction
#fieldnames.extend(['wind_speed_selection', 'wind_dir_selection'])
#return fieldnames
#def read_field(self, fieldname):
#"""
#Return the field, without its values.
#Actual values can be retrieved with read_values() method.
#"""
## special implementation case for time field which is not
## available as a variable in IFREMER OSCAT files
#if fieldname == 'time':
## create a field for time
#variable = Variable(
#shortname=fieldname,
#description='time',
#authority=self.get_naming_authority(),
#standardname='time'
#)
#field = Field(
#variable,
#OrderedDict([('row', self.get_dimsize('row')),
#('cell', self.get_dimsize('cell'))
#]),
#datatype=numpy.dtype(numpy.float32),
#units='seconds since 1990-01-01 00:00:00'
#)
#field.attach_storage(self.get_field_handler(fieldname))
#elif fieldname in ['wind_speed_selection', 'wind_dir_selection']:
## create a virtual field
#variable = Variable(
#shortname=fieldname,
#description='best wind % solution'
#% VIRTUALFIELD_DESCR[fieldname],
#authority=self.get_naming_authority(),
#standardname='wind %s' % VIRTUALFIELD_DESCR[fieldname]
#)
#field = Field(
#variable,
#OrderedDict([('row', self.get_dimsize('row')),
#('cell', self.get_dimsize('cell'))
#]),
#datatype=numpy.dtype(numpy.float32),
#units=VIRTUALFIELD_UNITS[fieldname]
#)
#field.attach_storage(self.get_field_handler(fieldname))
#else:
#field = NCFile.read_field(self, fieldname)
#return field
def read_values(self, fieldname, slices=None,indices=None):
"""
"""
test=fieldname in ['wind_speed_selection', 'wind_dir_selection']
#print 'debuug agrouaze, i am in readvalues from oscatmmapper',fieldname,test,indices
if fieldname == 'time':#creation of virtual variable
if self._handler is None:
self._handler = self.get_handler()
if slices:
datevar = self.get_handler().variables['Date'][slices]
else:
datevar = self.get_handler().variables['Date'][:]
if self.get_handler().variables['Date'].units\
!= "julian day since 1990-01-01 0:0:0":
raise Exception("Inconsistent start date")
if slices:
millisecvar = self.get_handler().variables['Millisec'][slices]
else:
millisecvar = self.get_handler().variables['Millisec'][:]
nbsecinday=numpy.float(86400)
mille=numpy.float(1000)
millisecvar=millisecvar.astype('float64')
datevar=datevar.astype('float64')
times = datevar * nbsecinday + millisecvar / mille
#times = datevar * 86400. + millisecvar / 1000.
#jojo=millisecvar[825,0]
#joja=millisecvar[826,0]
#jojo=mille[825,0]
#joja=mille[826,0]
#tralal=1151.
#print 'jojo',jojo,joja,type(datevar[0,0]),type(millisecvar[0,0]),tralal,type(tralal),numpy.shape(times),datevar[825,0]*nbsecinday,datevar[826,0]*nbsecinday
#print 'times 825 ','{0:.8f}'.format(float(times[825,0])),'{0:.8f}'.format(float(times[826,0])),
#input()
if slices is None and indices is None:
return times
elif slices is None and not indices is None:
#print 'agrouaze debug indices time',indices
return times[indices]
elif not slices is None and indices is None:
return times[slices]
else:
raise Exception("cannot handle slice and indice at the same time")
elif fieldname in ['wind_speed_selection', 'wind_dir_selection']:
idxname = 'Index_of_selected_wind_vector'
if slices:
idx = self.get_handler().variables[idxname][slices]
else:
idx = self.get_handler().variables[idxname][:]
varname = VIRTUALFIELD_MATCHING[fieldname]
solutions = []
for sol in range(1,5):
solname = varname % sol
#logging.debug('varname used : %s',solname)
if solname in self.get_handler().variables:
solutions.append(self.get_handler().variables[solname])
values = numpy.ma.masked_all(
(self.get_dimsize('row'), self.get_dimsize('cell')),
dtype=numpy.dtype(numpy.float32)
)
#print 'agrouaze debbug ',values
if slices is not None:
values = values[slices]
#logging.debug('range(len(solutions)): %s',range(len(solutions)))
for sol in range(len(solutions)):
ind = numpy.ma.where(idx == sol) #formerly sol+1
if slices:
solvalues = solutions[sol][slices]
else:
solvalues = solutions[sol][:]
values[ind] = solvalues[ind]
#print 'agrouaze debug mapper oscat',values
return values
else:
return super(OscatIFRNCFile, self).read_values(fieldname,
slices=slices)
#def get_start_time(self):
#"""Return start of temporal coverage"""
#start = datetime.strptime(
#self.get_handler().Start_Date,
#'%Y%m%dT%H%M%S'
#)
#return start
#def get_end_time(self):
#"""Return end of temporal coverage"""
#end = datetime.strptime(
#self.get_handler().Stop_Date,
#'%Y%m%dT%H%M%S'
#)
#return end
#def get_bbox(self):
#"""
#return the bounding box of the feature, as a tuple
#(lonmin, latmin, lonmax, latmax)
#"""
#return (float(self.get_handler().West_Longitude),
#float(self.get_handler().South_Latitude),
#float(self.get_handler().East_Longitude),
#float(self.get_handler().North_Latitude)
#)
#def get_collection_id(self): #agrouaze add inspired from ghrsstmapper
#"""return the identifier of the product collection"""
#attrs = self.get_handler().ncattrs()
#if 'DSD_entry_id' in attrs:
#return self.get_handler().DSD_entry_id
#elif 'id' in attrs:
#return self.get_handler().id
#else:
#return self.get_handler().PlatForm_Id+self.get_handler().Sensor_Id+self.get_handler().Product_Id
#return None
This diff is collapsed.
......@@ -79,6 +79,10 @@ class SAFEOCNNCFile(NCFile):
if product not in [WIND, WAVE, DOPPLER]:
raise Exception("Unknown product type (must be WIND, WAVE or DOPPLER) : %s",
product)
if ('IW' in url or 'EW' in url) and product=='OSW':
raise Exception("IW and EW product do not contains any WAVE data : %s",
product)
print "PPPP", product
self._product = product
return
......@@ -341,8 +345,10 @@ class SAFEOCNNCFile(NCFile):
returns the bounding box of the feature, as a tuple
(lonmin, latmin, lonmax, latmax)
'''
vlon = self.get_handler().variables['oswLon']
vlat = self.get_handler().variables['oswLat']
dimlonname=self.get_geolocation_field('lon')
dillatname=self.get_geolocation_field('lat')
vlon = self.get_handler().variables[dimlonname]
vlat = self.get_handler().variables[dillatname]
if vlon.shape[0] == 1:
lonmin = lonmax = vlon[0, 0]
latmin = latmax = vlat[0, 0]
......
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