def test_calculate_temperature_em(): # Create GOESLightcurve object, then create new one with # temperature & EM using with calculate_temperature_em(). goeslc = lightcurve.GOESLightCurve.create("2014-01-01 00:00", "2014-01-01 01:00") goeslc_new = goes.calculate_temperature_em(goeslc) # Test correct exception is raised if a GOESLightCurve object is # not inputted. with pytest.raises(TypeError): goes.calculate_temperature_em([]) # Find temperature and EM manually with _goes_chianti_tem() temp, em = goes._goes_chianti_tem( Quantity(goeslc.data.xrsb, unit='W/m**2'), Quantity(goeslc.data.xrsa, unit='W/m**2'), satellite=int(goeslc.meta["TELESCOP"].split()[1]), date="2014-01-01") # Check that temperature and EM arrays from _goes_chianti_tem() # are same as those in new GOESLightcurve object. assert goeslc_new.data.temperature.all() == temp.value.all() assert goeslc_new.data.em.all() == em.value.all() # Check rest of data frame of new GOESLightCurve object is same # as that in original object. goeslc_revert = copy.deepcopy(goeslc_new) del goeslc_revert.data["temperature"] del goeslc_revert.data["em"] assert_frame_equal(goeslc_revert.data, goeslc.data)
def test_goes_chianti_tem_case1(): # test case 1: satellite > 7, abundances = coronal temp1, em1 = goes._goes_chianti_tem(LONGFLUX, SHORTFLUX, satellite=15, date=DATE) np.testing.assert_allclose(temp1, Quantity([11.28], unit="MK"), rtol=0.01) assert all(em1 < Quantity([4.79e+48], unit="1/cm**3")) and \ em1 > Quantity([4.78e+48], unit="1/cm**3")
def read_csv(filename): with open(filename, 'r') as f: buf = f.read() idx = [i.end() for i in re.finditer('data:', buf)] d = pa.read_csv(sio.StringIO(buf[idx[0]:])) #Quality Flag Filter and SWPC Flux Factor Removal For True Fluxes [1] d = d[d['A_QUAL_FLAG'] & d['B_QUAL_FLAG'] == 0] d['A_FLUX'] /= 0.85 d['B_FLUX'] /= 0.7 #Calculate the emission measure and temperature satellite = int(re.findall(':satellite_id = "GOES-(\d+)"', buf)[0]) r = d['A_FLUX'] / d['B_FLUX'] bf, af = [ units.Quantity(d[i], unit='W/m/m') for i in ['B_FLUX', 'A_FLUX'] ] r = af / bf msk = (r > 2.43e-6) & (r < 0.694) d['T [MK]'] = np.nan d['Emission Measure [1/cm2]'] = np.nan if np.sum(msk) != 0: em = goes._goes_chianti_tem(bf[msk], af[msk], satellite=satellite) d['T [MK]'][msk] = em[0].value d['Emission Measure [1/cm2]'][msk] = em[1].value #Time Tag Indexing d['Time [UT]'] = d['time_tag'].apply(pa.Timestamp) return d.set_index('Time [UT]')
def test_calculate_temperature_em(): # Create XRSTimeSeries object, then create new one with # temperature & EM using with calculate_temperature_em(). goeslc = timeseries.TimeSeries(get_test_filepath("go1520110607.fits")) goeslc_new = goes.calculate_temperature_em(goeslc) # Test correct exception is raised if a XRSTimeSeries object is # not inputted. with pytest.raises(TypeError): goes.calculate_temperature_em([]) # Find temperature and EM manually with _goes_chianti_tem() temp, em = goes._goes_chianti_tem( goeslc.quantity("xrsb"), goeslc.quantity("xrsa"), satellite=int(goeslc.meta.metas[0]["TELESCOP"].split()[1]), date="2014-01-01") # Check that temperature and EM arrays from _goes_chianti_tem() # are same as those in new XRSTimeSeries object. assert goeslc_new.data.temperature.all() == temp.value.all() assert goeslc_new.data.em.all() == em.value.all() # Check rest of data frame of new XRSTimeSeries object is same # as that in original object. goeslc_revert = copy.deepcopy(goeslc_new) del goeslc_revert.data["temperature"] del goeslc_revert.data["em"] assert_frame_equal(goeslc_revert.data, goeslc.data)
def test_goes_chianti_tem_errors(): # Define input variables. ratio = SHORTFLUX / LONGFLUX shortflux_toomany = Quantity(np.append(SHORTFLUX.value, SHORTFLUX.value[0]), unit="W/m**2") shortflux_toosmall = copy.deepcopy(SHORTFLUX) shortflux_toosmall.value[0] = -1 shortflux_toobig = copy.deepcopy(SHORTFLUX) shortflux_toobig.value[0] = 1 temp_test = Quantity(np.zeros(len(LONGFLUX)) + 10, unit="MK") temp_test_toomany = Quantity(np.append(temp_test.value, 0), unit="MK") temp_test_toosmall = copy.deepcopy(temp_test) temp_test_toosmall.value[0] = -1 temp_test_toobig = copy.deepcopy(temp_test) temp_test_toobig.value[0] = 101 # First test correct exceptions are raised if incorrect inputs are # entered. with pytest.raises(ValueError): temp, em = goes._goes_chianti_tem(LONGFLUX, SHORTFLUX, satellite=-1) with pytest.raises(ValueError): temp, em = goes._goes_chianti_tem(LONGFLUX, shortflux_toomany) with pytest.raises(ValueError): temp = goes._goes_get_chianti_temp(ratio, satellite=-1) with pytest.raises(ValueError): temp, em = goes._goes_chianti_tem(LONGFLUX, SHORTFLUX, abundances="Neither") with pytest.raises(ValueError): temp = goes._goes_get_chianti_temp(ratio, abundances="Neither") with pytest.raises(ValueError): temp, em = goes._goes_chianti_tem(LONGFLUX, shortflux_toobig) with pytest.raises(ValueError): em = goes._goes_get_chianti_em(LONGFLUX, temp_test, satellite=-1) with pytest.raises(ValueError): em = goes._goes_get_chianti_em(LONGFLUX, temp_test, abundances="Neither") with pytest.raises(ValueError): em = goes._goes_get_chianti_em(LONGFLUX, temp_test, abundances="Neither") with pytest.raises(ValueError): em = goes._goes_get_chianti_em(LONGFLUX, temp_test_toosmall) with pytest.raises(ValueError): em = goes._goes_get_chianti_em(LONGFLUX, temp_test_toobig)
def test_goes_chianti_tem_case2(): # test case 2: satellite > 7, abundances = photospheric temp2, em2 = goes._goes_chianti_tem(LONGFLUX, SHORTFLUX, satellite=15, date=DATE, abundances="photospheric") assert all(temp2 < Quantity([10.25], unit="MK")) and \ all(temp2 > Quantity([10.24], unit="MK")) assert all(em2 < Quantity([1.12e+49], unit="1/cm**3")) and \ all(em2 > Quantity([1.11e+49], unit="1/cm**3"))
def test_goes_chianti_tem_case8(): # test case 8: satellite = 6, date > 1983-06-28, abundances = photospheric temp8, em8 = goes._goes_chianti_tem(LONGFLUX, SHORTFLUX, satellite=6, date=DATE, abundances="photospheric") assert all(temp8 < Quantity(10.36, unit="MK")) and \ all(temp8 > Quantity(10.35, unit="MK")) assert all(em8 < Quantity(9.39e+48, unit="1/cm**3")) and \ all(em8 > Quantity(9.38e+48, unit="1/cm**3"))
def test_goes_chianti_tem_case7(): # test case 7: satellite = 6, date > 1983-06-28, abundances = coronal temp7, em7 = goes._goes_chianti_tem(LONGFLUX, SHORTFLUX, satellite=6, date=DATE, abundances="coronal") assert all(temp7 < Quantity(11.34, unit="MK")) and \ all(temp7 > Quantity(11.33, unit="MK")) assert all(em7 < Quantity(4.08e+48, unit="1/cm**3")) and \ all(em7 > Quantity(4.07e+48, unit="1/cm**3"))
def test_goes_chianti_tem_case6(): # test case 6: satellite = 6, date < 1983-06-28, abundances = photospheric temp6, em6 = goes._goes_chianti_tem(LONGFLUX, SHORTFLUX, satellite=6, date="1983-06-27", abundances="photospheric") assert all(temp6 < Quantity(11.44, unit="MK")) and \ all(temp6 > Quantity(11.43, unit="MK")) assert all(em6 < Quantity(6.74e+48, unit="1/cm**3")) and \ all(em6 > Quantity(6.73e+48, unit="1/cm**3"))
def test_goes_chianti_tem_case5(): # test case 5: satellite = 6, date < 1983-06-28, abundances = coronal temp5, em5 = goes._goes_chianti_tem(LONGFLUX, SHORTFLUX, satellite=6, date="1983-06-27", abundances="coronal") assert all(temp5 < Quantity(12.30, unit="MK")) and \ all(temp5 > Quantity(12.29, unit="MK")) assert all(em5 < Quantity(3.13e+48, unit="1/cm**3")) and \ all(em5 > Quantity(3.12e+48, unit="1/cm**3"))
def test_goes_chianti_tem_case4(): # test case 4: satellite < 8 and != 6, abundances = photospheric temp4, em4 = goes._goes_chianti_tem(LONGFLUX, SHORTFLUX, satellite=5, date=DATE, abundances="photospheric") assert all(temp4 < Quantity([10.42], unit="MK")) and \ all(temp4 > Quantity([10.41], unit="MK")) assert all(em4 < Quantity(8.81e+48, unit="1/cm**3")) and \ all(em4 > Quantity(8.80e+48, unit="1/cm**3"))
def test_goes_chianti_tem_case3(): # test case 3: satellite < 8 and != 6, abundances = coronal temp3, em3 = goes._goes_chianti_tem(LONGFLUX, SHORTFLUX, satellite=5, date=DATE, abundances="coronal") assert all(temp3 < Quantity([11.43], unit="MK")) and \ all(temp3 > Quantity([11.42], unit="MK")) assert all(em3 < Quantity([3.85e+48], unit="1/cm**3")) and \ all(em3 > Quantity([3.84e+48], unit="1/cm**3"))
def test_goes_chianti_tem_errors(): # Define input variables. ratio = SHORTFLUX/LONGFLUX shortflux_toomany = Quantity( np.append(SHORTFLUX.value, SHORTFLUX.value[0]), unit="W/m**2") shortflux_toosmall = copy.deepcopy(SHORTFLUX) shortflux_toosmall.value[0] = -1 shortflux_toobig = copy.deepcopy(SHORTFLUX) shortflux_toobig.value[0] = 1 temp_test = Quantity(np.zeros(len(LONGFLUX))+10, unit="MK") temp_test_toomany = Quantity(np.append(temp_test.value, 0), unit="MK") temp_test_toosmall = copy.deepcopy(temp_test) temp_test_toosmall.value[0] = -1 temp_test_toobig = copy.deepcopy(temp_test) temp_test_toobig.value[0] = 101 # First test correct exceptions are raised if incorrect inputs are # entered. with pytest.raises(ValueError): temp, em = goes._goes_chianti_tem(LONGFLUX, SHORTFLUX, satellite=-1) with pytest.raises(ValueError): temp, em = goes._goes_chianti_tem(LONGFLUX, shortflux_toomany) with pytest.raises(ValueError): temp = goes._goes_get_chianti_temp(ratio, satellite=-1) with pytest.raises(ValueError): temp, em = goes._goes_chianti_tem(LONGFLUX, SHORTFLUX, abundances="Neither") with pytest.raises(ValueError): temp = goes._goes_get_chianti_temp(ratio, abundances="Neither") with pytest.raises(ValueError): temp, em = goes._goes_chianti_tem(LONGFLUX, shortflux_toobig) with pytest.raises(ValueError): em = goes._goes_get_chianti_em(LONGFLUX, temp_test, satellite=-1) with pytest.raises(ValueError): em = goes._goes_get_chianti_em(LONGFLUX, temp_test, abundances="Neither") with pytest.raises(ValueError): em = goes._goes_get_chianti_em(LONGFLUX, temp_test, abundances="Neither") with pytest.raises(ValueError): em = goes._goes_get_chianti_em(LONGFLUX, temp_test_toosmall) with pytest.raises(ValueError): em = goes._goes_get_chianti_em(LONGFLUX, temp_test_toobig)