How to use the astroquery.mast.Observations.download_products function in astroquery

To help you get started, we’ve selected a few astroquery examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nespinoza / juliet / juliet / utils.py View on Github external
obs_table = Observations.query_object(object_name,radius=radius)
    out_dict = {}
    times = {}
    fluxes = {}
    fluxes_errors = {}
    for i in range(len(obs_table['dataURL'])):
        if 's_lc.fits' in obs_table['dataURL'][i]:
            fname = obs_table['dataURL'][i].split('/')[-1]
            metadata = fname.split('-')
            if len(metadata) == 5:
                # Extract metadata:
                sector = np.int(metadata[1].split('s')[-1])
                ticid = np.int(metadata[2])
                # Download files:
                data_products = Observations.get_product_list(obs_table[i])
                manifest = Observations.download_products(data_products)
                # Read lightcurve file:
                d,h = fits.getdata('mastDownload/TESS/'+fname[:-8]+'/'+fname,header=True)
                t,fs,fserr,f,ferr = d['TIME']+h['BJDREFI'],d['SAP_FLUX'],d['SAP_FLUX_ERR'],\
                                    d['PDCSAP_FLUX'],d['PDCSAP_FLUX_ERR']
                idx_goodpdc = np.where((f != 0.)&(~np.isnan(f)))[0]
                idx_goodsap = np.where((fs != 0.)&(~np.isnan(fs)))[0]
                # Save to output dictionary:
                if 'TIC' not in out_dict.keys():
                    out_dict['TIC'] = ticid
                out_dict[sector] = {}
                out_dict[sector]['TIME_PDCSAP_FLUX'] = t[idx_goodpdc]
                out_dict[sector]['PDCSAP_FLUX'] = f[idx_goodpdc]
                out_dict[sector]['PDCSAP_FLUX_ERR'] = ferr[idx_goodpdc]
                out_dict[sector]['TIME_SAP_FLUX'] = t[idx_goodsap]
                out_dict[sector]['SAP_FLUX'] = fs[idx_goodsap]
                out_dict[sector]['SAP_FLUX_ERR'] = fserr[idx_goodsap]
github afeinstein20 / eleanor / eleanor / source.py View on Github external
if local == False:
        
            postcard_obs = Observations.query_criteria(provenance_name="ELEANOR",
                                                       target_name=self.postcard,
                                                       obs_collection="HLSP")

            if len(postcard_obs) > 0:
                product_list = Observations.get_product_list(postcard_obs)
                self.pointing = check_pointing(self.sector, self.camera, self.chip, self.pm_dir)

                if self.pointing is None:
                    extension = ["pc.fits", "bkg.fits", "pm.txt"]
                else:
                    extension = ["pc.fits", "bkg.fits"]

                results = Observations.download_products(product_list, extension=extension,
                                                         download_dir=self.fn_dir)
                postcard_path = results['Local Path'][0]
                self.postcard_path = '/'.join(e for e in postcard_path.split('/')[:-1])
                self.postcard  = results['Local Path'][1].split('/')[-1]
                self.postcard_bkg = results['Local Path'][0].split('/')[-1]
                self.mast_results = results
                self.cutout    = None  # Attribute for TessCut only
                # only downloaded the pointing model if the search for it above failed, so only
                # update it in that case here
                if self.pointing is None:
                    self.pm_dir = self.postcard_path
                    self.pointing = check_pointing(self.sector, self.camera, self.chip, self.pm_dir)


            else:
                print("No eleanor postcard has been made for your target (yet). Using TessCut instead.")
github KeplerGO / lightkurve / lightkurve / mast.py View on Github external
# check if download directory exists (~/.lightkurve-cache)
    cache_dir = os.path.join(os.path.expanduser('~'), '.lightkurve-cache')
    if os.path.isdir(cache_dir):
        download_dir = cache_dir
    else:
        # if it doesn't exist, make a new cache directory
        try:
            os.mkdir(cache_dir)
            download_dir = cache_dir
        # downloads locally if OS error occurs
        except OSError:
            log.warning('Warning: unable to create .lightkurve-cache directory. '
                        'Downloading MAST files to local directory.')
            download_dir = '.'

    dl = Observations.download_products(products, mrp_only=False,
                                        download_dir=download_dir)
    return dl['Local Path']
github KeplerGO / lightkurve / lightkurve / search.py View on Github external
else:
                    raise SearchError('Unable to download FFI cutout. Desired target '
                                    'coordinates may be too near the edge of the FFI.'
                                    'Error: {}'.format(exc))

            return _open_downloaded_file(path,
                                         quality_bitmask=quality_bitmask,
                                         targetid=table[0]['targetid'])

        else:
            if cutout_size is not None:
                warnings.warn('`cutout_size` can only be specified for TESS '
                              'Full Frame Image cutouts.', LightkurveWarning)
            from astroquery.mast import Observations
            log.debug("Started downloading {}.".format(table[:1]['dataURL'][0]))
            path = Observations.download_products(table[:1], mrp_only=False,
                                                  download_dir=download_dir)['Local Path'][0]
            log.debug("Finished downloading.")
            # open() will determine filetype and return
            return _open_downloaded_file(path, quality_bitmask=quality_bitmask)
github alexteachey / MoonPy / mp_lcfind.py View on Github external
except:
		traceback.print_exc()
		time.sleep(60)

		obsTable = Observations.query_object(targID, radius='0.001 deg')
		TESS_idxs = np.where(np.array(obsTable['obs_collection']) == 'TESS')[0]
		minTESSidx, maxTESSidx = np.nanmin(TESS_idxs), np.nanmax(TESS_idxs)+1
		dataproducts = Observations.get_product_list(obsTable[minTESSidx:maxTESSidx])
		timeseries_idxs = np.where(np.array(dataproducts['dataproduct_type']) == 'timeseries')[0]
		obsids = np.array(dataproducts)['obsID'][timeseries_idxs]

		for obsid in np.unique(obsids):
			print ("obsid = ", obsid)
			dataproductsbyID = Observations.get_product_list(obsid)
			manifest = Observations.download_products(dataproductsbyID, download_dir=moonpydir+'/TESS_lcs', dataproduct_type='timeseries', extension='lc.fits', mrp_only=True)
			

			for nmanfile,manfile in enumerate(manifest):
				manfilepath = manfile[0]
				if "_lc.fits" in manfilepath:
					print('found the light curve!')
					### this is the only one you want to save!
					lcpath = manfilepath
					print("lcpath = ", lcpath)

					### open the file, grab the data!
					lcfile = pyfits.open(lcpath)
					lcfiles.append(lcfile)
					lcdata = lcfile[1].data
					lctimes = np.array(lcdata['TIME'])
					if lc_format == 'pdc':
github waqasbhatti / astrobase / astrobase / services / tesslightcurves.py View on Github external
lcfiles = []

    for hlsp in hlsp_products:

        obs_table = Observations.query_criteria(
            target_name=tic_id, provenance_name=hlsp
        )

        if verbose:
            LOGINFO('Found {} {} light-curves.'.format(len(obs_table), hlsp))

        # Get list of available products for this Observation.
        cdips_products = Observations.get_product_list(obs_table)

        # Download the products for this Observation.
        manifest = Observations.download_products(cdips_products,
                                                  download_dir=download_dir)
        if verbose:
            LOGINFO("Done")

        if len(manifest) >= 1:
            lcfiles.append(list(manifest['Local Path']))

    #
    # flatten lcfiles list
    #
    if len(lcfiles) >= 1:
        return_lcfiles = [item for sublist in lcfiles for item in sublist]
    else:
        return_lcfiles = None

    return return_lcfiles