How to add a module (METRo)
From Documentation
The modules of METRo are created in such a way that the input and output are standardized. It is easy in this way to add another module in the sequence of those that are already there.
[edit] Pre-process and post-process
There currently 2 big families of module: pre-process and post-process. Those module are contained in files in the directory metro/src/frontend/executable_module/.
The pre-process modules are executed before the physical model of METRo. They concern all the input methods (XML to python), the interpolation of data (observation and atmospherical forecast) and the QA/QC of data (as explained in the documentation page).
The post-process modules are executed after the physical model of METRo. They concern all the output methods (python to XML), the downscaling of data (road forecast is given at every 30 seconds) and the determination of the road condition based on the forecast weather elements.
[edit] Execution order
The order of execution can be in 2 places: in the configuration file or if this one does not exist, in the metro_config.py file.
The default is:
1- metro_read_forecast 2- metro_validate_forecast 3- metro_string2dom_forecast 4- metro_read_observation 5- metro_validate_observation 6- metro_string2dom_observation 7- metro_read_station 8- metro_validate_station 9- metro_string2dom_station 10- metro_read_observation_ref 11- metro_validate_observation_ref 12- metro_string2dom_observation_ref 13- metro_dom2metro 14- metro_preprocess_validate_input 15- metro_preprocess_qa_qc_forecast 16- metro_preprocess_interpol_forecast 17- metro_preprocess_fsint2 18- metro_preprocess_qa_qc_observation 19- metro_preprocess_validate_input 20- metro_preprocess_interpol_observation 21- metro_preprocess_combine 22- metro_model <---- physical mode of METRo 23- metro_postprocess_subsample_roadcast 24- metro_postprocess_round_roadcast 25- metro_metro2dom 26- metro_write_roadcast 27- metro_write_forecast
[edit] Example of module
A module of METRo must contains a start method and... that's it. Modifications on I/O or any other data or actions can be done in this method.
For example, suppose we want to add a module that change the name of the station in the output. We could have called this module Metro_postprocess_bidon and execute it after, say, the metro_model module.
The module could be:
from metro_postprocess import Metro_postprocess
class Metro_postprocess_bidon(Metro_postprocess):
def start(self):
Metro_postprocess.start(self)
# Get the roadcast
pRoadcast = self.get_infdata_reference('ROADCAST')
# Get the roadcast with the verified value (QA/QC)
roadcast_data = pRoadcast.get_data_collection()
controlled_roadcast = roadcast_data.get_controlled_data()
# Print in the stdout the name of the station
print controlled_roadcast.get_header_value('ROAD_STATION')
# Change the name of the road station
controlled_roadcast.set_header_value('ROAD_STATION',"a_new_name")
# Print the new value of the field 'ROAD_STATION'
print controlled_roadcast.get_header_value('ROAD_STATION')
Then we only have to add one line in the configuration file:
<key>INIT_MODULE_EXECUTION_SEQUENCE</key>
<array>
<string>metro_read_forecast</string>
<string>metro_string2dom_forecast</string>
<string>metro_read_observation</string>
<string>metro_string2dom_observation</string>
<string>metro_read_station</string>
<string>metro_string2dom_station</string>
<string>metro_dom2metro</string>
<string>metro_preprocess_bidon</string>
<string>metro_preprocess_interpol_forecast</string>
<string>metro_preprocess_fsint2</string>
<string>metro_preprocess_qa_qc_observation</string>
<string>metro_preprocess_interpol_observation</string>
<string>metro_preprocess_combine</string>
<string>metro_model</string>
<string>metro_postprocess_bidon</string>
<string>metro_metro2dom</string>
<string>metro_write_roadcast</string>
<string>metro_write_forecast</string>
</array>
The name in the station file would be overwritten. The header of the roadcast, if we would run METRo with the --selftest flag, would be:
<roadcast>
<header>
<filetype>roadcast</filetype>
<version>1.4</version>
<road-station>a_new_name</road-station>
<production-date>2004-08-26T01:00Z</production-date>
<first-roadcast>2004-08-25T23:12Z</first-roadcast>
</header>
...
</roadcast>
| This page is part of the documentation of the METRo software. Back to the table of content. |
