Beispiel #1
0
    def load_select_data(self, Pole, Type, OppositionDate):
        #import ephem
        import marstime
        from astropy.time import Time
        import numpy as np
        import MarsPolarLibrary as MPL

        self.DateTimeString = []
        self.DateTime = []
        self.PoleandObject = []
        self.Latitude = []
        self.hlon = []
        self.hlat = []

        Odate64 = np.datetime64(OppositionDate)
        for recordindex in range(1, self.nrecords):
            fields = self.CfgLines[recordindex].split(',')
            datetimestring = MPL.MakeDateTime(fields[4], fields[5])
            dt64 = np.datetime64(datetimestring)
            if Odate64 - 180 <= dt64 <= Odate64 + 180:
                self.DateTimeString.append(datetimestring)
                self.DateTime.append(dt64)
                self.PoleandObject.append(fields[1])
                self.Latitude.append(float(fields[10]))

                t = Time(str(dt64), format='isot', scale='utc')
                ott = t.jd - 2451545.0
                Ls = marstime.Mars_Ls(j2000_ott=ott)
                self.hlon.append(Ls)
                self.hlat.append(marstime.solar_declination(ls=Ls))
Beispiel #2
0
def declination_mars(j2000_offsets):   
    ''' Calculates the declination based on the time of the day that it is. 
        INPUT: jd is the julian day'''
        
    dec = marstime.solar_declination(marstime.Mars_Ls(j2000_offsets)) #takes Ls, not MSD
    
    return dec
Beispiel #3
0
def test_spirit_landing():
    mil = 1073137591000
    longitude=184.702
    latitude=-14.460
    jdut = marstime.julian(mil)
    assert within_error(jdut,2453008.07397,1e-3)
    
    tt_utc = marstime.utc_to_tt_offset(jdut)
    assert within_error(tt_utc,64.184,1e-3)
    
    jday_tt = marstime.julian_tt(jdut)
    assert within_error(jday_tt, 2453008.07471,1e-3)
    
    j2000_ott = marstime.j2000_offset_tt(jday_tt)
    assert within_error(j2000_ott, 1463.07471, 1e-3)

    m = marstime.Mars_Mean_Anomaly(j2000_ott)
    assert within_error(m, 66.06851,1e3)

    alpha = marstime.FMS_Angle(j2000_ott)
    assert within_error(alpha, 317.09363,1e-4)

    pbs = marstime.alpha_perturbs(j2000_ott)
    assert within_error(pbs, 0.01614, 1e-3)

    v_m = marstime.equation_of_center(j2000_ott)
    assert within_error(v_m, 10.22959, 1e-4)

    ls = marstime.Mars_Ls(j2000_ott)
    assert within_error(ls, 327.32322, 1e-4)

    eot = marstime.equation_of_time(j2000_ott)
    assert within_error(eot, -12.77557, 1e-4)

    mtc = marstime.Coordinated_Mars_Time(j2000_ott)
    assert within_error(mtc,13.16542, 1e-4)

    lmst = marstime.Local_Mean_Solar_Time(longitude,j2000_ott)
    assert within_error(lmst, 0.85196, 1e-4)

    ltst = marstime.Local_True_Solar_Time(longitude,j2000_ott)
    assert within_error(ltst, 0.00025, 1e-5)

    subsol = marstime.subsolar_longitude(j2000_ott)
    assert within_error(subsol, 4.70575,1e-4)

    dec = marstime.solar_declination(ls)
    assert within_error(dec, -13.42105,1e-2)

    rm = marstime.heliocentric_distance(j2000_ott)
    assert within_error(rm,1.47767, 1e-4)

    im = marstime.heliocentric_longitude(j2000_ott)
    assert within_error(im, 52.37469, 1e-4)

    bm = marstime.heliocentric_latitude(j2000_ott)
    assert within_error(bm, 0.08962, 1e-4)

#This is where we deviate significantly from the original marstime algorithm.
    sz = marstime.solar_zenith(longitude, latitude,j2000_ott)
    assert within_error(sz, 151.93895, 0.2)

    sa = marstime.solar_azimuth(longitude, latitude,j2000_ott)
    assert within_error(sa, 179.99225,1e-2)
Beispiel #4
0
def test_midnight_crossing():
    mil = 947116800000
    longitude=0.
    latitude=0.
    jdut = marstime.julian(mil)
    assert within_error(jdut,2451549.5,1e-3)
    
    tt_utc = marstime.utc_to_tt_offset(jdut)
    assert within_error(tt_utc,64.184,1e-3)
    
    jday_tt = marstime.julian_tt(jdut)
    assert within_error(jday_tt, 2451549.50074,1e-3)
    
    j2000_ott = marstime.j2000_offset_tt(jday_tt)
    assert within_error(j2000_ott, 4.50074, 1e-3)

    m = marstime.Mars_Mean_Anomaly(j2000_ott)
    assert within_error(m, 21.74548,1e3)

    alpha = marstime.FMS_Angle(j2000_ott)
    assert within_error(alpha, 272.74486,1e-4)

    pbs = marstime.alpha_perturbs(j2000_ott)
    assert within_error(pbs, 0.00142, 1e-3)

    v_m = marstime.equation_of_center(j2000_ott)
    assert within_error(v_m, 4.44191, 1e-4)

    ls = marstime.Mars_Ls(j2000_ott)
    assert within_error(ls, 277.18677, 1e-4)

    eot = marstime.equation_of_time(j2000_ott)
    assert within_error(eot, -5.18764, 1e-4)

    mtc = marstime.Coordinated_Mars_Time(j2000_ott)
    assert within_error(mtc,23.99431, 1e-4)

    lmst = marstime.Local_Mean_Solar_Time(longitude,j2000_ott)
    assert within_error(lmst, 23.99431, 1e-4)

    ltst = marstime.Local_True_Solar_Time(longitude,j2000_ott)
    assert within_error(ltst, 23.64847, 1e-4)

    subsol = marstime.subsolar_longitude(j2000_ott)
    assert within_error(subsol, 174.72703,1e-4)

    dec = marstime.solar_declination(ls)
    assert within_error(dec, -25.22838,1e-4)

    rm = marstime.heliocentric_distance(j2000_ott)
    assert within_error(rm, 1.39358, 1e-4)

    im = marstime.heliocentric_longitude(j2000_ott)
    assert within_error(im, 2.26270, 1e-4)

    bm = marstime.heliocentric_latitude(j2000_ott)
    assert within_error(bm, -1.35959, 1e-4)

    sz = marstime.solar_zenith(longitude, latitude,j2000_ott)
    assert within_error(sz, 154.26182, 1e-4)

    sa = marstime.solar_azimuth(longitude, latitude,j2000_ott)
    assert within_error(sa, 191.03687,1e-4)
Beispiel #5
0
def test_solar_declination():
    assert within_error(marstime.solar_declination(0.0)  ,0.0,1e-3)
    assert within_error(marstime.solar_declination(90.0) ,25.441,1e-3)
    assert within_error(marstime.solar_declination(180.0),0.0,1e-3)
    assert within_error(marstime.solar_declination(270.0),-25.441,1e-3)
Beispiel #6
0
mpl.rc("xtick", labelsize=10)
mpl.rc("ytick", labelsize=10)
mpl.rc("legend", fontsize=10)
import pylab as pl
import numpy as np
import marstime

#define mars solar days to use in the plot
start_j2000_ott = 151.27365  # sometime in May 2000, start of MY25

msd = np.linspace(0, 669, 120)
#calculate the j2000 offset dates
j2000_offsets = marstime.j2000_from_Mars_Solar_Date(
    msd + marstime.Mars_Solar_Date(start_j2000_ott))

eot_axis = marstime.equation_of_time(
    j2000_offsets) * 60 / 15.  #convert from degrees to minutes
dec_axis = marstime.solar_declination(
    marstime.Mars_Ls(j2000_offsets))  #takes Ls, not MSD

pl.figure(figsize=(4, 6))
pl.subplots_adjust(left=0.15)
pl.plot(eot_axis, dec_axis, marker='.', ls='none', color='k')
pl.plot(eot_axis[::10], dec_axis[::10], marker='.', ls='none', color='r')
pl.ylim(-28, 28)
pl.xlim(-55, 45)
pl.xticks(np.arange(-50, 50, 10))
pl.yticks(np.arange(-30, 30, 5))
pl.ylabel("Declination (degrees)")
pl.xlabel("Equation of Time (minutes)")
pl.savefig("analemma.png")
Beispiel #7
0
import matplotlib as mpl
mpl.use("Agg")
mpl.rc("axes",labelsize=10)
mpl.rc("xtick",labelsize=10)
mpl.rc("ytick",labelsize=10)
mpl.rc("legend",fontsize=10)
import pylab as pl
import numpy as np
import marstime

#define mars solar days to use in the plot
start_j2000_ott = 151.27365 # sometime in May 2000, start of MY25

msd = np.linspace(0,669,120)
#calculate the j2000 offset dates
j2000_offsets = marstime.j2000_from_Mars_Solar_Date(msd + marstime.Mars_Solar_Date(start_j2000_ott))

eot_axis = marstime.equation_of_time(j2000_offsets)*60/15. #convert from degrees to minutes
dec_axis = marstime.solar_declination(marstime.Mars_Ls(j2000_offsets)) #takes Ls, not MSD

pl.figure(figsize=(4,6))
pl.subplots_adjust(left=0.15)
pl.plot(eot_axis, dec_axis, marker='.', ls='none',color='k')
pl.plot(eot_axis[::10], dec_axis[::10], marker='.', ls='none',color='r')
pl.ylim(-28,28)
pl.xlim(-55,45)
pl.xticks(np.arange(-50,50,10))
pl.yticks(np.arange(-30,30,5))
pl.ylabel("Declination (degrees)")
pl.xlabel("Equation of Time (minutes)")
pl.savefig("analemma.png")
import marstime
import datetime
import scipy
import scipy.optimize
import argparse

import test_simple_julian_offset

if __name__ == "__main__":
    parser = argparse.ArgumentParser(
        description="Testsuite for marstime library")
    parser.add_argument("date",
                        type=str,
                        nargs="?",
                        help="Earth date in ISO format YYYY/MM/DD")
    parser.add_argument("time",
                        type=str,
                        nargs="?",
                        help="Earth time in ISO format HH:ii:ss")
    args = parser.parse_args()

    dt = args.date + " " + args.time
    jdate = test_simple_julian_offset.simple_julian_offset(
        datetime.datetime.strptime(dt, "%Y/%m/%d %H:%M:%S"))
    print marstime.solar_declination(marstime.Mars_Ls(jdate))
Beispiel #9
0
def SetupMarsPlot():
    import matplotlib.pyplot as pl
    import numpy as np
    import marstime
    from astropy.time import Time
    from astropy import constants as const

    canvas = pl.figure(figsize=(8.0, 6.0), dpi=150, facecolor="white")
    x0, x1, xtks = -180., 180., 13
    y0, y1, ytks = 25., 90., 14

    #NORTH
    axN = canvas.add_subplot(3, 1, 1, axisbg="white")

    axN.set_xlim(x0, x1)
    axN.set_xticks(np.linspace(x0, x1, xtks, endpoint=True))

    axN.set_ylim(y0, y1)
    axN.set_yticks(np.linspace(y0, y1, ytks, endpoint=True))

    axN.grid(linewidth=0.5)
    axN.tick_params(axis='y', which='major', labelsize=9)
    axN.tick_params(labelbottom=False)
    axN.set_ylabel("Latitude (deg)", fontsize=9)
    axN.set_title("North Pole", fontsize=10)

    LS_ALPO = np.linspace(40, 135, 20)
    LAT_ALPO = [
        65.1, 67.4, 67.6, 68.0, 69.7, 72.2, 74.0, 75.5, 77.8, 79.8, 81.2, 81.6,
        82.7, 83.1, 82.9, 82.4, 82.8, 83.5, 83.6, 83.4
    ]
    LAT_SD_ALPO = [
        4.4, 4.5, 3.4, 2.4, 2.4, 2.1, 1.4, 1.8, 2.8, 2.9, 2.5, 2.2, 1.3, 1.5,
        1.6, 1.8, 1.9, 1.0, 0.7, 0.6
    ]
    axN.plot(LS_ALPO, LAT_ALPO, color='k', label="ALPO 1980-2003 Average")
    axN.plot(LS_ALPO,
             np.array(LAT_ALPO) + 1.96 * np.array(LAT_SD_ALPO),
             color='k',
             linewidth=0.5,
             label="95% Confidence")
    axN.plot(LS_ALPO,
             np.array(LAT_ALPO) - 1.96 * np.array(LAT_SD_ALPO),
             color='k',
             linewidth=0.5)

    #SOUTH
    axS = canvas.add_subplot(3, 1, 3, axisbg="white")
    y0, y1, ytks = 25., 90., 14

    axS.set_xlim(x0, x1)
    axS.set_xticks(np.linspace(x0, x1, xtks, endpoint=True))
    axS.set_ylim(-y1, -y0)
    axS.set_yticks(np.linspace(-y1, -y0, ytks, endpoint=True))

    axS.grid(linewidth=0.5)
    axS.tick_params(axis='both', which='major', labelsize=8)
    axS.set_ylabel("Latitude (deg)", fontsize=9)
    axS.set_xlabel("Solar Longitude (deg)", fontsize=9)
    axS.set_title("South Pole", fontsize=10)

    LS_ALPO = np.linspace(200, 300, 21) - 360.
    W_ALPO = [
        54.0, 51.2, 49.1, 47.4, 44.4, 40.4, 38.2, 35.1, 31.3, 28.9, 23.9, 21.6,
        20.6, 19.2, 16.8, 16.0, 14.6, 12.1, 9.8, 9.5, 10.6
    ]
    LAT_SD_ALPO = [
        7.1, 6.5, 4.6, 5.5, 4.9, 7.5, 7.8, 6.5, 6.1, 5.4, 4.2, 3.1, 1.7, 2.2,
        2.2, 2.3, 3.0, 3.2, 1.8, 1.4, 1.0
    ]
    LAT_ALPO = -(90. - np.array(W_ALPO) / 2.)
    axS.plot(LS_ALPO, LAT_ALPO, color='k', label="ALPO 1986-2003 Average")
    axS.plot(LS_ALPO,
             np.array(LAT_ALPO) + 1.96 * np.array(LAT_SD_ALPO),
             color='k',
             linewidth=0.5,
             label="95% Confidence")
    axS.plot(LS_ALPO,
             np.array(LAT_ALPO) - 1.96 * np.array(LAT_SD_ALPO),
             color='k',
             linewidth=0.5)

    #SOLAR LATITUDE
    Target = "Solar Latitude"

    axL = canvas.add_subplot(3, 1, 2, axisbg="white")
    y0, y1, ytks = -30., 30., 13
    axL.set_xlim(x0, x1)
    axL.set_xticks(np.linspace(x0, x1, xtks, endpoint=True))
    axL.set_ylim(y0, y1)
    axL.set_yticks(np.linspace(y0, y1, ytks, endpoint=True))
    axL.grid(linewidth=0.5)
    axL.tick_params(axis='y', which='major', labelsize=9)
    axL.tick_params(labelbottom=False)
    axL.set_ylabel("Solar Latitude (deg)", fontsize=9)

    axL.set_title(Target, fontsize=9)

    #306 days to start at Autumn equinox rather than vernal equinox
    dateoffset = np.arange(0, 686, 2, dtype=int) - 306
    datearray = np.datetime64('2000-06-03') + dateoffset

    LS_array = []
    SL_array = []
    D_array = []
    F_array = []
    for d in datearray:
        t = Time(str(d), format='isot', scale='utc')
        ott = t.jd - 2451545.0
        LS_temp = marstime.Mars_Ls(j2000_ott=ott)
        SL_temp = marstime.solar_declination(ls=LS_temp)
        D_temp = marstime.heliocentric_distance(j2000_ott=ott)
        F_temp = const.L_sun / (4. * np.pi * (const.au * D_temp)**2)
        print ott, LS_temp, SL_temp, D_temp, F_temp
        LS_array.append(float(LS_temp))
        SL_array.append(float(SL_temp))
        D_array.append(float(D_temp))
        F_array.append(float(F_temp.value))
    LS_array = np.array(LS_array)
    SL_array = np.array(SL_array)

    LS_array = np.mod(LS_array + 180.0, 360.) - 180.

    axL.plot(LS_array, SL_array, color='k', label="Solar Latitude (deg)")

    axD = axL.twinx()
    axD.set_xlim(x0, x1)
    axD.set_xticks(np.linspace(x0, x1, xtks, endpoint=True))
    axD.set_ylim(500, 700)
    axD.set_yticks(np.linspace(400, 800, 9, endpoint=True))
    axD.tick_params(axis='y', which='major', labelsize=9)
    axD.set_ylabel("Solar Flux (W/m^2)", fontsize=9)

    axD.plot(LS_array, F_array, color='b', label="Solar Distance")

    Seasons = ['Autumn', 'Winter', 'Spring', 'Summer']
    for j in range(0, len(Seasons)):
        axL.annotate(Seasons[j],
                     xy=(-135. + 90. * j, 27.5),
                     size=9,
                     horizontalalignment='center',
                     verticalalignment='center')
        axL.annotate(Seasons[np.mod(j + 2, 4)],
                     xy=(-135. + 90. * j, -27.5),
                     size=9,
                     horizontalalignment='center',
                     verticalalignment='center')

    pl.subplots_adjust(left=0.1, right=0.9, top=0.95, bottom=0.09)

    return axN, axS