def _update_rawdata(self):
     (period, observation) = (self.period, self.observation)
     # Get the table name
     if period == "MON":
         tbname = "averages_monthly_%s" % observation
         nbseasons = 12
     else:
         tbname = "averages_%s_%s" % (period, observation)
         nbseasons = 4
     # Construct the query
     query_tpl = "select * from %s where COOPID='%s' and ENSOI='%s'"
     query = query_tpl % (tbname, self.coopid, self.ensoi_str)
     # Get the data
     try:
         connection = sql.connect(self.dbname, detect_types=sql.DETECT_TYPES)
         records = connection.execute(query).fetchall()
     except:
         return {}
     finally:
         connection.close()
     # Process the ENSO data
     data = np.empty(nbseasons, dtype=[(_, float) for _ in "ACNW"])
     for r in records:
         data[r[3]] = r[4:]
     try:
         self.multibarplot.rawdata = data
     except AttributeError:
         pass
     self.rawdata = data
 def _update_rawdata(self):
     # Open the connection with the database
     connection = sql.connect(self.dbname, detect_types=sql.DETECT_TYPES)
     # Construct the query
     tbname = "series_monthly_%s" % self.observation
     colname = "COOP%s" % self.coopid
     query_tpl = "select dates,%s from %s"
     query = query_tpl % (colname, tbname)
     # Get the data
     ndtype = [("dates", object), ("val", float)]
     try:
         records = connection.execute(query).fetchall()
     except:
         records = []
         return np.empty(0, dtype=ndtype)
     finally:
         connection.close()
     self.rawdata = data = np.array(records, dtype=ndtype)
     self.update_plots()
     return data
 def _coopid_changed(self, coopid):
     """
 
     """
     connection = sql.connect(self.dbname, detect_types=sql.DETECT_TYPES)
     fields = "STATION_NAME, LATITUDE, LONGITUDE, ELEVATION, COUNTY_REPRESENT"
     query_template = "select %s from %s where COOPID='%s'"
     query = query_template % (fields, self.stations_table, coopid)
     print "query_template:%s - dbname:%s" % (query, self.dbname)
     try:
         info = connection.execute(query).fetchone()
     finally:
         connection.close()
     #
     fnames = ("name", "latitude", "longitude", "elevation", "counties_list")
     params = dict(coopid=coopid)
     params.update((k, v) for (k, v) in zip(fnames, info))
     params["elevation"] = params["elevation"] or np.nan
     print "#%s: %s" % (coopid, params)
     (self.name, self.latitude, self.longitude, self.elevation, self.counties_list) = info
     return params
 def __init__(self, dbname, **kwargs):
     self.dbname = dbname
     # Open the connection
     connection = sql.connect(dbname, detect_types=sql.DETECT_TYPES)
     ndtype = [('coopid', '|S6'), ('name', '|S30'),
               ('lat', float), ('lon', float)]
     # Define the query
     fields = "COOPID, STATION_NAME, LATITUDE, LONGITUDE"
     query = "select %s from %s" % (fields, self.stations_table)
     # Retrieve the fields and close
     try:
         info = connection.execute(query).fetchall()
         self.all_stations = np.array(info, dtype=ndtype)
     finally:
         connection.close()
     # Update the default available stations
     self.find_reference_coordinates()
     self.find_available_stations()
     # Define the action to perform if the reference changes
     self.on_trait_change(self.find_reference_coordinates,
                          "ref_address")
     self.on_trait_change(self.find_available_stations,
                          'ref_dec_latitude,ref_dec_longitude,selection_radius')