def test_load_save_load(self): ''' Code tested: load_csv save_csv ''' ts1 = pqh.load_csv(r".\pixiepython\tests\test_data\r040134.csv") pqh.save_csv( ts1, r".\pixiepython\tests\test_data\output\r040134_resaved.csv") ts2 = pqh.load_csv( r".\pixiepython\tests\test_data\output\r040134_resaved.csv") comparison_results = ts1.compare(ts2) self.assertTrue(comparison_results[0] == True)
def test_infill_wt93b3(self): ''' Code tested: Timeseries.infill_wt93b(others) ''' r040695 = pqh.load_csv(r".\pyqhtools\tests\test_data\r040695.csv") r040547 = pqh.load_csv(r".\pyqhtools\tests\test_data\r040547.csv") p040264 = pqh.load_csv(r".\pyqhtools\tests\test_data\p040264.csv") r040695.infill_wt93b([r040547, p040264]) pqh.save_csv( r040695, r".\pyqhtools\tests\test_data\output\r040695_r040547_p040264.csv") self.assertTrue(abs(r040695.mean - 4.6781753769) < 0.0000001)
def test_infill_scale_force_factor(self): ''' Code tested: Timeseries.infill_scale(other, factor=None) ''' gappy_data = pqh.load_csv(r".\pixiepython\tests\test_data\r040134.csv") all_ones = pqh.load_csv(r".\pixiepython\tests\test_data\all_ones.csv") gappy_data.infill_scale(all_ones, factor=0.6666) pqh.save_csv( gappy_data, r".\pixiepython\tests\test_data\output\r040134_infilled2.csv") #Check the results self.assertTrue(abs(gappy_data.mean - 4.339904801) < 0.00001)
def test_infill_wt93b2(self): ''' Code tested: Timeseries.infill_wt93b(others) ''' r040134 = pqh.load_csv(r".\pyqhtools\tests\test_data\r040134.csv") r040168 = pqh.load_csv(r".\pyqhtools\tests\test_data\r040168.csv") p040850 = pqh.load_csv(r".\pyqhtools\tests\test_data\p040850.csv") r040134.infill_wt93b([r040168, p040850]) pqh.save_csv( r040134, r".\pyqhtools\tests\test_data\output\r040134_r040168_p040850.csv") self.assertTrue(r040134.missing == 0)
def test_infill_scalemonthly_4factors(self): ''' Code tested: Timeseries.infill_scalemonthly(other, factors=None) ''' gappy_data = pqh.load_csv(r".\pixiepython\tests\test_data\r040134.csv") all_ones = pqh.load_csv(r".\pixiepython\tests\test_data\all_ones.csv") monthly_factors = [1.1, 1.2, 0.9, 0.8] gappy_data.infill_scalemonthly(all_ones, factors=monthly_factors) pqh.save_csv( gappy_data, r".\pixiepython\tests\test_data\output\r040134_infilled4.csv") #Check the results self.assertTrue(abs(gappy_data.mean - 4.4031751048) < 0.000001)
def test_infill_scalemonthly_wt93b_2(self): ''' Code tested: Timeseries.infill_scalemonthly(other) ''' #This is the WT93b test gappy_data = pqh.load_csv(r".\pyqhtools\tests\test_data\r040134.csv") all_ones = pqh.load_csv(r".\pyqhtools\tests\test_data\all_ones.csv") gappy_data.infill_scalemonthly(all_ones) pqh.save_csv( gappy_data, r".\pyqhtools\tests\test_data\output\r040134_infilled5_wt93b.csv") #Check the results self.assertTrue(abs(gappy_data.mean - 5.21500501) < 0.0001)
def test_infill_scalemonthly(self): ''' Code tested: Timeseries.infill_scalemonthly(other, factors=None) ''' gappy_data = pqh.load_csv(r".\pixiepython\tests\test_data\r040134.csv") all_ones = pqh.load_csv(r".\pixiepython\tests\test_data\all_ones.csv") monthly_factors = [ 0.7, 0.9, 1.1, 1.3, 1.5, 1.6, 1.4, 1.2, 1.0, 0.8, 0.6, 0.5 ] gappy_data.infill_scalemonthly(all_ones, factors=monthly_factors) pqh.save_csv( gappy_data, r".\pixiepython\tests\test_data\output\r040134_infilled3.csv") #Check the results self.assertTrue(abs(gappy_data.mean - 4.412548722) < 0.0001)
def test_infill_scale_auto_factor(self): ''' Code tested: Timeseries.infill_scale(other) ''' gappy_data = pqh.load_csv(r".\pixiepython\tests\test_data\r040134.csv") all_ones = pqh.load_csv(r".\pixiepython\tests\test_data\all_ones.csv") mean_before_infilling = gappy_data.mean #infilling by infill_scale should preserve the mean gappy_data.infill_scale(all_ones) pqh.save_csv( gappy_data, r".\pixiepython\tests\test_data\output\r040134_infilled.csv") #Check the results mean_after_infilling = gappy_data.mean self.assertTrue( abs(mean_before_infilling - mean_after_infilling) < 0.00001) self.assertTrue(gappy_data.get_value(1910, 6, 1) == 26.9) self.assertTrue(gappy_data.missing == 0)
def test_set_start_end2(self): ''' Code tested: Timeseries.set_start_end(start_and_end) Timeseries.set_start(year, month, day) Timeseries.set_end(year, month, day) ''' ts1 = pqh.load_csv(r".\pixiepython\tests\test_data\p040134.csv") ts2 = pqh.load_csv(r".\pixiepython\tests\test_data\r040134.csv") ts2_start_end = ts2.get_start_end() self.assertTrue(ts1.length != ts2.length) self.assertTrue(ts1.get_value(1910, 6, 1) == 26.9) ts1.set_start_end(ts2_start_end) #Save the result for visual inspection pqh.save_csv( ts1, r".\pixiepython\tests\test_data\output\r040134_redated2.csv") #Assert expected results self.assertTrue(ts1.length == ts2.length) self.assertTrue(ts1.get_value(1910, 6, 1) == 26.9)
def test_mul_rmul_number(self): ''' Code tested: Timeseries.__mul__(value) Timeseries.__rmul__(value) ''' ts1 = pqh.load_csv(r".\pixiepython\tests\test_data\r040134.csv") ts2 = ts1 * 2.0 ts3 = 2.0 * ts1 self.assertTrue( abs(ts1.mean - 5.19659885) < 0.000001 ) #__mul__ and __rmul__ do not modify the original timeseries self.assertTrue(abs(ts2.mean - 10.3931977) < 0.000001) self.assertTrue(ts2.min == 0) self.assertTrue(ts2.max == 988) self.assertTrue(ts2.length == ts1.length) self.assertTrue(ts2.compare(ts3)[0]) pqh.save_csv( ts2, r".\pixiepython\tests\test_data\output\r040134_mul_2.csv")
def test_set_start_end(self): ''' Code tested: Timeseries.set_start_end(start_and_end) Timeseries.set_start(year, month, day) Timeseries.set_end(year, month, day) ''' #Load some patched-point data ts1 = pqh.load_csv(r".\pixiepython\tests\test_data\p040134.csv") ts1_start_end = ts1.get_start_end() #Load some raw data and check length is different to above ts2 = pqh.load_csv(r".\pixiepython\tests\test_data\r040134.csv") self.assertTrue(ts1.length != ts2.length) self.assertTrue(ts2.get_value(1910, 6, 1) == 26.9) #Extend the dates to be same as above and check lengths are now same ts2.set_start_end(ts1_start_end) self.assertTrue(ts1.length == ts2.length) self.assertTrue(ts2.get_value(1910, 6, 1) == 26.9) #Save the result for visual inspection pqh.save_csv( ts2, r".\pixiepython\tests\test_data\output\r040134_redated.csv")
def test_sub_rsub_number(self): ''' Code tested: Timeseries.__sub__(value) Timeseries.__rsub__(value) ''' ts1 = pqh.load_csv(r".\pixiepython\tests\test_data\r040134.csv") ts2 = ts1 - 1.1 ts3 = 1.1 - ts1 self.assertTrue( abs(ts1.mean - 5.19659885) < 0.000001 ) #__sub__ and __rsub__ do not modify the original timeseries self.assertTrue(abs(ts2.mean - 4.09659885) < 0.000001) self.assertTrue(ts2.min == -1.1) self.assertTrue(ts2.max == 492.9) self.assertTrue(ts2.length == ts1.length) self.assertTrue(ts3.length == ts1.length) self.assertTrue(abs(ts3.mean + 4.09659885) < 0.000001) pqh.save_csv( ts2, r".\pixiepython\tests\test_data\output\r040134_minus_1point1.csv")
def test_infill_wt93b(self): ''' Code tested: Timeseries.infill_wt93b(others) ''' r040134 = pqh.load_csv(r".\pyqhtools\tests\test_data\r040134.csv") #r040168 = pqh.load_csv(r".\pyqhtools\tests\test_data\r040168.csv") p040850 = pqh.load_csv(r".\pyqhtools\tests\test_data\p040850.csv") factors = r040134.get_wt93_factors(p040850) known_answers = [ 1.0412290338857493, 1.0065128956703973, 1.0598426339157894, 1.0476595992884017, 1.0548171248637521, 1.0538393731635654, 1.0441554098438972, 1.0498160869346143, 1.0296487322003494, 1.0394039501112953, 1.0631576523681232, 1.0712720135216185 ] for i in range(12): self.assertTrue(abs(factors[i] - known_answers[i]) < 0.0000001) r040134.infill_wt93b([p040850]) pqh.save_csv( r040134, r".\pyqhtools\tests\test_data\output\r040134_p040850.csv") self.assertTrue(r040134.missing == 0)
def test_add_radd_timeseries(self): ''' Code tested: Timeseries.__add__(other) Timeseries.__radd__(other) ''' ts1 = pqh.load_csv(r".\pixiepython\tests\test_data\r040134.csv") ts2 = pqh.load_csv(r".\pixiepython\tests\test_data\r040168.csv") ts3 = ts1 + ts2 ts4 = ts2 + ts1 self.assertTrue( abs(ts1.mean - 5.19659885) < 0.000001 ) #__add__ and __radd__ do not modify the original timeseries self.assertTrue( abs(ts2.mean - 4.453350651058) < 0.000001 ) #__add__ and __radd__ do not modify the original timeseries self.assertTrue(abs(ts3.mean - 9.56699353053) < 0.000001) self.assertTrue( ts3.length == 45691 ) #length should be the union of ts1 and ts2 (not the intersect) self.assertTrue(ts4.compare(ts3)[0]) #ts3 and ts4 should be identical pqh.save_csv( ts3, r".\pixiepython\tests\test_data\output\r040134_plus_r040168.csv")