コード例 #1
0
    def test_LC_request_response(self):
        # Call the service, which will send a request to the server.
        alltime, allflux, allflux_err, all_md, alltimebinned, allfluxbinned, allx1, allx2, ally1, ally2, alltime12, allfbkg, start_sec, end_sec, in_sec, tessmag, teff, srad = utils.download_data(
            indir,
            sector,
            tic,
            binfac=5,
            test='./LATTE/tests/tic55525572_lc.fits')

        # If the request is sent successfully, then I expect a response to be returned.
        self.assertAlmostEqual(float(alltime[100]),
                               float(1438.1174094083246),
                               places=5,
                               msg='LC data is not what it should be.')
        self.assertAlmostEqual(float(allflux[100]),
                               float(1.0003796815872192),
                               places=5)
        self.assertAlmostEqual(float(allflux_err[100]),
                               float(0.0011117355898022652),
                               places=5)
        self.assertAlmostEqual(float(all_md[0]),
                               float(1441.0243360822994),
                               places=5)
        self.assertAlmostEqual(float(alltimebinned[100]),
                               float(1438.6757392292352),
                               places=5)
        self.assertAlmostEqual(float(allfluxbinned[100]),
                               float(0.9995232224464417),
                               places=5)
        self.assertAlmostEqual(float(allx1[100]),
                               float(-0.010814569022272735),
                               places=5)
        self.assertAlmostEqual(float(allx2[100]),
                               float(-0.011804798617959023),
                               places=5)
        self.assertAlmostEqual(float(ally1[100]),
                               float(-0.024266568269581512),
                               places=5)
        self.assertAlmostEqual(float(ally2[100]),
                               float(-0.02981671877205372),
                               places=5)
        self.assertAlmostEqual(float(alltime12[100]),
                               float(1438.1312982026025),
                               places=5)
コード例 #2
0
    def test_plot(self):

        # download data needed to generate the plots
        alltime, allflux, allflux_err, all_md, alltimebinned, allfluxbinned, allx1, allx2, ally1, ally2, alltime12, allfbkg, start_sec, end_sec, in_sec, tessmag, teff, srad = utils.download_data(
            indir,
            sector,
            tic,
            binfac=5,
            test='./LATTE/tests/tic55525572_lc.fits')

        #X1_list, X4_list, oot_list, intr_list, bkg_list, apmask_list, arrshape_list, t_list, T0_list, tpf_filt_list = utils.download_tpf_mast(indir, transit_sec, transit_list, tic, test = './LATTE/tests/tic55525572_tp.fits')

        # this function downloads the data and saved plots that show the aperture sizes (for the large and small apertures)
        X1_list, X4_list, oot_list, intr_list, bkg_list, apmask_list, arrshape_list, t_list, T0_list, tpf_filt_list, TESS_unbinned_t_l, TESS_binned_t_l, small_binned_t_l, TESS_unbinned_l, TESS_binned_l, small_binned_l, tpf_list = utils.download_tpf(
            indir,
            transit_sec,
            transit_list,
            tic,
            test='./LATTE/tests/tic55525572_tp.fits')
        # ---------

        # create the plots that the normal routine makes
        utils.plot_full_md(tic, indir, alltime, allflux, all_md, alltimebinned,
                           allfluxbinned, transit_list, args)
        utils.plot_centroid(tic, indir, alltime12, allx1, ally1, allx2, ally2,
                            transit_list, args)
        utils.plot_background(tic, indir, alltime, allfbkg, transit_list, args)
        utils.plot_pixel_level_LC(tic, indir, X1_list, X4_list, oot_list,
                                  intr_list, bkg_list, apmask_list,
                                  arrshape_list, t_list, transit_list, args)
        utils.plot_aperturesize(tic, indir, TESS_unbinned_t_l, TESS_binned_t_l,
                                small_binned_t_l, TESS_unbinned_l,
                                TESS_binned_l, small_binned_l, transit_list,
                                args)
        utils.plot_periodigram(tic, indir, alltime, allflux, args)
        utils.eep_target(tic, indir, syspath, teff, srad, args)

        # --------
        # now check that the plots were actually made!

        # in order to be able to run this code multiple times, assert that the files were created in the last minuet - if the code takes lomger than that to run something is goimg wrong...?
        # without checking when the file is made, the files would have to be manually deleted after every test

        # these are the paths of the files that should have bee created
        full_LC_path = '{}/55525572/55525572_fullLC_md.png'.format(indir)
        full_centroid = '{}/55525572/55525572_centroids.png'.format(indir)
        bkg_path = '{}/55525572/55525572_background.png'.format(indir)
        pixel_path = '{}/55525572/55525572_individual_pixel_LCs_0.png'.format(
            indir)

        ap_LC_path = '{}/55525572/55525572_aperture_size.png'.format(indir)
        apertures_path = '{}/55525572/55525572_apertures_0.png'.format(indir)

        # Get file's Last modification time stamp only in terms of seconds since epoch
        time_created_full_LC = os.path.getmtime(full_LC_path)
        time_created_centroid = os.path.getmtime(full_centroid)
        time_created_bkg = os.path.getmtime(bkg_path)
        time_created_pixel = os.path.getmtime(pixel_path)

        time_created_ap_LC = os.path.getmtime(ap_LC_path)
        time_created_apertures = os.path.getmtime(apertures_path)

        # Convert seconds since epoch to readable timestamp
        t_create_full_LC = parser.parse(
            time.strftime('%Y-%m-%d %H:%M:%S',
                          time.localtime(time_created_full_LC)))
        t_create_centroid = parser.parse(
            time.strftime('%Y-%m-%d %H:%M:%S',
                          time.localtime(time_created_centroid)))
        t_create_bkg = parser.parse(
            time.strftime('%Y-%m-%d %H:%M:%S',
                          time.localtime(time_created_bkg)))
        t_create_pixel = parser.parse(
            time.strftime('%Y-%m-%d %H:%M:%S',
                          time.localtime(time_created_pixel)))

        t_create_ap_LC = parser.parse(
            time.strftime('%Y-%m-%d %H:%M:%S',
                          time.localtime(time_created_ap_LC)))
        t_create_apertures = parser.parse(
            time.strftime('%Y-%m-%d %H:%M:%S',
                          time.localtime(time_created_apertures)))

        # the time now (needed to get the time since creation)
        t_now = (datetime.datetime.now())

        # -------
        # time difference in minutes
        time_since_creation_full_LC = ((t_now - t_create_full_LC).seconds / 60)
        time_since_creation_centroid = ((t_now - t_create_centroid).seconds /
                                        60)
        time_since_creation_bkg = ((t_now - t_create_bkg).seconds / 60)
        time_since_creation_pixel = ((t_now - t_create_pixel).seconds / 60)

        # check that the expected files were created less than a minute ago
        self.assertLess(
            time_since_creation_full_LC, 1,
            "No (new) full LC plot was made in the last five minutes"
        )  # a less than b
        self.assertLess(
            time_since_creation_centroid, 1,
            "No (new) centroid plot was made in the last five minutes"
        )  # a less than b
        self.assertLess(
            time_since_creation_bkg, 1,
            "No (new) background plot was made in the last five minutes"
        )  # a less than b
        self.assertLess(
            time_since_creation_pixel, 1,
            "No (new) pixel level LC plot was made in the last five minutes"
        )  # a less than b
コード例 #3
0
def process(indir, tic, sectors_in, transit_list, args):

	sectors_all, ra, dec = LATTEutils.tess_point(indir, tic) 

	try:
		# Sucessfully entered sectors
		# check that the target was actually observed in the stated sector
		sectors = list(set(sectors_in) & set(sectors_all))

		if len(sectors) == 0:
			print ("The target was not observed in the sector(s) you stated ({}). \
					Therefore take all sectors that it was observed in: {}".format(sectors, sectors_all))
			sectors = sectors_all
	except:
		sectors = sectors_all

	# download the data 
	alltime, allflux, allflux_err, all_md, alltimebinned, allfluxbinned, allx1, allx2, ally1, ally2, alltime12, allfbkg, start_sec, end_sec, in_sec, tessmag, teff, srad = LATTEutils.download_data(indir, sectors, tic)

	# in my input file the the times start at 0 for each sector so I need the line below
	#transit_list = list(np.array(transit_list) + np.nanmin(alltime))
	# ------------

	simple = False
	BLS = False
	model = False
	save = True
	DV = True

	

	# generate the plots
	try:
		LATTEbrew.brew_LATTE(tic, indir, syspath, transit_list, simple, BLS, model, save, DV, sectors, sectors_all, alltime, allflux, allflux_err, all_md, alltimebinned, allfluxbinned, allx1, allx2, ally1, ally2, alltime12, allfbkg, start_sec, end_sec, in_sec, tessmag, teff, srad, ra, dec, args)
		tp_downloaded = True
	except:
		# see if it made any plots - often it just fails on the TPs as they are very large
		if exists("{}/{}/{}_fullLC_md.png".format(indir,tic,tic)):
			print ("couldn't download TP but continue anyway")
			tp_downloaded = False
		else:
			mnd = {}
			mnd['TICID'] = -99
			return mnd

	# check again whether the TPs downloaded - depending on where the code failed it might still have worked. 
	if exists("{}/{}/{}_aperture_size.png".format(indir,tic,tic)):
		tp_downloaded = True
	else:
		tp_downloaded = False
		print ("code ran but no TP -- continue anyway")
		
	# -------------
	# check whether it's a TCE or a TOI

	# TCE -----
	lc_dv = np.genfromtxt('{}/data/tesscurl_sector_all_dv.sh'.format(indir), dtype = str)

	TCE_links = []

	for i in lc_dv:
		if str(tic) in str(i[6]):
			TCE_links.append(i[6])

	if len(TCE_links) == 0:
		TCE = " - "
		TCE = False
	else:
		TCE_links = np.sort(TCE_links)
		TCE_link = TCE_links[0]  # this link should allow you to acess the MAST DV report
		TCE = True
	# TOI -----
	TOI_planets = pd.read_csv('{}/data/TOI_list.txt'.format(indir), comment = "#")
	
	TOIpl = TOI_planets.loc[TOI_planets['TIC'] == float(tic)]
		
	if len(TOIpl) == 0:
		TOI = False

	else:
		TOI = True
		TOI_name = (float(TOIpl["Full TOI ID"]))
	
	# -------------

	# return the tic so that it can be stored in the manifest to keep track of which files have already been produced
	# and to be able to skip the ones that have already been processed if the code has to be restarted.

	mnd = {}
	mnd['TICID'] = tic
	mnd['MarkedTransits'] = transit_list
	mnd['Sectors'] = sectors_all
	mnd['RA'] = ra
	mnd['DEC'] = dec
	mnd['SolarRad'] = srad
	mnd['TMag'] = tessmag
	mnd['Teff'] = teff
	mnd['thissector'] = sectors

	# make empty fields for the test to be checked
	if TOI == True:
		mnd['TOI'] = TOI_name
	else:
		mnd['TOI'] = " "

	if TCE == True:
		mnd['TCE'] = "Yes"
		mnd['TCE_link'] = TCE_link
	else:
		mnd['TCE'] = " "
		mnd['TCE_link'] = " "


	mnd['EB'] = " "
	mnd['Systematics'] = " "
	mnd['TransitShape'] = " "
	mnd['BackgroundFlux'] = " "
	mnd['CentroidsPositions'] = " "
	mnd['MomentumDumps'] = " "
	mnd['ApertureSize'] = " "
	mnd['InoutFlux'] = " "
	mnd['Keep'] = " "
	mnd['Comment'] = " "
	mnd['starttime'] = np.nanmin(alltime)

	return mnd
コード例 #4
0
ファイル: test_BLS.py プロジェクト: martindevora/LATTE
    def test_BLS(self):

        # get data needed to run the BLS - use other unittest to make sure that te data handling works as expected to get to this point. 

        alltime, allflux, allflux_err, all_md, alltimebinned, allfluxbinned, allx1, allx2, ally1, ally2, alltime12, allfbkg, start_sec, end_sec, in_sec, tessmag, teff, srad = utils.download_data(indir,sector, tic, binfac = 5, test = './LATTE/tests/tic55525572_lc.fits')

        # run the BLS
        # the plotting is called from within this 
        bls_stats1, bls_stats2 = utils.data_bls(tic, indir, alltime, allflux, allfluxbinned, alltimebinned, args)

        # this function should output a plot tahts hows the detrending, and two BLS plots. 
        # Ensure that these are generated and that the number are what we expect them to be. 

        #these are the paths of the files that should have bee created
        BLS1_path = '{}/55525572/55525572_bls_first.png'.format(indir)
        BLS2_path = '{}/55525572/55525572_bls_second.png'.format(indir)

        # Get file's Last modification time stamp only in terms of seconds since epoch 
        time_created_BLS1= os.path.getmtime(BLS1_path)
        time_created_BLS2= os.path.getmtime(BLS2_path)

        # Convert seconds since epoch to readable timestamp
        t_create_BLS1 = parser.parse(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time_created_BLS1)))
        t_create_BLS2 = parser.parse(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time_created_BLS2)))
      
        # the time now (needed to get the time since creation)
        t_now = (datetime.datetime.now())

        # -------
        # time difference in minutes
        time_since_creation_BLS1 =  ((t_now - t_create_BLS1).seconds / 60)
        time_since_creation_BLS2 =  ((t_now - t_create_BLS2).seconds / 60)

        self.assertLess(time_since_creation_BLS1, 1, "No BLS plot generated in the last 60 seconds") # a less than b

        # check that the output numbers make sense
        self.assertAlmostEqual(float(bls_stats1[0]), float(16.910000000000014), places=5)
        self.assertAlmostEqual(float(bls_stats1[1]), float(0.3901880448498858), places=5)

        self.assertAlmostEqual(float(bls_stats2[0]), float(0.51))
        self.assertAlmostEqual(float(bls_stats2[1]), float( 0.305186334480843), places=5)
コード例 #5
0
ファイル: __main__.py プロジェクト: martindevora/LATTE
					args.FFI = True


				# --- other SETTINGS ---
				simple = False  # we don't want to run the simple version - that's option is simply to do quick test
				save = True  # always save the files - no point running this if you're not going to save them
				DV = True   # we'll make a DV report for all of them
				args.noshow = True  # don't show these, just save them
				args.auto = True # the code will automatically choose it's own apertures in this mode

				if args.FFI == False:
					try:
						# ----------------------------------------
						# 			 DOWNLOAD DATA 
						# ----------------------------------------
						alltime, allflux, allflux_err, all_md, alltimebinned, allfluxbinned, allx1, allx2, ally1, ally2, alltime12, allfbkg, start_sec, end_sec, in_sec, tessmag, teff, srad = utils.download_data(indir, sectors, tic)
					
						# ----------------------------------------
						#			   START BREWING ....
						# ----------------------------------------
						
						brew.brew_LATTE(tic, indir, syspath,transit_list, simple, BLS, model, save, DV, sectors, sectors_all, alltime, allflux, allflux_err, all_md, alltimebinned, allfluxbinned, allx1, allx2, ally1, ally2, alltime12, allfbkg, start_sec, end_sec, in_sec, tessmag, teff, srad, ra, dec, args)
					except:

						failed_tics.append(tic)
						print ("TIC {} failed to complete. Continue anyway. You can find a list of the failed IDs stored in the output folder.".format(tic))
						continue
				else:
					try:
						# ----------------------------------------
						# 			 DOWNLOAD DATA 
コード例 #6
0
    def test_downloadLC(self):
        alltime, allflux, allflux_err, all_md, alltimebinned, allfluxbinned, allx1, allx2, ally1, ally2, alltimel2, allfbkg, start_sec, end_sec, in_sec, tessmag, teff, srad = LATTEutils.download_data(
            outdir, [5], '55525572', binfac=5)

        self.assertAlmostEqual(float(alltime[0]),
                               1437.9785214992496,
                               places=5,
                               msg="alltime is incorrect")
        self.assertAlmostEqual(float(allflux[1000]),
                               1.0011740922927856,
                               places=5,
                               msg="allflux is incorrect")
        self.assertAlmostEqual(float(allflux_err[1000]),
                               0.0009966295910999179,
                               places=5,
                               msg="allflux_err is incorrect")
        self.assertAlmostEqual(float(all_md[0]),
                               1441.0243360822994,
                               places=5,
                               msg="all_md is incorrect")
        self.assertAlmostEqual(float(alltimebinned[0]),
                               1437.9812992567897,
                               places=5,
                               msg="alltimebinned is incorrect")
        self.assertAlmostEqual(float(allfluxbinned[1000]),
                               1.000087034702301,
                               places=5,
                               msg="alltimebinned is incorrect")

        self.assertAlmostEqual(float(allx1[0]),
                               -0.006673532877357502,
                               places=5,
                               msg="allx1 is incorrect")
        self.assertAlmostEqual(float(allx2[0]),
                               -0.008006655611097813,
                               places=5,
                               msg="allx2 is incorrect")
        self.assertAlmostEqual(float(ally1[0]),
                               -0.018879381330179967,
                               places=5,
                               msg="ally1 is incorrect")
        self.assertAlmostEqual(float(ally2[0]),
                               -0.02256738394498825,
                               places=5,
                               msg="ally2 is incorrect")
        self.assertAlmostEqual(float(alltimel2[0]),
                               1437.9924102871835,
                               places=5,
                               msg="alltimel2 is incorrect")
        self.assertAlmostEqual(float(allfbkg[1000]),
                               974.2296752929688,
                               places=5,
                               msg="allfbkg is incorrect")

        self.assertAlmostEqual(float(start_sec[0][0]),
                               1437.9785214992496,
                               places=5,
                               msg="start_sec is incorrect")
        self.assertAlmostEqual(float(end_sec[0][0]),
                               1464.2879709506096,
                               places=5,
                               msg="end_sec is incorrect")
        self.assertAlmostEqual(float(in_sec[0]),
                               5.0,
                               msg="in_sec is incorrect")

        self.assertAlmostEqual(float(tessmag),
                               9.81999969,
                               places=5,
                               msg="tessmag is incorrect")
        self.assertAlmostEqual(float(teff),
                               5823.70019531,
                               places=5,
                               msg="teff is incorrect")
        self.assertAlmostEqual(float(srad),
                               1.93253005,
                               places=5,
                               msg="srad is incorrect")