예제 #1
0
    def create_moc(self):
        """Creating a MOC map from the contour_ipix table."""

        self.moc = MOC.from_table(self.contour_ipix, 'RA[deg]', 'DEC[deg]',
                                  self.moc_order)

        return self.moc
예제 #2
0
파일: moc.py 프로젝트: tahumada/gwemopt
def Fov2Moc(params, config_struct, telescope, ra_pointing, dec_pointing, nside):
    """Return a MOC in fits file of a fov footprint.
       The MOC fov is displayed in real time in an Aladin plan.

       Input:
           ra--> right ascention of fov center [deg]
           dec --> declination of fov center [deg]
           fov_width --> fov width [deg]
           fov_height --> fov height [deg]
           nside --> healpix resolution; by default 
           """

    moc_struct = {}
    
    if config_struct["FOV_type"] == "square": 
        ipix, radecs, patch, area = gwemopt.utils.getSquarePixels(ra_pointing, dec_pointing, config_struct["FOV"], nside)
    elif config_struct["FOV_type"] == "circle":
        ipix, radecs, patch, area = gwemopt.utils.getCirclePixels(ra_pointing, dec_pointing, config_struct["FOV"], nside)

    if params["doChipGaps"]:
        npix = hp.nside2npix(nside)
        pixel_index = np.arange(npix)
        RAs, Decs = hp.pix2ang(nside, pixel_index, lonlat=True, nest=False)

        if telescope == "ZTF":
            Z = gwemopt.quadrants.ZTFtile(ra_pointing, dec_pointing, config_struct)
            #ipix = np.where(Z.inside_nogaps(RAs, Decs))[0]  # Ignore chip gaps
            ipix = np.where(Z.inside(RAs, Decs))[0]
        else:
            raise ValueError("Requested chip gaps with non-ZTF detector, failing.")

    moc_struct["ra"] = ra_pointing
    moc_struct["dec"] = dec_pointing
    moc_struct["ipix"] = ipix
    moc_struct["corners"] = radecs
    moc_struct["patch"] = patch
    moc_struct["area"] = area

    if False:
    #if len(ipix) > 0:
        # from index to polar coordinates
        theta, phi = hp.pix2ang(nside, ipix)

        # converting these to right ascension and declination in degrees
        ra = np.rad2deg(phi)
        dec = np.rad2deg(0.5 * np.pi - theta)

        box_ipix = Table([ra, dec], names = ('RA[deg]', 'DEC[deg]'),
                 meta = {'ipix': 'ipix table'})

        moc_order = int(np.log(nside)/ np.log(2))
        moc = MOC.from_table( box_ipix, 'RA[deg]', 'DEC[deg]', moc_order )

        moc_struct["moc"] = moc
    else:
        moc_struct["moc"] = []

    return moc_struct
예제 #3
0
파일: moc.py 프로젝트: ishuihan/gwemopt
def Fov2Moc(config_struct, ra_pointing, dec_pointing, nside):
    """Return a MOC in fits file of a fov footprint.
       The MOC fov is displayed in real time in an Aladin plan.

       Input:
           ra--> right ascention of fov center [deg]
           dec --> declination of fov center [deg]
           fov_width --> fov width [deg]
           fov_height --> fov height [deg]
           nside --> healpix resolution; by default 
           """

    moc_struct = {}
    
    if config_struct["FOV_type"] == "square": 
        ipix, radecs, patch, area = gwemopt.utils.getSquarePixels(ra_pointing, dec_pointing, config_struct["FOV"], nside)
    elif config_struct["FOV_type"] == "circle":
        ipix, radecs, patch, area = gwemopt.utils.getCirclePixels(ra_pointing, dec_pointing, config_struct["FOV"], nside)

    moc_struct["ra"] = ra_pointing
    moc_struct["dec"] = dec_pointing
    moc_struct["ipix"] = ipix
    moc_struct["corners"] = radecs
    moc_struct["patch"] = patch
    moc_struct["area"] = area

    if False:
    #if len(ipix) > 0:
        # from index to polar coordinates
        theta, phi = hp.pix2ang(nside, ipix)

        # converting these to right ascension and declination in degrees
        ra = np.rad2deg(phi)
        dec = np.rad2deg(0.5 * np.pi - theta)

        box_ipix = Table([ra, dec], names = ('RA[deg]', 'DEC[deg]'),
                 meta = {'ipix': 'ipix table'})

        moc_order = int(np.log(nside)/ np.log(2))
        moc = MOC.from_table( box_ipix, 'RA[deg]', 'DEC[deg]', moc_order )

        moc_struct["moc"] = moc
    else:
        moc_struct["moc"] = []

    return moc_struct
예제 #4
0
    def from_ipixs_to_moc(self, time_input):
        """Return ipix table with the associated airmass"""

        prob = self.moc.read_prob(self.user.get_skymap())
        percentage = float(self.entry_percentage.get()) / 100.0
        ipixs = self.moc.ipixs_in_percentage(prob, percentage)
        nside = int(self.user.get_nside())
        ra, dec = self.moc.sky_coords(ipixs, nside)

        sky_coord = SkyCoord(ra=ra * u.deg, dec=dec * u.deg, frame='icrs')
        altaz = sky_coord.transform_to(
            AltAz(obstime=time_input, location=self.observatory))
        airmass_values = altaz.secz

        contour_ipix = Table([ra, dec, airmass_values, ipixs],
                             names=('RA[deg]', 'DEC[deg]', 'airmass', 'ipix'),
                             meta={'ipix': 'ipix table'})  # astropy table

        mask = (contour_ipix['airmass']) >= 1  # clearing
        obs1 = contour_ipix[mask]

        mask2 = (obs1['airmass']) <= float(
            self.entry_airmass.get())  # airmass user values
        obs = obs1[mask2]

        # test
        print obs

        nside = self.user.get_nside()

        if len(obs) == 0:
            tkMessageBox.showinfo('MOC visibility',
                                  'No region for the selected  airmass')
        else:
            moc_order = self.moc.moc_order(nside)
            moc = MOC.from_table(obs, 'RA[deg]', 'DEC[deg]',
                                 moc_order)  # moc creation
            moc.write('obs_airmass_', format='fits')  # fit file

            return aladin.send_file('obs_airmass_')
    def from_ipixs_to_moc(self, time_input):
        """Return ipix table with the associated airmass"""

        prob = self.moc.read_prob(self.user.get_skymap())       
        percentage = float(self.entry_percentage.get())/100.0    
        ipixs = self.moc.ipixs_in_percentage(prob, percentage )
        nside = int(self.user.get_nside())       
        ra, dec = self.moc.sky_coords(ipixs, nside)
        
        sky_coord = SkyCoord(ra = ra*u.deg,dec=dec*u.deg, frame='icrs')
        altaz = sky_coord.transform_to(AltAz(obstime=time_input, location=self.observatory))
        airmass_values = altaz.secz
        
        contour_ipix = Table([ ra, dec, airmass_values, ipixs ],
                             names = ('RA[deg]', 'DEC[deg]', 'airmass', 'ipix'),
                             meta = {'ipix': 'ipix table'})             # astropy table       

        mask = (contour_ipix['airmass']) >= 1 # clearing
        obs1 = contour_ipix[mask]

        mask2 = (obs1['airmass']) <= float(self.entry_airmass.get())  # airmass user values
        obs = obs1[mask2]

        # test
        print obs
        
        nside = self.user.get_nside()

        if len(obs)==0:
            tkMessageBox.showinfo('MOC visibility',
                                  'No region for the selected  airmass')
        else:
            moc_order = self.moc.moc_order(nside)
            moc = MOC.from_table( obs, 'RA[deg]', 'DEC[deg]',
                                  moc_order )                # moc creation
            moc.write( 'obs_airmass_', format = 'fits' )     # fit file
            
            return aladin.send_file('obs_airmass_')
예제 #6
0
def Fov2Moc(params, config_struct, telescope, ra_pointing, dec_pointing,
            nside):
    """Return a MOC in fits file of a fov footprint.
       The MOC fov is displayed in real time in an Aladin plan.

       Input:
           ra--> right ascention of fov center [deg]
           dec --> declination of fov center [deg]
           fov_width --> fov width [deg]
           fov_height --> fov height [deg]
           nside --> healpix resolution; by default 
           """

    moc_struct = {}

    if "rotation" in params:
        rotation = params["rotation"]
    else:
        rotation = None

    if config_struct["FOV_type"] == "square":
        ipix, radecs, patch, area = gwemopt.utils.getSquarePixels(
            ra_pointing,
            dec_pointing,
            config_struct["FOV"],
            nside,
            rotation=rotation)
    elif config_struct["FOV_type"] == "circle":
        ipix, radecs, patch, area = gwemopt.utils.getCirclePixels(
            ra_pointing,
            dec_pointing,
            config_struct["FOV"],
            nside,
            rotation=rotation)

    if params["doChipGaps"]:
        if telescope == "ZTF":
            ipixs = gwemopt.ztf_tiling.get_quadrant_ipix(
                nside, ra_pointing, dec_pointing)
            ipix = list({y for x in ipixs for y in x})
        elif telescope == "DECam":
            ipixs = gwemopt.decam_tiling.get_quadrant_ipix(
                nside, ra_pointing, dec_pointing)
            ipix = list({y for x in ipixs for y in x})
        #else:
        #    print("Requested chip gaps with non-ZTF detector, will use moc.")

    moc_struct["ra"] = ra_pointing
    moc_struct["dec"] = dec_pointing
    moc_struct["ipix"] = ipix
    moc_struct["corners"] = radecs
    moc_struct["patch"] = patch
    moc_struct["area"] = area

    if False:
        #if len(ipix) > 0:
        # from index to polar coordinates
        theta, phi = hp.pix2ang(nside, ipix)

        # converting these to right ascension and declination in degrees
        ra = np.rad2deg(phi)
        dec = np.rad2deg(0.5 * np.pi - theta)

        box_ipix = Table([ra, dec],
                         names=('RA[deg]', 'DEC[deg]'),
                         meta={'ipix': 'ipix table'})

        moc_order = int(np.log(nside) / np.log(2))
        moc = MOC.from_table(box_ipix, 'RA[deg]', 'DEC[deg]', moc_order)

        moc_struct["moc"] = moc
    else:
        moc_struct["moc"] = []

    return moc_struct
    def moc_obs(self):
        """Creating a MOC region in which the airmass is less than a value defined by users."""

        percentage = float(self.entry_percentage.get())/100.0

        hpx = hp.read_map(self.user.get_skymap(), verbose = False)
        
        sort = sorted(hpx, reverse = True)
        cumsum = np.cumsum(sort)
        index, value = min(enumerate(cumsum), key = lambda x: abs(x[1] - percentage))
        value = round(value, 1) # value --> threshold
        print percentage
        print index, value

        # finding ipix indices confined in a given percentage 
        index_hpx = range(0, len(hpx))
        hpx_index = np.c_[hpx, index_hpx]

        sort_2array = sorted(hpx_index, key = lambda x: x[0], reverse = True)
        value_contour = sort_2array[0:index]

        j = 1 
        table_ipix_contour = [ ]

        for i in range (0, len(value_contour)):
            ipix_contour = int(value_contour[i][j])
            table_ipix_contour.append(ipix_contour)
          
     
        # from index to polar coordinates
        theta, phi = hp.pix2ang(self.user.get_nside(), table_ipix_contour)

        # converting these to right ascension and declination in degrees
        ra = np.rad2deg(phi)
        dec = np.rad2deg(0.5 * np.pi - theta)

        #print ra

        # airmass calculation
        obs_time = Time(self.user.get_obs_time())

        observatory = astropy.coordinates.EarthLocation(
           lat=self.user.get_latitude()*u.deg, lon=self.user.get_longitude()*u.deg,height=self.user.get_altitude()*u.m)

        sky_coord = SkyCoord(ra = ra*u.deg,dec=dec*u.deg, frame='icrs')

        altaz = sky_coord.transform_to(AltAz(obstime=self.user.get_obs_time(),
                                             location=observatory))

        airmass_values = altaz.secz
        print airmass_values
        # creating an astropy.table with RA[deg] and DEC[deg] ipix positions
        contour_ipix = Table([ ra, dec, airmass_values ], names = (
           'RA[deg]', 'DEC[deg]', 'airmass'), meta = {'ipix': 'ipix table'})

        mask = (contour_ipix['airmass']) >1 # clear

        obs1=contour_ipix[mask]

        mask2 = (obs1['airmass']) <= float(self.entry_airmass.get())  # user values

        obs = obs1[mask2]

        # setting MOC order
        from math import log
        moc_order = int(log( self.user.get_nside(), 2))

        # creating a MOC map from the contour_ipix table
        moc = MOC.from_table( obs, 'RA[deg]', 'DEC[deg]', moc_order )

        # writing MOC file in fits
        moc.write( 'obs_airmass_'+self.entry_airmass.get()+'MOC_'+str(percentage), format = 'fits' )
        print type(self.entry_airmass.get())
예제 #8
0
    def moc_obs(self):
        """Creating a MOC region in which the airmass is less than a value defined by users."""

        percentage = float(self.entry_percentage.get()) / 100.0

        hpx = hp.read_map(self.user.get_skymap(), verbose=False)

        sort = sorted(hpx, reverse=True)
        cumsum = np.cumsum(sort)
        index, value = min(enumerate(cumsum),
                           key=lambda x: abs(x[1] - percentage))
        value = round(value, 1)  # value --> threshold
        print percentage
        print index, value

        # finding ipix indices confined in a given percentage
        index_hpx = range(0, len(hpx))
        hpx_index = np.c_[hpx, index_hpx]

        sort_2array = sorted(hpx_index, key=lambda x: x[0], reverse=True)
        value_contour = sort_2array[0:index]

        j = 1
        table_ipix_contour = []

        for i in range(0, len(value_contour)):
            ipix_contour = int(value_contour[i][j])
            table_ipix_contour.append(ipix_contour)

        # from index to polar coordinates
        theta, phi = hp.pix2ang(self.user.get_nside(), table_ipix_contour)

        # converting these to right ascension and declination in degrees
        ra = np.rad2deg(phi)
        dec = np.rad2deg(0.5 * np.pi - theta)

        #print ra

        # airmass calculation
        obs_time = Time(self.user.get_obs_time())

        observatory = astropy.coordinates.EarthLocation(
            lat=self.user.get_latitude() * u.deg,
            lon=self.user.get_longitude() * u.deg,
            height=self.user.get_altitude() * u.m)

        sky_coord = SkyCoord(ra=ra * u.deg, dec=dec * u.deg, frame='icrs')

        altaz = sky_coord.transform_to(
            AltAz(obstime=self.user.get_obs_time(), location=observatory))

        airmass_values = altaz.secz
        print airmass_values
        # creating an astropy.table with RA[deg] and DEC[deg] ipix positions
        contour_ipix = Table([ra, dec, airmass_values],
                             names=('RA[deg]', 'DEC[deg]', 'airmass'),
                             meta={'ipix': 'ipix table'})

        mask = (contour_ipix['airmass']) > 1  # clear

        obs1 = contour_ipix[mask]

        mask2 = (obs1['airmass']) <= float(
            self.entry_airmass.get())  # user values

        obs = obs1[mask2]

        # setting MOC order
        from math import log
        moc_order = int(log(self.user.get_nside(), 2))

        # creating a MOC map from the contour_ipix table
        moc = MOC.from_table(obs, 'RA[deg]', 'DEC[deg]', moc_order)

        # writing MOC file in fits
        moc.write('obs_airmass_' + self.entry_airmass.get() + 'MOC_' +
                  str(percentage),
                  format='fits')
        print type(self.entry_airmass.get())