metro_data_station.py 5.4 KB
Newer Older
1
2
# METRo : Model of the Environment and Temperature of Roads
# METRo is Free and is proudly provided by the Government of Canada
Miguel Tremblay's avatar
Miguel Tremblay committed
3
# Copyright (C) Her Majesty The Queen in Right of Canada, Environment Canada, 2006
Sasa Zhang's avatar
Sasa Zhang committed
4
#
5
#  Questions or bugs report: metro@ec.gc.ca
6
#  METRo repository: https://framagit.org/metroprojects/metro
7
#  Documentation: https://framagit.org/metroprojects/metro/wikis/home
8
9
10
11
12
13
14
#
# Code contributed by:
#  Miguel Tremblay - Canadian meteorological center
#  Francois Fortin - Canadian meteorological center
#
#  $LastChangedDate$
#  $LastChangedRevision$
Sasa Zhang's avatar
Sasa Zhang committed
15
################################################################################
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


Sasa Zhang's avatar
Sasa Zhang committed
31
from data_module.metro_data import Metro_data
32
import metro_logger
33
34
35
import metro_config
from toolbox import metro_util

Sasa Zhang's avatar
Sasa Zhang committed
36

37
38
_ = metro_util.init_translation('metro_data_station')

Sasa Zhang's avatar
Sasa Zhang committed
39
40

# ===============================================================================
41
42
43
44
45
# Name: Metro_dada_station
#
# Description: Contenue d'un fichier "station" . Les donnees sont contenus
#              dans un dictionnaire (header). La partie matrix de l'objet
#              contient les roadlayer.
Sasa Zhang's avatar
Sasa Zhang committed
46
# ===============================================================================
47
48


Sasa Zhang's avatar
Sasa Zhang committed
49
50
51
class Metro_data_station(Metro_data):
    """
        Specialised class for station data.
Sasa Zhang's avatar
Sasa Zhang committed
52
        This class inherit Metro_data. It add some method facilitating the manipulation of station data.
53
54
55
56
    """

    # Get the longitude of the station
    def get_longitude(self):
Sasa Zhang's avatar
Sasa Zhang committed
57
58
59
        """
            Get the longitude of the station.
        """
60
61
62
63
64
65
66
        dStation_header = self.get_header()
        tLatlon = dStation_header['COORDINATE']
        fLon = tLatlon[1]
        return fLon

    # Get the latitude of the station
    def get_latitude(self):
Sasa Zhang's avatar
Sasa Zhang committed
67
68
69
        """
            Get the latitude of the station.
        """
70
71
72
73
74
75
        dStation_header = self.get_header()
        tLatlon = dStation_header['COORDINATE']
        fLat = tLatlon[0]
        return fLat

    def get_station_name(self):
Sasa Zhang's avatar
Sasa Zhang committed
76
77
78
        """
            Get the station name
        """
79
80
81
        dStation_header = self.get_header()
        return dStation_header['ROAD_STATION']

Sasa Zhang's avatar
Sasa Zhang committed
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
    # ----------------------------------------------------------------------------
    # Name: get_station_type
    #
    # Parameters:
    #
    # Returns: bool bFlat : True if the station is on a bridge, False if it
    #  is on a road.
    #
    # Functions Called:
    #   . . .
    #
    # Description: Returns a boolean indicating if the RWIS station is on a
    #  road or a bridge
    #
    # Notes:
    #
    # Revision History:
    #  Author		Date		Reason
    # Miguel Tremblay      August 19th 2004
    # ------------------------------------------------------------------------------

    def get_station_type(self):
        """
            Get the station type
            Return True if the station is on a bridge, False if on the road.
107
108
109
        """
        dStation_header = self.get_header()
        sStation_type = dStation_header['STATION_TYPE']
Sasa Zhang's avatar
Sasa Zhang committed
110
        if sStation_type == "road" or sStation_type == "route":
111
            bFlat = False
Sasa Zhang's avatar
Sasa Zhang committed
112
        elif sStation_type == "bridge" or sStation_type == "pont":
113
114
            bFlat = True
        else:
Sasa Zhang's avatar
Sasa Zhang committed
115
116
            sMessage = _("Wrong argument in the station config file %s.") \
                       % (metro_config.get_value('FILE_STATION_FILENAME')) + \
117
                       _("Station type must be \"road\" or \"bridge\". ") + \
Sasa Zhang's avatar
Sasa Zhang committed
118
119
                       _("Using \"road\" as default.")
            metro_logger.print_message(metro_logger.LOGGER_MSG_CRITICAL, sMessage)
120
121
            bFlat = False
        return bFlat
122
123
124

    def get_sst_depth(self):
        """
Sasa Zhang's avatar
Sasa Zhang committed
125
126
127
128
129
            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.
130

Sasa Zhang's avatar
Sasa Zhang committed
131
132
            See METRo documentation page for more details:
            https://framagit.org/metroprojects/metro/wikis/Vertical_levels_(METRo)
133
        """
Sasa Zhang's avatar
Sasa Zhang committed
134
        if not metro_config.get_value('SST_DEPTH'):
135
136
137
            return 0.4
        else:
            dStation_header = self.get_header()
138
            fStation_sst_depth = dStation_header['SST_DEPTH']
Sasa Zhang's avatar
Sasa Zhang committed
139
140
            # if fStation_sst_depth == "None" or fStation_sst_depth > 1.4 or fStation_sst_depth < 0.01:
            if fStation_sst_depth is None or fStation_sst_depth > 1.4 or fStation_sst_depth < 0.01:
Sasa Zhang's avatar
Sasa Zhang committed
141
142
143
                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)
144
            else:
145
                return fStation_sst_depth