Exemple #1
0
 def test_getSolarRotation_Bartels(self):
     """make sure getSolarRotation returns known values"""
     dates = spt.Ticktock([dup.parse(t) for t in ['1832-02-08T00:00:00','2004-05-06T12:00:00','2012-12-12T00:00:00']])
     real_ans = np.array([1,2331,2447]).astype(int)
     ans = em.getSolarRotation(dates, rtype='bartels')
     np.testing.assert_almost_equal(real_ans, ans)
     float_ans = np.array([1.0, 2331.0185185185187, 2447.3703703703704])
     ans = em.getSolarRotation(dates, rtype='bartels', fp=True)
     np.testing.assert_almost_equal(float_ans, ans)
Exemple #2
0
 def test_getSolarRotation_Carrington(self):
     """make sure getSolarRotation returns known values"""
     dates = spt.Ticktock([dup.parse(t) for t in ['1853-11-10T00:00:00','1973-08-22T18:00:00','2003-03-19T12:02:45']])
     real_ans = np.array([1,1605,2001]).astype(int)
     ans = em.getSolarRotation(dates, rtype='carrington')
     np.testing.assert_almost_equal(real_ans, ans)
     float_ans = np.array([1.003596660715006, 1605.009785410243, 2001.000000356448])
     ans = em.getSolarRotation(dates, rtype='carrington', fp=True)
     np.testing.assert_almost_equal(float_ans, ans)
Exemple #3
0
def solarRotationPlot(ticks, data, targ_ax=None, rtype='bartels', nbins=27):
    '''Plots a 1-D time series as a Carrington or Bartels plot

    '''
    SRlength = {'bartels': 27.0, 'carrington': 27.2753}
    if not targ_ax:
        #setup axes
        fig, targ_ax = plt.subplots()

    #data are 1-D, get range of SR numbers for Y-axis
    min_sr = emp.getSolarRotation(ticks[0], rtype=rtype)
    max_sr = emp.getSolarRotation(ticks[-1], rtype=rtype)
    n_sr = 1 + max_sr - min_sr
    sr_values = np.linspace(min_sr, max_sr, n_sr)

    #get bin size in time
    start_time = emp.getSolarRotation(
        min_sr, rtype=rtype, reverse=True
    )[0]  #convert back from Solar Rotation to date, so we get the start time of the rotation
    end_time = emp.getSolarRotation(max_sr + 1, rtype=rtype, reverse=True)[
        0]  #add 1 to last solar rotation number then convert back to date
    binned_times = spt.tickrange(start_time, end_time,
                                 SRlength[rtype.lower()] / nbins)

    #now bin data on new time grid -- TODO: use windowMean from toolbox??
    digital = np.digitize(ticks.RDT, binned_times.RDT)
    bin_means = np.zeros(len(binned_times) - 1)
    bin_means.fill(np.nan)
    for i in range(1, len(binned_times)):
        try:
            bin_means[i] = data[digital == i].mean()
        except (
                ZeroDivisionError, IndexError
        ):  #ZDE happens when no data for that bin, IE is when bins extend beyond data
            pass

    plot_view = np.array(bin_means).reshape((n_sr, nbins))
    im = targ_ax.imshow(plot_view,
                        interpolation='nearest',
                        vmin=data.min(),
                        vmax=data.max(),
                        extent=[1, nbins, max_sr, min_sr],
                        aspect=100)
    plt.colorbar(im, ax=targ_ax)
    targ_ax.set_xlabel('Day of Rotation')
    targ_ax.set_ylabel('{0} Rotation number'.format(rtype.title()))
    #targ_ax.pcolormesh(plot_view)

    return
Exemple #4
0
 def test_getSolarRotation_BartelsDateTime(self):
     """make sure getSolarRotation returns known values"""
     dates = [dup.parse(t) for t in ['1832-02-08T00:00:00','2004-05-06T12:00:00','2012-12-12T00:00:00']]
     real_ans = np.array([1,2331,2447]).astype(int)
     for dd, aa in zip(dates, real_ans):
         ans = em.getSolarRotation(dd, rtype='bartels')
         np.testing.assert_almost_equal(aa, ans)
Exemple #5
0
def solarRotationPlot(ticks, data, targ_ax=None, rtype='bartels', nbins=27):
    '''Plots a 1-D time series as a Carrington or Bartels plot

    '''
    SRlength = {'bartels': 27.0, 'carrington':27.2753}
    if not targ_ax:
        #setup axes
        fig, targ_ax = plt.subplots()

    #data are 1-D, get range of SR numbers for Y-axis
    min_sr = emp.getSolarRotation(ticks[0],  rtype=rtype)
    max_sr = emp.getSolarRotation(ticks[-1], rtype=rtype)
    n_sr = 1+max_sr-min_sr
    sr_values = np.linspace(min_sr, max_sr, n_sr)

    #get bin size in time
    start_time = emp.getSolarRotation(min_sr,  rtype=rtype, reverse=True)[0] #convert back from Solar Rotation to date, so we get the start time of the rotation
    end_time = emp.getSolarRotation(max_sr+1,  rtype=rtype, reverse=True)[0] #add 1 to last solar rotation number then convert back to date
    binned_times = spt.tickrange(start_time, end_time, SRlength[rtype.lower()]/nbins)

    #now bin data on new time grid -- TODO: use windowMean from toolbox??
    digital = np.digitize(ticks.RDT, binned_times.RDT)
    bin_means = np.zeros(len(binned_times)-1)
    bin_means.fill(np.nan)
    for i in range(1, len(binned_times)):
        try:
            bin_means[i] = data[digital == i].mean()
        except (ZeroDivisionError, IndexError): #ZDE happens when no data for that bin, IE is when bins extend beyond data
            pass

    plot_view = np.array(bin_means).reshape((n_sr, nbins))
    im = targ_ax.imshow(plot_view, interpolation='nearest', vmin=data.min(), vmax=data.max(), extent=[1,nbins, max_sr,min_sr], aspect=100)
    plt.colorbar(im, ax=targ_ax)
    targ_ax.set_xlabel('Day of Rotation')
    targ_ax.set_ylabel('{0} Rotation number'.format(rtype.title()))
    #targ_ax.pcolormesh(plot_view)
    
    return