def get_space_frame(self, element):
            #ref_location = self.table_mapper.search_instance_by_role("coords:StdRefLocation.position", 
            #                                                root_element=ele)[0]['@value']
            #print(ref_location)               
            frame_instance = self.table_mapper.search_instance_by_type("coords:SpaceFrame", 
                                                            root_element=element)[0]
                                                            
            ref_frame = self.table_mapper.search_instance_by_role("coords:SpaceFrame.spaceRefFrame", 
                                                            root_element=frame_instance)[0]['@value'].upper()  
            if ref_frame == "Galactic":
                retour =  Galactic()
            elif ref_frame == "ICRS":
                retour =  ICRS()
            else :
                ref_equinox = self.table_mapper.search_instance_by_role("coords:SpaceFrame.equinox", 
                                                            root_element=frame_instance)[0]['@value'] 
                         
                if ref_frame == "FK4":
                    if not ref_equinox :
                        retour = FK4()
                    else:
                        retour = FK4(equinox=ref_equinox)

                elif ref_frame == "FK5":
                    if not ref_equinox :
                        retour = FK5()
                    else:
                        retour = FK5(equinox=ref_equinox)
                else:
                    raise Exception ( "unsupported frame: " + ref_frame)    
            return retour   
Ejemplo n.º 2
0
def apply_aberration(ra, dec, mjd, use_astropy=False):
    """ apply aberration given date in MJD

    Args:
        ra: float or 1D np.array RA in degrees
        dec: float or 1D np.array dec in degrees
        mjd: float, mjd

    Returns: alt, az 
        alt: float or 1D np.array refracted altitude in degrees

    """
    if use_astropy:
        from astropy.coordinates import SkyCoord, FK5, GCRS
        import astropy.time

        gcrs = GCRS(obstime=astropy.time.Time(
            mjd, format="mjd"))  # precession? + aberration
        fk5_J2000 = FK5(equinox="J2000")
        fk5 = FK5(equinox=astropy.time.Time(mjd, format="mjd"))  # precession
        c1 = SkyCoord(ra, dec, frame='icrs', unit='deg')
        c2 = c1.transform_to(gcrs)
        ra_equ = c2.ra.value
        dec_equ = c2.dec.value
    else:
        ra_eclip, dec_eclip = radec2eclip(ra, dec)
        ra_eclip, dec_eclip = compute_aberration(ra_eclip, dec_eclip, mjd, 1.)
        ra_equ, dec_equ = eclip2radec(ra_eclip, dec_eclip)

    return ra_equ, dec_equ
Ejemplo n.º 3
0
def estimate_wcs_from_reference(ref, fname):
    # Read header of reference
    hdu = fits.open(ref)
    hdu[0].header["NAXIS"] = 2
    w = wcs.WCS(hdu[0].header)

    # Check for sidereal tracking
    # TODO: use fourframe class
    try:
        tracked = bool(hdu[0].header['TRACKED'])
    except KeyError:
        tracked = False

    # Get time and position from reference
    tref = Time(hdu[0].header["MJD-OBS"], format="mjd", scale="utc")
    pref = SkyCoord(ra=w.wcs.crval[0],
                    dec=w.wcs.crval[1],
                    unit="deg",
                    frame="icrs").transform_to(FK5(equinox=tref))

    # Read time from target
    hdu = fits.open(fname)
    t = Time(hdu[0].header["MJD-OBS"], format="mjd", scale="utc")

    # Correct wcs
    if tracked:
        dra = 0.0 * u.deg
    else:
        dra = (t.sidereal_time("mean", "greenwich") -
               tref.sidereal_time("mean", "greenwich"))
    p = FK5(ra=pref.ra + dra, dec=pref.dec, equinox=t).transform_to(ICRS)
    w.wcs.crval = np.array([p.ra.degree, p.dec.degree])

    return w
Ejemplo n.º 4
0
def angsep2(ra1, dec1, ra2, dec2):
    """Returns angular separation between two coordinates (all in degrees)"""
    from astropy.coordinates import FK5
    import astropy.units as u

    coord1 = FK5(ra1, dec1, unit=(u.degree, u.degree))
    coord2 = FK5(ra2, dec2, unit=(u.degree, u.degree))

    return coord1.separation(coord2)
Ejemplo n.º 5
0
def test_fk5_seps():
    """
    This tests if `separation` works for FK5Coordinate objects.

    This is a regression test for github issue #891
    """
    from astropy.coordinates import FK5

    a = FK5(1., 1., unit=('deg', 'deg'))
    b = FK5(2., 2., unit=('deg', 'deg'))
    a.separation(b)
Ejemplo n.º 6
0
def test_array_precession():
    """
    Ensures that FK5 coordinates as arrays precess their equinoxes
    """
    j2000 = Time('J2000')
    j1975 = Time('J1975')

    fk5 = FK5([1, 1.1] * u.radian, [0.5, 0.6] * u.radian)
    assert fk5.equinox.jyear == j2000.jyear
    fk5_2 = fk5.transform_to(FK5(equinox=j1975))
    assert fk5_2.equinox.jyear == j1975.jyear

    npt.assert_array_less(0.05, np.abs(fk5.ra.degree - fk5_2.ra.degree))
    npt.assert_array_less(0.05, np.abs(fk5.dec.degree - fk5_2.dec.degree))
Ejemplo n.º 7
0
def undo_precession_from_icrs(ra, dec, mjd, use_astropy=False):
    """ apply precession from ICRS to the date of observation given in MJD

    Args:
        ra: float or 1D np.array RA in degrees
        dec: float or 1D np.array dec in degrees
        
    Returns: alt, az 
        alt: float or 1D np.array refracted altitude in degrees

    """
    if use_astropy:  #  using astropy
        from astropy.coordinates import SkyCoord, FK5
        import astropy.time
        fk5 = FK5(equinox=astropy.time.Time(mjd, format="mjd"))  # precession
        #c1   = SkyCoord(ra,dec, frame='icrs', unit='deg')
        #c2   = c1.transform_to(fk5)
        #ra2  = c2.ra.value
        #dec2 = c2.dec.value

        c1 = SkyCoord(ra, dec, frame=fk5, unit='deg')
        c2 = c1.transform_to('icrs')
        ra2 = c2.ra.value
        dec2 = c2.dec.value

    else:
        # precession
        years = (ICRS_MJD - mjd) / DAYS_PER_YEAR
        ra2, dec2 = apply_precession(ra, dec, years)
    return ra2, dec2
Ejemplo n.º 8
0
def test_concatenate():
    from astropy.coordinates import FK5, SkyCoord, ICRS
    from astropy.coordinates.funcs import concatenate

    # Just positions
    fk5 = FK5(1*u.deg, 2*u.deg)
    sc = SkyCoord(3*u.deg, 4*u.deg, frame='fk5')

    res = concatenate([fk5, sc])
    np.testing.assert_allclose(res.ra, [1, 3]*u.deg)
    np.testing.assert_allclose(res.dec, [2, 4]*u.deg)

    with pytest.raises(TypeError):
        concatenate(fk5)

    with pytest.raises(TypeError):
        concatenate(1*u.deg)

    # positions and velocities
    fr = ICRS(ra=10*u.deg, dec=11.*u.deg,
              pm_ra_cosdec=12*u.mas/u.yr,
              pm_dec=13*u.mas/u.yr)
    sc = SkyCoord(ra=20*u.deg, dec=21.*u.deg,
                  pm_ra_cosdec=22*u.mas/u.yr,
                  pm_dec=23*u.mas/u.yr)

    res = concatenate([fr, sc])

    with pytest.raises(ValueError):
        concatenate([fr, fk5])

    fr2 = ICRS(ra=10*u.deg, dec=11.*u.deg)
    with pytest.raises(ValueError):
        concatenate([fr, fr2])
Ejemplo n.º 9
0
def convert_j2000_to_apparent(ra: float, dec: float) -> Tuple[float, float]:
    """
    Parameters
    ----------
    ra : FLOAT
        Right ascension to be converted from J2000 coordinates to apparent
        coordinates.
    dec : FLOAT
        Declination to be converted from J2000 coordinates to apparent coordinates.

    Returns
    -------
    coords_apparent.ra.hour: FLOAT
        Right ascension of target in local topocentric coordinates ("JNow").
    coords_apparent.dec.degree: FLOAT
        Declination of target in local topocentric coordinates ("JNow").
    """
    obstime = Time(datetime.datetime.now(datetime.timezone.utc))
    # Start with ICRS
    coords_j2000 = SkyCoord(ra=ra * u.hourangle,
                            dec=dec * u.degree,
                            frame='icrs')
    # Convert to FK5 (close enough to ICRS) with equinox at current time
    coords_apparent = coords_j2000.transform_to(FK5(equinox=obstime))
    return coords_apparent.ra.hour, coords_apparent.dec.degree
Ejemplo n.º 10
0
def test_constellations(recwarn):
    from astropy.coordinates import ICRS, FK5, SkyCoord
    from astropy.coordinates.funcs import get_constellation

    inuma = ICRS(9*u.hour, 65*u.deg)

    n_prewarn = len(recwarn)
    res = get_constellation(inuma)
    res_short = get_constellation(inuma, short_name=True)
    assert len(recwarn) == n_prewarn  # neither version should not make warnings

    assert res == 'Ursa Major'
    assert res_short == 'UMa'
    assert isinstance(res, str) or getattr(res, 'shape', None) == tuple()

    # these are taken from the ReadMe for Roman 1987
    ras = [9, 23.5, 5.12, 9.4555, 12.8888, 15.6687, 19, 6.2222]
    decs = [65, -20, 9.12, -19.9, 22, -12.1234, -40, -81.1234]
    shortnames = ['UMa', 'Aqr', 'Ori', 'Hya', 'Com', 'Lib', 'CrA', 'Men']

    testcoos = FK5(ras*u.hour, decs*u.deg, equinox='B1950')
    npt.assert_equal(get_constellation(testcoos, short_name=True), shortnames)

    # test on a SkyCoord, *and* test Boötes, which is special in that it has a
    # non-ASCII character
    bootest = SkyCoord(15*u.hour, 30*u.deg, frame='icrs')
    boores = get_constellation(bootest)
    assert boores == 'Boötes'
    assert isinstance(boores, str) or getattr(boores, 'shape', None) == tuple()
Ejemplo n.º 11
0
def test_constellation_edge_cases():
    from astropy.coordinates import FK5
    from astropy.coordinates.funcs import get_constellation

    # Test edge cases close to borders, using B1875.0 coordinates
    # Look for HMS / DMS roundoff-to-decimal issues from Roman (1987) data,
    # and misuse of PrecessedGeocentric, as documented in
    # https://github.com/astropy/astropy/issues/9855

    # Define eight test points.
    # The first four cross the boundary at 06h14m30 == 6.2416666666666... hours
    # with Monoceros on the west side of Orion at Dec +3.0.
    ras = [6.24100, 6.24160, 6.24166, 6.24171]
    # aka ['6h14m27.6s' '6h14m29.76s' '6h14m29.976s' '6h14m30.156s']

    decs = [3.0, 3.0, 3.0, 3.0]

    # Correct constellations for given RA/Dec coordinates
    shortnames = ['Ori', 'Ori', 'Ori', 'Mon']

    # The second four sample northward along RA 22 hours, crossing the boundary
    # at 86° 10' == 86.1666... degrees between Cepheus and Ursa Minor
    decs += [86.16, 86.1666, 86.16668, 86.1668]
    ras += [22.0, 22.0, 22.0, 22.0]
    shortnames += ['Cep', 'Cep', 'Umi', 'Umi']

    testcoos = FK5(ras*u.hour, decs*u.deg, equinox='B1875')
    npt.assert_equal(get_constellation(testcoos, short_name=True), shortnames,
      "get_constellation() error: misusing Roman approximations, vs IAU boundaries from Delporte?")
Ejemplo n.º 12
0
 def _positionAtEquinox(self, time):
     """
     """
     fk5 = self.target.transform_to(
         FK5(equinox=time)
     )
     self._fk5 = fk5
Ejemplo n.º 13
0
def convert_apparent_to_j2000(ra: float, dec: float) -> Tuple[float, float]:
    """
    Parameters
    ----------
    ra : FLOAT
        Right ascension to be converted from apparent to J2000 coordinates.
        coordinates.
    dec : FLOAT
        Declination to be converted from apparent to J2000 coordinates.

    Returns
    -------
    coords_j2000.ra.hour: FLOAT
        Right ascension of target in J2000.
    coords_j2000.dec.degree: FLOAT
        Declination of target in J2000.
    """
    obstime = Time(datetime.datetime.now(datetime.timezone.utc))
    # Start with FK5 (close enough to ICRS) with equinox at apparent time
    coords_apparent = SkyCoord(ra=ra * u.hourangle,
                               dec=dec * u.degree,
                               frame=FK5(equinox=obstime))
    # ICRS Equinox is always J2000
    coords_j2000 = coords_apparent.transform_to('icrs')
    return coords_j2000.ra.hour, coords_j2000.dec.degree
Ejemplo n.º 14
0
def get_coords(l, b):
    #get coordinates
    gal = SkyCoord(l=l * u.degree, b=b * u.degree, frame='galactic')
    eq = gal.fk5
    eq.transform_to(FK5(equinox='J2019'))
    Ra = eq.ra.degree
    Dec = eq.dec.degree
    print(Ra)
    print(Dec)
    lat = ugradio.leo.lat
    lon = ugradio.leo.lon
    alt = ugradio.leo.alt
    t = astropy.time.Time(time.time(), format='unix')
    l = astropy.coordinates.EarthLocation(lat=lat * u.deg,
                                          lon=lon * u.deg,
                                          height=alt * u.m)
    f = astropy.coordinates.AltAz(obstime=t, location=l)
    equinox = 'J2019'
    c = astropy.coordinates.SkyCoord(Ra,
                                     Dec,
                                     frame='fk5',
                                     unit='deg',
                                     equinox=equinox)
    altaz = c.transform_to(f)

    return altaz.alt.degree, altaz.az.degree
Ejemplo n.º 15
0
def transform_coords():

    pos = SkyCoord(ra=ra[0] * u.deg, dec=dec[0] * u.deg, frame='icrs')

    ObsStartTime = Time(times[0],
                        scale='utc',
                        format='jd',
                        location=hera_location)

    frame_2020 = FK5(equinox=Time(2020, format='jyear'))
    frame_current = FK5(equinox=ObsStartTime)
    pos_current = pos.transform_to(frame_current)
    pos_2020 = pos.transform_to(frame_2020)
    print(pos)
    print(pos_current)
    print(pos_2020)
Ejemplo n.º 16
0
def bprecess(ra, dec, epoch="J2000.0"):
    """
    WARNING: THIS WILL PROBABLY NOT WORK ASK YOU EXPECT IT.
             UNTESTED, UNVERIFIED. PLEASE REFER TO THE ORIGINAL DOCSTRING
             BELOW FOR THE EXPECTED BEHAVIOR, AS WELL AS ASTROPY.COORDINATES
             DOCUMENTATION FOR WHERE WE SHOULD GO FROM HERE.

    Given RA and Dec in degrees for a given epoch (default 2000.0), returns
    the precessed RA and Dec in degrees in B1950 coordinates (FK4)

    Example Usage:

       >>> ra = ten('4:23:43')*360/24.
       >>> dec = ten('65:42:55')
       >>> ra1950, dec1950 = jprecess(ra, dec)
       >>> print ra1950, dec1950

    @param ra: Right Ascension in degrees. Or you can give a vector or list
       of RA coordinates.
    @type ra: float in degrees
    @param dec: Declination in degrees. Or you can give a vector or list of
       Dec coordinates
    @type dec: float in degrees
    @param epoch: Scalar giving epoch of original observations, default 2000.0
    @type epoch: string or float
    @return: a tuple of RA and Dec or list of tuples (if input is a vector)
       precessed to FK4 system of B1950. Angles are in degrees.
    """
    c = SkyCoord(ra=ra, dec=dec, unit='deg', frame="fk5", equinox=epoch)
    c1950 = c.transform_to(FK5(equinox="B1950.0"))
    return (c1950.ra.degree, c1950.dec.degree)
Ejemplo n.º 17
0
 def precess(self, coord, time):
     """
     """
     timeut = time - self.fuse
     coord = self.coord_pack(coord)
     fk5_data = FK5(equinox=timeut)
     coord_prec = coord.transform_to(fk5_data)
     return coord_prec
    def precession(self, skyCoo, year):
        c = SkyCoord(ra=skyCoo[0] * u.degree, dec=skyCoo[1] * u.degree)

        c_fk5 = c.transform_to('fk5')

        c_fk5.transform_to(FK5(equinox=('J' + str(year))))

        return c_fk5
Ejemplo n.º 19
0
 def _sky_coords(self):
     """An astropy SkyCoord"""
     return SkyCoord(
         ra=np.degrees(self.point_source_pos[:, 0]) * u.deg,
         dec=np.degrees(self.point_source_pos[:, 1]) * u.deg,
         frame='fk5',
         equinox=Time(2000.0, format='jyear', scale='utc'),
     ).transform_to(FK5(equinox=self._astropy_times[0]))
Ejemplo n.º 20
0
 def update(self):
     self.t = Time.now()
     p = AltAz(az=self.az * u.deg,
               alt=self.alt * u.deg,
               obstime=self.t,
               location=self.loc).transform_to(FK5(equinox=self.t))
     self.ra = p.ra
     self.dec = p.dec
Ejemplo n.º 21
0
def compute_paral_angles(header, latitude, ra_key, dec_key, lst_key, 
                         acqtime_key, date_key='DATE-OBS'):
    """Calculates the parallactic angle for a frame, taking coordinates and
    local sidereal time from fits-headers (frames taken in an alt-az telescope 
    with the image rotator off).
    
    The coordinates in the header are assumed to be J2000 FK5 coordinates.
    The spherical trigonometry formula for calculating the parallactic angle
    is taken from Astronomical Algorithms (Meeus, 1998).
    
    Parameters
    ----------
    header : dictionary
        Header of current frame.
    latitude : float
        Latitude of the observatory in degrees. The dictionaries in 
        vip_hci/conf/param.py can be used like: latitude=LBT['latitude'].
    ra_key, dec_key, lst_key, acqtime_key, date_key : strings
        Keywords where the values are stored in the header.
        
    Returns
    -------
    pa.value : float
        Parallactic angle in degrees for current header (frame).
    """                                    
    obs_epoch = Time(header[date_key], format='iso', scale='utc')
       
    # equatorial coordinates in J2000
    ra = header[ra_key]                                                         
    dec = header[dec_key]   
    coor = sky_coordinate.SkyCoord(ra=ra, dec=dec, unit=(hourangle,degree),
                                   frame=FK5, equinox='J2000.0')
    # recalculate for DATE-OBS (precession)
    coor_curr = coor.transform_to(FK5(equinox=obs_epoch))
    
    # new ra and dec in radians
    ra_curr = coor_curr.ra                                                      
    dec_curr = coor_curr.dec
        
    lst_split = header[lst_key].split(':')
    lst = float(lst_split[0])+float(lst_split[1])/60+float(lst_split[2])/3600
    exp_delay = (header[acqtime_key] * 0.5) / 3600
    # solar to sidereal time
    exp_delay = exp_delay*1.0027                                                
    
    # hour angle in degrees
    hour_angle = (lst + exp_delay) * 15 - ra_curr.deg                           
    hour_angle = np.deg2rad(hour_angle)                                         
    latitude = np.deg2rad(latitude)                                             
    
    # PA formula from Astronomical Algorithms 
    pa = -np.rad2deg(np.arctan2(-np.sin(hour_angle), np.cos(dec_curr) * \
                 np.tan(latitude) - np.sin(dec_curr) * np.cos(hour_angle)))     
  
    #if dec_curr.value > latitude:  pa = (pa.value + 360) % 360
    
    return pa.value
Ejemplo n.º 22
0
def precess(coord, timeut):
    """
    """
    while not timeut.isscalar:
        timeut=timeut[0]
    coord = coord_pack(coord)
    fk5_data = FK5(equinox=timeut)
    coord_prec = coord.transform_to(fk5_data)
    return coord_prec
Ejemplo n.º 23
0
def get_source(name, source_list):
    if name in source_list.keys():
        ra = Angle(source_list[name][0], unit=u.hourangle)
        dec = Angle(source_list[name][1], unit=u.degree)

        source = SkyCoord(ra, dec, frame=FK5(equinox="J2000"))
        return source
    else:
        return None
Ejemplo n.º 24
0
def _wcs_to_celestial_frame_builtin(wcs):

    # Import astropy.coordinates here to avoid circular imports
    from astropy.coordinates import (FK4, FK4NoETerms, FK5, ICRS, ITRS,
                                     Galactic, SphericalRepresentation)

    # Import astropy.time here otherwise setup.py fails before extensions are compiled
    from astropy.time import Time

    if wcs.wcs.lng == -1 or wcs.wcs.lat == -1:
        return None

    radesys = wcs.wcs.radesys

    if np.isnan(wcs.wcs.equinox):
        equinox = None
    else:
        equinox = wcs.wcs.equinox

    xcoord = wcs.wcs.ctype[wcs.wcs.lng][:4]
    ycoord = wcs.wcs.ctype[wcs.wcs.lat][:4]

    # Apply logic from FITS standard to determine the default radesys
    if radesys == '' and xcoord == 'RA--' and ycoord == 'DEC-':
        if equinox is None:
            radesys = "ICRS"
        elif equinox < 1984.:
            radesys = "FK4"
        else:
            radesys = "FK5"

    if radesys == 'FK4':
        if equinox is not None:
            equinox = Time(equinox, format='byear')
        frame = FK4(equinox=equinox)
    elif radesys == 'FK4-NO-E':
        if equinox is not None:
            equinox = Time(equinox, format='byear')
        frame = FK4NoETerms(equinox=equinox)
    elif radesys == 'FK5':
        if equinox is not None:
            equinox = Time(equinox, format='jyear')
        frame = FK5(equinox=equinox)
    elif radesys == 'ICRS':
        frame = ICRS()
    else:
        if xcoord == 'GLON' and ycoord == 'GLAT':
            frame = Galactic()
        elif xcoord == 'TLON' and ycoord == 'TLAT':
            # The default representation for ITRS is cartesian, but for WCS
            # purposes, we need the spherical representation.
            frame = ITRS(representation_type=SphericalRepresentation,
                         obstime=wcs.wcs.dateobs or None)
        else:
            frame = None

    return frame
Ejemplo n.º 25
0
 def find_ha_transit(times: Time):
     """ """
     fk5 = self._get_source_coordinates(time=times).transform_to(
         FK5(equinox=times))
     ha = hour_angle(radec=fk5,
                     time=times,
                     observer=self.observer,
                     fast_compute=fast_compute)
     return np.where((np.roll(ha, shift=-1, axis=1) - ha)[:, :-1] < 0)
Ejemplo n.º 26
0
def _wcs_to_celestial_frame_builtin(wcs):

    # Import astropy.coordinates here to avoid circular imports
    from astropy.coordinates import FK4, FK4NoETerms, FK5, ICRS, ITRS, Galactic

    # Import astropy.time here otherwise setup.py fails before extensions are compiled
    from astropy.time import Time

    # Keep only the celestial part of the axes
    wcs = wcs.sub([WCSSUB_LONGITUDE, WCSSUB_LATITUDE])

    if wcs.wcs.lng == -1 or wcs.wcs.lat == -1:
        return None

    radesys = wcs.wcs.radesys

    if np.isnan(wcs.wcs.equinox):
        equinox = None
    else:
        equinox = wcs.wcs.equinox

    xcoord = wcs.wcs.ctype[0][:4]
    ycoord = wcs.wcs.ctype[1][:4]

    # Apply logic from FITS standard to determine the default radesys
    if radesys == '' and xcoord == 'RA--' and ycoord == 'DEC-':
        if equinox is None:
            radesys = "ICRS"
        elif equinox < 1984.:
            radesys = "FK4"
        else:
            radesys = "FK5"

    if radesys == 'FK4':
        if equinox is not None:
            equinox = Time(equinox, format='byear')
        frame = FK4(equinox=equinox)
    elif radesys == 'FK4-NO-E':
        if equinox is not None:
            equinox = Time(equinox, format='byear')
        frame = FK4NoETerms(equinox=equinox)
    elif radesys == 'FK5':
        if equinox is not None:
            equinox = Time(equinox, format='jyear')
        frame = FK5(equinox=equinox)
    elif radesys == 'ICRS':
        frame = ICRS()
    else:
        if xcoord == 'GLON' and ycoord == 'GLAT':
            frame = Galactic()
        elif xcoord == 'TLON' and ycoord == 'TLAT':
            frame = ITRS(obstime=wcs.wcs.dateobs or None)
        else:
            frame = None

    return frame
    def precess_JNOW_to_J2000(pos_JNOW):
        """
        Precess J2000 coordinates to JNOW

        :param SkyCoord pos_JNOW: JNow sky coordinate to precess

        :return: J2000 coordiante.
        :type: SkyCoord
        """
        return pos_JNOW.transform_to(FK5(equinox='J2000'))
Ejemplo n.º 28
0
def _get_position(header):
    obs_type = _get_obs_type(header)
    ra_deg = None
    dec_deg = None
    if obs_type in ['comparison', 'dark', 'object']:
        if header.get('EQUINOX') is not None:
            # DB - 11-09-19 - precession with astropy
            ra = header.get('RA', 0)
            dec = header.get('DEC', 0)
            equinox = f'J{header.get("EQUINOX")}'
            fk5 = FK5(equinox=equinox)
            coord = SkyCoord(f'{ra} {dec}',
                             unit=(u.hourangle, u.deg),
                             frame=fk5)
            j2000 = FK5(equinox='J2000')
            result = coord.transform_to(j2000)
            ra_deg = result.ra.degree
            dec_deg = result.dec.degree
    return ra_deg, dec_deg
Ejemplo n.º 29
0
 def __tojnow(self, coordinates, equinox):
     current_datetime = datetime.now().isoformat()
     if equinox.upper() == 'JNOW':
         return SkyCoord(ra=coordinates['ra'] * u.hour,
                         dec=coordinates['dec'] * u.deg,
                         equinox=current_datetime)
     return SkyCoord(ra=coordinates['ra'] * u.hour,
                     dec=coordinates['dec'] * u.deg,
                     equinox=equinox).transform_to(
                         FK5(equinox=current_datetime))
Ejemplo n.º 30
0
def wcsTest(dr):
    """
    HIERARCH LBTO LUCI WCS CTYPE1 = 'RA---TAN' / the coordinate type and projection 
    HIERARCH LBTO LUCI WCS CTYPE2 = 'DEC--TAN' / the coordinate type and projection 
    HIERARCH LBTO LUCI WCS CRPIX1 = 1024. / the pixel coordinates of the reference p
    HIERARCH LBTO LUCI WCS CRPIX2 = 1024. / the pixel coordinates of the reference p
    HIERARCH LBTO LUCI WCS CRVAL1 = 205.7395 / the WCS coordinates on the reference 
    HIERARCH LBTO LUCI WCS CRVAL2 = 32. / the WCS coordinates on the reference point
    HIERARCH LBTO LUCI WCS CD1_1 = -3.3E-05 / the rotation matrix for scaling and ro
    HIERARCH LBTO LUCI WCS CD1_2 = 0. / the rotation matrix for scaling and rotation
    HIERARCH LBTO LUCI WCS CD2_1 = 0. / the rotation matrix for scaling and rotation
    HIERARCH LBTO LUCI WCS CD2_2 = 3.3E-05 / the rotation matrix for scaling and rot
    TELRA   = '07 38 9.002'        / Telescope Right Accention
    TELDEC  = '+38 53 11.504'      / Telescope Declination
    OBJRA   = '07 38 9.002'        / Target Right Ascension from preset
    OBJDEC  = '+38 53 11.504'      / Target Declination from preset
    OBJRADEC= 'FK5     '           / Target Coordinate System
    OBJEQUIN= 'J2000   '           / Target Coordinate System Equinox
    OBJPMRA =                   0. / Target RA proper motion [mas per yr]
    OBJPMDEC=                   0. / Target DEC proper motion [mas per yr]
    OBJEPOCH=                2000. / Target Epoch
    GUIRA   = '07 38 19.187'       / Guide Star RA
    GUIDEC  = '+38 55 15.648'      / Guide Star DEC
    AONAME  = 'N1288-0180843'      / AO Star Name
    AORA    = '07 38 15.702'       / AO Star RA
    AODEC   = '+38 53 33.108'      / AO Star DEC
    """
    import astropy.units as u
    from astropy import wcs
    from astropy.coordinates import SkyCoord, FK5

    sciences = dr._scienceIma
    ccd0 = sciences[0]
    hdr0 = ccd0.header
    ccd0wcs = wcs.WCS(hdr0)
    pxs = np.array([[0, 0], [1024, 1024], [512, 1024]], np.float)
    ccd0wcs.all_pix2world(pxs, 1)

    px = np.arange(ccd0.shape[1])
    py = np.arange(ccd0.shape[0])
    wx, wy = ccd0wcs.all_pix2world(px, py, 1)

    if hdr0['OBJRADEC'] == 'FK5':
        frameType = FK5()
    c = SkyCoord(ccd0.header['OBJRA'],
                 ccd0.header['OBJDEC'],
                 frame=frameType,
                 unit=(u.hourangle, u.deg))

    # AO guide star. Find it in image
    aoStarCoordW = SkyCoord(ccd0.header['AORA'],
                            ccd0.header['AODEC'],
                            frame=frameType,
                            unit=(u.hourangle, u.deg))
    aoStarCoordPx = ccd0wcs.world_to_pixel(aoStarCoordW)