Exemple #1
0
    def test_empty_db_tables(self):
        db_session = db.Session()
        db_session.add(Catchment(location="Aberdeen", watercourse="River Dee"))
        db_session.commit()

        db.empty_db_tables()

        self.assertEqual(self.all_tables,
                         sorted(list(db.metadata.tables.keys())))
        self.assertEqual(db_session.query(Catchment).count(), 0)
        db_session.close()
    def setUpClass(cls):
        settings.config['nrfa']['oh_json_url'] = \
            'file:' + pathname2url(os.path.abspath('./floodestimation/fehdata_test.json'))
        cls.db_session = db.Session()

        cls.catchment = Catchment("Dundee", "River Tay")
        cls.catchment.country = 'gb'
        cls.catchment.descriptors = Descriptors(dtm_area=2.345,
                                                bfihost=0.0,
                                                sprhost=100,
                                                saar=2000,
                                                farl=0.5,
                                                urbext2000=0,
                                                fpext=0.2,
                                                centroid_ngr=Point(
                                                    276125, 688424))
from floodestimation.loaders import load_catchment
from floodestimation import db
from floodestimation.collections import CatchmentCollections
from floodestimation.analysis import QmedAnalysis

db_session = db.Session()

dee_catchment = load_catchment('nith_cds.cd3')
gauged_catchments = CatchmentCollections(db_session)

qmed_analysis = QmedAnalysis(dee_catchment, gauged_catchments)
print(qmed_analysis.qmed())

print(qmed_analysis.methods)

print(qmed_analysis.qmed_all_methods())

print(qmed_analysis.urban_adj_factor())

print(qmed_analysis.find_donor_catchments(5, 200.0))

qmed_analysis.idw_power = 1.5
print(qmed_analysis.idw_power)

donors = qmed_analysis.find_donor_catchments(5, 200.0)

for donor in donors:
    Q = QmedAnalysis(donors[0], gauged_catchments)
    print(donor, qmed_analysis._error_correlation(donor), Q.qmed_all_methods())
db_session.close()
Exemple #4
0
 def setUpClass(cls):
     settings.config['nrfa']['oh_json_url'] = \
         'file:' + pathname2url(os.path.abspath('./floodestimation/fehdata_test.json'))
     cls.db_session = db.Session()
     db.empty_db_tables()
 def setUpClass(cls):
     cls.session = db.Session()
Exemple #6
0
 def __init__(self):
     self.name = None
     self.catchment = Catchment("River Town", "River Burn")
     self.db_session = db.Session()
     self.gauged_catchments = CatchmentCollections(self.db_session)
     self.qmed = None
Exemple #7
0
 def test_open_and_close_session(self):
     db_session = db.Session()
     db_session.close()
Exemple #8
0
    def __init__(self, parent, p):
        wx.Panel.__init__(self, parent)
        self.p = p

        db_session = db.Session()
        self.gauged_catchments = CatchmentCollections(db_session)
        self.qmed_analysis = QmedAnalysis(config.target_catchment,
                                          self.gauged_catchments)
        db_session.close()

        self.qmed_method = 'best'
        self.donor_search_criteria_refreshed = True
        self.suggested_donors = None
        self.adopted_donors = None
        self.keep_rural = False
        config.analysis.catchment.pot_records = None

        self.adoptedQmed = '-'

        self.calc_obs_amax_btn = wx.Button(self, -1, ' AMAX SERIES ')
        self.calc_obs_amax_btn.Bind(wx.EVT_BUTTON, self.amax_area)
        self.calc_obs_pot_btn = wx.Button(self, -1, ' POT SERIES ')
        self.calc_obs_pot_btn.Bind(wx.EVT_BUTTON, self.pot_area)
        self.refresh_calcs_btn = wx.Button(self, -1, ' REFRESH CALCS ')

        self.qmed_notes = wx.TextCtrl(self,
                                      -1,
                                      "Notes on QMED",
                                      size=(350, 150),
                                      style=wx.TE_MULTILINE)

        self.qmed_2008_label = wx.StaticText(self, -1, "QMED CDS 2008")
        self.qmed_1999_label = wx.StaticText(self, -1, "QMED CDS 1999")
        self.qmed_area_label = wx.StaticText(self, -1, "QMED AREA")
        self.qmed_amax_label = wx.StaticText(self, -1, "QMED AMAX")
        self.qmed_pot_label = wx.StaticText(self, -1, "QMED POT")
        self.qmed_width_label = wx.StaticText(self, -1, "QMED Channel width")
        self.user_qmed_label = wx.StaticText(self, -1, "User QMED")
        self.selected_unadj_qmed_label = wx.StaticText(self, -1,
                                                       "Selected rural QMED")
        self.station_search_distance_label = wx.StaticText(
            self, -1, "Station search distance")
        self.station_search_limit_label = wx.StaticText(
            self, -1, "Station search limit")
        self.idw_label = wx.StaticText(self, -1, "IDW")
        self.selected_unadj_qmed = wx.TextCtrl(self,
                                               -1,
                                               "-",
                                               style=wx.TE_READONLY)

        self.qmed_cds2008 = wx.TextCtrl(self, -1, "-", style=wx.TE_READONLY)
        self.qmed_cds1999 = wx.TextCtrl(self, -1, "-", style=wx.TE_READONLY)
        self.qmed_areaOnly = wx.TextCtrl(self, -1, "-", style=wx.TE_READONLY)
        self.qmed_obs_amax = wx.TextCtrl(self, -1, "-", style=wx.TE_READONLY)
        self.qmed_obs_pot = wx.TextCtrl(self, -1, "-", style=wx.TE_READONLY)
        self.qmed_geom = wx.TextCtrl(self, -1, "-", style=wx.TE_READONLY)
        self.qmed_user = wx.TextCtrl(self, -1, "-")

        self.rb1 = wx.RadioButton(self, -1, '', style=wx.RB_GROUP)
        self.rb2 = wx.RadioButton(self, -1, '')
        self.rb3 = wx.RadioButton(self, -1, '')
        self.rb4 = wx.RadioButton(self, -1, '')
        self.rb5 = wx.RadioButton(self, -1, '')
        self.rb6 = wx.RadioButton(self, -1, '')
        self.rb7 = wx.RadioButton(self, -1, '')

        self.Bind(wx.EVT_RADIOBUTTON, self.SetVal, id=self.rb1.GetId())
        self.Bind(wx.EVT_RADIOBUTTON, self.SetVal, id=self.rb2.GetId())
        self.Bind(wx.EVT_RADIOBUTTON, self.SetVal, id=self.rb3.GetId())
        self.Bind(wx.EVT_RADIOBUTTON, self.SetVal, id=self.rb4.GetId())
        self.Bind(wx.EVT_RADIOBUTTON, self.SetVal, id=self.rb5.GetId())
        self.Bind(wx.EVT_RADIOBUTTON, self.SetVal, id=self.rb6.GetId())
        self.Bind(wx.EVT_RADIOBUTTON, self.SetVal, id=self.rb7.GetId())

        self.station_search_distance = wx.TextCtrl(self, -1, "500.0")
        self.station_limit = wx.TextCtrl(self, -1, "5")
        self.idw_weight = wx.TextCtrl(self, -1, "3")

        self.station_search_distance.Bind(wx.EVT_TEXT,
                                          self.UpdateDonorCriteria)
        self.station_limit.Bind(wx.EVT_TEXT, self.UpdateDonorCriteria)

        #self.calcQMeds()

        self.distance_decay_update = wx.RadioButton(self,
                                                    -1,
                                                    "Decaying with distance",
                                                    style=wx.RB_GROUP)
        self.direct_transfer_update = wx.RadioButton(self, -1,
                                                     'Equal weighting')
        self.dont_update = wx.RadioButton(self, -1, "Don't update")

        #self.Bind(wx.EVT_RADIOBUTTON, self.SetUpdate, id=self.dont_update.GetId())
        #self.Bind(wx.EVT_RADIOBUTTON, self.SetUpdate, id=self.distance_decay_update.GetId())
        #self.Bind(wx.EVT_RADIOBUTTON, self.SetUpdate, id=self.direct_transfer_update.GetId())

        self.local_qmed_adjustment_label = wx.StaticText(
            self, -1, "Local QMED adjustment")
        self.locally_adjusted_qmed_label = wx.StaticText(
            self, -1, "Locally adjusted QMED")
        self.locally_adjusted_qmed = wx.TextCtrl(self,
                                                 -1,
                                                 "-",
                                                 style=wx.TE_READONLY)
        self.local_qmed_adjustment = wx.TextCtrl(self,
                                                 -1,
                                                 "-",
                                                 style=wx.TE_READONLY)

        self.update_for_urb_chk = wx.CheckBox(self, -1,
                                              'Update for urbanisation')
        self.update_for_urb_chk.Bind(wx.EVT_CHECKBOX,
                                     self.SetUrbanChk,
                                     id=self.update_for_urb_chk.GetId())

        self.urban_expansion_factor_label = wx.StaticText(
            self, -1, "Urban expansion factor")
        self.adjusted_urbext_label = wx.StaticText(self, -1, "Adjusted URBEXT")
        self.urban_adjustment_factor_label = wx.StaticText(
            self, -1, "Urban adjustment factor")

        self.urban_expansion_factor = wx.TextCtrl(self,
                                                  -1,
                                                  "-",
                                                  style=wx.TE_READONLY)
        self.adjusted_urbext = wx.TextCtrl(self, -1, "-", style=wx.TE_READONLY)
        self.urban_adjustment_factor = wx.TextCtrl(self,
                                                   -1,
                                                   "-",
                                                   style=wx.TE_READONLY)

        self.adopted_qmed_label = wx.StaticText(self, -1, "Adopted QMED")
        self.adopted_qmed = wx.TextCtrl(self, -1, "-", style=wx.TE_READONLY)

        sizer = wx.GridBagSizer(vgap=5, hgap=10)
        sizer.Add(self.calc_obs_amax_btn, pos=(7, 3))
        sizer.Add(self.calc_obs_pot_btn, pos=(7, 4))

        sizer.Add(self.refresh_calcs_btn, pos=(0, 3))
        sizer.Add(self.qmed_notes, pos=(1, 3), span=(5, 3))

        sizer.Add(self.qmed_2008_label, pos=(0, 0))
        sizer.Add(self.qmed_1999_label, pos=(1, 0))
        sizer.Add(self.qmed_area_label, pos=(2, 0))
        sizer.Add(self.qmed_amax_label, pos=(3, 0))
        sizer.Add(self.qmed_pot_label, pos=(4, 0))
        sizer.Add(self.qmed_width_label, pos=(5, 0))
        sizer.Add(self.user_qmed_label, pos=(6, 0))
        sizer.Add(self.selected_unadj_qmed_label, pos=(7, 0))

        sizer.Add(self.qmed_cds2008, pos=(0, 1))
        sizer.Add(self.qmed_cds1999, pos=(1, 1))
        sizer.Add(self.qmed_areaOnly, pos=(2, 1))
        sizer.Add(self.qmed_obs_amax, pos=(3, 1))
        sizer.Add(self.qmed_obs_pot, pos=(4, 1))
        sizer.Add(self.qmed_geom, pos=(5, 1))
        sizer.Add(self.qmed_user, pos=(6, 1))
        sizer.Add(self.selected_unadj_qmed, pos=(7, 1))

        sizer.Add(self.rb1, pos=(0, 2))
        sizer.Add(self.rb2, pos=(1, 2))
        sizer.Add(self.rb3, pos=(2, 2))
        sizer.Add(self.rb4, pos=(3, 2))
        sizer.Add(self.rb5, pos=(4, 2))
        sizer.Add(self.rb6, pos=(5, 2))
        sizer.Add(self.rb7, pos=(6, 2))

        self.table = wx.Panel(self, -1)
        self.list = CheckListCtrl(self.table)
        self.list.InsertColumn(0, 'STATION')
        self.list.InsertColumn(1, 'DISTANCE')
        self.list.InsertColumn(2, 'ADJUSTMENT FACTOR')
        self.list.InsertColumn(3, 'ERROR CORRELATION')
        self.list.InsertColumn(4, 'WEIGHT')
        self.list.SetColumnWidth(0, 250)
        self.list.SetColumnWidth(1, 100)
        self.list.SetColumnWidth(2, 100)
        self.list.SetColumnWidth(3, 100)
        self.list.SetColumnWidth(4, 100)

        sizer.Add(self.table, pos=(9, 0), span=(1, 6), flag=wx.EXPAND)
        sizer.Add(self.station_search_distance_label, pos=(10, 0), span=(1, 1))
        sizer.Add(self.station_search_distance, pos=(10, 1), span=(1, 1))
        sizer.Add(self.station_search_limit_label, pos=(10, 2), span=(1, 1))
        sizer.Add(self.station_limit, pos=(10, 3), span=(1, 1))
        sizer.Add(self.idw_label, pos=(10, 4), span=(1, 1))
        sizer.Add(self.idw_weight, pos=(10, 5), span=(1, 1))
        sizer.Add(self.dont_update, pos=(11, 0), span=(1, 2))
        sizer.Add(self.distance_decay_update, pos=(12, 0), span=(1, 2))
        sizer.Add(self.direct_transfer_update, pos=(13, 0), span=(1, 2))

        sizer.Add(self.local_qmed_adjustment_label, pos=(12, 2), span=(1, 1))
        sizer.Add(self.local_qmed_adjustment, pos=(12, 3), span=(1, 1))
        sizer.Add(self.locally_adjusted_qmed_label, pos=(13, 2), span=(1, 1))
        sizer.Add(self.locally_adjusted_qmed, pos=(13, 3), span=(1, 1))

        sizer.Add(self.update_for_urb_chk, pos=(15, 0), span=(1, 1))
        sizer.Add(self.urban_expansion_factor, pos=(16, 1), span=(1, 1))
        sizer.Add(self.adjusted_urbext, pos=(17, 1), span=(1, 1))
        sizer.Add(self.urban_adjustment_factor, pos=(18, 1), span=(1, 1))
        sizer.Add(self.urban_expansion_factor_label, pos=(16, 0), span=(1, 1))
        sizer.Add(self.adjusted_urbext_label, pos=(17, 0), span=(1, 1))
        sizer.Add(self.urban_adjustment_factor_label, pos=(18, 0), span=(1, 1))

        sizer.Add(self.adopted_qmed_label, pos=(18, 4), span=(1, 1))
        sizer.Add(self.adopted_qmed, pos=(18, 5), span=(1, 1))

        #  Assign actions to buttons
        self.refresh_calcs_btn.Bind(wx.EVT_BUTTON, self.onRefresh)

        border = wx.BoxSizer()
        border.Add(sizer, 0, wx.ALL, 20)
        self.SetSizerAndFit(border)
        self.Fit()