Пример #1
0
    def compare_file(self, hor_file, obj):

        hor = read_horizons(hor_file)

        for i, date in enumerate(hor['date']):
            t = dataclasses.make_I3Time(date)
            if obj == 'sun':
                d = astro.I3GetSunDirection(t)
            elif obj == 'moon':
                d = astro.I3GetMoonDirection(t)
            el = 90 - math.degrees(d.zenith)
            az = (90 -
                  math.degrees(d.azimuth + astro.ICECUBE_LONGITUDE)) % 360.

            eq = astro.I3GetEquatorialFromDirection(d, t)

            ra = math.degrees(eq.ra)
            dec = math.degrees(eq.dec)

            gal = astro.I3GetGalacticFromEquatorial(eq)

            l = math.degrees(gal.l)
            b = math.degrees(gal.b)

            #print el - hor['el'][i], az - hor['az'][i], ra - hor['ra'][i], dec - hor['dec'][i],l - hor['l'][i],b -hor['b'][i]

            assert (abs(el - hor['el'][i]) < 0.003)
            assert (azimuth_distance(az, hor['az'][i]) < 1.0)
            assert (abs(ra - hor['ra'][i]) < 0.005)
            assert (abs(dec - hor['dec'][i]) < 0.004)
            assert (abs(l - hor['l'][i]) < 0.02)
            assert (abs(b - hor['b'][i]) < 0.01)
Пример #2
0
def get_run_start(run):
    try:
        import MySQLdb
    except:
        print("Module MySQLdb not found. This is needed to find the start time of the given run.")
        sys.exit(-1)
    i3db = MySQLdb.connect(
        host = dbserver,
        db = "I3OmDb",
        user = dbuser,
        passwd = ""
        )
    cursor = i3db.cursor()
    sqlcommand = "SELECT start FROM run_summary WHERE run=%d" % run
    cursor.execute(sqlcommand)
    row = cursor.fetchone()
    dt = datetime.today()   # a dummy
    if row is None:
        print("Run %d not found in run_summary table." % run)
        sys.exit(-1)
    else:
        dt = row[0]

    i3time = dataclasses.make_I3Time(dt)
    return (i3time.GetModJulianDay(), i3time.GetModJulianSec(), i3time.GetModJulianNanoSec())
Пример #3
0
    def run_booker(self, horizons_filename, body):

        ephem = test_horizons.read_horizons(horizons_filename)

        csv_dir_name = "tableout"
        csv_filename = os.path.join(csv_dir_name, "I3EventHeader.csv")

        tray = I3Tray()
        tray.Add(generator, times=ephem['date'])
        tray.Add(tableio.I3TableWriter,
                 tableservice=[tableio.I3CSVTableService(csv_dir_name)],
                 keys={
                     'I3EventHeader': [
                         astro.converters.I3SunAndMoonConverter(),
                         dataclasses.converters.I3EventHeaderConverter()
                     ],
                 })

        tray.Execute()
        tray.Finish()
        del tray

        with open(csv_filename, 'r') as csvfile:
            reader = csv.reader(csvfile)
            header = reader.next()

            keys = [
                'time_start_mjd_day [days]', 'time_start_mjd_sec [seconds]',
                'time_start_mjd_ns [ns]', body + '_zenith [radian]',
                body + '_azimuth [radian]'
            ]
            indices = {}
            for k in keys:
                indices[k] = header.index(k)

            #skip info row
            reader.next()

            for line_number, row in enumerate(reader):

                #row_values = [row[indices[k]] for k in keys]

                t = dataclasses.I3Time()
                t.set_mod_julian_time(
                    int(row[indices['time_start_mjd_day [days]']]),
                    int(row[indices['time_start_mjd_sec [seconds]']]),
                    float(row[indices['time_start_mjd_ns [ns]']]))
                self.assertEqual(
                    t, dataclasses.make_I3Time(ephem['date'][line_number]))

                assert (
                    abs(90 - float(row[indices[body + '_zenith [radian]']]) /
                        I3Units.degree - ephem['el'][line_number]) < 0.003)

                assert (test_horizons.azimuth_distance(
                    90 - (float(row[indices[body + '_azimuth [radian]']]) +
                          astro.ICECUBE_LONGITUDE) / I3Units.degree,
                    ephem['az'][line_number]) < 1.)
Пример #4
0
    def test_eqn_of_time(self):

        for n in range(3000):

            i3time = dataclasses.make_I3Time(
                datetime(2010, 1, 1, 12) + timedelta(n))
            sun = astro.I3GetSunDirection(i3time)

            deltat = -(90 -
                       sun.azimuth / I3Units.degree) * 4  #convert to minutes
            assert (abs(deltat - equation_of_time(n)) < 0.3)
Пример #5
0
    def Process(self):
        try:
            t = self.times.next()
        except StopIteration:
            self.RequestSuspension()
            return

        header = dataclasses.I3EventHeader()
        header.start_time = dataclasses.make_I3Time(t)

        frame = icetray.I3Frame("P")
        frame["I3EventHeader"] = header

        self.PushFrame(frame)
Пример #6
0
def parse_date_time(date, time):
    datestring = options.date
    dateformat = '%Y-%m-%d'

    if not time is None:
        datestring += ' ' + options.time
        dateformat = '%Y-%m-%d %H:%M:%S.%f'
        
    dt = datetime.today()   # just a dummy
    try:
        dt = datetime.strptime(datestring, dateformat)
    except:
        print("Failed to parse date and/or time.")
        sys.exit(-1)
        
    i3time = dataclasses.make_I3Time(dt)
    return (i3time.GetModJulianDay(), i3time.GetModJulianSec(), i3time.GetModJulianNanoSec())
#store Modified julian date of days with leap seconds here
leap_sec_mjd = []

#The first 13 lines of this file contian an older way to do leapseconds which arn't supported
for line in open(filename).readlines()[13:]:
    #column 17-23 contian the julian date of the day after a leap second
    #subract 2400000 to obtian the modified julian date
    leap_sec_mjd.append(int(line[17:24]) - 2400000)

#first make sure first leap second is JAN 1, 1972
assert (leap_sec_mjd[0] == 41317)

#test every day from 1970 to
for mjd in range(
        40587,
        max(dataclasses.make_I3Time(now).mod_julian_day, leap_sec_mjd[-1]) +
        3 * 365):
    if mjd + 1 in leap_sec_mjd:
        if not dataclasses.leap_second_on_mjd(mjd):
            err_str = "MJD "+str(mjd)+" not in I3Time list of leap seconds, "\
                "possibly a leap second was added and I3Time.cxx needs to be updated"
            raise Exception(err_str)
    elif dataclasses.leap_second_on_mjd(mjd):
        err_str = str(mjd) + " incorrectly registers as a leap seconds"
        raise Exception(err_str)

#instantiate I3Time for leapsecond testing
t1 = dataclasses.I3Time()
t2 = dataclasses.I3Time()

#check every year from 1970 to 3 years in the future
Пример #8
0
from datetime import datetime,timedelta
import pylab as plt
from matplotlib.ticker import FormatStrFormatter
from icecube.icetray import I3Units
from icecube import astro,dataclasses

days = range(367)

sun_azimuth =[]
sun_elevation = []
day = []
for n in days:

    d = datetime(2000,1,1,12)+timedelta(n-1)
    day.append(d)
    i3time = dataclasses.make_I3Time(d)

    sun = astro.I3GetSunDirection(i3time)

    sun_azimuth.append(90 - sun.azimuth/I3Units.degree)
    sun_elevation.append(90 - sun.zenith/I3Units.degree)

plt.plot_date(day,
              -4*plt.array(sun_azimuth)*plt.cos(plt.radians(sun_elevation)),
              ls='-',marker=None
)
plt.title("Equation of Time")
plt.ylabel("Sundial Faster [minutes]")

plt.figure()
plt.plot_date(day,sun_elevation,ls='-',marker=None)
    raise RuntimeError("tai-utc.dat is older than seven months, re-download from http://maia.usno.navy.mil/ser7/tai-utc.dat")

#store Modified julian date of days with leap seconds here
leap_sec_mjd = []

#The first 13 lines of this file contian an older way to do leapseconds which arn't supported
for line in open(filename).readlines()[13:]:
    #column 17-23 contian the julian date of the day after a leap second
    #subract 2400000 to obtian the modified julian date
    leap_sec_mjd.append(int(line[17:24])-2400000)

#first make sure first leap second is JAN 1, 1972
assert(leap_sec_mjd[0]==41317)

#test every day from 1970 to 
for mjd in range(40587,max(dataclasses.make_I3Time(now).mod_julian_day,leap_sec_mjd[-1])+3*365):
    if mjd+1 in leap_sec_mjd:
        if not dataclasses.leap_second_on_mjd(mjd):
            err_str = "MJD "+str(mjd)+" not in I3Time list of leap seconds, "\
                "possibly a leap second was added and I3Time.cxx needs to be updated"
            raise Exception(err_str)
    elif dataclasses.leap_second_on_mjd(mjd):
        err_str = str(mjd)+" incorrectly registers as a leap seconds"
        raise Exception(err_str)

#instantiate I3Time for leapsecond testing
t1=dataclasses.I3Time()
t2=dataclasses.I3Time()

#check every year from 1970 to 3 years in the future
for year in range (1970,max(dataclasses.year_of(leap_sec_mjd[-1]),now.year)+3):