예제 #1
0
파일: bounds.py 프로젝트: schlafly/lsd
def rectangle(lon0, lat0, lon1, lat1, coordsys="equ"):
    """
	Return a polygon (in bhpix projection) corresponding to the
	requested lon/lat rectangle.
	"""
    if lon0 > lon1:
        lon1 = lon1 + 360

        # Generate CCW rectangle bounded by great circles
        # nsplit = int(round((lon1 - lon0) / 0.1) + 1)
        # lon = np.linspace(lon0, lon1, nsplit)
        # lon = np.concatenate((lon, lon[::-1]))
        # lat = [lat0] * nsplit + [lat1]*nsplit

        # Generate a well sampled CCW rectangle
    nlon = max(int(round((lon1 - lon0) / 0.1) + 1), 10)
    nlat = max(int(round((lat1 - lat0) / 0.1) + 1), 10)
    vlon0 = np.linspace(lon0, lon1, nlon)
    vlon1 = vlon0[::-1]
    vlat0 = np.linspace(lat0, lat1, nlat)
    vlat1 = vlat0[::-1]
    lon = np.concatenate((vlon0, [lon1] * nlat, list(vlon1), [lon0] * nlat))
    lat = np.concatenate(([lat0] * nlon, list(vlat0), [lat1] * nlon, list(vlat1)))

    # transform it from the desired coordinate system
    if coordsys == "gal":
        for i in xrange(len(lon)):
            (lon[i], lat[i]) = np.degrees(sla_galeq(np.radians(lon[i]), np.radians(lat[i])))
    elif coordsys == "equ":
        pass
    else:
        raise Exception("Unknown coordinate system")

    return make_healpix_poly(lon, lat)
예제 #2
0
    def get_vobs(self, mjdtmp, xtmp, ytmp, mode, offx, offy, dcos, offmode):
        if offmode == self.coord_dict["SAME"] | offmode == mode :
            ytmp += offy
            if dcos == 0 :
                xtmp += offx
            else :
                xtmp += offx/math.cos(ytmp)
        else :
            print("error coord != off_coord")
            pass
        if mode == self.coord_dict["J2000"] :
            xxtmp = xtmp
            yytmp = ytmp
        elif mode == self.coord_dict["B1950"] :
            ret = slalib.sla_fk45z(xtmp, ytmp, 1950)
            xxtmp = ret[0]
            yytmp = ret[1]
        elif mode == self.coord_dict["LB"] :
            ret = slalib.sla_galeq(xtmp, ytmp)
            xxtmp = ret[0]
            yytmp = ret[1]
        else :
            xxtmp = xtmp
            yytmp = ytmp

        vobs = self.calc_vobs(mjdtmp+2400000.5, xxtmp, yytmp)
        return vobs
예제 #3
0
 def move_lb(self, gx, gy, temp, pressure, humid, lamda, dcos, hosei = 'hosei_230.txt', off_coord = "HORIZONTAL", off_x = 0, off_y = 0, az_max_rate=16000, el_max_rate=12000):
     if off_x != 0 or off_y != 0: # for test
         self.set_offset(off_coord, off_x, off_y)
     if dcos == 0:
         gy += self.off_list["off_b"]/3600.*math.pi/180
         gx += self.off_list["off_l"]/3600.*math.pi/180
     else:
         gy += self.off_list["off_b"]/3600.*math.pi/180
         gx = gx+(self.off_list["off_l"]/3600.*math.pi/180)/math.cos(gy)
     
     ret = slalib.sla_galeq(gx, gy)
     """
     gaJ2000 = ret[0]
     gdj2000 = ret[1]
     gpaJ2000 = gpdJ2000 = 0
     """
     
     track = self.move_radec(ret[0], ret[1], 0, 0, "J2000", temp, pressure, humid, lamda, dcos, hosei, az_max_rate=az_max_rate, el_max_rate=el_max_rate, off_coord=off_coord, off_x=off_x, off_y=off_y)
     return track
 def move_lb(self, gx, gy, temp, pressure, humid, lamda, dcos, hosei = 'hosei_230.txt', off_coord = "HORIZONTAL", off_x = 0, off_y = 0, az_max_rate=16000, el_max_rate=12000):
     if off_x != 0 or off_y != 0: # for test
         self.set_offset(off_coord, off_x, off_y)
     if dcos == 0:
         gy += self.off_list["off_b"]/3600.*math.pi/180
         gx += self.off_list["off_l"]/3600.*math.pi/180
     else:
         gy += self.off_list["off_b"]/3600.*math.pi/180
         gx = gx+(self.off_list["off_l"]/3600.*math.pi/180)/math.cos(gy)
     
     ret = slalib.sla_galeq(gx, gy)
     """
     gaJ2000 = ret[0]
     gdj2000 = ret[1]
     gpaJ2000 = gpdJ2000 = 0
     """
     
     track = self.move_radec(ret[0], ret[1], 0, 0, "J2000", temp, pressure, humid, lamda, dcos, hosei, az_max_rate=az_max_rate, el_max_rate=el_max_rate, off_coord=off_coord, off_x=off_x, off_y=off_y)
     return track
예제 #5
0
 def get_vobs(self, mjdtmp, xtmp, ytmp, mode, offx, offy, dcos, offmode):
     #modeを見て、j2000へ座標変換してる
     mode = mode.lower()
     offmode = offmode.lower()
     mode = self.coord_dict[mode]
     offmode = self.coord_dict[offmode]
     if offmode == self.coord_dict["same"]:
         ytmp += offy
         if dcos == 0:
             xtmp += offx
         else:
             xtmp += offx / math.cos(ytmp)
     elif offmode == mode:
         ytmp += offy
         if dcos == 0:
             xtmp += offx
         else:
             xtmp += offx / math.cos(ytmp)
     else:
         print("error coord != off_coord")
         pass
     if mode == self.coord_dict["j2000"]:
         xxtmp = xtmp
         yytmp = ytmp
     elif mode == self.coord_dict["b1950"]:
         ret = slalib.sla_fk45z(xtmp, ytmp, 1950)
         xxtmp = ret[0]
         yytmp = ret[1]
     elif mode == self.coord_dict["lb"] or mode == self.coord_dict[
             "galactic"] or mode == self.coord_dict["gal"]:
         ret = slalib.sla_galeq(xtmp, ytmp)
         xxtmp = ret[0]
         yytmp = ret[1]
     else:
         xxtmp = xtmp
         yytmp = ytmp
     print(xxtmp, yytmp)
     print(xxtmp / 3600.)
     print(xxtmp * 360. / 2 * 3.14)
     vobs = self.calc_vobs(mjdtmp + 2400000.5, xxtmp, yytmp)
     print('vobs', vobs, type(vobs))
     return vobs
예제 #6
0
파일: bounds.py 프로젝트: schlafly/lsd
def beam(lon0, lat0, radius=1.0, coordsys="equ", npts=360):
    """
	Return a polygon (in bhpix projection) corresponding to the
	requested lon/lat/radius beam.
	"""
    # transform from the desired coordinate system to equatorial
    if coordsys == "gal":
        lon0, lat0 = degrees(sla_galeq(radians(lon0), radians(lat0)))
    elif coordsys == "equ":
        pass
    else:
        raise Exception("Unknown coordinate system")

    r, _ = lambert_proj(0, 90 - radius, 270, 90)  # Obtain beam radius in Lambert coordinates
    phi = np.linspace(
        0, 2 * pi, npts, endpoint=False
    )  # Construct the polygon (approximating a circle, when npts is large)
    x, y = r * cos(phi), r * sin(phi)  #
    l, b = lambert_deproj(x, y, lon0, lat0)  # Deproject to circle on the sky

    return make_healpix_poly(l, b)
예제 #7
0
def transform_celestial(coords, systems):
    lons, lats = np.radians(coords['lon']), np.radians(coords['lat'])

    out = Table()
    out['lon'] = np.zeros(len(coords), dtype='float64')
    out['lat'] = np.zeros(len(coords), dtype='float64')

    for ii, (lon, lat) in enumerate(zip(lons, lats)):

        # First convert to FK5 J2000 in all cases
        if systems['in'] == 'fk4':
            lon, lat = slalib.sla_fk45z(lon, lat, 2000.0012775136652)
        elif systems['in'] == 'icrs':
            lon, lat = slalib.sla_hfk5z(lon, lat, 2000)[:2]
        elif systems['in'] == 'galactic':
            lon, lat = slalib.sla_galeq(lon, lat)
        elif systems['in'] == 'ecliptic':
            lon, lat = slalib.sla_ecleq(lon, lat, 51544)

        # Now convert from FK5 J2000 to out system    
        if systems['out'] == 'fk4':
            # FK5 -> FK4 at BEPOCH 2000 assuming no proper motion or parallax
            lon, lat = slalib.sla_fk54z(lon, lat, 2000.0012775136652)[:2]
        elif systems['out'] == 'icrs':
            # FK5 -> Hipparcos (i.e. ICRF, which is as close as SLALIB
            # gets to ICRS) at epoch 2000 and with no proper motion
            lon, lat = slalib.sla_fk5hz(lon, lat, 2000)
        elif systems['out'] == 'galactic':
            # FK5 -> Galactic
            lon, lat = slalib.sla_eqgal(lon, lat)
        elif systems['out'] == 'ecliptic':
            # FK5 -> Ecliptic at TDB (MJD) 51544 (i.e. J2000)
            lon, lat = slalib.sla_eqecl(lon, lat, 51544)

        out[ii]['lon'] = np.degrees(lon)
        out[ii]['lat'] = np.degrees(lat)

    return out
예제 #8
0
def transform_celestial(coords, systems):
    lons, lats = np.radians(coords['lon']), np.radians(coords['lat'])

    out = Table()
    out['lon'] = np.zeros(len(coords), dtype='float64')
    out['lat'] = np.zeros(len(coords), dtype='float64')

    for ii, (lon, lat) in enumerate(zip(lons, lats)):

        # First convert to FK5 J2000 in all cases
        if systems['in'] == 'fk4':
            lon, lat = slalib.sla_fk45z(lon, lat, 2000.0012775136652)
        elif systems['in'] == 'icrs':
            lon, lat = slalib.sla_hfk5z(lon, lat, 2000)[:2]
        elif systems['in'] == 'galactic':
            lon, lat = slalib.sla_galeq(lon, lat)
        elif systems['in'] == 'ecliptic':
            lon, lat = slalib.sla_ecleq(lon, lat, 51544)

        # Now convert from FK5 J2000 to out system
        if systems['out'] == 'fk4':
            # FK5 -> FK4 at BEPOCH 2000 assuming no proper motion or parallax
            lon, lat = slalib.sla_fk54z(lon, lat, 2000.0012775136652)[:2]
        elif systems['out'] == 'icrs':
            # FK5 -> Hipparcos (i.e. ICRF, which is as close as SLALIB
            # gets to ICRS) at epoch 2000 and with no proper motion
            lon, lat = slalib.sla_fk5hz(lon, lat, 2000)
        elif systems['out'] == 'galactic':
            # FK5 -> Galactic
            lon, lat = slalib.sla_eqgal(lon, lat)
        elif systems['out'] == 'ecliptic':
            # FK5 -> Ecliptic at TDB (MJD) 51544 (i.e. J2000)
            lon, lat = slalib.sla_eqecl(lon, lat, 51544)

        out[ii]['lon'] = np.degrees(lon)
        out[ii]['lat'] = np.degrees(lat)

    return out
예제 #9
0
def convert(coords, systems):
    
    if not set(systems.values()).issubset(SUPPORTED_SYSTEMS):
        return None

    lons, lats = np.radians(coords['lon']), np.radians(coords['lat'])

    for ii, (lon, lat) in enumerate(zip(lons, lats)):

        # First convert to FK5 J2000 in all cases
        if systems['in'] == 'fk4':
            lon, lat = slalib.sla_fk45z(lon, lat, 2000.0012775136652)
        elif systems['in'] == 'icrs':
            lon, lat = slalib.sla_hfk5z(lon, lat, 2000)[:2]
        elif systems['in'] == 'galactic':
            lon, lat = slalib.sla_galeq(lon, lat)
        elif systems['in'] == 'ecliptic':
            lon, lat = slalib.sla_ecleq(lon, lat, 51544)
        
        # Now convert from FK5 J2000 to out system    
        if systems['out'] == 'fk4':
            # FK5 -> FK4 at BEPOCH 2000 assuming no proper motion or parallax
            lon, lat = slalib.sla_fk54z (lon, lat, 2000.0012775136652)[:2]
        elif systems['out'] == 'icrs':
            # FK5 -> Hipparcos (i.e. ICRF, which is as close as SLALIB
            # gets to ICRS) at epoch 2000 and with no proper motion
            lon, lat = slalib.sla_fk5hz(lon, lat, 2000)
        elif systems['out'] == 'galactic':
            # FK5 -> Galactic
            lon, lat = slalib.sla_eqgal(lon, lat)
        elif systems['out'] == 'ecliptic':
            # FK5 -> Ecliptic at TDB (MJD) 51544 (i.e. J2000)
            lon, lat = slalib.sla_eqecl(lon, lat, 51544)

        lons[ii], lats[ii] = lon, lat

    return dict(lon=np.degrees(lons), lat=np.degrees(lats))
예제 #10
0
    def get_vobs(self, mjdtmp, xtmp, ytmp, mode, offx, offy, dcos, offmode):

        mode = mode.lower()
        offmode = offmode.lower()
        ### for 'coord == horizontal' skip
        try:
            mode = self.coord_dict[mode]
        except:
            xxtmp = xtmp
            yytmp = ytmp
        try:
            offmode = self.coord_dict[offmode]
        except:
            xxtmp = xtmp
            yytmp = ytmp

        if mode == 1:  #j2000
            if offmode == 0 or offmode == 1:  #same or j2000
                yytmp = ytmp + offy
                if dcos == 0:
                    xxtmp = xtmp + offx
                else:
                    xxtmp = xtmp + offx / math.cos(yytmp)

            elif offmode == 2:  #b1950
                ret = slalib.sla_fk54z(xtmp, ytmp, 2000)
                xtmp_b = ret[0]
                ytmp_b = ret[1]
                ytmp_b += offy
                if dcos == 0:
                    xtmp_b += offx
                else:
                    xtmp_b += offx / math.cos(ytmp_b)
                ret_1 = slalib.sla_fk45z(xtmp_b, ytmp_b, 1950)
                xxtmp = ret_1[0]
                yytmp = ret_1[1]

            elif offmode == 3:  #lb,galactic,gal
                ret = slalib.sla_eqgal(xtmp, ytmp)
                xtmp_g = ret[0]
                ytmp_g = ret[1]
                ytmp_g += offy
                if dcos == 0:
                    xtmp_g += offx
                else:
                    xtmp_g += offx / math.cos(ytmp_g)
                ret_1 = slalib.sla_galeq(xtmp_g, ytmp_g)
                xxtmp = ret_1[0]
                yytmp = ret_1[1]

        if mode == 2:  #b1950
            if offmode == 1:  #j2000
                ret = slalib.sla_fk45z(xtmp, ytmp, 1950)
                xtmp_j = ret[0]
                ytmp_j = ret[1]
                yytmp = ytmp_j + offy
                if dcos == 0:
                    xxtmp = xtmp_j + offx
                else:
                    xxtmp = xtmp_j + offx / math.cos(ytmp_j)

            elif offmode == 2 or offmode == 0:  #b1950
                ytmp += offy
                if dcos == 0:
                    xtmp += offx
                else:
                    xtmp += offx / math.cos(ytmp)
                ret = slalib.sla_fk45z(xtmp, ytmp, 1950)
                xxtmp = ret[0]
                yytmp = ret[1]

            elif offmode == 3:  #lb,galactic,gal
                ret = slalib.sla_eg50(xtmp, ytmp)
                xtmp_g = ret[0]
                ytmp_g = ret[1]
                ytmp_g += offy
                if dcos == 0:
                    xtmp_g += offx
                else:
                    xtmp_g += offx / math.cos(ytmp_g)
                ret = slalib.sla_galeq(xtmp_g, ytmp_g)
                xxtmp = ret[0]
                yytmp = ret[1]

        if mode == 3:  #lb,galactic,gal
            if offmode == 1:  #j2000
                ret_2 = slalib.sla_galeq(xtmp, ytmp)
                xtmp_j = ret_2[0]
                ytmp_j = ret_2[1]
                yytmp = ytmp_j + offy
                if dcos == 0:
                    xxtmp = xtmp_j + offx
                else:
                    xxtmp = xtmp_j + offx / math.cos(ytmp_j)

            elif offmode == 2:  #b1950
                ret = slalib.sla_ge50(xtmp, ytmp)
                xtmp_b = ret[0]
                ytmp_b = ret[1]
                ytmp_b += offy
                if dcos == 0:
                    xtmp_b += offx
                else:
                    xtmp_b += offx / math.cos(ytmp_b)
                ret = slalib.sla_fk45z(xtmp_b, ytmp_b, 1950)
                xxtmp = ret[0]
                yytmp = ret[1]

            elif offmode == 0 or offmode == 3:  #gal,lb,galactic
                ytmp += offy
                if dcos == 0:
                    xtmp += offx
                else:
                    xtmp += offx / math.cos(ytmp)
                ret = slalib.sla_galeq(xtmp, ytmp)
                xxtmp = ret[0]
                yytmp = ret[1]

        vobs = self.calc_vobs(mjdtmp + 2400000.5, xxtmp, yytmp)
        #print('vobs',vobs,type(vobs))
        return vobs
예제 #11
0
    def get_vobs(self, mjdtmp, xtmp, ytmp, mode, offx, offy, dcos, offmode):

        mode = mode.lower()
        offmode = offmode.lower()
        mode = self.coord_dict[mode]
        offmode = self.coord_dict[offmode]
        #if offmode == self.coord_dict["same"]:
        #ytmp += offy
        #if dcos == 0 :
        #xtmp += offx
        #else :
        #xtmp += offx/math.cos(ytmp)
        #elif offmode == mode :
        #ytmp += offy
        #if dcos == 0 :
        #xtmp += offx
        #else :
        #xtmp += offx/math.cos(ytmp)
        #else :
        #print("error coord != off_coord")
        #pass
        if mode == self.coord_dict["j2000"]:
            xtmp = xtmp
            ytmp = ytmp
        elif mode == self.coord_dict["b1950"]:
            ret = slalib.sla_fk45z(xtmp, ytmp, 1950)
            xtmp = ret[0]
            ytmp = ret[1]
        elif mode == self.coord_dict["lb"]:
            ret = slalib.sla_galeq(xtmp, ytmp)
            xtmp = ret[0]
            ytmp = ret[1]
        elif mode == self.coord_dict["galactic"]:
            ret = slalib.sla_galeq(xtmp, ytmp)
            xtmp = ret[0]
            ytmp = ret[1]
        elif mode == self.coord_dict["gal"]:
            ret = slalib.sla_galeq(xtmp, ytmp)
            xtmp = ret[0]
            ytmp = ret[1]
        else:
            print("error coord !")  #
            #xxtmp = xtmp
            #yytmp = ytmp
        if offmode == self.coord_dict["j2000"]:
            offx = offx
            offy = offy
        elif offmode == self.coord_dict["b1950"]:
            ret = slalib.sla_fk45z(offx, offy, 1950)
            offx = ret[0]
            offy = ret[1]
        elif offmode == self.coord_dict["lb"]:
            ret = slalib.sla_galeq(offx, offy)
            offx = ret[0]
            offy = ret[1]
        elif offmode == self.coord_dict["galactic"]:
            ret = slalib.sla_galeq(offx, offy)
            offx = ret[0]
            offy = ret[1]
        elif offmode == self.coord_dict["gal"]:
            ret = slalib.sla_galeq(offx, offy)
            offx = ret[0]
            offy = ret[1]
        else:  #horizontal
            offx = 0
            offy = 0
        ytmp += offy
        if dcos == 0:
            xtmp += offx
        elif dcos == 1:
            xtmp += offx / math.cos(ytmp)

        vobs = self.calc_vobs(mjdtmp + 2400000.5, xtmp, ytmp)
        print('vobs', vobs, type(vobs))
        return vobs
예제 #12
0
    def get_vobs(self, mjdtmp, xtmp, ytmp, mode, offx, offy, dcos, offmode):

        mode = mode.lower()
        offmode = offmode.lower()
        ### for 'coord == horizontal' skip
        try :
            mode = self.coord_dict[mode]
        except:
            xxtmp = xtmp
            yytmp = ytmp
        try:
            offmode = self.coord_dict[offmode]
        except:
            xxtmp = xtmp
            yytmp = ytmp

        if mode == 1:#j2000
            if offmode == 0 or offmode == 1:#same or j2000
                yytmp = ytmp+offy
                if dcos == 0 :
                    xxtmp = xtmp+offx
                else :  
                    xxtmp = xtmp+offx/math.cos(yytmp)
                    
            elif offmode == 2:#b1950
                ret = slalib.sla_fk54z(xtmp, ytmp, 2000)
                xtmp_b = ret[0]
                ytmp_b = ret[1]
                ytmp_b += offy
                if dcos == 0 :
                    xtmp_b += offx
                else :
                    xtmp_b += offx/math.cos(ytmp_b)
                ret_1 = slalib.sla_fk45z(xtmp_b, ytmp_b,1950)
                xxtmp = ret_1[0]
                yytmp = ret_1[1]
                
            elif offmode == 3:#lb,galactic,gal
                ret = slalib.sla_eqgal(xtmp,ytmp)
                xtmp_g = ret[0]
                ytmp_g = ret[1]
                ytmp_g += offy
                if dcos == 0 :
                    xtmp_g += offx
                else :
                    xtmp_g += offx/math.cos(ytmp_g)
                ret_1 = slalib.sla_galeq(xtmp_g, ytmp_g)
                xxtmp = ret_1[0]
                yytmp = ret_1[1]
                
        if mode == 2:#b1950
            if offmode == 1:#j2000
                ret = slalib.sla_fk45z(xtmp, ytmp, 1950)
                xtmp_j = ret[0]
                ytmp_j = ret[1]
                yytmp = ytmp_j+offy
                if dcos == 0 :
                    xxtmp = xtmp_j+offx
                else :  
                    xxtmp = xtmp_j+offx/math.cos(ytmp_j)
                    
            elif offmode == 2 or offmode ==0:#b1950
                ytmp += offy
                if dcos == 0 :
                    xtmp += offx
                else:   
                    xtmp += offx/math.cos(ytmp)
                ret = slalib.sla_fk45z(xtmp, ytmp, 1950)
                xxtmp = ret[0]
                yytmp = ret[1]
                
            elif offmode == 3:#lb,galactic,gal
                ret = slalib.sla_eg50(xtmp,ytmp)
                xtmp_g = ret[0]
                ytmp_g = ret[1]
                ytmp_g += offy
                if dcos == 0 :
                    xtmp_g += offx
                else :  
                    xtmp_g += offx/math.cos(ytmp_g)
                ret = slalib.sla_galeq(xtmp_g, ytmp_g)
                xxtmp = ret[0]
                yytmp = ret[1]
                
        if mode == 3:#lb,galactic,gal
            if offmode == 1:#j2000
                ret_2 = slalib.sla_galeq(xtmp, ytmp)
                xtmp_j = ret_2[0]
                ytmp_j = ret_2[1]
                yytmp = ytmp_j+offy
                if dcos == 0 :
                    xxtmp = xtmp_j+offx
                else :
                    xxtmp = xtmp_j+offx/math.cos(ytmp_j)
                    
            elif offmode == 2:#b1950
                ret = slalib.sla_ge50(xtmp,ytmp)
                xtmp_b = ret[0]
                ytmp_b = ret[1]
                ytmp_b += offy
                if dcos == 0 :
                    xtmp_b += offx
                else :  
                    xtmp_b += offx/math.cos(ytmp_b)
                ret = slalib.sla_fk45z(xtmp_b, ytmp_b, 1950)
                xxtmp = ret[0]
                yytmp = ret[1]
                    
            elif offmode == 0 or offmode == 3:#gal,lb,galactic
                ytmp += offy
                if dcos == 0 :
                    xtmp += offx
                else :  
                    xtmp += offx/math.cos(ytmp)
                ret = slalib.sla_galeq(xtmp, ytmp)
                xxtmp = ret[0]
                yytmp = ret[1]
                
        vobs = self.calc_vobs(mjdtmp+2400000.5, xxtmp, yytmp)
        #print('vobs',vobs,type(vobs))
        return vobs