def test_convert_ap_to_kp_inf_input(self): """ Test conversion of ap to Kp where ap is Inf""" kp_out, kp_meta = kp_ap.convert_ap_to_kp(self.testInst['ap_inf']) # Assert original and coverted there and back Kp are equal assert all(kp_out[1:] == -1) # Assert the converted Kp meta data exists and is reasonable assert 'Kp' in kp_meta.keys() assert(kp_meta['Kp'][kp_meta.labels.fill_val] == -1) del kp_out, kp_meta
def test_convert_ap_to_kp(self): """ Test conversion of ap to Kp""" kp_ap.convert_3hr_kp_to_ap(self.testInst) kp_out, kp_meta = kp_ap.convert_ap_to_kp(self.testInst['3hr_ap']) # Assert original and coverted there and back Kp are equal assert all(abs(kp_out - self.testInst.data['Kp']) < 1.0e-4) # Assert the converted Kp meta data exists and is reasonable assert 'Kp' in kp_meta.keys() assert kp_meta['Kp'][kp_meta.labels.fill_val] == -1 del kp_out, kp_meta
def test_convert_ap_to_kp_fill_val(self): """ Test conversion of ap to Kp with fill values""" # Set the first Kp value to a fill value fill_val = self.testInst.meta.labels.fill_val self.testInst['Kp'][0] = self.testInst.meta['Kp', fill_val] # Calculate ap kp_ap.convert_3hr_kp_to_ap(self.testInst) # Recalculate Kp from ap kp_out, kp_meta = kp_ap.convert_ap_to_kp( self.testInst['3hr_ap'], fill_val=self.testInst.meta['Kp', fill_val]) # Test non-fill ap values assert all(abs(kp_out[1:] - self.testInst.data['Kp'][1:]) < 1.0e-4) # Test the fill value in the data and metadata assert np.isnan(kp_out[0]) assert np.isnan(kp_meta['Kp'][fill_val]) del fill_val, kp_out, kp_meta