Commit 44143ff0 authored by François Fortin's avatar François Fortin
Browse files

we can now check if a colomn is standard or extended

in the file  executable_module/metro_preprocess_qa_qc_forecast.py
That enable us to treat an error in extended data as less critical 
parent b397f1ca
......@@ -73,13 +73,39 @@ class Metro_data:
is raised.
"""
def __init__(self, lData_types=[]):
## def __init__(self, lData_types=[]):
## """
## Perform initialisation of a Metro_data object
## Arguments:
## lData_types = use to initialised the matrix with a number of column
## determined by len(lData_types).
## """
## self.bRead_only = False
## self.dHeader = {}
## self.npMatrix = numpy.array([], dtype=numpy.float)
## # Name of the columns of the matrix
## self.lMatrix_col_name = []
## for data_type in lData_types:
## self.lMatrix_col_name.append(data_type['NAME'])
def __init__(self, lStdData_types=[], lExtData_types=[]):
"""
Perform initialisation of a Metro_data object
Perform initialisation of a Metro_data object.
Column are of to kind: Standard Element and Extended element.
Both are treated the same way but a call to the method:
'is_standardCol' can be use to distinguish both.
Arguments:
lData_types = use to initialised the matrix with a number of column
determined by len(lData_types).
lStdData_types = use to initialised the matrix with a number of column
determined by len(lStdData_types) + len(lExtData_types).
lExtData_types = use to initialised the matrix with a number of column
determined by len(lStdData_types) + len(lExtData_types).
"""
......@@ -87,10 +113,18 @@ class Metro_data:
self.dHeader = {}
self.npMatrix = numpy.array([], dtype=numpy.float)
# Name of the columns of the matrix
self.lMatrix_col_name = []
for data_type in lData_types:
self.lMatrix_col_name.append(data_type['NAME'])
# Name of the columns of the matrix
self.lMatrix_std_col_name = []
for data_type in lStdData_types:
self.lMatrix_std_col_name.append(data_type['NAME'])
self.lMatrix_ext_col_name = []
for data_type in lExtData_types:
self.lMatrix_ext_col_name.append(data_type['NAME'])
self.lMatrix_col_name = self.lMatrix_std_col_name + self.lMatrix_ext_col_name
def set_readonly( self, bIs_read_only ):
"""
......@@ -104,6 +138,12 @@ class Metro_data:
"""
return self.bRead_only
def is_standardCol( self, sColName ):
"""
Return True if sColName is a standard column.
"""
return sColName in self.lMatrix_std_col_name
#-------------------------------------------------------------------------------
#
# Name: set_header_value
......@@ -268,11 +308,13 @@ class Metro_data:
Descriptions: Append a new column of data to the matrix. Matix column
will be accessible with the name specified by sCol_name.
Column will be treated as extended
"""
if not self.is_readonly():
if sCol_name not in self.lMatrix_col_name:
self.lMatrix_col_name.append(sCol_name)
self.lMatrix_ext_col_name.append(sCol_name)
# Append column in the matrix
self.npMatrix = self.__append_col_to_matrix(self.npMatrix,\
......
......@@ -112,16 +112,15 @@ class Metro_dom2metro(Metro_module):
metro_config.get_value('XML_FORECAST_PREDICTION_STANDARD_ITEMS')
lExtended_forecast = \
metro_config.get_value('XML_FORECAST_PREDICTION_EXTENDED_ITEMS')
lData_types = lStandard_forecast + lExtended_forecast
for_data = metro_data.Metro_data(lData_types)
for_data = metro_data.Metro_data(lStandard_forecast,lExtended_forecast)
forecast_data = self.__extract_data_from_dom(for_data,
self.domForecast,
lHeader_keys,
sHeader_xpath,
lData_types,
lStandard_forecast,
lExtended_forecast,
sData_xpath)
except "IOERROR":
sXmlError = _("XML error in file '%s'.") % (sFilename)
......@@ -165,15 +164,15 @@ class Metro_dom2metro(Metro_module):
'XML_OBSERVATION_MEASURE_STANDARD_ITEMS')
lExtended_observation = metro_config.get_value( \
'XML_OBSERVATION_MEASURE_EXTENDED_ITEMS')
lData_types = lStandard_observation + lExtended_observation
obs_data = metro_data.Metro_data(lData_types)
obs_data = metro_data.Metro_data(lStandard_observation,lExtended_observation)
observation_data = self.__extract_data_from_dom(obs_data,
self.domObservation,
lHeader_keys,
sHeader_xpath,
lData_types,
lStandard_observation,
lExtended_observation,
sData_xpath)
except "METRoDateError", sError:
sXmlError = _("XML error in file '%s'.\n") % (sFilename) +\
......@@ -228,16 +227,16 @@ class Metro_dom2metro(Metro_module):
'XML_OBSERVATION_MEASURE_STANDARD_ITEMS')
lExtended_observation = metro_config.get_value( \
'XML_OBSERVATION_MEASURE_EXTENDED_ITEMS')
lData_types = lStandard_observation + lExtended_observation
obs_data = metro_data.Metro_data(lData_types)
obs_data = metro_data.Metro_data(lStandard_observation,lExtended_observation)
observation_data = \
self.__extract_data_from_dom(obs_data,
self.domObservation_ref,
lHeader_keys,
sHeader_xpath,
lData_types,
lStandard_observation,
lExtended_observation,
sData_xpath)
except:
sXmlError = _("XML error in file '%s'.") % (sFilename)
......@@ -286,14 +285,14 @@ class Metro_dom2metro(Metro_module):
'XML_STATION_ROADLAYER_STANDARD_ITEMS')
lExtended_roadlayer = metro_config.get_value( \
'XML_STATION_ROADLAYER_EXTENDED_ITEMS')
lData_types = lStandard_roadlayer + lExtended_roadlayer
cs_data = metro_data_station.Metro_data_station(lData_types)
cs_data = metro_data_station.Metro_data_station(lStandard_roadlayer,lExtended_roadlayer )
station_data = self.__extract_data_from_dom(cs_data,
self.domStation,
lHeader_defs,
sHeader_xpath,
lData_types,
lStandard_roadlayer,
lExtended_roadlayer,
sData_xpath)
except:
......@@ -324,7 +323,8 @@ class Metro_dom2metro(Metro_module):
def __extract_data_from_dom(self, metro_data, domDom,
ldHeader_keys, sHeader_xpath,
lData_keys, sData_xpath):
lStdData_keys, lExtData_keys,
sData_xpath):
"""
Name: __extract_data_from_dom
......@@ -334,7 +334,8 @@ class Metro_dom2metro(Metro_module):
[I] ldHeader_keys: List of dictionnaries containing the date
definitions as defined in metro_config.py
[I] sHeader_xpath: xpath of the header
[I] lData_keys: like ldHeader_keys but for data
[I] lStdData_keys: like ldHeader_keys but for standard data
[I] lExtData_keys: like ldHeader_keys but for extended data
[I] sData_xpath : xpath for the data.
Output: metro_data : object containing all the data extracted.
......@@ -358,6 +359,8 @@ class Metro_dom2metro(Metro_module):
metro_data.set_header(dHeader)
lData_keys = lStdData_keys + lExtData_keys
if lData_keys != None and sData_xpath != None:
# extraction de toute les nodes de mesure contenue dans le DOM
lData_matrix = metro_xml.extract_xpath(lData_keys, domDom,\
......
......@@ -91,11 +91,17 @@ class Metro_preprocess_qa_qc_forecast(Metro_preprocess):
npElement = wf_controlled_data.get_matrix_col(sElement)
for fElement in npElement:
if fpconst.isNaN(fElement):
sMessage = _("Value in forecast file must be valid.\n") +\
_("A value for the element <%s> is invalid") % (sElement.lower())+\
_(" in the file\n'%s'") % (metro_config.get_value("FILE_FORECAST_IN_FILENAME"))
if wf_controlled_data.is_standardCol(sElement):
sMessage = _("Value in forecast file must be valid.\n") +\
_("A value for the element <%s> is invalid") % (sElement.lower())+\
_(" in the file\n'%s'") % (metro_config.get_value("FILE_FORECAST_IN_FILENAME"))
raise "MetroAtmosphericForecastError", sMessage
raise "MetroAtmosphericForecastError", sMessage
else:
sMessage = _("A value for the extended element <%s> is invalid") % (sElement.lower())+\
_(" in the file\n'%s'") % (metro_config.get_value("FILE_FORECAST_IN_FILENAME"))
metro_logger.print_message(metro_logger.LOGGER_MSG_WARNING,\
sMessage)
......
Supports Markdown
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