コード例 #1
0
 def __check_if_all_value_are_numbers(self, wf_controlled_data):
     """
     Check if all the values in the forecast are numbers.
     """
     for sElement in wf_controlled_data.get_matrix_col_list():
         if sElement.find('TIME') > 0:
             continue
         npElement = wf_controlled_data.get_matrix_col(sElement)
         # In the case of 'CC', only return an error if both SF and IR
         #  are not given
         if sElement is 'CC':
             if metro_config.get_value('SF') and metro_config.get_value('IR'):
                 continue
         for fElement in npElement:
             if fpconst.isNaN(fElement):
                 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 metro_error.Metro_data_error(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_STOP,\
                                                sMessage)
コード例 #2
0
ファイル: metro_read_station.py プロジェクト: akrherz/metro
    def start(self):
        Metro_read.start(self)

        if metro_config.key_exist('FILE_STATION_FILENAME'):
            sFilename = metro_config.get_value('FILE_STATION_FILENAME')
        else:
            sFilename = ""

        if sFilename != "":

            try:
                sFile_content = self._read_input_data(sFilename)
            except IOError:
                sError_message = _("METRo need a valid station file.") 
                metro_logger.print_message(metro_logger.LOGGER_MSG_STOP,
                                           sError_message)
            else:
                # Create and add infdata
                infdata_station = metro_infdata.Metro_infdata(
                    'STATION', metro_infdata.DATATYPE_METRO_DATA)        
                infdata_station.set_input_information(sFile_content)
                self.add_infdata(infdata_station)

                if metro_config.get_value('SUNSHADOW'):
		    infdata_horizon = metro_infdata.Metro_infdata(
                        'HORIZON', metro_infdata.DATATYPE_METRO_DATA)        
                    self.add_infdata(infdata_horizon)

        else:
            sError_message = _("METRo need a station file, please use the ") +\
                             _("option: '--input-station'") 
            metro_logger.print_message(metro_logger.LOGGER_MSG_STOP,
                                       sError_message)
コード例 #3
0
    def __round_roadcast_header( self, roadcast):
        if 'VERTICAL_LEVELS' in roadcast.get_header():
            # Get the default value for the accurary of "float" of the roadcast
            iDefault_precision = \
                metro_config.get_value('DEFAULT_ROADCAST_PREDICTION_PRECISION')

            dData_types = metro_config.get_value('XML_DATATYPE_STANDARD')
            dExtended_data_type = metro_config.get_value('XML_DATATYPE_EXTENDED')

            dData_types.update(dExtended_data_type)
            
            sCurrent_data_type = 'VERTICAL_LEVELS'

            # get precision
            if 'CHILD' in dData_types[sCurrent_data_type]:
                if len(dData_types[sCurrent_data_type]['CHILD']) == 1 and \
                   dData_types[sCurrent_data_type]['CHILD'][0]['DATA_TYPE'] == 'REAL':
                    # If the accuracy have been specified: use it.
                    # Otherwhise use the default value for the roadcast.
                    if 'PRECISION' in dData_types[sCurrent_data_type]['CHILD'][0]:
                        iPrecision = dData_types[sCurrent_data_type]['CHILD'][0]['PRECISION']
                    else:
                        iPrecision = iDefault_precision
                    
            lLevels = roadcast.get_header_value('VERTICAL_LEVELS')

            lRounded = [round(x,iPrecision) for x in lLevels]

            roadcast.set_header_value('VERTICAL_LEVELS',lRounded)
コード例 #4
0
ファイル: metro_xml.py プロジェクト: jacobg0/METRoWin
def create_node_tree_from_dict(domDoc, nodeParent, lDefs, dWriteHandlers,
                               dData):

    # Retrieve the informations on the data types
    dStandard_data_type = metro_config.get_value('XML_DATATYPE_STANDARD')
    dExtended_data_type = metro_config.get_value('XML_DATATYPE_EXTENDED')

    dData_type = metro_util.join_dictionaries(dStandard_data_type,
                                              dExtended_data_type)

    for dDef in lDefs:
        # Retrieve the name and the item type
        sTag = dDef['NAME']
        sXml_tag = dDef['XML_TAG']
        sData_type_name = dDef['DATA_TYPE']

        if dData_type[sData_type_name].has_key('CHILD'):
            #  create the node containing a list of "sub-node"
            lChildList = dData_type[sData_type_name]['CHILD']
            nodeData = dWriteHandlers[sData_type_name](sXml_tag, lChildList,
                                                       dData[sTag],
                                                       dWriteHandlers)
        else:
            #  create the node
            nodeData = dWriteHandlers[sData_type_name](sXml_tag, dData[sTag])

        append_child(nodeParent, nodeData)
コード例 #5
0
    def __validate_optional_args_forecast(self, forecast_data):
        """
        In the case the user asked to use infra-red and/or solar flux
        as input, check if the values are really in the input files.
        """

        # Check for solar-flux
        if metro_config.get_value('SF') and  \
           'SF' not in forecast_data.lMatrix_col_name:
            sInputAtmosphericForecast = metro_config.\
                                        get_value('FILE_FORECAST_IN_FILENAME')
            sMessage = _("The option '--use-solarflux-forecast' was used\n") +\
                       _("but the information was not in the atmospheric\n") +\
                       _("forecast file. Please check for the tag '<sf>'\n") +\
                       _("in the file: %s") % (sInputAtmosphericForecast)
            metro_logger.print_message(metro_logger.LOGGER_MSG_STOP, sMessage)
        # Check for infra-red
        if metro_config.get_value('IR') and  \
           'IR' not in forecast_data.lMatrix_col_name:
            sInputAtmosphericForecast = metro_config.\
                                        get_value('FILE_FORECAST_IN_FILENAME')
            sMessage = _("The option '--use-infrared-forecast' was used\n") +\
                       _("but the information was not in the atmospheric\n") +\
                       _("forecast file. Please check for the tag '<ir>'\n") +\
                       _("in the file: %s") % (sInputAtmosphericForecast)
            metro_logger.print_message(metro_logger.LOGGER_MSG_STOP, sMessage)
コード例 #6
0
ファイル: metro_xml.py プロジェクト: jacobg0/METRoWin
def get_handler(sHandlerType, dDefData, dAllDefData=None):

    if dAllDefData == None:
        # Retrieve the informations about the data types
        dStandard_data_type = metro_config.get_value('XML_DATATYPE_STANDARD')
        dExtended_data_type = metro_config.get_value('XML_DATATYPE_EXTENDED')
        dAllDefData = metro_util.join_dictionaries(dStandard_data_type,
                                                   dExtended_data_type)

    sTag = dDefData['NAME']
    sXml_tag = dDefData['XML_TAG']
    sData_type_name = dDefData['DATA_TYPE']

    if sData_type_name not in dAllDefData.keys():
        sMessage = _("Invalid data_type: (%s) for the following ") \
                   % (sData_type_name) +\
                   _("tag:(%s). Default data type will be used.") \
                   % (sTag)
        metro_logger.print_message(metro_logger.LOGGER_MSG_WARNING, sMessage)
        sData_type_name = 'DEFAULT'

    # The data type needs the call of a function to create the node
    sHandler = dAllDefData[sData_type_name][sHandlerType]

    return sHandler
コード例 #7
0
    def __round_roadcast_header( self, roadcast):
        if 'VERTICAL_LEVELS' in roadcast.get_header():
            # Get the default value for the accurary of "float" of the roadcast
            iDefault_precision = \
                metro_config.get_value('DEFAULT_ROADCAST_PREDICTION_PRECISION')

            dData_types = metro_config.get_value('XML_DATATYPE_STANDARD')
            dExtended_data_type = metro_config.get_value('XML_DATATYPE_EXTENDED')

            dData_types.update(dExtended_data_type)
            
            sCurrent_data_type = 'VERTICAL_LEVELS'

            # get precision
            if 'CHILD' in dData_types[sCurrent_data_type]:
                if len(dData_types[sCurrent_data_type]['CHILD']) == 1 and \
                   dData_types[sCurrent_data_type]['CHILD'][0]['DATA_TYPE'] == 'REAL':
                    # If the accuracy have been specified: use it.
                    # Otherwhise use the default value for the roadcast.
                    if 'PRECISION' in dData_types[sCurrent_data_type]['CHILD'][0]:
                        iPrecision = dData_types[sCurrent_data_type]['CHILD'][0]['PRECISION']
                    else:
                        iPrecision = iDefault_precision
                    
            lLevels = roadcast.get_header_value('VERTICAL_LEVELS')

            lRounded = [round(x,iPrecision) for x in lLevels]

            roadcast.set_header_value('VERTICAL_LEVELS',lRounded)
コード例 #8
0
def validate_xml_file_def(dConf):

    # file definition to check
    lXML_files = [
        'XML_FORECAST_HEADER_STANDARD_ITEMS',
        'XML_FORECAST_HEADER_EXTENDED_ITEMS',
        'XML_FORECAST_PREDICTION_STANDARD_ITEMS',
        'XML_FORECAST_PREDICTION_EXTENDED_ITEMS',
        'XML_OBSERVATION_HEADER_STANDARD_ITEMS',
        'XML_OBSERVATION_HEADER_EXTENDED_ITEMS',
        'XML_OBSERVATION_MEASURE_STANDARD_ITEMS',
        'XML_OBSERVATION_MEASURE_EXTENDED_ITEMS',
        'XML_STATION_HEADER_STANDARD_ITEMS',
        'XML_STATION_HEADER_EXTENDED_ITEMS',
        'XML_STATION_ROADLAYER_STANDARD_ITEMS',
        'XML_STATION_ROADLAYER_EXTENDED_ITEMS',
        'XML_ROADCAST_HEADER_STANDARD_ITEMS',
        'XML_ROADCAST_HEADER_EXTENDED_ITEMS',
        'XML_ROADCAST_PREDICTION_STANDARD_ITEMS',
        'XML_ROADCAST_PREDICTION_EXTENDED_ITEMS',
    ]

    # extract all data type
    dStandard_data_type = metro_config.get_value('XML_DATATYPE_STANDARD')
    dExtended_data_type = metro_config.get_value('XML_DATATYPE_EXTENDED')
    dAll_data_type = metro_util.join_dictionaries(dStandard_data_type,
                                                  dExtended_data_type)

    for sXML_file in lXML_files:
        iFrom = dConf[sXML_file]['FROM']
        lXML_items = dConf[sXML_file]['VALUE']
        validate_xml_itemlist_def(sXML_file, iFrom, lXML_items, dAll_data_type)
コード例 #9
0
 def __check_if_all_value_are_numbers(self, wf_controlled_data):
     """
     Check if all the values in the forecast are numbers.
     """
     for sElement in wf_controlled_data.get_matrix_col_list():
         if sElement.find('TIME') > 0:
             continue
         npElement = wf_controlled_data.get_matrix_col(sElement)
         # In the case of 'CC', only return an error if both SF and IR
         #  are not given
         if sElement is 'CC':
             if metro_config.get_value('SF') and metro_config.get_value(
                     'IR'):
                 continue
         for fElement in npElement:
             if fpconst.isNaN(fElement):
                 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 metro_error.Metro_data_error(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_STOP,\
                                                sMessage)
コード例 #10
0
    def start(self):
        Metro_read.start(self)

        if metro_config.key_exist('FILE_STATION_FILENAME'):
            sFilename = metro_config.get_value('FILE_STATION_FILENAME')
        else:
            sFilename = ""

        if sFilename != "":

            try:
                sFile_content = self._read_input_data(sFilename)
            except IOError:
                sError_message = _("METRo need a valid station file.")
                metro_logger.print_message(metro_logger.LOGGER_MSG_STOP,
                                           sError_message)
            else:
                # Create and add infdata
                infdata_station = metro_infdata.Metro_infdata(
                    'STATION', metro_infdata.DATATYPE_METRO_DATA)
                infdata_station.set_input_information(sFile_content)
                self.add_infdata(infdata_station)

                if metro_config.get_value('SUNSHADOW'):
                    infdata_horizon = metro_infdata.Metro_infdata(
                        'HORIZON', metro_infdata.DATATYPE_METRO_DATA)
                    self.add_infdata(infdata_horizon)

        else:
            sError_message = _("METRo need a station file, please use the ") +\
                             _("option: '--input-station'")
            metro_logger.print_message(metro_logger.LOGGER_MSG_STOP,
                                       sError_message)
コード例 #11
0
    def __validate_optional_args_forecast(self, forecast_data):
        """
        In the case the user asked to use infra-red and/or solar flux
        as input, check if the values are really in the input files.
        """

        # Check for solar-flux
        if metro_config.get_value('SF') and  \
           'SF' not in forecast_data.lMatrix_col_name:
            sInputAtmosphericForecast = metro_config.\
                                        get_value('FILE_FORECAST_IN_FILENAME')
            sMessage = _("The option '--use-solarflux-forecast' was used\n") +\
                       _("but the information was not in the atmospheric\n") +\
                       _("forecast file. Please check for the tag '<sf>'\n") +\
                       _("in the file: %s") % (sInputAtmosphericForecast)
            metro_logger.print_message(
                metro_logger.LOGGER_MSG_STOP, sMessage)
        # Check for infra-red
        if metro_config.get_value('IR') and  \
           'IR' not in forecast_data.lMatrix_col_name:
            sInputAtmosphericForecast = metro_config.\
                                        get_value('FILE_FORECAST_IN_FILENAME')
            sMessage = _("The option '--use-infrared-forecast' was used\n") +\
                       _("but the information was not in the atmospheric\n") +\
                       _("forecast file. Please check for the tag '<ir>'\n") +\
                       _("in the file: %s") % (sInputAtmosphericForecast)
            metro_logger.print_message(
                metro_logger.LOGGER_MSG_STOP, sMessage)
コード例 #12
0
ファイル: metro_xml.py プロジェクト: akrherz/metro
def get_handler(sHandlerType, dDefData, dAllDefData=None):

    if dAllDefData == None:
        # Retrieve the informations about the data types
        dStandard_data_type = metro_config.get_value('XML_DATATYPE_STANDARD')
        dExtended_data_type = metro_config.get_value('XML_DATATYPE_EXTENDED')
        dAllDefData = metro_util.join_dictionaries(dStandard_data_type,
                                              dExtended_data_type)
    
    sTag = dDefData['NAME']
    sXml_tag = dDefData['XML_TAG']
    sData_type_name = dDefData['DATA_TYPE']

    if sData_type_name not in dAllDefData.keys():
        sMessage = _("Invalid data_type: (%s) for the following ") \
                   % (sData_type_name) +\
                   _("tag:(%s). Default data type will be used.") \
                   % (sTag)
        metro_logger.print_message(metro_logger.LOGGER_MSG_WARNING,
                                           sMessage)
        sData_type_name = 'DEFAULT'
                
    # The data type needs the call of a function to create the node
    sHandler = dAllDefData[sData_type_name][sHandlerType]

    return sHandler
コード例 #13
0
    def __set_first_roadcast_date(self, observation_data, roadcast_data):
        """
        Name: ___set_first_roadcast_date
        Parameters: Observation and roadcast

        Description: If the date of the first roadcast is not specified in the input
                     (command line or config file), set it to first round 20 minutes after
                     the last observation.

        Author: Miguel Tremblay
        Date: March 5th 2007
        """
        # Check if the value is given as an argument
        if metro_config.get_value('INIT_ROADCAST_START_DATE') != "":
             # Set the xml header value
             controlled_roadcast = roadcast_data.get_subsampled_data()
             controlled_roadcast.set_header_value('FIRST_ROADCAST',\
                                                  metro_config.get_value('INIT_ROADCAST_START_DATE'))
             return 0
        else : # if value of INIT_ROADCAST_START_DATE is not given, fetch the first
            # round 20 minutes.
            naOT = observation_data.get_matrix_col('OBSERVATION_TIME')
            fLast_observation_date = naOT[len(naOT)-1]
            sLast_observation_date = metro_date.seconds2iso8601(fLast_observation_date)

            # Fetch the first 20 minutes value.
            iNb_timesteps = roadcast_data.get_attribute('FORECAST_NB_TIMESTEPS')
            nSecondsForOutput = metro_constant.nMinutesForOutput*60
            lTimeStep = roadcast_data.get_controlled_data().get_matrix_col('HH')
            for i in range(0, iNb_timesteps):
                fCurrentTime = lTimeStep[i]*3600
                # Forecast at every 20 minutes, i.e. 1200 seconds  
                # if current time is a 20 minute interval
                # and roadcast time is >= roadcast start date
                if round(fCurrentTime)%nSecondsForOutput == 0:
                    sLast_observation =  metro_config.\
                                        get_value('DATA_ATTRIBUTE_LAST_OBSERVATION')
                    fLast_observation = metro_date.parse_date_string(sLast_observation)
                    sStart_date = metro_date.seconds2iso8601(fLast_observation + \
                                                             (i+1)*\
                                                             metro_constant.fTimeStep)
                    metro_config.set_value('INIT_ROADCAST_START_DATE', sStart_date)
                    sMessage = _("Roadcast start date set to: ''%s'") % (sStart_date)
                    metro_logger.print_message(metro_logger.LOGGER_MSG_INFORMATIVE,\
                                               sMessage)
                    # Set the xml header value
                    controlled_roadcast = roadcast_data.get_subsampled_data()
                    controlled_roadcast.set_header_value('FIRST_ROADCAST', sStart_date)
                    return i



            #  Something bad hapened.
            sMessage = _("Unable to determine the first time of roadcast!")
            metro_logger.print_message(metro_logger.LOGGER_MSG_STOP,\
                                       sMessage)
コード例 #14
0
    def __round_roadcast_data( self, roadcast_data):

        # Get the matrix columns definition
        lStandard_roadcast = metro_config.get_value( \
            'XML_ROADCAST_PREDICTION_STANDARD_ITEMS')
        lExtended_roadcast = metro_config.get_value( \
            'XML_ROADCAST_PREDICTION_EXTENDED_ITEMS')        
        lRoadcast_items = lStandard_roadcast + lExtended_roadcast

        # Get the default value for the accurary of "float" of the roadcast
        iDefault_precision = \
            metro_config.get_value('DEFAULT_ROADCAST_PREDICTION_PRECISION')


        dData_types = metro_config.get_value('XML_DATATYPE_STANDARD')
        dExtended_data_type = metro_config.get_value('XML_DATATYPE_EXTENDED')

        dData_types.update(dExtended_data_type)

        # Process of each column of roadcast
        iItem_id = 0
        for dRoadcast_item in lRoadcast_items:

            sCurrent_data_type = dRoadcast_item['DATA_TYPE']
            # If this column contains float data
            if dRoadcast_item['DATA_TYPE'] == 'REAL':

                # If the accuracy have been specified: use it.
                # Otherwhise use the default value for the roadcast.
                if 'PRECISION' in dRoadcast_item:
                    iPrecision = dRoadcast_item['PRECISION']
                else:
                    iPrecision = iDefault_precision

                # Perform the round operation
                npCol = roadcast_data.get_matrix_col(dRoadcast_item['NAME'])
                npCol = numpy.around(npCol,iPrecision)
                roadcast_data.set_matrix_col(dRoadcast_item['NAME'], npCol)

            # If this column as only one child who is a REAL: its probably a list of float
            elif 'CHILD' in dData_types[sCurrent_data_type]:
                if len(dData_types[sCurrent_data_type]['CHILD']) == 1 and \
                   dData_types[sCurrent_data_type]['CHILD'][0]['DATA_TYPE'] == 'REAL':
                    # If the accuracy have been specified: use it.
                    # Otherwhise use the default value for the roadcast.
                    if 'PRECISION' in dData_types[sCurrent_data_type]['CHILD'][0]:
                        iPrecision = dData_types[sCurrent_data_type]['CHILD'][0]['PRECISION']
                    else:
                        iPrecision = iDefault_precision

                    npCol = roadcast_data.get_matrix_col(dRoadcast_item['NAME'])
            
                    npCol = numpy.around(npCol,iPrecision)
                    roadcast_data.set_matrix_multiCol(dRoadcast_item['NAME'], npCol)
コード例 #15
0
    def __round_roadcast_data( self, roadcast_data):

        # Get the matrix columns definition
        lStandard_roadcast = metro_config.get_value( \
            'XML_ROADCAST_PREDICTION_STANDARD_ITEMS')
        lExtended_roadcast = metro_config.get_value( \
            'XML_ROADCAST_PREDICTION_EXTENDED_ITEMS')        
        lRoadcast_items = lStandard_roadcast + lExtended_roadcast

        # Get the default value for the accurary of "float" of the roadcast
        iDefault_precision = \
            metro_config.get_value('DEFAULT_ROADCAST_PREDICTION_PRECISION')


        dData_types = metro_config.get_value('XML_DATATYPE_STANDARD')
        dExtended_data_type = metro_config.get_value('XML_DATATYPE_EXTENDED')

        dData_types.update(dExtended_data_type)

        # Process of each column of roadcast
        iItem_id = 0
        for dRoadcast_item in lRoadcast_items:

            sCurrent_data_type = dRoadcast_item['DATA_TYPE']
            # If this column contains float data
            if dRoadcast_item['DATA_TYPE'] == 'REAL':

                # If the accuracy have been specified: use it.
                # Otherwhise use the default value for the roadcast.
                if 'PRECISION' in dRoadcast_item:
                    iPrecision = dRoadcast_item['PRECISION']
                else:
                    iPrecision = iDefault_precision

                # Perform the round operation
                npCol = roadcast_data.get_matrix_col(dRoadcast_item['NAME'])
                npCol = numpy.around(npCol,iPrecision)
                roadcast_data.set_matrix_col(dRoadcast_item['NAME'], npCol)

            # If this column as only one child who is a REAL: its probably a list of float
            elif 'CHILD' in dData_types[sCurrent_data_type]:
                if len(dData_types[sCurrent_data_type]['CHILD']) == 1 and \
                   dData_types[sCurrent_data_type]['CHILD'][0]['DATA_TYPE'] == 'REAL':
                    # If the accuracy have been specified: use it.
                    # Otherwhise use the default value for the roadcast.
                    if 'PRECISION' in dData_types[sCurrent_data_type]['CHILD'][0]:
                        iPrecision = dData_types[sCurrent_data_type]['CHILD'][0]['PRECISION']
                    else:
                        iPrecision = iDefault_precision

                    npCol = roadcast_data.get_matrix_col(dRoadcast_item['NAME'])
            
                    npCol = numpy.around(npCol,iPrecision)
                    roadcast_data.set_matrix_multiCol(dRoadcast_item['NAME'], npCol)
コード例 #16
0
ファイル: metro_logger.py プロジェクト: akrherz/metro
def init( ):
    """
    Name: init
    Parameters: none
    Return: none
    Description: Logger verbosity level initialization.
    """
    
    global iLogger_verbose_level
    global bLogger_shell_display
    global sLogger_filename
    global fLogger_file
    global bIs_initialised

    # Pre-initialization in order to not log logger init...
    iLogger_verbose_level     = LOGGER_VERBOSE_LEVEL_NOLOG
    bLogger_shell_display     = False

    sMessage = _("Starting METRo logger")
    print_init_message(LOGGER_INIT_MESSAGE,sMessage)

    # Retrieve configuration values
    sTmp_logger_filename      = metro_config.get_value("FILE_LOGGER_FILENAME")
    iTmp_logger_verbose_level = \
        metro_config.get_value("INIT_LOGGER_VERBOSE_LEVEL")
    bTmp_logger_shell_display = \
        metro_config.get_value("INIT_LOGGER_SHELL_DISPLAY")

    # Initialization
    sLogger_filename      = sTmp_logger_filename
    iLogger_verbose_level = iTmp_logger_verbose_level
    bLogger_shell_display = bTmp_logger_shell_display

    # Open log file
    try:
        fLogger_file = open(sLogger_filename,'a')
    except IOError:
        fLogger_file = None
        sError_message = _("can't open/create logger file:'%s'") \
                         % (sLogger_filename)
        print_init_message(LOGGER_INIT_ERROR,
                           sError_message)
    else:
        # Log header writing
        write_log_header(fLogger_file, iLogger_verbose_level)
        
        sSuccess_message = _("METRo logger started, log file:'%s'") \
                           % (sLogger_filename)
        print_init_message(LOGGER_INIT_SUCCESS,
                           sSuccess_message)

    bIs_initialised = True
コード例 #17
0
ファイル: metro_xml.py プロジェクト: jacobg0/METRoWin
def create_node_tree_from_matrix(domDoc, nodeParent, sPrediction_xpath, lDefs,
                                 dWriteHandlers, metro_data_object, npMatrix):
    """
    Each prediction will be contained in a node that will have the name
    given by sPrediction_xpath.
    """

    # Retrieve the informations about the data types
    dStandard_data_type = metro_config.get_value('XML_DATATYPE_STANDARD')
    dExtended_data_type = metro_config.get_value('XML_DATATYPE_EXTENDED')
    dData_type = metro_util.join_dictionaries(dStandard_data_type,
                                              dExtended_data_type)

    for npData in npMatrix:

        # If needed, creation of a node to contain the prediction
        if sPrediction_xpath != None and sPrediction_xpath != "":
            nodePrediction = mkdir_xpath(domDoc, nodeParent, sPrediction_xpath)
        else:
            nodePrediction = nodeParent

        for dDef in lDefs:
            # Get the name and the type of the item
            sTag = dDef['NAME']
            sXml_tag = dDef['XML_TAG']
            sData_type_name = dDef['DATA_TYPE']

            # Extraction of the data from the matrix
            lIndexList = metro_data_object.index_of_matrix_col(sTag)
            if not metro_data_object.is_multi_col(sTag):
                # single col
                val = npData[lIndexList[0]]
            else:
                # multi col
                # FFTODO good candidate for optimisation

                val = []

                for i in lIndexList:
                    val.append(npData[i])

            if dData_type[sData_type_name].has_key('CHILD'):
                #  create the node containing a list of "sub-node"
                lChildList = dData_type[sData_type_name]['CHILD']
                nodeData = dWriteHandlers[sData_type_name](sXml_tag,
                                                           lChildList, val,
                                                           dWriteHandlers)
            else:
                #  create the node
                nodeData = dWriteHandlers[sData_type_name](sXml_tag, val)

            append_child(nodePrediction, nodeData)
コード例 #18
0
ファイル: metro_logger.py プロジェクト: jacobg0/METRoWin
def init( ):
    """
    Name: init
    Parameters: none
    Return: none
    Description: Logger verbosity level initialization.
    """
    
    global iLogger_verbose_level
    global bLogger_shell_display
    global sLogger_filename
    global fLogger_file
    global bIs_initialised

    # Pre-initialization in order to not log logger init...
    iLogger_verbose_level     = LOGGER_VERBOSE_LEVEL_NOLOG
    bLogger_shell_display     = False

    sMessage = _("Starting METRo logger")
    print_init_message(LOGGER_INIT_MESSAGE,sMessage)

    # Retrieve configuration values
    sTmp_logger_filename      = metro_config.get_value("FILE_LOGGER_FILENAME")
    iTmp_logger_verbose_level = \
        metro_config.get_value("INIT_LOGGER_VERBOSE_LEVEL")
    bTmp_logger_shell_display = \
        metro_config.get_value("INIT_LOGGER_SHELL_DISPLAY")

    # Initialization
    sLogger_filename      = sTmp_logger_filename
    iLogger_verbose_level = iTmp_logger_verbose_level
    bLogger_shell_display = bTmp_logger_shell_display

    # Open log file
    try:
        fLogger_file = open(sLogger_filename,'a')
    except IOError:
        fLogger_file = None
        sError_message = _("can't open/create logger file:'%s'") \
                         % (sLogger_filename)
        print_init_message(LOGGER_INIT_ERROR,
                           sError_message)
    else:
        # Log header writing
        write_log_header(fLogger_file, iLogger_verbose_level)
        
        sSuccess_message = _("METRo logger started, log file:'%s'") \
                           % (sLogger_filename)
        print_init_message(LOGGER_INIT_SUCCESS,
                           sSuccess_message)

    bIs_initialised = True
コード例 #19
0
    def __set_sf(self, wf_controlled_data, wf_interpolated_data):
        """
        Set the theoretical solar flux.
           
        Parameters:
        wf_controlled_data (metro_data) : controlled data. Read-only
        """
        npTime = wf_controlled_data.get_matrix_col('Time')

        # Only interpolate if SF is given
        if metro_config.get_value('SF'):
            npSF = wf_controlled_data.get_matrix_col('SF')
            npSF2 = metro_util.interpolate(npTime, npSF)
            if ((self.infdata_exist('HORIZON')) and (self.npAzim != None)):
                npFT2 = wf_interpolated_data.get_matrix_col('FORECAST_TIME')
                tDate2 = [time.gmtime(x) for x in npFT2]
                sunshadw_method = metro_config.get_value('SUNSHADOW_METHOD')
                npSF2 = metro_preprocess_sunshadw.\
                                  get_corrected_solar_flux(tDate2, npSF2, \
                                                           self.fLat, self.fLon,\
                                                           zip(self.npAzim, self.npElev),\
                                                           m=sunshadw_method)

            wf_interpolated_data.append_matrix_col('SF', npSF2)
            return

        # Get data
        npCloudOctal = wf_controlled_data.get_matrix_col('CC')
        npTimeHour = wf_controlled_data.get_matrix_col('Hour')
        npForecastedTime = wf_controlled_data.\
                             get_matrix_col('FORECAST_TIME')
        fStartForecastTime = npForecastedTime[0]
        # Get solar fluxes for this cloud cover for this specific day
        npSF  = metro_physics.get_sf(npCloudOctal, npTimeHour, \
                                    npForecastedTime,\
                                    self.fSunrise, self.fSunset,\
                                    self.fLat, self.fLon)

        npSF2 = metro_util.interpolate(npTime, npSF)

        if ((self.infdata_exist('HORIZON')) and (self.npAzim != None)):
            npFT2 = wf_interpolated_data.get_matrix_col('FORECAST_TIME')
            tDate2 = [time.gmtime(x) for x in npFT2]
            sunshadw_method = metro_config.get_value('SUNSHADOW_METHOD')
            npSF2 = metro_preprocess_sunshadw.\
                           get_corrected_solar_flux(tDate2, npSF2, \
                                                    self.fLat, self.fLon,\
                                                    zip(self.npAzim, self.npElev),\
                                                    m=sunshadw_method)

        wf_controlled_data.append_matrix_col('SF', npSF)
        wf_interpolated_data.append_matrix_col('SF', npSF2)
コード例 #20
0
    def __set_sf(self, wf_controlled_data, wf_interpolated_data):
        """
        Set the theoretical solar flux.
           
        Parameters:
        wf_controlled_data (metro_data) : controlled data. Read-only
        """
        npTime = wf_controlled_data.get_matrix_col('Time') 

        # Only interpolate if SF is given
        if  metro_config.get_value('SF'):
            npSF = wf_controlled_data.get_matrix_col('SF')
            npSF2 = metro_util.interpolate(npTime, npSF)
            if ((self.infdata_exist('HORIZON')) and (self.npAzim != None)):
	    	npFT2 = wf_interpolated_data.get_matrix_col('FORECAST_TIME')
		tDate2 = [time.gmtime(x) for x in npFT2]
		sunshadw_method = metro_config.get_value('SUNSHADOW_METHOD')
	    	npSF2 = metro_preprocess_sunshadw.\
                        get_corrected_solar_flux(tDate2, npSF2, \
                                                 self.fLat, self.fLon,\
                                                 zip(self.npAzim, self.npElev),\
                                                 m=sunshadw_method)

            wf_interpolated_data.append_matrix_col('SF', npSF2)
	    return
        
        # Get data
        npCloudOctal = wf_controlled_data.get_matrix_col('CC')
        npTimeHour =  wf_controlled_data.get_matrix_col('Hour')
        npForecastedTime = wf_controlled_data.\
                             get_matrix_col('FORECAST_TIME')
        fStartForecastTime =npForecastedTime [0]
        # Get solar fluxes for this cloud cover for this specific day
        npSF  = metro_physics.get_sf(npCloudOctal, npTimeHour, \
                                    npForecastedTime,\
                                    self.fSunrise, self.fSunset,\
                                    self.fLat, self.fLon)

	npSF2  = metro_util.interpolate(npTime, npSF)

        if ((self.infdata_exist('HORIZON')) and (self.npAzim != None)):
	    npFT2 = wf_interpolated_data.get_matrix_col('FORECAST_TIME')
	    tDate2 = [time.gmtime(x) for x in npFT2]
	    sunshadw_method = metro_config.get_value('SUNSHADOW_METHOD')
	    npSF2 = metro_preprocess_sunshadw.\
                    get_corrected_solar_flux(tDate2, npSF2, \
                                             self.fLat, self.fLon,\
                                             zip(self.npAzim, self.npElev),\
                                             m=sunshadw_method)

        wf_controlled_data.append_matrix_col('SF', npSF)
        wf_interpolated_data.append_matrix_col('SF',  npSF2)
コード例 #21
0
ファイル: metro_xml.py プロジェクト: akrherz/metro
def create_node_tree_from_matrix( domDoc, nodeParent, sPrediction_xpath,
                                  lDefs, dWriteHandlers, metro_data_object, npMatrix ):
    """
    Each prediction will be contained in a node that will have the name
    given by sPrediction_xpath.
    """


    # Retrieve the informations about the data types
    dStandard_data_type = metro_config.get_value('XML_DATATYPE_STANDARD')
    dExtended_data_type = metro_config.get_value('XML_DATATYPE_EXTENDED')
    dData_type = metro_util.join_dictionaries(dStandard_data_type,
                                              dExtended_data_type)

    for npData in npMatrix:

        # If needed, creation of a node to contain the prediction
        if sPrediction_xpath != None and sPrediction_xpath != "":
            nodePrediction = mkdir_xpath(domDoc, nodeParent, sPrediction_xpath)
        else:
            nodePrediction = nodeParent

        for dDef in lDefs:
            # Get the name and the type of the item
            sTag = dDef['NAME']
            sXml_tag = dDef['XML_TAG']
            sData_type_name = dDef['DATA_TYPE']

            # Extraction of the data from the matrix
            lIndexList = metro_data_object.index_of_matrix_col(sTag)
            if not metro_data_object.is_multi_col(sTag):
                # single col
                val = npData[lIndexList[0]]
            else:
                # multi col
                # FFTODO good candidate for optimisation
                
                val = []
                
                for i in lIndexList:
                    val.append(npData[i])
            
            if dData_type[sData_type_name].has_key('CHILD'):
                #  create the node containing a list of "sub-node"
                lChildList = dData_type[sData_type_name]['CHILD']
                nodeData = dWriteHandlers[sData_type_name](sXml_tag,lChildList,val,dWriteHandlers)
            else:
                #  create the node 
                nodeData = dWriteHandlers[sData_type_name](sXml_tag,val)

            append_child(nodePrediction, nodeData)
コード例 #22
0
ファイル: metro_xml.py プロジェクト: jacobg0/METRoWin
def extract_data(lDefs, dReadHandlers, nodeItems):
    """
    Name: extract_data

    Arguments:  [I] lDefs: list of dictionary containing the
                           definition of XML element in metro_config.py
                [I] dReadHandlers: dictionnay of read handler.
                                   key = data type name (ex: INTEGER),
                                   value = handler (ex: toolbox.metro_dom2metro_handler.read_integer)
                [I] nodeItems: fecth the elements in theses nodes

    Output:   lData :: list of values, one per definition in lDefs.

    Description: Extract the data from one node containing more nodes.
    """

    lData = []

    # Retrieve the informations about the data type
    dStandard_data_type = metro_config.get_value('XML_DATATYPE_STANDARD')
    dExtended_data_type = metro_config.get_value('XML_DATATYPE_EXTENDED')

    dData_type = metro_util.join_dictionaries(dStandard_data_type,
                                              dExtended_data_type)

    # For each definitions of item
    for dDef in lDefs:
        # Get the name and the type of the item
        sTag = dDef['XML_TAG']
        sData_type_name = dDef['DATA_TYPE']

        if dData_type[sData_type_name].has_key('CHILD'):
            #  extract the data containing a list of "sub-data"
            nodeTmp = metro_xml_lib.xpath(nodeItems, sTag)
            lChildList = dData_type[sData_type_name]['CHILD']
            data = dReadHandlers[sData_type_name](lChildList, nodeTmp,
                                                  dReadHandlers)
        else:
            #  extract the data
            data = dReadHandlers[sData_type_name](sTag, nodeItems)

        lData.append(data)

    # If there is only one definition of data (lDefs), it is an "array".
    #  In this case, we must extract the "array" from the list
    #  [[1,2,3,...,N]]  ==>  [1,2,3,...,N]
    if len(lDefs) == 1:
        if lData:
            lData = lData[0]

    return lData
コード例 #23
0
ファイル: metro_xml.py プロジェクト: akrherz/metro
def extract_data(lDefs, dReadHandlers, nodeItems):
    """
    Name: extract_data

    Arguments:  [I] lDefs: list of dictionary containing the
                           definition of XML element in metro_config.py
                [I] dReadHandlers: dictionnay of read handler.
                                   key = data type name (ex: INTEGER),
                                   value = handler (ex: toolbox.metro_dom2metro_handler.read_integer)
                [I] nodeItems: fecth the elements in theses nodes

    Output:   lData :: list of values, one per definition in lDefs.

    Description: Extract the data from one node containing more nodes.
    """

    lData = []

    # Retrieve the informations about the data type
    dStandard_data_type = metro_config.get_value('XML_DATATYPE_STANDARD')
    dExtended_data_type = metro_config.get_value('XML_DATATYPE_EXTENDED')

    dData_type = metro_util.join_dictionaries(dStandard_data_type,
                                              dExtended_data_type)

    # For each definitions of item
    for dDef in lDefs:
        # Get the name and the type of the item
        sTag = dDef['XML_TAG']
        sData_type_name = dDef['DATA_TYPE']
        
        if dData_type[sData_type_name].has_key('CHILD'):
            #  extract the data containing a list of "sub-data"
            nodeTmp = metro_xml_lib.xpath(nodeItems,sTag)
            lChildList = dData_type[sData_type_name]['CHILD']
            data = dReadHandlers[sData_type_name](lChildList,nodeTmp,dReadHandlers)
        else:
            #  extract the data
            data = dReadHandlers[sData_type_name](sTag,nodeItems)

        lData.append(data)

    # If there is only one definition of data (lDefs), it is an "array".
    #  In this case, we must extract the "array" from the list
    #  [[1,2,3,...,N]]  ==>  [1,2,3,...,N]
    if len(lDefs) == 1:
        if lData:
            lData = lData[0]

    return lData
コード例 #24
0
 def __set_cc(self, wf_controlled_data, wf_interpolated_data):
     """
     In the case that SF and IR are given, put the values of CC to -1.
        
     Parameters:
     wf_controlled_data (metro_data) : controlled data. Read-only
     """
     if metro_config.get_value('SF') and metro_config.get_value('IR'):
         npTime = wf_controlled_data.get_matrix_col('Time') 
         npCloudOctal = wf_controlled_data.get_matrix_col('CC')
         nLength = len(npCloudOctal)
         npCloud = numpy.ones(nLength) * (-1)
         npCloud2  = metro_util.interpolate(npTime, npCloud)
         
         wf_controlled_data.set_matrix_col('CC', npCloud)
         wf_interpolated_data.set_matrix_col('CC',  npCloud2)
コード例 #25
0
ファイル: metro_model.py プロジェクト: jacobg0/METRoWin
    def start( self ):
        Metro_module.start(self)

        pForecast = self.get_infdata_reference('FORECAST')
        forecast_data = pForecast.get_data_collection()
        pObservation = self.get_infdata_reference('OBSERVATION')
        observation_data = pObservation.get_data_collection()
        pStation = self.get_infdata_reference('STATION')
        station_data = pStation.get_data()

        if metro_config.get_value('T_BYPASS_CORE') == False:

            self.__send_data_to_metro_core(forecast_data,
                                           observation_data,
                                           station_data )
            
            roadcast_data = self.__create_roadcast_collection(forecast_data,
                                                              observation_data,
                                                              station_data)
        else:
            roadcast_data = None
            metro_logger.print_message(
                metro_logger.LOGGER_MSG_INFORMATIVE,
                _("Bypassing METRo core, roadcast not created."))

        pForecast.set_data_collection(forecast_data)
        pObservation.set_data_collection(observation_data)
        pStation.set_data(station_data)

        # creer et ajouter infdata
        # Creation and adding infdata
        infdata_roadcast = metro_infdata.Metro_infdata(
            'ROADCAST', metro_infdata.DATATYPE_METRO_DATA_COLLECTION)
        infdata_roadcast.set_data_collection(roadcast_data)
        self.add_infdata(infdata_roadcast)
コード例 #26
0
ファイル: metro_model.py プロジェクト: akrherz/metro
    def start( self ):
        Metro_module.start(self)

        pForecast = self.get_infdata_reference('FORECAST')
        forecast_data = pForecast.get_data_collection()
        pObservation = self.get_infdata_reference('OBSERVATION')
        observation_data = pObservation.get_data_collection()
        pStation = self.get_infdata_reference('STATION')
        station_data = pStation.get_data()

        if metro_config.get_value('T_BYPASS_CORE') == False:

            self.__send_data_to_metro_core(forecast_data,
                                           observation_data,
                                           station_data )
            
            roadcast_data = self.__create_roadcast_collection(forecast_data,
                                                              observation_data,
                                                              station_data)
        else:
            roadcast_data = None
            metro_logger.print_message(
                metro_logger.LOGGER_MSG_INFORMATIVE,
                _("Bypassing METRo core, roadcast not created."))

        pForecast.set_data_collection(forecast_data)
        pObservation.set_data_collection(observation_data)
        pStation.set_data(station_data)

        # creer et ajouter infdata
        # Creation and adding infdata
        infdata_roadcast = metro_infdata.Metro_infdata(
            'ROADCAST', metro_infdata.DATATYPE_METRO_DATA_COLLECTION)
        infdata_roadcast.set_data_collection(roadcast_data)
        self.add_infdata(infdata_roadcast)
コード例 #27
0
    def __check_if_cloud_octal(self, wf_controlled_data):
        """        
        Name: __check_if_cloud_octal
        
        Parameters:[I] metro_data wf_controlled_data : controlled data.
                Read-only data.
        Returns: None

        Functions Called:  self.forecast_data.get_matrix_col
              
        Description: Check if all the value of the variable CC is in [0,8]

        Notes: Metro gives funny surface temperature if a strange value of CC
        is entered.  Raise an exception if this occurs.

        Revision History:
        Author		Date		Reason
        Miguel Tremblay      February 28th 2005
        """
        npCloudsOctal = wf_controlled_data.get_matrix_col('CC')

        if len(numpy.where(npCloudsOctal<0)[0]) != 0  or \
               len(numpy.where(npCloudsOctal>8)[0]) != 0 :
            import metro_config
            sMessage = _("All the clouds value (<cc>) of atmospheric forecast must be") +\
                   _(" integers in interval 0-8. See file '%s'") %\
                   (metro_config.get_value("FILE_FORECAST_IN_FILENAME"))
            
            raise metro_error.Metro_data_error(sMessage)
コード例 #28
0
    def __check_precipitation_well_define(self, wf_controlled_data):
        """        
        Name: __check_precipitation_well_define

        Parameters:[I] metro_data wf_controlled_data : controlled data.
             Read-only data.
        Returns: None

        Functions Called:  self.forecast_data.get_matrix_col
              
        Description: Check if the values of precipitations represent the total
        amount of precipitation from the beginning of the period. Thus, all
        the values must monotone in the RA and SN array.

        Notes: 

        Revision History:
        Author		Date		Reason
        Miguel Tremblay      February 28th 2005
        """
        lPrecip = []
        lPrecip.append(wf_controlled_data.get_matrix_col('RA'))
        lPrecip.append(wf_controlled_data.get_matrix_col('SN'))

        for npPrecip in lPrecip:
            npDiff = npPrecip - metro_util.shift_right(npPrecip, 0)
            if len(numpy.where(npDiff[:-1] < 0)[0]) != 0:
                sMessage = _("All the precipitation value (<ra> and <sn>)") +\
                           _(" of atmospheric forecast represent the TOTAL") +\
                           _(" amount of precipitation since the beginning") +\
                           _(" of the period. See file '%s'") %\
                           (metro_config.get_value("FILE_FORECAST_IN_FILENAME"))

                raise metro_error.Metro_data_error(sMessage)
コード例 #29
0
    def __set_cc(self, wf_controlled_data, wf_interpolated_data):
        """
        In the case that SF and IR are given, put the values of CC to -1.
           
        Parameters:
        wf_controlled_data (metro_data) : controlled data. Read-only
        """
        if metro_config.get_value('SF') and metro_config.get_value('IR'):
            npTime = wf_controlled_data.get_matrix_col('Time')
            npCloudOctal = wf_controlled_data.get_matrix_col('CC')
            nLength = len(npCloudOctal)
            npCloud = numpy.ones(nLength) * (-1)
            npCloud2 = metro_util.interpolate(npTime, npCloud)

            wf_controlled_data.set_matrix_col('CC', npCloud)
            wf_interpolated_data.set_matrix_col('CC', npCloud2)
コード例 #30
0
    def __check_precipitation_well_define(self, wf_controlled_data):
        """        
        Name: __check_precipitation_well_define

        Parameters:[I] metro_data wf_controlled_data : controlled data.
             Read-only data.
        Returns: None

        Functions Called:  self.forecast_data.get_matrix_col
              
        Description: Check if the values of precipitations represent the total
        amount of precipitation from the beginning of the period. Thus, all
        the values must monotone in the RA and SN array.

        Notes: 

        Revision History:
        Author		Date		Reason
        Miguel Tremblay      February 28th 2005
        """
        lPrecip = []
        lPrecip.append(wf_controlled_data.get_matrix_col('RA'))
        lPrecip.append(wf_controlled_data.get_matrix_col('SN'))


        for npPrecip in lPrecip:
            npDiff = npPrecip - metro_util.shift_right(npPrecip,0)
            if len(numpy.where(npDiff[:-1] < 0)[0]) != 0:
                sMessage = _("All the precipitation value (<ra> and <sn>)") +\
                           _(" of atmospheric forecast represent the TOTAL") +\
                           _(" amount of precipitation since the beginning") +\
                           _(" of the period. See file '%s'") %\
                           (metro_config.get_value("FILE_FORECAST_IN_FILENAME"))
                
                raise metro_error.Metro_data_error(sMessage)
コード例 #31
0
    def __interpolate_FA(self, wf_originpl_data, wf_interpolated_data):
        """
        Name: __interpolate_FA
        
        Parameters:[I] metro_data wf_originpl_data : originpl data.  Read-only
                   [I] metro_data wf_processed_data : container of the interpolated
                    data.

        Returns: None

        Functions Called: metro_util.interpolate,
                          metro_data.get_matrix_col
                          metro_data.append_matrix_col

        Description: Does the interpolation of the anthropogenic flux


        Revision History:
        Author		Date		Reason
        Rok Krsmanc      October 22th 2010
        """

        if metro_config.get_value('FA') == True:
            npFA = wf_originpl_data.get_matrix_col('FA')
        # If anthropogenic flux is not specified, FA is set to a constant value of 10 W/m^2
        else:
            lFA = [10]
            npFA = numpy.array(lFA)

        npFA = metro_util.interpolate(self.npTime, npFA)
        wf_interpolated_data.append_matrix_col('FA', npFA)
コード例 #32
0
    def __check_if_cloud_octal(self, wf_controlled_data):
        """        
        Name: __check_if_cloud_octal
        
        Parameters:[I] metro_data wf_controlled_data : controlled data.
                Read-only data.
        Returns: None

        Functions Called:  self.forecast_data.get_matrix_col
              
        Description: Check if all the value of the variable CC is in [0,8]

        Notes: Metro gives funny surface temperature if a strange value of CC
        is entered.  Raise an exception if this occurs.

        Revision History:
        Author		Date		Reason
        Miguel Tremblay      February 28th 2005
        """
        npCloudsOctal = wf_controlled_data.get_matrix_col('CC')

        if len(numpy.where(npCloudsOctal<0)[0]) != 0  or \
               len(numpy.where(npCloudsOctal>8)[0]) != 0 :
            import metro_config
            sMessage = _("All the clouds value (<cc>) of atmospheric forecast must be") +\
                   _(" integers in interval 0-8. See file '%s'") %\
                   (metro_config.get_value("FILE_FORECAST_IN_FILENAME"))

            raise metro_error.Metro_data_error(sMessage)
コード例 #33
0
    def start(self):
        Metro_read.start(self)
        if metro_config.key_exist('FILE_OBSERVATION_REF_FILENAME'):
            sFilename = metro_config.get_value('FILE_OBSERVATION_REF_FILENAME')
        else:
            sFilename = ""

        if sFilename != "":
            try:
                sFile_content = self._read_input_data(sFilename)
            except IOError:
                sError_message = _("No file was read. METRo may need this ") +\
                                 _("file content later.")
                metro_logger.print_message(metro_logger.LOGGER_MSG_CRITICAL,
                                           sError_message)
            else:
                # creer et ajouter infdata
                infdata_observation_ref = metro_infdata.Metro_infdata( \
                    'OBSERVATION_REF', \
                    metro_infdata.DATATYPE_METRO_DATA_COLLECTION)
                infdata_observation_ref.set_input_information(sFile_content)
                self.add_infdata(infdata_observation_ref)
        else:
            sError_message = _("If you want to read a second observation file,")+\
                             _("\nplease use the option: ") +\
                             _("'--input-observation-ref'.") +\
                             _("\nYou can safely remove this module from the ") +\
                             _("EXECUTION SEQUENCE\nif you don't need it.") 
            metro_logger.print_message(metro_logger.LOGGER_MSG_WARNING,
                                       sError_message)            
コード例 #34
0
    def __interpolate_FA(self, wf_originpl_data, wf_interpolated_data):
        """
        Name: __interpolate_FA
        
        Parameters:[I] metro_data wf_originpl_data : originpl data.  Read-only
                   [I] metro_data wf_processed_data : container of the interpolated
                    data.

        Returns: None

        Functions Called: metro_util.interpolate,
                          metro_data.get_matrix_col
                          metro_data.append_matrix_col

        Description: Does the interpolation of the anthropogenic flux


        Revision History:
        Author		Date		Reason
        Rok Krsmanc      October 22th 2010
        """

        if metro_config.get_value('FA') == True:
            npFA = wf_originpl_data.get_matrix_col('FA')
        # If anthropogenic flux is not specified, FA is set to a constant value of 10 W/m^2
        else:
            lFA = [10]
            npFA = numpy.array(lFA)

        npFA = metro_util.interpolate(self.npTime, npFA)
        wf_interpolated_data.append_matrix_col('FA', npFA)
コード例 #35
0
    def start(self):
        Metro_read.start(self)
        if metro_config.key_exist('FILE_OBSERVATION_REF_FILENAME'):
            sFilename = metro_config.get_value('FILE_OBSERVATION_REF_FILENAME')
        else:
            sFilename = ""

        if sFilename != "":
            try:
                sFile_content = self._read_input_data(sFilename)
            except IOError:
                sError_message = _("No file was read. METRo may need this ") +\
                                 _("file content later.")
                metro_logger.print_message(metro_logger.LOGGER_MSG_CRITICAL,
                                           sError_message)
            else:
                # creer et ajouter infdata
                infdata_observation_ref = metro_infdata.Metro_infdata( \
                    'OBSERVATION_REF', \
                    metro_infdata.DATATYPE_METRO_DATA_COLLECTION)
                infdata_observation_ref.set_input_information(sFile_content)
                self.add_infdata(infdata_observation_ref)
        else:
            sError_message = _("If you want to read a second observation file,")+\
                             _("\nplease use the option: ") +\
                             _("'--input-observation-ref'.") +\
                             _("\nYou can safely remove this module from the ") +\
                             _("EXECUTION SEQUENCE\nif you don't need it.") 
            metro_logger.print_message(metro_logger.LOGGER_MSG_WARNING,
                                       sError_message)            
コード例 #36
0
    def start(self):
        Metro_read.start(self)

        if metro_config.key_exist('FILE_OBSERVATION_FILENAME'):
            sFilename = metro_config.get_value('FILE_OBSERVATION_FILENAME')
        else:
            sFilename = ""

        if sFilename != "":

            try:
                sFile_content = self._read_input_data(sFilename)
            except IOError:
                sError_message = _("METRo need a valid observation file.")
                metro_logger.print_message(metro_logger.LOGGER_MSG_STOP,
                                           sError_message)
            else:
                # Create and add infdata
                infdata_observation = metro_infdata.Metro_infdata(
                    'OBSERVATION',
                    metro_infdata.DATATYPE_METRO_DATA_COLLECTION)
                infdata_observation.set_input_information(sFile_content)
                self.add_infdata(infdata_observation)
        else:
            sError_message = _("METRo need an observation file, please use ") +\
                             _("the option: '--input-observation'")
            metro_logger.print_message(metro_logger.LOGGER_MSG_STOP,
                                       sError_message)
コード例 #37
0
    def start(self):
        Metro_module.start(self)

        pRoadcast = self.get_infdata_reference('ROADCAST')
        roadcast_data = pRoadcast.get_data_collection()

        #
        # construct dictionnary of write handler
        #

        import toolbox.metro_metro2dom_handler

        # Retrieve the informations about the data type
        dStandard_data_type = metro_config.get_value('XML_DATATYPE_STANDARD')
        dExtended_data_type = metro_config.get_value('XML_DATATYPE_EXTENDED')

        dData_type = metro_util.join_dictionaries(dStandard_data_type,
                                                  dExtended_data_type)

        dWriteHandlers = {}

        # construct dictionnary of write handlers (only done once so not expensive)
        sMessage = _(
            "-------------------------- Write handlers available --------------------------\n"
        )
        for dType in dData_type:
            if dData_type[dType]['WRITE'] != "":
                sCode = "handler = " + dData_type[dType]['WRITE']
                exec sCode
                dWriteHandlers[dType] = handler
                sMessage += _("TYPE: %s , HANDLER: %s\n") % (
                    dType.ljust(15), dData_type[dType]['WRITE'])
        sMessage += "-----------------------------------------------------------------------------"
        metro_logger.print_message(metro_logger.LOGGER_MSG_DEBUG, sMessage)

        # Create roadcast
        if roadcast_data != None:
            domRoadcast = \
                self.__create_roadcast(roadcast_data.get_subsampled_data(),dWriteHandlers)

        else:
            metro_logger.print_message(
                metro_logger.LOGGER_MSG_WARNING,
                _("No roadcast, can't create DOM roadcast"))
            domRoadcast = None

        pRoadcast.set_output_information(domRoadcast)
コード例 #38
0
    def __check_deep_soil_value(self):
        """
        Description: Check if the value given to --fix-deep-soil-temperature
         is valid.
        """

        # If the option is not used, do not perform the check
        if not metro_config.get_value('DEEP_SOIL_TEMP'):
            return
        
        # Check if the option is given while on a bridge
        pStation = self.get_infdata_reference('STATION')
        station_data = pStation.get_data()
        if station_data.get_station_type():
            sMessage = _("Option '--fix-deep-soil-temperature' is used while ") +\
                       _("the station is of type BRIDGE. Deep soil ") +\
                       _("Temperature  will not be used.") 
            metro_logger.print_message(metro_logger.LOGGER_MSG_WARNING,\
                                       sMessage)
        else: # In case of a road verify if the value is a double
            sTemperature = metro_config.get_value('DEEP_SOIL_TEMP_VALUE')
            try:
                dTemperature = float(sTemperature)
                if dTemperature > metro_constant.nRoadTemperatureHigh or \
                   dTemperature < metro_constant.nRoadTemperatureMin:
                    sMessage = _("Deep soil temperature following the option ")+\
                               _("'-fix-deep-soil-temperature' must be between ") +\
                               _("boundaries [") +\
                               str(metro_constant.nRoadTemperatureMin)+ "," +\
                               str(metro_constant.nRoadTemperatureHigh)+ "]. '"+\
                               sTemperature + "' is not in those boundaries."
                    metro_logger.print_message(metro_logger.LOGGER_MSG_STOP,\
                                                sMessage)

                
                # If there is no error, the value is a number, we can continue
                sMessage = _("Using deep soil temperature: ") + sTemperature +\
                           _(" degree Celsius")
                metro_logger.print_message(metro_logger.LOGGER_MSG_INFORMATIVE,\
                                           sMessage)
            except ValueError:
                sMessage = _("Option '-fix-deep-soil-temperature' must be ") +\
                       _("followed by a numeric value. The given value '") +\
                       sTemperature + _("' is not a number.") 
                metro_logger.print_message(metro_logger.LOGGER_MSG_STOP,\
                                           sMessage)
コード例 #39
0
ファイル: metro_metro2dom.py プロジェクト: akrherz/metro
    def start( self ):
        Metro_module.start(self)

        pRoadcast = self.get_infdata_reference('ROADCAST')
        roadcast_data = pRoadcast.get_data_collection()


        #
        # construct dictionnary of write handler
        #
        
        import toolbox.metro_metro2dom_handler 

        # Retrieve the informations about the data type
        dStandard_data_type = metro_config.get_value('XML_DATATYPE_STANDARD')
        dExtended_data_type = metro_config.get_value('XML_DATATYPE_EXTENDED')

        dData_type = metro_util.join_dictionaries(dStandard_data_type,
                                                  dExtended_data_type)

        dWriteHandlers = {}

        # construct dictionnary of write handlers (only done once so not expensive)
        sMessage = _("-------------------------- Write handlers available --------------------------\n")
        for dType in dData_type:
            if dData_type[dType]['WRITE'] != "":
                sCode = "handler = " + dData_type[dType]['WRITE']
                exec sCode
                dWriteHandlers[dType] = handler
                sMessage += _("TYPE: %s , HANDLER: %s\n") % (dType.ljust(15),dData_type[dType]['WRITE'])
        sMessage += "-----------------------------------------------------------------------------"        
        metro_logger.print_message(metro_logger.LOGGER_MSG_DEBUG,
                                   sMessage)                
        
        # Create roadcast
        if roadcast_data != None:
            domRoadcast = \
                self.__create_roadcast(roadcast_data.get_subsampled_data(),dWriteHandlers)

        else:
            metro_logger.print_message(metro_logger.LOGGER_MSG_WARNING,
                _("No roadcast, can't create DOM roadcast"))
            domRoadcast = None

        pRoadcast.set_output_information(domRoadcast)
コード例 #40
0
    def __check_deep_soil_value(self):
        """
        Description: Check if the value given to --fix-deep-soil-temperature
         is valid.
        """

        # If the option is not used, do not perform the check
        if not metro_config.get_value('DEEP_SOIL_TEMP'):
            return

        # Check if the option is given while on a bridge
        pStation = self.get_infdata_reference('STATION')
        station_data = pStation.get_data()
        if station_data.get_station_type():
            sMessage = _("Option '--fix-deep-soil-temperature' is used while ") +\
                       _("the station is of type BRIDGE. Deep soil ") +\
                       _("Temperature  will not be used.")
            metro_logger.print_message(metro_logger.LOGGER_MSG_WARNING,\
                                       sMessage)
        else:  # In case of a road verify if the value is a double
            sTemperature = metro_config.get_value('DEEP_SOIL_TEMP_VALUE')
            try:
                dTemperature = float(sTemperature)
                if dTemperature > metro_constant.nRoadTemperatureHigh or \
                   dTemperature < metro_constant.nRoadTemperatureMin:
                    sMessage = _("Deep soil temperature following the option ")+\
                               _("'-fix-deep-soil-temperature' must be between ") +\
                               _("boundaries [") +\
                               str(metro_constant.nRoadTemperatureMin)+ "," +\
                               str(metro_constant.nRoadTemperatureHigh)+ "]. '"+\
                               sTemperature + "' is not in those boundaries."
                    metro_logger.print_message(metro_logger.LOGGER_MSG_STOP,\
                                                sMessage)

                # If there is no error, the value is a number, we can continue
                sMessage = _("Using deep soil temperature: ") + sTemperature +\
                           _(" degree Celsius")
                metro_logger.print_message(metro_logger.LOGGER_MSG_INFORMATIVE,\
                                           sMessage)
            except ValueError:
                sMessage = _("Option '-fix-deep-soil-temperature' must be ") +\
                       _("followed by a numeric value. The given value '") +\
                       sTemperature + _("' is not a number.")
                metro_logger.print_message(metro_logger.LOGGER_MSG_STOP,\
                                           sMessage)
コード例 #41
0
    def __set_time(self, ro_controlled_data, ro_interpolated_data,
                   observation_data):
        """
        Name: __set_time
        
        Parameters: metro_data controlled_data : controlled forecast data
        
        Returns: None
        
        Functions Called:  numpy.arange, astype
                           numpy.zeros
                           metro_data.set_matrix
                           metro_data.get_matrix_col
                           metro_data.append_matrix_col
                           observation_data.set_attribute
                           metro_config.get_value('FILE_OBSERVATION_FILENAME')

        Description: Set the time array in the interpolated matrix.

        Notes:

        Revision History:
        Author		Date		Reason
        Miguel Tremblay      August 5th 2004
        """

        # Set the time in the interpolated matrix.
        npTime =  ro_controlled_data.get_matrix_col('Time')
        self.npTimeInterpolated = numpy.arange(npTime[0], \
                                               npTime[len(npTime)-1],
                                               metro_constant.fTimeStep)

        # 1.1574e-5 is the conversion from seconds to day.
        #  1/(24*3600) = 1.1574e-5
        self.npTimeInterpolated =  self.npTimeInterpolated/3600 -\
                                  24*((self.npTimeInterpolated*1.1574e-5)\
                                      .astype(numpy.int32))

        # Save the time array
        if len(self.npTimeInterpolated) > 1:
            ro_interpolated_data.append_matrix_col('Time', \
                                                self.npTimeInterpolated)
        # Only one observation, abort interpolation
        elif len(self.npTimeInterpolated) == 1:
            observation_data.set_attribute('NO_OBS',\
                                           [False, False, False, True])
            raise metro_error.Metro_input_error(OneObservationException)
        else:
            observation_data.set_attribute('NO_OBS',\
                                           [True, True, True, True])
            sMessage = _("No valid observation in: ") +\
                       metro_config.get_value('FILE_OBSERVATION_FILENAME')
            metro_logger.print_message(metro_logger.LOGGER_MSG_STOP,
                                       sMessage)

            raise metro_error.Metro_input_error(NoObservationException)
コード例 #42
0
def validate_datatype(dConf):

    # extract data type
    dStandard_data_type = metro_config.get_value('XML_DATATYPE_STANDARD')
    dExtended_data_type = metro_config.get_value('XML_DATATYPE_EXTENDED')
    dAll_data_type = metro_util.join_dictionaries(dStandard_data_type,
                                                  dExtended_data_type)

    # validate Metro standard data type
    sConfig_item = 'XML_DATATYPE_STANDARD'
    iFrom = dConf[sConfig_item]['FROM']
    validate_datatype_category(sConfig_item, iFrom, dStandard_data_type,
                               dAll_data_type)

    # validate User data type
    sConfig_item = 'XML_DATATYPE_EXTENDED'
    iFrom = dConf[sConfig_item]['FROM']
    validate_datatype_category(sConfig_item, iFrom, dExtended_data_type,
                               dAll_data_type)
コード例 #43
0
    def __set_time(self, ro_controlled_data, ro_interpolated_data,
                   observation_data):
        """
        Name: __set_time
        
        Parameters: metro_data controlled_data : controlled forecast data
        
        Returns: None
        
        Functions Called:  numpy.arange, astype
                           numpy.zeros
                           metro_data.set_matrix
                           metro_data.get_matrix_col
                           metro_data.append_matrix_col
                           observation_data.set_attribute
                           metro_config.get_value('FILE_OBSERVATION_FILENAME')

        Description: Set the time array in the interpolated matrix.

        Notes:

        Revision History:
        Author		Date		Reason
        Miguel Tremblay      August 5th 2004
        """

        # Set the time in the interpolated matrix.
        npTime = ro_controlled_data.get_matrix_col('Time')
        self.npTimeInterpolated = numpy.arange(npTime[0], \
                                               npTime[len(npTime)-1],
                                               metro_constant.fTimeStep)

        # 1.1574e-5 is the conversion from seconds to day.
        #  1/(24*3600) = 1.1574e-5
        self.npTimeInterpolated =  self.npTimeInterpolated/3600 -\
                                  24*((self.npTimeInterpolated*1.1574e-5)\
                                      .astype(numpy.int32))

        # Save the time array
        if len(self.npTimeInterpolated) > 1:
            ro_interpolated_data.append_matrix_col('Time', \
                                                self.npTimeInterpolated)
        # Only one observation, abort interpolation
        elif len(self.npTimeInterpolated) == 1:
            observation_data.set_attribute('NO_OBS',\
                                           [False, False, False, True])
            raise metro_error.Metro_input_error(OneObservationException)
        else:
            observation_data.set_attribute('NO_OBS',\
                                           [True, True, True, True])
            sMessage = _("No valid observation in: ") +\
                       metro_config.get_value('FILE_OBSERVATION_FILENAME')
            metro_logger.print_message(metro_logger.LOGGER_MSG_STOP, sMessage)

            raise metro_error.Metro_input_error(NoObservationException)
コード例 #44
0
ファイル: metro_write_forecast.py プロジェクト: akrherz/metro
    def start(self):
        Metro_write.start(self)

        pForecast = self.get_infdata_reference('FORECAST')
        self.domForecast =  pForecast.get_output_information()
    
        if self.domForecast != None:
            sFilename = metro_config.get_value('FILE_FORECAST_OUT_FILENAME')
            self._write_dom(sFilename,self.domForecast)
        else:
            metro_logger.print_message(metro_logger.LOGGER_MSG_WARNING,
                                       _("no DOM forecast, nothing to write"))

        pForecast.set_output_information(None)
コード例 #45
0
    def start(self):
        Metro_write.start(self)

        pForecast = self.get_infdata_reference('FORECAST')
        self.domForecast = pForecast.get_output_information()

        if self.domForecast != None:
            sFilename = metro_config.get_value('FILE_FORECAST_OUT_FILENAME')
            self._write_dom(sFilename, self.domForecast)
        else:
            metro_logger.print_message(metro_logger.LOGGER_MSG_WARNING,
                                       _("no DOM forecast, nothing to write"))

        pForecast.set_output_information(None)
コード例 #46
0
def roadlayer_type_to_roadlayer_code(sLayerType):
    dValidLayerType = metro_config.get_value(\
        'XML_STATION_ROADLAYER_VALID_TYPE')

    sLayerType = sLayerType.upper()
    if sLayerType in dValidLayerType:
        iLayer_code = dValidLayerType[sLayerType]
    else:
        # raise an error
        sMessage = _("'%s' is not a valid road layer type. ") % (sLayerType) +\
                   _("Valid type are %s " ) % (dValidLayerType.keys()) +\
                   _("Check the station configuration file")
        metro_logger.print_message(metro_logger.LOGGER_MSG_STOP, sMessage)
        
    return iLayer_code
コード例 #47
0
ファイル: metro_xml.py プロジェクト: akrherz/metro
def create_node_tree_from_dict( domDoc, nodeParent, lDefs, dWriteHandlers, dData ):

    # Retrieve the informations on the data types
    dStandard_data_type = metro_config.get_value('XML_DATATYPE_STANDARD')
    dExtended_data_type = metro_config.get_value('XML_DATATYPE_EXTENDED')

    dData_type = metro_util.join_dictionaries(dStandard_data_type,
                                              dExtended_data_type)

    for dDef in lDefs:
        # Retrieve the name and the item type
        sTag = dDef['NAME']
        sXml_tag = dDef['XML_TAG']
        sData_type_name = dDef['DATA_TYPE']

        if dData_type[sData_type_name].has_key('CHILD'):
            #  create the node containing a list of "sub-node"
            lChildList = dData_type[sData_type_name]['CHILD']
            nodeData = dWriteHandlers[sData_type_name](sXml_tag,lChildList,dData[sTag],dWriteHandlers)
        else:
            #  create the node 
            nodeData = dWriteHandlers[sData_type_name](sXml_tag,dData[sTag])

        append_child(nodeParent, nodeData)
コード例 #48
0
def roadlayer_type_to_roadlayer_code(sLayerType):
    dValidLayerType = metro_config.get_value(\
        'XML_STATION_ROADLAYER_VALID_TYPE')

    sLayerType = sLayerType.upper()
    if sLayerType in dValidLayerType:
        iLayer_code = dValidLayerType[sLayerType]
    else:
        # raise an error
        sMessage = _("'%s' is not a valid road layer type. ") % (sLayerType) +\
                   _("Valid type are %s " ) % (dValidLayerType.keys()) +\
                   _("Check the station configuration file")
        metro_logger.print_message(metro_logger.LOGGER_MSG_STOP, sMessage)

    return iLayer_code
コード例 #49
0
    def start(self):
        Metro_postprocess.start(self)

        pRoadcast = self.get_infdata_reference('ROADCAST')
        roadcast_data = pRoadcast.get_data_collection()

        iPrecision = \
            metro_config.get_value('DEFAULT_ROADCAST_PREDICTION_PRECISION')

        if roadcast_data != None:
            self.__round_roadcast_header(roadcast_data.get_subsampled_data())
            self.__round_roadcast_data(roadcast_data.get_subsampled_data())            
        else:
            metro_logger.print_message(metro_logger.LOGGER_MSG_WARNING,
                                       _("No roadcast!"))

        pRoadcast.set_data_collection(roadcast_data)
コード例 #50
0
    def start(self):
        Metro_postprocess.start(self)

        pRoadcast = self.get_infdata_reference('ROADCAST')
        roadcast_data = pRoadcast.get_data_collection()

        iPrecision = \
            metro_config.get_value('DEFAULT_ROADCAST_PREDICTION_PRECISION')

        if roadcast_data != None:
            self.__round_roadcast_header(roadcast_data.get_subsampled_data())
            self.__round_roadcast_data(roadcast_data.get_subsampled_data())            
        else:
            metro_logger.print_message(metro_logger.LOGGER_MSG_WARNING,
                                       _("No roadcast!"))

        pRoadcast.set_data_collection(roadcast_data)
コード例 #51
0
ファイル: metro_data_station.py プロジェクト: akrherz/metro
    def get_sst_depth(self):
        """
        Get the sensor SST depth value

        Return 0.4 if value in station config file is not between 0.2 and 0.6 and if no flag '--use-sst-sensor-depth' is used. Else returns value provided for sensor SST depth in station config file.
        """
        if metro_config.get_value('SST_DEPTH') == False:
            return 0.4
        else:
            dStation_header = self.get_header()
            sStation_sst_depth = dStation_header['SST_DEPTH']
            if sStation_sst_depth == "None" or sStation_sst_depth > 0.6 or sStation_sst_depth < 0.2:
                sMessage = _("Sensor SST depth value in station config file is not between 0.2 and 0.6. Value 0.4 for sensor SST depth will be used.")
                metro_logger.print_message(metro_logger.LOGGER_MSG_CRITICAL,\
                                      sMessage)
                return 0.4
            else:
                return sStation_sst_depth
コード例 #52
0
ファイル: metro_data_station.py プロジェクト: akrherz/metro
    def get_station_type(self):
        """Get the station type

        Return True if the station is on a bridge, False if on the road.
        """
        dStation_header = self.get_header()
        sStation_type = dStation_header['STATION_TYPE']
        if sStation_type == "road" or  sStation_type == "route":
            bFlat = False
        elif sStation_type == "bridge" or  sStation_type == "pont":
            bFlat = True
        else:
            sMessage =  _("Wrong argument in the station config file %s.") \
                       % (metro_config.get_value('FILE_STATION_FILENAME')) +\
                       _("Station type must be \"road\" or \"bridge\". ") + \
                       _( "Using \"road\" as default.")
            metro_logger.print_message(metro_logger.LOGGER_MSG_CRITICAL,\
                                      sMessage)
            bFlat = False
            
        return bFlat
コード例 #53
0
    def get_station_type(self):
        """Get the station type

        Return True if the station is on a bridge, False if on the road.
        """
        dStation_header = self.get_header()
        sStation_type = dStation_header['STATION_TYPE']
        if sStation_type == "road" or sStation_type == "route":
            bFlat = False
        elif sStation_type == "bridge" or sStation_type == "pont":
            bFlat = True
        else:
            sMessage =  _("Wrong argument in the station config file %s.") \
                       % (metro_config.get_value('FILE_STATION_FILENAME')) +\
                       _("Station type must be \"road\" or \"bridge\". ") + \
                       _( "Using \"road\" as default.")
            metro_logger.print_message(metro_logger.LOGGER_MSG_CRITICAL,\
                                      sMessage)
            bFlat = False

        return bFlat
コード例 #54
0
ファイル: metro_metro2dom.py プロジェクト: akrherz/metro
    def __create_roadcast( self, data, dWriteHandlers ):

        #
        # DOM and root element creation
        #

        sRoot_xpath = metro_config.get_value('XML_ROADCAST_XPATH_ROOT')
        domDoc = metro_xml.create_dom(sRoot_xpath)
        nodeRoot = metro_xml.get_dom_root(domDoc)

        #
        # Roadcast header creation
        #

        # Concatenation of all header keys
        lHeader_keys = \
            metro_config.get_value('XML_ROADCAST_HEADER_STANDARD_ITEMS') + \
            metro_config.get_value('XML_ROADCAST_HEADER_EXTENDED_ITEMS')

        # xpath creation
        sHeader_xpath = metro_config.get_value('XML_ROADCAST_XPATH_HEADER')

        self.__create_header(domDoc, nodeRoot, sHeader_xpath,
                             lHeader_keys, dWriteHandlers, data)


        #
        # reation of the roadcast matrix
        #

        # Concatentation of all prediction types
        lPrediction_keys = \
            metro_config.get_value('XML_ROADCAST_PREDICTION_STANDARD_ITEMS') + \
            metro_config.get_value('XML_ROADCAST_PREDICTION_EXTENDED_ITEMS')

        #  xpath creation
        sPrediction_xpath = \
            metro_config.get_value('XML_ROADCAST_XPATH_PREDICTION')

        self.__create_matrix(domDoc, nodeRoot, sPrediction_xpath,
                             lPrediction_keys, dWriteHandlers, data)

        return domDoc
コード例 #55
0
    def __create_roadcast(self, data, dWriteHandlers):

        #
        # DOM and root element creation
        #

        sRoot_xpath = metro_config.get_value('XML_ROADCAST_XPATH_ROOT')
        domDoc = metro_xml.create_dom(sRoot_xpath)
        nodeRoot = metro_xml.get_dom_root(domDoc)

        #
        # Roadcast header creation
        #

        # Concatenation of all header keys
        lHeader_keys = \
            metro_config.get_value('XML_ROADCAST_HEADER_STANDARD_ITEMS') + \
            metro_config.get_value('XML_ROADCAST_HEADER_EXTENDED_ITEMS')

        # xpath creation
        sHeader_xpath = metro_config.get_value('XML_ROADCAST_XPATH_HEADER')

        self.__create_header(domDoc, nodeRoot, sHeader_xpath, lHeader_keys,
                             dWriteHandlers, data)

        #
        # reation of the roadcast matrix
        #

        # Concatentation of all prediction types
        lPrediction_keys = \
            metro_config.get_value('XML_ROADCAST_PREDICTION_STANDARD_ITEMS') + \
            metro_config.get_value('XML_ROADCAST_PREDICTION_EXTENDED_ITEMS')

        #  xpath creation
        sPrediction_xpath = \
            metro_config.get_value('XML_ROADCAST_XPATH_PREDICTION')

        self.__create_matrix(domDoc, nodeRoot, sPrediction_xpath,
                             lPrediction_keys, dWriteHandlers, data)

        return domDoc
コード例 #56
0
ファイル: metro_read_forecast.py プロジェクト: akrherz/metro
 def start(self):
     Metro_read.start(self)
     
     if metro_config.key_exist('FILE_FORECAST_IN_FILENAME'):
         sFilename = metro_config.get_value('FILE_FORECAST_IN_FILENAME')
         try:
             sFile_content = self._read_input_data(sFilename)
         except IOError:
             sError_message = _("METRo need a valid forecast file.") 
             metro_logger.print_message(metro_logger.LOGGER_MSG_STOP,
                                        sError_message)
         else:
             # Create and append infdata
             infdata_forecast = metro_infdata.Metro_infdata(
                 'FORECAST', metro_infdata.DATATYPE_METRO_DATA_COLLECTION)
             infdata_forecast.set_input_information(sFile_content)
             self.add_infdata(infdata_forecast)
     else:
         sError_message = _("METRo need a forecast file, please use the ") +\
                          _("option: '--input-forecast'") 
         metro_logger.print_message(metro_logger.LOGGER_MSG_STOP,
                                    sError_message)                        
コード例 #57
0
    def start(self):
        Metro_read.start(self)

        if metro_config.key_exist('FILE_FORECAST_IN_FILENAME'):
            sFilename = metro_config.get_value('FILE_FORECAST_IN_FILENAME')
            try:
                sFile_content = self._read_input_data(sFilename)
            except IOError:
                sError_message = _("METRo need a valid forecast file.")
                metro_logger.print_message(metro_logger.LOGGER_MSG_STOP,
                                           sError_message)
            else:
                # Create and append infdata
                infdata_forecast = metro_infdata.Metro_infdata(
                    'FORECAST', metro_infdata.DATATYPE_METRO_DATA_COLLECTION)
                infdata_forecast.set_input_information(sFile_content)
                self.add_infdata(infdata_forecast)
        else:
            sError_message = _("METRo need a forecast file, please use the ") +\
                             _("option: '--input-forecast'")
            metro_logger.print_message(metro_logger.LOGGER_MSG_STOP,
                                       sError_message)
コード例 #58
0
    def __set_ir(self, wf_controlled_data, wf_interpolated_data):
        """
        Set the theoretical infrared flux.
           
        Parameters:
        wf_controlled_data (metro_data) : controlled data. Read-only
        """
        npTime = wf_controlled_data.get_matrix_col('Time') 

        # Only interpolate if IR is given
        if  metro_config.get_value('IR'):
            npIR = wf_controlled_data.get_matrix_col('IR')
            npIR2 = metro_util.interpolate(npTime, npIR)
            wf_interpolated_data.append_matrix_col('IR', npIR2)
            return
        
        npCloudOctal = wf_controlled_data.get_matrix_col('CC')
        (npCoeff1, npCoeff2) = metro_physics.get_cloud_coefficient(npCloudOctal)
        npAT = wf_controlled_data.get_matrix_col('AT')
        npIR = npCoeff1*npAT+npCoeff2
        npIR2 = metro_util.interpolate(npTime, npIR)
        wf_controlled_data.append_matrix_col('IR', npIR)
        wf_interpolated_data.append_matrix_col('IR', npIR2)
コード例 #59
0
    def get_sst_depth(self):
        """
        Get the sensor SST depth value

        Return 0.4 if no flag '--use-sst-sensor-depth' is used.
        Else returns value provided for sensor SST depth in station config file,
        provided that it is included in METRo grid, ie. [0.01,1.4] m.
        See METRo documentation page for more details:
	https://framagit.org/metroprojects/metro/wikis/Vertical_levels_(METRo)
        """
        if metro_config.get_value('SST_DEPTH') == False:
            return 0.4
        else:
            dStation_header = self.get_header()
            fStation_sst_depth = dStation_header['SST_DEPTH']
            if fStation_sst_depth == "None" \
                   or fStation_sst_depth > 1.4 \
                   or fStation_sst_depth < 0.01:
                sMessage = _("Sensor SST depth value in station config file is not between 0.01 m and 1.4 m. Given value: '%s' m.") \
                           % fStation_sst_depth
                metro_logger.print_message(metro_logger.LOGGER_MSG_STOP,\
                                           sMessage)
            else:
                return fStation_sst_depth
コード例 #60
0
    def __check_time_order(self, ro_controlled_data, wf_controlled_data):
        """
        Name: __check_time_order

        Parameters: metro_data controlled_data : controlled observation data

        Returns: None
        
        Functions Called: metro_data.get_matrix_col
                          metro_util.get_difference_array
                          numpy.where, nonzero, arange
                          metro_date.get_day, get_hour, get_minute
                          metro_data.del_matrix_row
                          metro_logger.print_message

        Description: Check if the time of the observation are in order.  
                     Cut the information that are spaced by more than 240 minutes.
        Notes: 

        Revision History:
        Author		Date		Reason
        Miguel Tremblay      August 4th 2004
        """
        
        npTime = ro_controlled_data.get_matrix_col('Time')
        npCheck = metro_util.get_difference_array(npTime)
        # If a gap of more than nGapMinuteObservation
        #  minutes is identify, cut the value before.
        npCheck = metro_util.get_difference_array(npTime)        
        npBad = numpy.where( npCheck > metro_constant.\
                                nGapMinuteObservation*60, 1, 0)
        npBadIndice =  (numpy.nonzero(npBad))[0]
        if len(npBadIndice) > 0:
            sMessage =  _("More than %d minutes between 2 measures")\
                          % (metro_constant.nGapMinuteObservation)
            metro_logger.print_message(metro_logger.LOGGER_MSG_INFORMATIVE,\
                                       sMessage)
            npOT = ro_controlled_data.get_matrix_col('OBSERVATION_TIME')
            for i in range(0,len(npBadIndice)):
                nIndice = npBadIndice[i]
                sMessage = _("Indice: %d") % (nIndice)
                metro_logger.print_message(metro_logger.LOGGER_MSG_DEBUG,\
                                           sMessage)
                sMessage =  _("Cutoff time: day:%d hour:%d minute:%d") %\
                      (metro_date.get_day(npOT[nIndice]),\
                       metro_date.get_hour(npOT[nIndice]),\
                       metro_date.get_minute(npOT[nIndice]))
                metro_logger.print_message(metro_logger.LOGGER_MSG_DEBUG,\
                                           sMessage)

            
            toto = numpy.arange(0,npBadIndice[len(npBadIndice)-1]+1) 
            ro_controlled_data.del_matrix_row(toto)
        npTime = ro_controlled_data.get_matrix_col('Time')
        npBad = numpy.where( npCheck < 0, 1, 0)
        npBadIndice = (numpy.nonzero(npBad))[0]
        # Accept 1 value under zero because the last value of
        #  npBadIndice = npCheck[len(npCheck)-1] - npCheck[0]
        if len(npBadIndice) > 1:
            sMessage = _("Time of observation are not in order. ") + \
                       _("Check the %d th value") %(npBadIndice[1])
            metro_logger.print_message(metro_logger.LOGGER_MSG_STOP,\
                                      sMessage )
        # Remove the values that are equal.
        npBad = numpy.where( npCheck == 0, 1, 0)
        npBadIndice = (numpy.nonzero(npBad))[0]
        ro_controlled_data.del_matrix_row(npBadIndice)


########################################################

        npFT = wf_controlled_data.get_matrix_col('FORECAST_TIME')
        
        npOT = ro_controlled_data.get_matrix_col('Time')
        nHourStart = metro_date.get_hour(npFT[0])
        npDiff = - npOT + nHourStart*3600
        npBad = numpy.where(npDiff > metro_constant.\
                               nHourForExpirationOfObservation*3600, 1, 0)
        if len(npBad) > 0:
            npBadIndices = (numpy.nonzero(npBad))[0]
            if len(npBadIndices) > 0:
                npBadIndices = (numpy.nonzero(npBad))[0]
                sMessage = _("Observation is more than %d hours")  \
                           % ( metro_constant.nHourForExpirationOfObservation)\
                           + _("before the first roadcast")
                metro_logger.print_message(metro_logger.LOGGER_MSG_INFORMATIVE,
                                           sMessage)
                for i in range(0,len(npBadIndices)):
                    nIndice = npBadIndices[i]
                    sMessage = _("Indice: %d") % (nIndice)
                    metro_logger.print_message(metro_logger.LOGGER_MSG_DEBUG,
                                               sMessage)
                    ro_controlled_data.del_matrix_row(npBadIndices)
            
        # Get start time
        sStart_time = metro_config.get_value('INIT_ROADCAST_START_DATE')
        # If start time is not specified, default will be used
        if sStart_time == "":
            return

        # Check if the observation are not before the start of the roadcast
        #  if specified.
        fStart_time = metro_date.parse_date_string(sStart_time)
        npOT = ro_controlled_data.get_matrix_col('Time')\
               +nHourStart*3600
        npDiff = - npOT + int(metro_date.get_hour(fStart_time))*3600
        npBad = numpy.where(npDiff > metro_constant\
                               .nHourForExpirationOfObservation*3600, 1, 0)
        if len(npBad) > 0:
            npBadIndices = (numpy.nonzero(npBad))[0]
            if len(npBadIndices) > 0:
                sMessage = _("Observation after the first roadcast time of METRo")
                metro_logger.print_message(metro_logger.LOGGER_MSG_DEBUG,\
                                           sMessage)
                
                sMessage = _("Threshold: %d") \
                           % (int(metro_date.get_hour(fStart_time))*3600 \
                              +  int(metro_date.get_month(fStart_time))*60)
                metro_logger.print_message(metro_logger.LOGGER_MSG_DEBUG,\
                                           sMessage)
                for i in range(0,len(npBadIndices)):
                    nIndice = npBadIndices[i]
                    sMessage = _("Time difference: %f") \
                               % (npDiff[nIndice])
                    metro_logger.print_message(metro_logger.LOGGER_MSG_DEBUG,\
                                               sMessage)
                    ro_controlled_data.del_matrix_row(npBadIndices)