Ejemplo n.º 1
0
    def terrestrial_parallax(self, time_to_treat, altitude, longitude, latitude):
        """ Compute the position shift due to the distance of the obervatories from the Earth
        center.
        Please have a look on :
        "Parallax effects in binary microlensing events"
        Hardy, S.J and Walker, M.A. 1995. http://adsabs.harvard.edu/abs/1995MNRAS.276L..79H

        :param  time_to_treat: a numpy array containing the time where you want to compute this
        effect.
        :param altitude: the altitude of the telescope in meter
        :param longitude: the longitude of the telescope in degree
        :param latitude: the latitude of the telescope in degree
        :return: the shift induce by the distance of the telescope to the Earth center.
        :rtype: array_like

        **WARNING** : slalib use MJD time definition, which is MJD = JD-2400000.5
        """

        radius = (self.Earth_radius + altitude) / self.AU
        Longitude = longitude * np.pi / 180.0
        Latitude = latitude * np.pi / 180.0

        delta_telescope = []
        for time in time_to_treat:
            time_mjd = time - 2400000.5
            sideral_time = slalib.sla_gmst(time_mjd)
            telescope_longitude = - Longitude - self.target_angles_in_the_sky[
                0] + sideral_time

            delta_telescope.append(radius * slalib.sla_dcs2c(telescope_longitude, Latitude))

        delta_telescope = np.array(delta_telescope)
        delta_telescope_projected = np.array(
            [np.dot(delta_telescope, self.North), np.dot(delta_telescope, self.East)])
        return delta_telescope_projected
Ejemplo n.º 2
0
 def planet_J2000_geo_to_topo(self, gra, gdec, dist, radi, dut1, longitude, latitude, height):
     jd_utc = self.calc_jd_utc()
     date = jd_utc - 2400000.5 + dut1 / (24. * 3600.)
     jd = jd_utc - 2400000.5 + (self.tai_utc + 32.184) / (24. * 3600.) # reference => http://www.cv.nrao.edu/~rfisher/Ephemerides/times.html
     
     # Spherical to x,y,z 
     v = slalib.sla_dcs2c(gra, gdec)
     for i in range (3):
         v[i] *= dist
     
     # Precession to date. 
     rmat = slalib.sla_prec(2000.0, slalib.sla_epj(jd))
     vgp = slalib.sla_dmxv(rmat, v)
     
     # Geocenter to observer (date). 
     stl = slalib.sla_gmst(date) + longitude
     vgo = slalib.sla_pvobs(latitude, height, stl)
     
     # Observer to planet (date). 
     for i in range (3):
         v[i] = vgp[i] - vgo[i]
     
     disttmp = dist
     dist = math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2])
     radi *= disttmp / dist
     
     # Precession to J2000 
     rmat = slalib.sla_prec(slalib.sla_epj(jd), 2000.)
     vgp = slalib.sla_dmxv(rmat, v)
     
     # To RA,Dec. 
     ret = slalib.sla_dcc2s(vgp)
     tra = slalib.sla_dranrm(ret[0])
     tdec = ret[1]
     return [dist, radi, tra, tdec]
Ejemplo n.º 3
0
    def terrestrial_parallax(self, time_to_treat, altitude, longitude, latitude):
        """ Compute the position shift due to the distance of the obervatories from the Earth
        center.
        Please have a look on :
        "Parallax effects in binary microlensing events"
        Hardy, S.J and Walker, M.A. 1995. http://adsabs.harvard.edu/abs/1995MNRAS.276L..79H

        :param  time_to_treat: a numpy array containing the time where you want to compute this
        effect.
        :param altitude: the altitude of the telescope in meter
        :param longitude: the longitude of the telescope in degree
        :param latitude: the latitude of the telescope in degree
        :return: the shift induce by the distance of the telescope to the Earth center.
        :rtype: array_like

        **WARNING** : slalib use MJD time definition, which is MJD = JD-2400000.5
        """

        radius = (self.Earth_radius + altitude) / self.AU
        Longitude = longitude * np.pi / 180.0
        Latitude = latitude * np.pi / 180.0

        delta_telescope = []
        for time in time_to_treat:
            time_mjd = time - 2400000.5
            sideral_time = slalib.sla_gmst(time_mjd)
            telescope_longitude = - Longitude - self.target_angles_in_the_sky[
                0] + sideral_time

            delta_telescope.append(radius * slalib.sla_dcs2c(telescope_longitude, Latitude))

        delta_telescope = np.array(delta_telescope)
        delta_telescope_projected = np.array(
            [np.dot(delta_telescope, self.North), np.dot(delta_telescope, self.East)])
        return delta_telescope_projected
Ejemplo n.º 4
0
def Absolute2RelativeLST(absolute):
    "Returns LST as hours given UTC as a datetime."
    absolute = dt2mxDT(absolute)
    gmst = (180.0/math.pi)*slalib.sla_gmst(absolute.mjd)
    gbls = (gmst + GBTLONG)/15.0
    if gbls < 0:
        gbls = 24 + gbls
    return gbls
Ejemplo n.º 5
0
def Absolute2RelativeLST(absolute):
    "Returns LST as hours given UTC as a datetime."
    absolute = dt2mxDT(absolute)
    gmst = (180.0 / math.pi) * slalib.sla_gmst(absolute.mjd)
    gbls = (gmst + GBTLONG) / 15.0
    if gbls < 0:
        gbls = 24 + gbls
    return gbls
Ejemplo n.º 6
0
def get_lst(JD, e_long):
    MJD = convert_JD2MJD(JD)
    nb = len_all(JD)
    dT = sla.sla_dt(2000)
    if nb > 1:
        lst = np.zeros(nb)
        for i in range(0, nb):
            gmst = sla.sla_gmst(MJD[i])  # [radian]
            MJD_eoe = MJD[i] + dT
            equation_of_equinoxes = sla.sla_eqeqx(MJD_eoe)  # [radian]
            lst[i] = gmst + e_long + equation_of_equinoxes  # [radian]
    if nb == 1:
        MJD_eoe = MJD + dT
        equation_of_equinoxes = sla.sla_eqeqx(MJD_eoe)
        gmst = sla.sla_gmst(MJD)
        lst = gmst + e_long + equation_of_equinoxes
    lst = lst / pi * 180. / 15.  # [hour]
    lst = lst % 24  # our within 0~24
    return np.array(lst)  # [hour]
Ejemplo n.º 7
0
def ut_mjd_to_gmst(mjd):
    '''Convert UTC MJD to Greenwich mean sidereal time (an Angle).
       Note: We are assuming that UTC == UT1 here, which is what
       sla_gmst really expects. UT1 can't be easily determined, and
       we can only be out by less than 0.9s for as long as leap seconds
       persist.'''

    gmst_in_radians = sla.sla_gmst(mjd)

    return Angle(radians=gmst_in_radians)
Ejemplo n.º 8
0
def get_lst(JD,e_long):
    MJD = convert_JD2MJD(JD)
    nb = len_all(JD)
    dT = sla.sla_dt(2000)
    if nb>1:
        lst = np.zeros(nb)
        for i in range(0,nb):
            gmst = sla.sla_gmst(MJD[i]) # [radian]
            MJD_eoe = MJD[i] + dT
            equation_of_equinoxes = sla.sla_eqeqx(MJD_eoe) # [radian]
            lst[i] = gmst + e_long + equation_of_equinoxes # [radian]
    if nb==1:
        MJD_eoe = MJD + dT
        equation_of_equinoxes = sla.sla_eqeqx(MJD_eoe)
        gmst = sla.sla_gmst(MJD)
        lst = gmst + e_long + equation_of_equinoxes
    lst = lst / pi * 180. / 15. # [hour]
    lst = lst % 24 # our within 0~24
    return np.array(lst) # [hour]
Ejemplo n.º 9
0
    def hlst(self, mjd):
        global tellat, tellong, telelev

        # test 0.2 sec UT1 correction
        # dut1 = (0.2 /3600.0) * math.pi/12.0
        dut1 = 0.0

        last = s.sla_gmst(mjd) - tellong + s.sla_eqeqx(mjd) + dut1

        # lmst = s.sla_gmst(mjd) - tellong
        if last < 0.0: last = last + 2.0 * math.pi
        return last
Ejemplo n.º 10
0
 def compute_lst(self):
     """ Compute LST for observation """
     if self.header[b'telescope_id'] == 6:
         self.coords = gbt_coords
     elif self.header[b'telescope_id'] == 4:
         self.coords = parkes_coords
     else:
         raise RuntimeError("Currently only Parkes and GBT supported")
     if HAS_SLALIB:
         # dut1 = (0.2 /3600.0) * np.pi/12.0
         dut1 = 0.0
         mjd = self.header[b'tstart']
         tellong = np.deg2rad(self.coords[1])
         last = s.sla_gmst(mjd) - tellong + s.sla_eqeqx(mjd) + dut1
         # lmst = s.sla_gmst(mjd) - tellong
         if last < 0.0: last = last + 2.0 * np.pi
         return last
     else:
         raise RuntimeError("This method requires pySLALIB")
Ejemplo n.º 11
0
def findNightDuration(mjd):
    ctio_lat = -30.16527778
    ctio_lon = -70.8125
    ctio_height = 2215.

    degToRad = 2. * np.pi / 360.
    lat = ctio_lat * degToRad
    lon = ctio_lon * degToRad
    height = ctio_height

    imjd = np.int(mjd)
    start_mjd = imjd - 6. / 24.
    # before sunset at CTIO

    sunset = ""
    sunrise = ""
    # check every minute
    for i in np.arange(0, 1., 1. / (24. * 60)):
        mjd = start_mjd + i
        gmst = slalib.sla_gmst(mjd)
        eqEquinoxes = slalib.sla_eqeqx(mjd)
        lst = gmst + eqEquinoxes + lon

        sunra, sundec, diam = slalib.sla_rdplan(mjd, 0, lon, lat)
        sunha = lst - sunra
        sinAltRad = np.sin(lat)*np.sin(sundec) + \
            np.cos(lat)*np.cos(sundec)*np.cos(sunha)
        altRad = np.arcsin(sinAltRad)
        zenithDist = 90 * degToRad - altRad

        twilight = 100. * 2 * np.pi / 360.
        if zenithDist <= twilight:
            bright = True
        else:
            bright = False
        if sunset == "" and bright == False:
            sunset = mjd
        if sunset != "" and sunrise == "" and bright == True:
            sunrise = mjd
    duration = sunrise - sunset
    return duration, sunset, sunrise
Ejemplo n.º 12
0
def RelativeLST2AbsoluteTime(lst, now = None):
    """
    Returns today's DateTime in UTC, defined as first corresponding
    time after now, from given LST in hours.
    """
    lst = DateTime.DateTimeDelta(0, lst, 0, 0)
    if now is None:
        now = DateTime.gmt()
    else:
        now = dt2mxDT(now)

    # Now's mjd at 0h
    mjd0 = int(now.mjd)

    # Convert requested LST to degrees
    requested_lst = 15*lst.hours

    # Local LMST for 0h UT in degrees
    lst0 = (180.0/math.pi)*slalib.sla_gmst(mjd0) + GBTLONG

    # LST difference between 0h UT and requested LST
    lst_offset = requested_lst - lst0

    solar_sidereal_ratio = (365.25/366.25)

    # options for solar time at 1 day sidereal intervals
    options = []
    for cycle in range(720, -1080, -360):
        solar_time = ((lst_offset-cycle)/15.0)*solar_sidereal_ratio
        mjd = mjd0 + solar_time/24
        options.append(DateTime.DateTimeFromMJD(mjd))

    # Select the time following the target time
    target = DateTime.DateTimeFromMJD(now.mjd)
    for option in options:
        if target < option:
            return mxDT2dt(option)
    return mxDT2dt(option[-1])
Ejemplo n.º 13
0
def RelativeLST2AbsoluteTime(lst, now=None):
    """
    Returns today's DateTime in UTC, defined as first corresponding
    time after now, from given LST in hours.
    """
    lst = DateTime.DateTimeDelta(0, lst, 0, 0)
    if now is None:
        now = DateTime.gmt()
    else:
        now = dt2mxDT(now)

    # Now's mjd at 0h
    mjd0 = int(now.mjd)

    # Convert requested LST to degrees
    requested_lst = 15 * lst.hours

    # Local LMST for 0h UT in degrees
    lst0 = (180.0 / math.pi) * slalib.sla_gmst(mjd0) + GBTLONG

    # LST difference between 0h UT and requested LST
    lst_offset = requested_lst - lst0

    solar_sidereal_ratio = (365.25 / 366.25)

    # options for solar time at 1 day sidereal intervals
    options = []
    for cycle in range(720, -1080, -360):
        solar_time = ((lst_offset - cycle) / 15.0) * solar_sidereal_ratio
        mjd = mjd0 + solar_time / 24
        options.append(DateTime.DateTimeFromMJD(mjd))

    # Select the time following the target time
    target = DateTime.DateTimeFromMJD(now.mjd)
    for option in options:
        if target < option:
            return mxDT2dt(option)
    return mxDT2dt(option[-1])
Ejemplo n.º 14
0
    def planet_J2000_geo_to_topo(self, gra, gdec, dist, radi, dut1, longitude,
                                 latitude, height):
        jd_utc = self.calc_jd_utc()
        date = jd_utc - 2400000.5 + dut1 / (24. * 3600.)
        jd = jd_utc - 2400000.5 + (self.tai_utc + 32.184) / (
            24. * 3600.
        )  # reference => http://www.cv.nrao.edu/~rfisher/Ephemerides/times.html

        # Spherical to x,y,z
        v = slalib.sla_dcs2c(gra, gdec)
        for i in range(3):
            v[i] *= dist

        # Precession to date.
        rmat = slalib.sla_prec(2000.0, slalib.sla_epj(jd))
        vgp = slalib.sla_dmxv(rmat, v)

        # Geocenter to observer (date).
        stl = slalib.sla_gmst(date) + longitude
        vgo = slalib.sla_pvobs(latitude, height, stl)

        # Observer to planet (date).
        for i in range(3):
            v[i] = vgp[i] - vgo[i]

        disttmp = dist
        dist = math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2])
        radi *= disttmp / dist

        # Precession to J2000
        rmat = slalib.sla_prec(slalib.sla_epj(jd), 2000.)
        vgp = slalib.sla_dmxv(rmat, v)

        # To RA,Dec.
        ret = slalib.sla_dcc2s(vgp)
        tra = slalib.sla_dranrm(ret[0])
        tdec = ret[1]
        return [dist, radi, tra, tdec]
Ejemplo n.º 15
0
def datetime2st(d, obsvr_long=0.0):
    """Converts the passed datetime object in UTC to a Sidereal Time.
    If the site longitude [obsvr_long] (East +ve; radians) is passed, then
    the returned `stl` will be the Local Apparent Sidereal Time.
    If not passed (or zero), then the Greenwich Apparent Sidereal Time
    will be returned (Greenwich Mean Sidereal Time (GMST) plus the equation
    of the equinoxes.
    `stl`, the sidereal time, is returned in radians, normalized to the
    range 0...2*PI
    """

    # Compute MJD_UTC and MJD_TT
    mjd_utc = datetime2mjd_utc(d)
    mjd_tt = mjd_utc2mjd_tt(mjd_utc)
    # Determine UT1-UTC and hence MJD_UT1
    dut = ut1_minus_utc(mjd_utc)
    mjd_ut1 = mjd_utc + (dut / 86400.0)
    # Greenwich Mean Sidereal Time (GMST), just a function of UT1 ("Earth Rotation Angle")
    gmst = S.sla_gmst(mjd_ut1)
    # Compute Local Apparent Sidereal Time
    stl = gmst + obsvr_long + S.sla_eqeqx(mjd_tt)
    stl = S.sla_dranrm(stl)

    return stl
Ejemplo n.º 16
0
 def mjdToLST(self, mjd, eastLongitude):
     if self.verbose: print "\t MJD to LST"
     gmst = slalib.sla_gmst(mjd)
     eqEquinoxes = slalib.sla_eqeqx(mjd)
     lst = gmst + eqEquinoxes + eastLongitude
     return lst
Ejemplo n.º 17
0
    def _convert_coordinates(self, lat, long, ra_ref, dec_ref, date, time):
        """ Accurate conversion from equatorial coordiantes (RA, DEC) to Spherical (TH,PH) coordinates.
        The code uses the pyslalib library for a number of functions from the SLALIB Fortran library converted to Python.
        :param lat: latitude (decimal degrees)
        :param long: longitude (decimal degrees)
        :param ra_ref: RA(J2000) (decimal hours)
        :param dec_ref: Dec(J2000) (decimal degrees)
        :param date: vector date [iyear, imonth, iday]
        :param time: vector time [ihour imin isec]
        :return: [theta, pi]: Theta and Phi angles (degrees)
        """

        const_2pi = 2.0 * math.pi
        d2r = math.pi / 180
        r2d = 180 / math.pi

        # Conversion factor seconds of time to days
        const_st2day = 1.0/(24 * 3600)

        # Specify latitude and longitude (radians)
        lat *= d2r
        long *= d2r

        # Specify catalogued position (J2000 coordinates, radians)
        ra_ref = ra_ref * 15 * d2r
        dec_ref *= d2r

        # Specify current time and date %
        isec   = time[2]
        imin   = time[1]
        ihour  = time[0]
        iday   = date[2]
        imonth = date[1]
        iyear  = date[0]

        # Convert current UTC to Modified Julian date
        djm, j1   = slalib.sla_cldj(iyear, imonth, iday)
        fdutc, j2 = slalib.sla_dtf2d(ihour, imin, isec)
        djutc     = djm + fdutc

        # Calculate Greenwich Mean Sidereal Time from MJD
        gmst1 = slalib.sla_gmst(djutc)

        # Add longitude and Equation of Equinoxes for Local Apparent ST
        djtt = djutc + slalib.sla_dtt(djutc)*const_st2day
        last = gmst1 + long + slalib.sla_eqeqx(djtt)
        if last < 0.0:
            last += const_2pi

        # Convert catalogued position to apparent RA, Dec at current date
        pr = 0.e0
        pd = 0.e0
        px = 0.e0
        rv = 0.e0
        eq = 2000.0e0
        [raobs, decobs] = slalib.sla_map(ra_ref, dec_ref, pr, pd, px, rv, eq, djutc)

        # Get Hour Angle and Declination
        ha = last - raobs
        if ha < -math.pi:
            ha += const_2pi

        if ha > math.pi:
            ha -= const_2pi
        dec = decobs

        # Convert to Azimuth and Elevation
        azim, elev = slalib.sla_de2h(ha, dec, lat)

        theta = (90 - elev * r2d).real
        phi = (azim * r2d).real

        return [theta, phi]