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 _run_qmed_analysis(self):
        results = {}

        analysis = QmedAnalysis(self.catchment, self.gauged_catchments, results_log=results)
        self.qmed = analysis.qmed()

        results['qmed'] = self.qmed
        self.results['qmed'] = results
    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_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)
    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 _run_qmed_analysis(self):
        results = {}

        analysis = QmedAnalysis(self.catchment,
                                self.gauged_catchments,
                                results_log=results)
        self.qmed = analysis.qmed()

        results['qmed'] = self.qmed
        self.results['qmed'] = results
 def test_pot_records_by_month(self):
     catchment = Catchment("Aberdeen", "River Dee")
     catchment.pot_dataset = PotDataset(start_date=date(1998, 10, 1), end_date=date(2000, 1, 31))
     catchment.pot_dataset.pot_records = [PotRecord(date(1999, 1, 1), 3.0, 0.5),
                                          PotRecord(date(1999, 2, 1), 2.0, 0.5),
                                          PotRecord(date(1999, 2, 15), 2.0, 0.5),
                                          PotRecord(date(1999, 12, 31), 1.0, 0.5)]
     analysis = QmedAnalysis(catchment)
     records_by_month = analysis._pot_month_counts(catchment.pot_dataset)
     expected = [2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2]
     result = [len(month) for month in records_by_month]
     self.assertEqual(result, expected)
 def test_pot_complete_years(self):
     catchment = Catchment("Aberdeen", "River Dee")
     catchment.pot_dataset = PotDataset(start_date=date(1998, 10, 1), end_date=date(2000, 1, 31))
     catchment.pot_dataset.pot_records = [PotRecord(date(1999, 1, 1), 3.0, 0.5),
                                          PotRecord(date(1999, 2, 1), 2.0, 0.5),
                                          PotRecord(date(1999, 2, 15), 2.0, 0.5),
                                          PotRecord(date(1999, 12, 31), 1.0, 0.5)]
     analysis = QmedAnalysis(catchment)
     records, n = analysis._complete_pot_years(catchment.pot_dataset)
     result = [record.date for record in records]
     expected = [date(1999, 2, 1),
                 date(1999, 2, 15),
                 date(1999, 12, 31)]
     self.assertEqual(result, expected)
    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]])
class Analysis(object):
    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

    def finish(self):
        self.db_session.close()

    def run_qmed_analysis(self):
        self.qmed_analysis = QmedAnalysis(self.catchment, self.gauged_catchments)
        self.results = self.qmed_analysis.results_log
        self.results['qmed_all_methods'] = self.qmed_analysis.qmed_all_methods()
        

    def run_growthcurve(self):
        results = {}

        analysis = GrowthCurveAnalysis(self.catchment, self.gauged_catchments, results_log=results)
        gc = analysis.growth_curve()

        aeps = [0.5, 0.2, 0.1, 0.05, 0.03333, 0.02, 0.01333, 0.01, 0.005, 0.002, 0.001]
        growth_factors = gc(aeps)
        flows = growth_factors * self.qmed

        results['aeps'] = aeps
        results['growth_factors'] = growth_factors
        results['flows'] = flows
        self.results['gc'] = results
 def test_pot_2_years(self):
     catchment = Catchment("Aberdeen", "River Dee")
     catchment.pot_dataset = PotDataset(start_date=date(1998, 1, 1), end_date=date(1999, 12, 31))
     catchment.pot_dataset.pot_records = [PotRecord(date(1999, 1, 1), 3.0, 0.5),
                                          PotRecord(date(1999, 2, 1), 2.0, 0.5),
                                          PotRecord(date(1999, 12, 31), 1.0, 0.5)]
     self.assertAlmostEqual(QmedAnalysis(catchment).qmed(method='pot_records'), 1.8789, 4)
 def test_amax_long_records(self):
     catchment = Catchment("Aberdeen", "River Dee")
     catchment.amax_records = [AmaxRecord(date(1999, 12, 31), 5.0, 0.5),
                               AmaxRecord(date(2000, 12, 31), 1.0, 0.5),
                               AmaxRecord(date(2001, 12, 31), 4.0, 0.5),
                               AmaxRecord(date(2002, 12, 31), 2.0, 0.5),
                               AmaxRecord(date(2003, 12, 31), 3.0, 0.5)]
     self.assertEqual(QmedAnalysis(catchment).qmed(method='amax_records'), 3)
 def test_descriptors_2008_urban_adjustment(self):
     catchment = Catchment("Aberdeen", "River Dee")
     catchment.descriptors = Descriptors(dtm_area=1,
                                         bfihost=0.50,
                                         sprhost=50,
                                         saar=1000,
                                         farl=1,
                                         urbext2000=1)
     self.assertAlmostEqual(QmedAnalysis(catchment, year=2000).urban_adj_factor(), 2.970205798, 4)
 def test_descriptors_2008_1(self):
     catchment = Catchment("Aberdeen", "River Dee")
     catchment.descriptors = Descriptors(dtm_area=1,
                                         bfihost=0.50,
                                         sprhost=50,
                                         saar=1000,
                                         farl=1,
                                         urbext2000=0)
     self.assertAlmostEqual(QmedAnalysis(catchment).qmed(method='descriptors_2008'), 0.5907, 4)
 def test_descriptors_1999_2(self):
     catchment = Catchment("Aberdeen", "River Dee")
     catchment.descriptors = Descriptors(dtm_area=2.345,
                                         bfihost=0,
                                         sprhost=100,
                                         saar=2000,
                                         farl=0.5,
                                         urbext2000=0)
     self.assertAlmostEqual(QmedAnalysis(catchment).qmed(method='descriptors_1999'), 0.3729, 4)
 def test_descriptors_2008_urban(self):
     catchment = Catchment("Aberdeen", "River Dee")
     catchment.descriptors = Descriptors(dtm_area=1,
                                         bfihost=0.50,
                                         sprhost=50,
                                         saar=1000,
                                         farl=1,
                                         urbext2000=1)
     self.assertAlmostEqual(QmedAnalysis(catchment, year=2000).qmed(method='descriptors_2008', as_rural=False),
                            1.7546, 4)
 def test_all(self):
     catchment = Catchment("Aberdeen", "River Dee")
     catchment.channel_width = 1
     catchment.amax_records = [AmaxRecord(date(1999, 12, 31), 1.0, 0.5),
                               AmaxRecord(date(2000, 12, 31), 1.0, 0.5)]
     catchment.descriptors = Descriptors(dtm_area=1,
                                         bfihost=0.50,
                                         sprhost=50,
                                         saar=1000,
                                         farl=1,
                                         urbext2000=0)
     qmeds = QmedAnalysis(catchment).qmed_all_methods()
     self.assertEqual(qmeds['amax_records'], 1)
     self.assertEqual(qmeds['channel_width'], 0.182)
     self.assertEqual(qmeds['area'], 1.172)
     self.assertAlmostEqual(qmeds['descriptors_1999'], 0.2671, 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])
示例#19
0
class Analysis(object):
    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

    def finish(self):
        self.db_session.close()

    def run_qmed_analysis(self):
        self.qmed_analysis = QmedAnalysis(self.catchment,
                                          self.gauged_catchments)
        self.results = self.qmed_analysis.results_log
        self.results['qmed_all_methods'] = self.qmed_analysis.qmed_all_methods(
        )

    def run_growthcurve(self):
        results = {}

        analysis = GrowthCurveAnalysis(self.catchment,
                                       self.gauged_catchments,
                                       results_log=results)
        gc = analysis.growth_curve()

        aeps = [
            0.5, 0.2, 0.1, 0.05, 0.03333, 0.02, 0.01333, 0.01, 0.005, 0.002,
            0.001
        ]
        growth_factors = gc(aeps)
        flows = growth_factors * self.qmed

        results['aeps'] = aeps
        results['growth_factors'] = growth_factors
        results['flows'] = flows
        self.results['gc'] = results
 def test_no_descriptors_1999(self):
     catchment = Catchment("Aberdeen", "River Dee")
     try:
         QmedAnalysis(catchment).qmed(method='descriptors_1999')
     except InsufficientDataError as e:
         self.assertEqual(str(e), "Catchment `descriptors` attribute must be set first.")
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()
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())
def analyse_catchment(catchment, gauged_catchments):
    result = {}
    result['id'] = catchment.id

    analysis = QmedAnalysis(catchment)
    result['qmed_amax'] = analysis.qmed(method='amax_records')
    result['qmed_descr'] = analysis.qmed(method='descriptors')
    result['qmed_descr_1999'] = analysis.qmed(method='descriptors_1999')

    analysis.gauged_catchments = gauged_catchments
    donors = analysis.find_donor_catchments()
    analysis.idw_power = 2
    result['qmed_descr_idw'] = analysis.qmed(method='descriptors', donor_catchments=donors)

    analysis.idw_power = 3
    result['qmed_descr_idw3'] = analysis.qmed(method='descriptors', donor_catchments=donors)

    analysis.donor_weighting = 'equal'
    result['qmed_descr_first'] = analysis.qmed(method='descriptors', donor_catchments=donors[0:1])

    return result
示例#24
0
 def run_qmed_analysis(self):
     self.qmed_analysis = QmedAnalysis(self.catchment,
                                       self.gauged_catchments)
     self.results = self.qmed_analysis.results_log
     self.results['qmed_all_methods'] = self.qmed_analysis.qmed_all_methods(
     )
 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_area_3(self):
     catchment = Catchment("Aberdeen", "River Dee")
     catchment.descriptors.dtm_area = 100
     self.assertAlmostEqual(QmedAnalysis(catchment).qmed(method='area'), 81.2790, 4)
 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 run_qmed_analysis(self):
     self.qmed_analysis = QmedAnalysis(self.catchment, self.gauged_catchments)
     self.results = self.qmed_analysis.results_log
     self.results['qmed_all_methods'] = self.qmed_analysis.qmed_all_methods()
 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_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_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_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_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_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_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])