Exemplo n.º 1
0
 def get_nir_cat(self,clobber=False,use_twomass=True):
     """
     Get the NIR catalog
     Catalog (necessary for zero-point determination) is saved
     into self.data_dir as
     self.name+"_"+self.nir_survey+"cat.fits"
     """
     print("Fetching NIR catalog from server...")
     if use_twomass:
         if (not os.path.isfile(self.nir_cal_cat)) or clobber:
             from astroquery.irsa import Irsa
             Irsa.ROW_LIMIT = 2000.
             table = Irsa.query_region(coordinates.Galactic(l=self.glon,
                     b=self.glat,  unit=(u.deg, u.deg)), 
                     catalog="fp_psc", spatial="Box", 
                     width=self.nir_im_size)
             #print(table)
         #IPAC table does not take overwrite? But FITS does? So inconsistent and bad
             table.write(self.nir_cal_cat,format='votable',overwrite=clobber)
         else:
             print("NIR catalog already downloaded. Use clobber=True to fetch new versions.")
         
     else:
         if (not os.path.isfile(self.nir_cat)) or clobber:
             if self.nir_survey == "VISTA":
                 from astroquery.vista import Vista as NIR
             if self.nir_survey == "UKIDSS":
                 from astroquery.ukidss import Ukidss as NIR
             table = NIR.query_region(coordinates.Galactic(l=self.glon,
                     b=self.glat,  unit=(u.deg, u.deg)), radius=self.nir_im_size)
             table.write(self.nir_cat,format="fits",overwrite=clobber)
         else:
             print("NIR catalog already downloaded. Use clobber=True to fetch new versions.")
Exemplo n.º 2
0
    def get_nir_images(self,clobber=False):
        """
        Get NIR data/images for this region.
        This comes from astropy.astroquery

        Raw data is saved into self.data_dir as 
        self.name+"_"+self.nir_survey+"_J.fits"

        """
        #Get images
        if (not (os.path.isfile(self.kim) and os.path.isfile(self.him) 
            and os.path.isfile(self.jim)) or clobber):
            print("Fetching NIR images from server...")
            
            if self.nir_survey == "VISTA":
                from astroquery.vista import Vista as NIR
                kwargs = {"frame_type":"tilestack"}
            if self.nir_survey == "UKIDSS":
                from astroquery.ukidss import Ukidss as NIR
                kwargs = {}
            
            for filtername,filename in zip(["J","H","K"],(self.jim,self.him,self.kim)):
                #Need to trim on deprecated and distinguish between tilestack and tilestackconf?
                images = NIR.get_images(coordinates.Galactic(l=self.glon, b=self.glat, 
                                            unit=(u.deg, u.deg)),
                                            waveband=filtername,
                                            image_width=self.nir_im_size,
                                            **kwargs)
                #This makes a big assumption that the last UKIDSS/VISTA image is the one we want
                fits.writeto(filename,
                             images[0][-1].data,images[0][-1].header,clobber=True)
        else:
            print("NIR image already downloaded. Use clobber=True to fetch new versions.")
Exemplo n.º 3
0
    def get_nir_cat(self, clobber=False, use_twomass=True):
        """
        Get the NIR catalog
        Catalog (necessary for zero-point determination) is saved
        into self.data_dir as
        self.name+"_"+self.nir_survey+"cat.fits"
        """
        print("Fetching NIR catalog from server...")
        if use_twomass:
            if (not os.path.isfile(self.nir_cal_cat)) or clobber:
                from astroquery.irsa import Irsa
                Irsa.ROW_LIMIT = 2000.
                table = Irsa.query_region(coordinates.Galactic(l=self.glon,
                                                               b=self.glat,
                                                               unit=(u.deg,
                                                                     u.deg)),
                                          catalog="fp_psc",
                                          spatial="Box",
                                          width=self.nir_im_size)
                #print(table)
                #IPAC table does not take overwrite? But FITS does? So inconsistent and bad
                table.write(self.nir_cal_cat,
                            format='votable',
                            overwrite=clobber)
            else:
                print(
                    "NIR catalog already downloaded. Use clobber=True to fetch new versions."
                )

        else:
            if (not os.path.isfile(self.nir_cat)) or clobber:
                if self.nir_survey == "VISTA":
                    from astroquery.vista import Vista as NIR
                if self.nir_survey == "UKIDSS":
                    from astroquery.ukidss import Ukidss as NIR
                table = NIR.query_region(coordinates.Galactic(l=self.glon,
                                                              b=self.glat,
                                                              unit=(u.deg,
                                                                    u.deg)),
                                         radius=self.nir_im_size)
                table.write(self.nir_cat, format="fits", overwrite=clobber)
            else:
                print(
                    "NIR catalog already downloaded. Use clobber=True to fetch new versions."
                )
Exemplo n.º 4
0
    def get_nir_images(self, clobber=False):
        """
        Get NIR data/images for this region.
        This comes from astropy.astroquery

        Raw data is saved into self.data_dir as 
        self.name+"_"+self.nir_survey+"_J.fits"

        """
        #Get images
        if (not (os.path.isfile(self.kim) and os.path.isfile(self.him)
                 and os.path.isfile(self.jim)) or clobber):
            print("Fetching NIR images from server...")

            if self.nir_survey == "VISTA":
                from astroquery.vista import Vista as NIR
                kwargs = {"frame_type": "tilestack"}
            if self.nir_survey == "UKIDSS":
                from astroquery.ukidss import Ukidss as NIR
                kwargs = {}

            for filtername, filename in zip(["J", "H", "K"],
                                            (self.jim, self.him, self.kim)):
                #Need to trim on deprecated and distinguish between tilestack and tilestackconf?
                images = NIR.get_images(coordinates.Galactic(l=self.glon,
                                                             b=self.glat,
                                                             unit=(u.deg,
                                                                   u.deg)),
                                        waveband=filtername,
                                        image_width=self.nir_im_size,
                                        **kwargs)
                #This makes a big assumption that the last UKIDSS/VISTA image is the one we want
                fits.writeto(filename,
                             images[0][-1].data,
                             images[0][-1].header,
                             clobber=True)
        else:
            print(
                "NIR image already downloaded. Use clobber=True to fetch new versions."
            )
Exemplo n.º 5
0
def vista(obsids_table,
          data_folder,
          moc_folder,
          opt_moc=None,
          radius=15 * u.arcmin,
          moc_order=16,
          overwrite=True):
    """
    Get VISTA-VHS data using astroquery and the UKIDSS database
    For each observation in obsids_table, saves a fits file with
    name 'OBS_ID.fits' in 'data_folder/groups'.

    The function sends a query and selects all sources within 'radius'
    arcmin of the RA,DEC of the observation, then it filters the result
    selecting the sources in the corresponding MOC stored in 'moc_folder/mocs'
    (moc_order must be consistent with the order used to calculate the moc).

    If overwrite is True, always create a new fits file. If False, checks for
    an existing file and uses it to calculate the number of UKIDSS sources
    in the field. If it doesn't exist, creates the file.

    The function returns obsids_table with an additional column 'NSRC_VT'
    with the number of sources in the field.
    """
    # Groups folder
    groups_folder = os.path.join(data_folder, 'groups')
    if not os.path.exists(groups_folder):
        os.makedirs(groups_folder)

    moc_folder = os.path.join(moc_folder, 'mocs')

    if opt_moc is not None:
        moc_optsurvey = MOC()
        read_moc_fits(moc_optsurvey, opt_moc)

    nsources_field = np.full((len(obsids_table), ), np.nan)
    hp = HEALPix(nside=2**moc_order, order='nested', frame=ICRS())

    v = Vista()
    columns = 'sourceID, RA, Dec'
    constraint = '(jppErrBits | hppErrBits | ksppErrBits) < 65536'

    for i, row in enumerate(tqdm(obsids_table, desc="Making VISTA groups")):
        ## Group file name
        field_table_file = os.path.join(data_folder, groups_folder,
                                        '{}.fits'.format(row['OBS_ID']))
        is_field_table = os.path.exists(field_table_file)

        if overwrite or (not overwrite and not is_field_table):
            ## Select all sources in the field
            field_coords = SkyCoord(ra=row['RA'] * u.deg,
                                    dec=row['DEC'] * u.deg)

            vrsp = v.query_region(field_coords,
                                  radius=radius,
                                  database='VHSDR4',
                                  programme_id='VHS',
                                  select=columns,
                                  where=constraint)

            # Add error column and units
            err = np.full((len(vrsp), ), 0.1) * u.arcsec
            vrsp.add_column(Table.Column(err, name='RADECERR'))

            vrsp['RA'] = vrsp['RA'] * u.deg
            vrsp['Dec'] = vrsp['Dec'] * u.deg
            vrsp.rename_column('sourceID',
                               'objID')  # for consistency with 2MASS
            vrsp.remove_column('distance')

            ## Select sources in the non-overlaping area
            moc_field = MOC()
            read_moc_fits(
                moc_field,
                os.path.join(moc_folder, '{}.moc'.format(row['OBS_ID'])))
            if opt_moc is not None:
                moc_field = moc_optsurvey.intersection(moc_field)

            inmoc_table = sources_inmoc(vrsp,
                                        hp,
                                        moc_field,
                                        moc_order=moc_order,
                                        ra='RA',
                                        dec='Dec')
            ## Save sources
            field_table_file = os.path.join(data_folder, groups_folder,
                                            '{}.fits'.format(row['OBS_ID']))

            inmoc_table.meta['description'] = 'VISTA'
            inmoc_table.write(field_table_file, overwrite=True)

        else:
            inmoc_table = Table.read(field_table_file)

        nsources_field[i] = len(inmoc_table)

    colsrc = Table.Column(nsources_field, name='NSRC_VT')
    obsids_table.add_column(colsrc)

    return obsids_table