def test_descriptors(self): self.assertEqual(self.catchment.descriptors.ihdtm_ngr, Point(204000, 748400)) self.assertEqual(self.catchment.descriptors.centroid_ngr, Point(207378, 751487)) self.assertEqual(self.catchment.descriptors.dtm_area, 30.09) self.assertEqual(self.catchment.descriptors.altbar, 367) self.assertEqual(self.catchment.descriptors.aspbar, 247) self.assertEqual(self.catchment.descriptors.aspvar, 0.17) self.assertEqual(self.catchment.descriptors.bfihost, 0.394) self.assertEqual(self.catchment.descriptors.dplbar, 6.56) self.assertEqual(self.catchment.descriptors.dpsbar, 356.3) self.assertEqual(self.catchment.descriptors.farl, 0.986) self.assertEqual(self.catchment.descriptors.fpext, 0.0369) self.assertEqual(self.catchment.descriptors.ldp, 11.5) self.assertEqual(self.catchment.descriptors.propwet, 0.79) self.assertEqual(self.catchment.descriptors.rmed_1h, 13.9) self.assertEqual(self.catchment.descriptors.rmed_1d, 72.0) self.assertEqual(self.catchment.descriptors.rmed_2d, 112.4) self.assertEqual(self.catchment.descriptors.saar, 2810) self.assertEqual(self.catchment.descriptors.saar4170, 2969) self.assertEqual(self.catchment.descriptors.sprhost, 53.35) self.assertEqual(self.catchment.descriptors.urbconc1990, None) self.assertEqual(self.catchment.descriptors.urbext1990, 0.0) self.assertEqual(self.catchment.descriptors.urbloc1990, None) self.assertEqual(self.catchment.descriptors.urbconc2000, None) self.assertEqual(self.catchment.descriptors.urbext2000, 0.0) self.assertEqual(self.catchment.descriptors.urbloc2000, None)
def test_descriptors(self): self.assertEqual(self.catchment.descriptors.ihdtm_ngr, Point(336950, 700550)) self.assertEqual(self.catchment.descriptors.centroid_ngr, Point(317325, 699832)) self.assertEqual(self.catchment.descriptors.dtm_area, 416.56) self.assertEqual(self.catchment.descriptors.altbar, 151) self.assertEqual(self.catchment.descriptors.aspbar, 123) self.assertEqual(self.catchment.descriptors.aspvar, 0.22) self.assertEqual(self.catchment.descriptors.bfihost, 0.511) self.assertEqual(self.catchment.descriptors.dplbar, 26.93) self.assertEqual(self.catchment.descriptors.dpsbar, 62.9) self.assertEqual(self.catchment.descriptors.farl, 0.824) self.assertEqual(self.catchment.descriptors.fpext, 0.1009) self.assertEqual(self.catchment.descriptors.ldp, 48.74) self.assertEqual(self.catchment.descriptors.propwet, 0.45) self.assertEqual(self.catchment.descriptors.rmed_1h, 8.8) self.assertEqual(self.catchment.descriptors.rmed_1d, 35.5) self.assertEqual(self.catchment.descriptors.rmed_2d, 47.1) self.assertEqual(self.catchment.descriptors.saar, 947) self.assertEqual(self.catchment.descriptors.saar4170, 951) self.assertEqual(self.catchment.descriptors.sprhost, 34.62) self.assertEqual(self.catchment.descriptors.urbconc1990, None) self.assertEqual(self.catchment.descriptors.urbext1990, 0.0173) self.assertEqual(self.catchment.descriptors.urbloc1990, None) self.assertEqual(self.catchment.descriptors.urbconc2000, 0.830) self.assertEqual(self.catchment.descriptors.urbext2000, 0.0361) self.assertEqual(self.catchment.descriptors.urbloc2000, 0.702)
def test_catchment_distance_no_country(self): catchment_1 = Catchment("Aberdeen", "River Dee") catchment_1.descriptors.centroid_ngr = Point(0, 0) catchment_2 = Catchment("Dundee", "River Tay") catchment_2.descriptors.centroid_ngr = Point(3000, 4000) self.assertEqual(catchment_1.distance_to(catchment_2), 5)
def test_catchment_distance_different_country(self): catchment_1 = Catchment("Aberdeen", "River Dee") catchment_1.descriptors.centroid_ngr = Point(0, 0) catchment_2 = Catchment("Belfast") catchment_2.descriptors.centroid_ngr = Point(3, 4) catchment_2.country = 'ni' self.assertEqual(catchment_1.distance_to(catchment_2), float('inf'))
def test_parse_from_string(self): s = """<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <!-- Created by FEH CD-ROM 3 at 13:05:09 GMT on Wed 10-Jun-2015 --> <FEHCDROMExportedDescriptors version="2.0.000" appVersion="3.0.000"> <CatchmentDescriptors grid="GB" x="204000" y="748400" mgr="NN 04000 48400"> <CatchmentCentroid grid="GB" x="207378" y="751487" mgr="NN 07378 51487" /> <area>30.09</area> <altbar>367</altbar> <aspbar>247</aspbar> <aspvar>0.17</aspvar> <bfihost>0.394</bfihost> <dplbar>6.56</dplbar> <dpsbar>356.3</dpsbar> <farl>0.986</farl> <fpext>0.0369</fpext> <fpdbar>0.825</fpdbar> <fploc>0.676</fploc> <ldp>11.5</ldp> <propwet>0.79</propwet> <rmed_1h>13.9</rmed_1h> <rmed_1d>72.0</rmed_1d> <rmed_2d>112.4</rmed_2d> <saar>2810</saar> <saar4170>2969</saar4170> <sprhost>53.35</sprhost> <urbconc1990>NaN</urbconc1990> <urbext1990>0.0</urbext1990> <urbloc1990>NaN</urbloc1990> <urbconc2000>NaN</urbconc2000> <urbext2000>0.0</urbext2000> <urbloc2000>NaN</urbloc2000> </CatchmentDescriptors> <CatchmentAverageDDFValues grid="GB" x="204000" y="748400" mgr="NN 04000 48400"> <c>-0.01884</c> <d1>0.53527</d1> <d2>0.5086</d2> <d3>0.49952</d3> <e>0.25011</e> <f>2.69933</f> </CatchmentAverageDDFValues> <PointDDFValues grid="GB" x="204000" yx="748000" mgr="NN 04000 48000"> <c_1_km>-0.019</c_1_km> <d1_1_km>0.566</d1_1_km> <d2_1_km>0.54</d2_1_km> <d3_1_km>0.602</d3_1_km> <e_1_km>0.251</e_1_km> <f_1_km>2.608</f_1_km> </PointDDFValues> </FEHCDROMExportedDescriptors> """ catchment = self.parser.parse_str(s) self.assertEqual(catchment.descriptors.centroid_ngr, Point(207378, 751487))
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))
def onChangeCds(self, event): if self.inside_load is False: try: config.analysis.catchment.country = str( self.outlet_grid.GetValue()) except: pass try: config.analysis.catchment.descriptors.ihdtm_ngr.x = int( self.outlet_x.GetValue()) except: pass try: config.analysis.catchment.descriptors.ihdtm_ngr.y = int( self.outlet_y.GetValue()) except: pass try: config.analysis.catchment.descriptors.centroid_ngr.x = int( self.centroid_x.GetValue()) except: pass try: config.analysis.catchment.descriptors.centroid_ngr.y = int( self.centroid_y.GetValue()) except: pass try: config.analysis.catchment.descriptors.centroid_ngr = Point( int(self.centroid_x.GetValue()), int(self.centroid_y.GetValue())) except: pass try: config.analysis.catchment.descriptors.dtm_area = float( self.carea.GetValue()) except: pass try: config.analysis.catchment.descriptors.altbar = float( self.altbar.GetValue()) except: pass try: config.analysis.catchment.descriptors.aspbar = float( self.aspbar.GetValue()) except: pass try: config.analysis.catchment.descriptors.aspvar = float( self.aspvar.GetValue()) except: pass try: config.analysis.catchment.descriptors.bfihost = float( self.bfihost.GetValue()) except: pass try: config.analysis.catchment.descriptors.dplbar = float( self.dplbar.GetValue()) except: pass try: config.analysis.catchment.descriptors.dpsbar = float( self.dpsbar.GetValue()) except: pass try: config.analysis.catchment.descriptors.farl = float( self.farl.GetValue()) except: pass try: config.analysis.catchment.descriptors.ldp = float( self.ldp.GetValue()) except: pass try: config.analysis.catchment.descriptors.propwet = float( self.propwet.GetValue()) except: pass try: config.analysis.catchment.descriptors.saar = float( self.saar.GetValue()) except: pass try: config.analysis.catchment.descriptors.sprhost = float( self.sprhost.GetValue()) except: pass try: config.analysis.catchment.descriptors.fpext = float( self.fpext.GetValue()) except: pass try: config.analysis.catchment.descriptors.urbconc1990 = float( self.urbconc1990.GetValue()) except: pass try: config.analysis.catchment.descriptors.urbext1990 = float( self.urbext1990.GetValue()) except: pass try: config.analysis.catchment.descriptors.urbloc1990 = float( self.urbloc1990.GetValue()) except: pass try: config.analysis.catchment.descriptors.urbloc2000 = float( self.urbloc2000.GetValue()) except: pass try: config.analysis.catchment.descriptors.urbconc2000 = float( self.urbconc2000.GetValue()) except: pass try: config.analysis.catchment.descriptors.urbext2000 = float( self.urbext2000.GetValue()) except: pass try: config.analysis.catchment.channel_width = float( self.chnl_width.GetValue()) except: pass
def test_coordinate(self): self.assertEqual(self.catchment.point, Point(336900, 700600))
def test_coordinate(self): self.assertEqual(self.catchment.point, Point(204000, 748400))
def test_descriptors(self): self.assertEqual(self.catchment.descriptors.ihdtm_ngr, Point(240500, 375700)) self.assertEqual(self.catchment.descriptors.centroid_ngr, Point(232140, 375415))
def test_coordinate(self): self.assertEqual(self.catchment.point, Point(240500, 375700))
class TestQmedDonor(unittest.TestCase): catchment = Catchment("Dundee", "River Tay") catchment.country = 'gb' catchment.descriptors = Descriptors(dtm_area=2.345, bfihost=1e-4, sprhost=100, saar=2000, farl=0.5, urbext2000=0, centroid_ngr=Point(276125, 688424)) # QMED descr = 0.61732109 donor_catchment = Catchment("Aberdeen", "River Dee") donor_catchment.country = 'gb' donor_catchment.descriptors = Descriptors(dtm_area=1, bfihost=0.50, sprhost=50, saar=1000, farl=1, urbext2000=0, centroid_ngr=Point(276125, 688424)) donor_catchment.amax_records = [AmaxRecord(date(1999, 12, 31), 1.0, 0.5), AmaxRecord(date(2000, 12, 31), 1.0, 0.5)] # donor QMED descr = 0.59072777 # donor QMED amax = 1.0 @classmethod def setUpClass(cls): settings.config['nrfa']['oh_json_url'] = \ 'file:' + pathname2url(os.path.abspath('./floodestimation/fehdata_test.json')) cls.db_session = db.Session() @classmethod def tearDownClass(cls): db.empty_db_tables() def tearDown(self): self.db_session.rollback() def test_donor_adjustment_factor(self): # 1.0/0.59072777 = 1.69282714 self.assertAlmostEqual(exp(QmedAnalysis(self.catchment). _lnqmed_residual(self.donor_catchment)), 1.69282714) def test_lnqmed_residual_one_donor(self): # ln(1.0 / 0.59072777) self.assertAlmostEqual(QmedAnalysis(self.catchment). _lnqmed_residual(self.donor_catchment), 0.5264, 4) def test_model_error_corr(self): # because we're at zero distance, error correlation = 1 self.assertAlmostEqual(QmedAnalysis(self.catchment). _model_error_corr(self.catchment, self.donor_catchment), 1) def test_vector_b_one_donor(self): assert_almost_equal(QmedAnalysis(self.catchment). _vec_b([self.donor_catchment]), [0.1175]) def test_matrix_sigma_eta_one_donor(self): result = QmedAnalysis(self.catchment)._matrix_sigma_eta([self.donor_catchment]) assert_almost_equal(result, [[0.1175]]) def test_beta_one_donor(self): result = QmedAnalysis(self.catchment)._beta(self.donor_catchment) self.assertAlmostEqual(result, 0.30242554) def test_matrix_sigma_eps_one_donor(self): # 4 * 0.30242554**2 / 2 = 0.18292242 result = QmedAnalysis(self.catchment)._matrix_sigma_eps([self.donor_catchment]) assert_almost_equal(result, [[0.18292242]]) def test_matrix_omega_one_donor(self): # 0.1175 + 0.18292242 = 0.30042242 result = QmedAnalysis(self.catchment)._matrix_omega([self.donor_catchment]) assert_almost_equal(result, [[0.30042242]]) def test_vector_alpha_one_donor(self): # 1/0.30042242 * 0.1175 = 0.39111595 result = QmedAnalysis(self.catchment)._vec_alpha([self.donor_catchment]) assert_almost_equal(result, [0.39111595]) def test_qmed_one_donor(self): # 0.61732109 * 1.69282714**0.39111595 = 0.75844685 result = QmedAnalysis(self.catchment).qmed(method='descriptors', donor_catchments=[self.donor_catchment]) self.assertAlmostEqual(result, 0.75844685, places=4) def test_distance_two_donors(self): analysis = QmedAnalysis(self.catchment, CatchmentCollections(self.db_session), year=2000) donors = analysis.find_donor_catchments()[0:2] # 17001, 10001 result = [d.distance_to(self.catchment) for d in donors] assert_almost_equal(result, [5, 183.8515], decimal=4) def test_lnqmed_residuals_two_donors(self): analysis = QmedAnalysis(self.catchment, CatchmentCollections(self.db_session), year=2000) donors = analysis.find_donor_catchments()[0:2] # 17001, 10001 qmed_amax = [QmedAnalysis(d).qmed() for d in donors] qmed_descr =[QmedAnalysis(d, year=2000).qmed(method='descriptors') for d in donors] assert_almost_equal(qmed_amax, [90.532, 50.18]) # not verified assert_almost_equal(qmed_descr, [51.73180402, 48.70106637]) # not verified result = [analysis._lnqmed_residual(d) for d in donors] assert_almost_equal(result, [0.55963062, 0.02991561]) def test_model_error_corr_two_donors(self): analysis = QmedAnalysis(self.catchment, CatchmentCollections(self.db_session), year=2000) donors = analysis.find_donor_catchments()[0:2] # 17001, 10001 result = [analysis._model_error_corr(self.catchment, d) for d in donors] assert_almost_equal(result, [0.352256808, 0.002198921]) def test_model_error_corr_between_two_donors(self): analysis = QmedAnalysis(self.catchment, CatchmentCollections(self.db_session), year=2000) donors = analysis.find_donor_catchments()[0:2] # 17001, 10001 dist = donors[0].distance_to(donors[1]) self.assertAlmostEqual(dist, 188.8487072) # not verified result = analysis._model_error_corr(donors[0], donors[1]) self.assertAlmostEqual(result, 0.001908936) def test_vector_b_two_donors(self): analysis = QmedAnalysis(self.catchment, CatchmentCollections(self.db_session), year=2000) donors = analysis.find_donor_catchments()[0:2] # 17001, 10001 # [0.352256808, 0.002198921] * 0.1175 = [0.041390175, 0.000258373] result = analysis._vec_b(donors) assert_almost_equal(result, [0.041390175, 0.000258373]) def test_matrix_sigma_eta_two_donors(self): analysis = QmedAnalysis(self.catchment, CatchmentCollections(self.db_session), year=2000) donors = analysis.find_donor_catchments()[0:2] # 17001, 10001 result = analysis._matrix_sigma_eta(donors) # 0.1175 * 0.001908936 = 0.00022430 assert_almost_equal(result, [[0.1175, 0.00022430], [0.00022430, 0.1175]]) def test_beta_two_donors(self): analysis = QmedAnalysis(self.catchment, CatchmentCollections(self.db_session), year=2000) donors = analysis.find_donor_catchments()[0:2] # 17001, 10001 result = [analysis._beta(d) for d in donors] assert_almost_equal(result, [0.16351290, 0.20423656]) def test_lnqmed_corr(self): analysis = QmedAnalysis(self.catchment, CatchmentCollections(self.db_session), year=2000) donors = analysis.find_donor_catchments()[0:2] # 17001, 10001 results = analysis._lnqmed_corr(donors[0], donors[1]) self.assertAlmostEqual(results, 0.133632774) def test_matrix_sigma_eps_two_donors(self): analysis = QmedAnalysis(self.catchment, CatchmentCollections(self.db_session), year=2000) donors = analysis.find_donor_catchments()[0:2] # 17001, 10001 record0 = [donors[0].amax_records_start(), donors[0].amax_records_end()] record1 = [donors[1].amax_records_start(), donors[1].amax_records_end()] self.assertEqual(record0, [1969, 2005]) # n=37 self.assertEqual(record1, [1939, 1984]) # n=46, 16 years overlapping result = analysis._matrix_sigma_eps(donors) # 4 * 0.16351290**2 / 37 = 0.00289043 # 4 * 0.16351290 * 0.20423656 * 16 / 37 / 46 * 0.133632774 = 0.00016781 # 4 * 0.20423656**2 / 46 = 0.00362718 assert_almost_equal(result, [[0.00289043, 0.00016781], [0.00016781, 0.00362718]]) def test_matrix_omega_two_donors(self): analysis = QmedAnalysis(self.catchment, CatchmentCollections(self.db_session), year=2000) donors = analysis.find_donor_catchments()[0:2] # 17001, 10001 result = analysis._matrix_omega(donors) assert_almost_equal(result, [[0.12039043, 0.00039211], [0.00039211, 0.12112718]]) def test_vector_alpha_two_donors(self): analysis = QmedAnalysis(self.catchment, CatchmentCollections(self.db_session), year=2000) donors = analysis.find_donor_catchments()[0:2] # 17001, 10001 result = analysis._vec_alpha(donors) assert_almost_equal(result, [0.34379622, 0.00102012]) # calculated in Excel def test_qmed_two_donors(self): analysis = QmedAnalysis(self.catchment, CatchmentCollections(self.db_session), year=2000) donors = analysis.find_donor_catchments()[0:2] # 17001, 10001 result = analysis.qmed(method='descriptors', donor_catchments=donors) # exp(ln(0.61732109) + 0.34379622 * 0.55963062 + 0.00102012 * 0.02991561) = # exp(ln(0.61732109) + 0.192429411) = 0.748311028 self.assertAlmostEqual(result, 0.748311028, places=5)