Package upoints :: Module weather_stations :: Class Stations
[hide private]
[frames] | no frames]

Class Stations

   object --+        
            |        
         dict --+    
                |    
point.KeyedPoints --+
                    |
                   Stations

Class for representing a group of Station objects

Since: 0.5.1

Instance Methods [hide private]
new empty dictionary

__init__(self, data=None, index='WMO')
Initialise a new Stations object
dict
import_locations(self, data, index='WMO')
Parse NOAA weather station data files

Inherited from point.KeyedPoints: __repr__, bearing, destination, distance, final_bearing, forward, inverse, midpoint, range, sun_events, sunrise, sunset, to_grid_locator

Inherited from dict: __cmp__, __contains__, __delitem__, __eq__, __ge__, __getattribute__, __getitem__, __gt__, __hash__, __iter__, __le__, __len__, __lt__, __ne__, __new__, __setitem__, clear, copy, fromkeys, get, has_key, items, iteritems, iterkeys, itervalues, keys, pop, popitem, setdefault, update, values

Inherited from object: __delattr__, __reduce__, __reduce_ex__, __setattr__, __str__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, data=None, index='WMO')
(Constructor)

 
Initialise a new Stations object
Parameters:
  • points - Point objects to wrap
  • parse - Whether to attempt import of points
  • units - Unit type to be used for distances when parsing string locations
Returns:
new empty dictionary

Overrides: object.__init__

import_locations(self, data, index='WMO')

 

Parse NOAA weather station data files

import_locations() returns a dictionary with keys containing either the WMO or ICAO identifier, and values that are Station objects that describes the large variety of data exported by NOAA.

It expects data files in one of the following formats:

00;000;PABL;Buckland, Buckland Airport;AK;United States;4;65-58-56N;161-09-07W;;;7;;
01;001;ENJA;Jan Mayen;;Norway;6;70-56N;008-40W;70-56N;008-40W;10;9;P
01;002;----;Grahuken;;Norway;6;79-47N;014-28E;;;;15;

or:

AYMD;94;014;Madang;;Papua New Guinea;5;05-13S;145-47E;05-13S;145-47E;3;5;P
AYMO;--;---;Manus Island/Momote;;Papua New Guinea;5;02-03-43S;147-25-27E;;;4;;
AYPY;94;035;Moresby;;Papua New Guinea;5;09-26S;147-13E;09-26S;147-13E;38;49;P

Files containing the data in this format can be downloaded from NOAA's site in their station location page.

WMO indexed files downloaded from the NOAA site when processed by import_locations() will return dict object of the following style:

{'00000': Station('PABL', 'Buckland, Buckland Airport', 'AK',
                  'United States', 4, 65.982222. -160.848055, None,
                  None, 7, False),
 '01001'; Station('ENJA', Jan Mayen, None, 'Norway', 6, 70.933333,
                  -7.333333, 70.933333, -7.333333, 10, 9, True),
 '01002': Station(None, 'Grahuken', None, 'Norway', 6, 79.783333,
                  13.533333, None, None, 15, False)}

And dict objects such as the following will be created when ICAO indexed data files are processed:

{'AYMD': Station("94", "014", "Madang", None, "Papua New Guinea",
                 5, -5.216666, 145.783333, -5.216666,
                 145.78333333333333, 3, 5, True,
 'AYMO': Station(None, None, "Manus Island/Momote", None,
                 "Papua New Guinea", 5, -2.061944, 147.424166,
                 None, None, 4, False,
 'AYPY': Station("94", "035", "Moresby", None, "Papua New Guinea",
                 5, -9.433333, 147.216667, -9.433333, 147.216667,
                 38, 49, True}
>>> stations = Stations(open("WMO_stations"))
>>> for key, value in sorted(stations.items()):
...     print("%s - %s" % (key, value))
00000 - Buckland, Buckland Airport (PABL - N65.982°; W161.152°)
01001 - Jan Mayen (ENJA - N70.933°; W008.667°)
01002 - Grahuken (N79.783°; E014.467°)
>>> stations = Stations(open("ICAO_stations"), "ICAO")
>>> for key, value in sorted(stations.items()):
...     print("%s - %s" % (key, value))
AYMD - Madang (94014 - S05.217°; E145.783°)
AYMO - Manus Island/Momote (S02.062°; E147.424°)
AYPY - Moresby (94035 - S09.433°; E147.217°)
>>> stations = Stations(open("broken_WMO_stations"))
>>> for key, value in sorted(stations.items()):
...     print("%s - %s" % (key, value))
71046 - Komakuk Beach, Y. T. (CWKM - N69.617°; W140.200°)
71899 - Langara, B. C. (CWLA - N54.250°; W133.133°)
>>> stations = Stations(open("broken_ICAO_stations"), "ICAO")
>>> for key, value in sorted(stations.items()):
...     print("%s - %s" % (key, value))
KBRX - Bordeaux (N41.933°; W104.950°)
KCQB - Chandler, Chandler Municipal Airport (N35.724°; W096.820°)
Parameters:
  • data (file, list or str) - NOAA station data to read
  • index (str) - The identifier type used in the file
Returns: dict
WMO locations with Station objects
Raises:
Overrides: point.KeyedPoints.import_locations