Esempio n. 1
0
 def test_getDststarTuple(self):
     """getDststar should give known results from tuple input (regression)"""
     real_ans = np.array([  6.39592274,   7.5959423 ,  -2.44532089,  16.2867821 ,
                           11.01399987,  17.01362653,  13.6810416 , -34.3206288 ,
                          -12.22368788,   1.03764047,  -9.03424456])
     ans = em.getDststar(self.ticks, model=(7.26, 11), dbase='Test')
     np.testing.assert_almost_equal(real_ans, ans)
Esempio n. 2
0
 def test_getDststarError(self):
     """getDststar should give known exceptions on bad input"""
     real_ans = np.array([-30.80228229, -26.85289053, -11.2457748 , -17.98012397,
                          -16.1640001 , -13.64888467, -14.75155876, -10.43928609,
                          -21.22360883,  -8.49354146,  -3.29620967])
     ans = em.getDststar(self.ticks, dbase='Test')
     self.assertRaises(ValueError, em.getDststar, self.ticks, model='bad')
     self.assertRaises(ValueError, em.getDststar, self.ticks, model={'a':7.26, 'b':11})
Esempio n. 3
0
def initialSW():
    """Construct initial estimate of hourly solar wind parameters"""
    st = dt.datetime(1989, 3, 12)
    en = dt.datetime(1989, 3, 15)
    hourly = getKondrashovSW()
    # Keep IMF By and n, set V to Boteler/Nagatsuma
    t_ssc1 = dt.datetime(1989, 3, 13, 1, 27)
    t_ssc2 = dt.datetime(1989, 3, 13, 7, 43)
    t_cme = dt.datetime(1989, 3, 13, 16)
    t_turn = dt.datetime(1989, 3, 14, 2)
    # Set Bx positive, in accordance with ISEE-3 data, Vy/Vz->0
    hourly['Bx'] = dm.dmfilled(hourly['By'].shape, fillval=3)
    hourly['Vy'] = dm.dmfilled(hourly['By'].shape, fillval=0)
    hourly['Vz'] = dm.dmfilled(hourly['By'].shape, fillval=0)
    # Before first SSC
    inds_before_1 = tb.tOverlapHalf([dt.datetime(1989, 3, 12), t_ssc1],
                                    hourly['DateTime'])
    hourly['V_sw'][inds_before_1] = 400
    # Between first and ssecond SSC
    inds_between_12 = tb.tOverlapHalf([t_ssc1, t_ssc2], hourly['DateTime'])
    hourly['V_sw'][inds_between_12] = 550
    # IMF turns north around 1989-03-14T02:00:00 according to inverse Burton and Kondrashov
    inds_mainphase = tb.tOverlapHalf([t_ssc2, t_turn], hourly['DateTime'])
    hourly['V_sw'][inds_mainphase] = 983
    # Then have speed decay towards IMP-8 measurement which is ballpark 820 km/s
    inds_rest = tb.tOverlapHalf([t_turn, hourly['DateTime'][-1]],
                                hourly['DateTime'])
    hourly['V_sw'][inds_rest] = np.linspace(983, 820, len(inds_rest))
    # Now we have speed, estimate temperature
    hourly['Plasma_temp'] = emp.getExpectedSWTemp(hourly['V_sw'],
                                                  model='XB15',
                                                  units='K')
    inds_cme = tb.tOverlapHalf([t_cme, en], hourly['DateTime'])
    hourly['Plasma_temp'][
        inds_cme] /= 3  # reduce by factor of 3 for CME-like temp
    # Get "Kondrashov VBs" using V from Boteler/Nagatsuma
    hourly['VBs_K'] = 1e-3 * hourly['V_sw'] * rectify(
        -1 * hourly['Bz'])  # mV/m
    # Now get VBs from inverse Burton
    ky_dat = kyo.fetch('dst', (st.year, st.month, st.day),
                       (en.year, en.month, en.day))
    inds = tb.tOverlapHalf([st, en], ky_dat['time'])
    # Pressure correct here using n and V
    hourly = calc_P(hourly)
    hourly['Dst'] = ky_dat['dst'][inds]
    dst_star = emp.getDststar(hourly, model='OBrien')
    hourly['VBs_OB'] = 1e-3 * inverseOBrienMcPherron(dst_star)
    # Make new Bz from VBs_OB
    hourly['Bz_OB'] = -1e3 * hourly['VBs_OB'] / hourly['V_sw']  # nT

    return hourly
Esempio n. 4
0
 def test_getDststarOmnivals(self):
     """getDststar should give known result using omnival dict input"""
     dst, pdyn = -10.0, 5.0
     real_ans = dst - np.sqrt(pdyn)
     ans = em.getDststar({'Pdyn': pdyn, 'Dst': dst}, model=(1,0))
     np.testing.assert_almost_equal(real_ans, ans)
Esempio n. 5
0
def makeSW_v2():
    """Construct initial estimate of hourly solar wind parameters"""
    st = dt.datetime(1989, 3, 12)
    en = dt.datetime(1989, 3, 15)
    hourly = getKondrashovSW()
    # Keep IMF By and n, set V to Boteler/Nagatsuma
    t_ssc1 = dt.datetime(1989, 3, 13, 1, 27)
    t_ssc2 = dt.datetime(1989, 3, 13, 7, 43)
    t_cme = dt.datetime(1989, 3, 13, 16)
    t_turn = dt.datetime(1989, 3, 14, 2)
    # Set Bx positive, in accordance with ISEE-3 data, Vy/Vz->0
    hourly['Bx'] = dm.dmfilled(hourly['By'].shape, fillval=3)
    hourly['Vy'] = dm.dmfilled(hourly['By'].shape, fillval=0)
    hourly['Vz'] = dm.dmfilled(hourly['By'].shape, fillval=0)
    # Before first SSC
    inds_before_1 = tb.tOverlapHalf([dt.datetime(1989, 3, 12), t_ssc1],
                                    hourly['DateTime'])
    hourly['V_sw'][inds_before_1] = 400
    # Between first and ssecond SSC
    inds_between_12 = tb.tOverlapHalf([t_ssc1, t_ssc2], hourly['DateTime'])
    hourly['V_sw'][inds_between_12] = 550
    # IMF turns north around 1989-03-14T02:00:00 according to inverse Burton and Kondrashov
    inds_mainphase = tb.tOverlapHalf([t_ssc2, t_turn], hourly['DateTime'])
    hourly['V_sw'][inds_mainphase] = 983
    # Then have speed decay towards IMP-8 measurement which is ballpark 820 km/s
    inds_rest = tb.tOverlapHalf([t_turn, hourly['DateTime'][-1]],
                                hourly['DateTime'])
    hourly['V_sw'][inds_rest] = np.linspace(983, 820, len(inds_rest))
    # Now we have speed, estimate temperature
    hourly['Plasma_temp'] = emp.getExpectedSWTemp(hourly['V_sw'],
                                                  model='XB15',
                                                  units='K')
    inds_cme = tb.tOverlapHalf([t_cme, en], hourly['DateTime'])
    hourly['Plasma_temp'][
        inds_cme] /= 3  # reduce by factor of 3 for CME-like temp
    # Get "Kondrashov VBs" using V from Boteler/Nagatsuma
    hourly['VBs_K'] = 1e-3 * hourly['V_sw'] * rectify(
        -1 * hourly['Bz'])  # mV/m
    # Now get VBs from inverse Burton
    ky_dat = kyo.fetch('dst', (st.year, st.month, st.day),
                       (en.year, en.month, en.day))
    inds = tb.tOverlapHalf([st, en], ky_dat['time'])
    # Substitute density curve from Sept. 2017 (double shock)
    sep17 = pybats.ImfInput(
        filename=
        '/home/smorley/projects/github/advect1d/IMF_201709_advect_filt.dat',
        load=True)
    den_inds = tb.tOverlapHalf(
        [t_ssc1 - dt.timedelta(hours=25), hourly['DateTime'][-1]],
        hourly['DateTime'])
    nhours = len(den_inds)
    # Keep the opening 8 hours from Kondrashov (2017 event gets high)
    hourly['Den_P'][den_inds[9:]] = 2 + (sep17['rho'][::60][9:nhours] * 2)
    # After shocks, ensure number density doesn't drop below 10 (keeps M_A over 2)
    after_ssc2 = hourly['DateTime'] > t_ssc2
    under_lim = hourly['Den_P'] <= 10
    limit_inds = np.logical_and(after_ssc2, under_lim)
    hourly['Den_P'][limit_inds] = 10
    # Pressure correct here using n and V
    hourly = calc_P(hourly)
    hourly['Dst'] = ky_dat['dst'][inds]
    dst_star = emp.getDststar(hourly, model='OBrien')
    hourly['VBs_OB'] = 1e-3 * inverseOBrienMcPherron(dst_star)
    # Make new Bz from VBs_OB
    hourly['Bz_OB'] = -1e3 * hourly['VBs_OB'] / hourly['V_sw']  # nT

    return hourly