Example #1
0
    def test_nn(self):
        output = LATTEutils.nn_ticids(outdir, [5], '55525572')

        self.assertEqual(
            output[0],
            [55525572, 55525518, 358806415, 55557836, 55557135, 55522986],
            msg="nearest neighbour TIC IDs are incorrect")

        self.assertEqual(output[1][0],
                         0.0,
                         msg="nearest neighbour distances are incorrect")
        self.assertAlmostEqual(output[1][1],
                               6.795727328666717,
                               places=5,
                               msg="nearest neighbour distances are incorrect")

        self.assertAlmostEqual(output[1][2],
                               10.622509290130298,
                               places=5,
                               msg="nearest neighbour distances are incorrect")
        self.assertAlmostEqual(output[1][3],
                               15.63959237521102,
                               places=5,
                               msg="nearest neighbour distances are incorrect")

        self.assertAlmostEqual(output[2],
                               72.6941,
                               places=3,
                               msg="RA is incorrect")
        self.assertAlmostEqual(output[3],
                               -60.9055,
                               places=3,
                               msg="DEC is incorrect")
Example #2
0
    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))
Example #3
0
    def test_testpoint(self):
        output = LATTEutils.tess_point(outdir, '55525572')

        self.assertAlmostEqual(output[1],
                               72.69404300000001,
                               places=5,
                               msg="TESS point RA is not correct")
        self.assertAlmostEqual(output[2],
                               -60.905449,
                               places=4,
                               msg="TESS point Dec is not correct")
Example #4
0
def brew_LATTE_FFI(tic, indir, syspath, transit_list, simple, BLS, model, save, DV, sectors, sectors_all, alltime, allflux_normal, allflux_small, allflux, all_md, allfbkg, allfbkg_t, start_sec, end_sec, in_sec, X1_list, X4_list, apmask_list, arrshape_list, tpf_filt_list, t_list, bkg_list, tpf_list, ra, dec, upper_axis_lim_final, lower_axis_lim_final, args):

	'''
	This function that runs LATTE - makes the plots, saves them, runs the BLS model and the pyaneti model before
	making a PHT DV report (if told to do so.)
	This function is very similar to brew_LATTE -
	except that it is designed to analyse the FFIs and therefore the data download is different.

	Parameters
	----------
	tic  :   str
		target TIC ID
	indir  :  str
		path to directory where all the plots and data will be saved.
	transit_list   : list
		list of the transit-like events
	simple   :   boolean
		whether or not to run the simple version
	BLS   :   boolean
		whether or not to run the BLS routine
	model   :   boolean
		whether or not to model the transit using pyaneti
	save   :	boolean
		whether or not to save the figures and data
	DV   :   boolean
		whether or not to write and save a DV report
	sectors_all  :   list
		all the sectors in which the target has been/ will be observed

	alltime  :  list
		times
	allflux_normal  :  list
		normalized flux extracted with the larger aperture (PCA corrected)
	allflux_small  : list
		normalized flux extracted with the smaller aperture (PCA corrected)
	allflux   : list
		normalized detrended flux extracted with the larger aperture
	all_md  :  list
		times of the momentum dumps
	allfbkg  :  list
		background flux
	allfbkg_t  :  list
		times used to plot the background
	start_sec  :  list
		times of the start of the sector
	end_sec  :  list
		times of the end of the sector
	in_sec  :  list
		the sectors for which data was downloaded
	X1_list  :  list
		flux vs time for each pixel (for each sector)
	X4_list  :  list
		PCA corrected flux vs time for each pixel (for each sector)
	apmask_list  :  list
		aperture masks from the pipeline
	arrshape_list  :  list
		list of the shape of the array (for each sector)
	tpf_filt_list   : list
		list of the filtered (masked) corrected target pixel data - from X4. (for each sector)
	t_list  :  list
		list of the time arrays (for each sector)
	bkg_list  :  list
		the flux that was used to normalise each pixel - i.e. what is used to make the background plot colour for each pixel.
	tpf_list   : list
		list of the target pixel files (for each sector)
	ra   :   float
		right ascension of the target star
	dec   :   float
		declination of the target star

	'''

	# ----------------------------------------
	#		   SAVE THE DATA FILES
	# ----------------------------------------


	if (save == True) or (DV == True):
		save = True

		# if this folder doesn't exist then create it. These are the folder where the images, data and reports for each TIC ID will be stored.
		newpath = '{}/{}'.format(indir,tic)

		if not exists(newpath):
			os.makedirs(newpath)

		# save the data used as a text file - these often come in use later for a quick re-analysis.
		with open('{}/{}/{}_data.txt'.format(indir, tic, tic), "w") as f:

			# get rid of nan values first using a mask
			good_mask = np.isfinite(np.array(alltime)) * np.isfinite(np.array(allflux))
			alltime_ar = np.array(alltime)[good_mask]
			allflux_ar = np.array(allflux)[good_mask]
			allflux_err_ar = allflux_ar * 0.001

			# save data
			writer = csv.writer(f, delimiter='\t')
			writer.writerow(['time', 'flux', 'flux_err'])
			writer.writerows(zip(alltime_ar,allflux_ar,allflux_err_ar))

		'''
		if the modelling option was also chose, save another data file with slightly different formatting to be called by Pyaneti.
		Pyaneti requires a very specific data format.

		Furhermore, in order for Pyaneti to run more efficiently (it has a Bayesian backend which scales with number of data points)
		we create a cutout of the times around the times of the marked transit events.
		'''

		if model == True:
			with open('{}/{}/{}_data_pyaneti.dat'.format(indir, tic, tic), "w") as f:
				writer = csv.writer(f, delimiter='\t')
				writer.writerow(['#time', 'flux', 'flux_err'])

			# if the dip separations are too small, then don't create cut outs and save the whole dataset
			if (len(transit_list) > 1) and ((transit_list[1] - transit_list[0]) < 2): # if there are LOTS of transit events on short period (if so it's probably a TOI but let's keep it here as a condition)
				with open('{}/{}/{}_data_pyaneti.dat'.format(indir, tic, tic), "a") as f:
					writer = csv.writer(f, delimiter='\t')
					writer.writerows(zip(alltime_ar,allflux_ar,allflux_err_ar)) # save all the data

			# else create a cut out of the data around the time of the transit event
			else:
				for transit in transit_list:
					# save the data
					# get rid of nan values first - this is used for the pyaneti code
					pyaneti_mask = (alltime_ar > (transit - 1)) * (alltime_ar < (transit + 1))

					with open('{}/{}/{}_data_pyaneti.dat'.format(indir, tic, tic), "a") as f:
						writer = csv.writer(f, delimiter='\t')
						writer.writerows(zip(alltime_ar[pyaneti_mask],allflux_ar[pyaneti_mask],allflux_err_ar[pyaneti_mask]))


	# ------------------------------------------
	#			   START PLOTTING
	# ------------------------------------------

	# create a plot of the fulllighcurves with the momentum dumps (MDs) marked and a zoom-in of the marked transits
	utils.plot_full_md(tic, indir, alltime, allflux, all_md, alltime, allflux, transit_list, upper_axis_lim_final, lower_axis_lim_final, args)

	# get the sectors that have a transit marked in them
	transit_sec = utils.transit_sec(in_sec,start_sec, end_sec, transit_list)

	# -----------

	# plot the background flux at the time of the transit event.
	utils.plot_background(tic, indir, allfbkg_t, allfbkg, transit_list, args)
	print ("Background plots... done.")
	# -----------

	if simple == True:
		print ("Simple option was selected, therefore end analysis here.")
		sys.exit('')
	# -----------

	# plot the LC using different aperture sizes
	utils.plot_aperturesize(tic,indir,alltime, alltime, alltime, allflux_normal, allflux_normal, allflux_small, transit_list, args)

	print ("Aperture size plots... done.")
	# -----------

	'''
	Plot the average pixel brightness of the cut-out around the target star and the corresponding SDSS field of view.
	Both are oriented so that North is pointing upwards.
	The former also shows the nearby stars with TESS magnitude brighter than 17. Queried from GAIA using astroquery.
	The function returns the TESS magnitude, effective temperature (K), the radius of the star (solar radii)and the
	mass of the star (solar mass) (also output from astroquery)- this is a useful input for the Pyaneti modelling
	'''

	if args.mpi == False:
		tessmag, teff, srad, mstar,vmag, logg, plx, c_id = utils.plot_TESS_stars(tic,indir, transit_sec, tpf_list, args)

		if tessmag == -111:
			tessmag, teff, srad, mstar,vmag, logg, plx, c_id = utils.plot_TESS_stars_not_proj(tic,indir, transit_list, transit_sec, tpf_list, args)
			args.mpi = True

	else:
		tessmag, teff, srad, mstar, vmag, logg, plx, c_id = utils.plot_TESS_stars_not_proj(tic,indir, transit_list, transit_sec, tpf_list, args)

	# keep track of whether astroquery is working (sometimes the site is down and we don't want this to stop us from running the code)
	astroquery_corrupt = False

	if tessmag == -999:
		astroquery_corrupt = True
		print ("Star Aperture plots... failed.")

	else:
		print ("Star Aperture plots... done.")


	# -----------

	# If more than one transit has been marked by the user, the LC is phase folded based on the period of the separation of the first two maarked peaks.
	# These plots are saved but do not feature in the DV report.

  # needs to know a period so can only do this if more than one transit has been marked.
	if len(transit_list) > 1:
		# find the period
		period = transit_list[1] - transit_list[0]
		t0 = transit_list[0] # time of the first marking

		# calculate the phase
		# phased = np.array([-0.5+( ( t - t0-0.5*period) % period) / period for t in alltime])

		# phased plot where odd and even are different colours
		phased = (np.array(alltime) - t0) % period
		phased2 = (np.array(alltime) - (t0)) % (period*2)

		index = phased>0.5*period
		index2 = phased2 >0.5*(period *2)

		phased[index] -= period
		phased2[index2] -= (period *2)

		fig, ax = plt.subplots(figsize=(5.55,5))

		ax.plot(phased,np.array(allflux), 'k.', markersize=5)
		ax.plot(phased2,np.array(allflux), 'r.', markersize=5)

		#ax.plot(phased, allflux,marker='o',color = 'navy', alpha = 0.7, lw = 0, markersize = 2, label = 'binning = 7', markerfacecolor='white')
		plt.title("Phase folded LC")
		ax.set_xlabel("Phase (days)")
		ax.set_ylabel("Normalized Flux")
		plt.plot()

		if save == True:
			plt.savefig('{}/{}/{}_phase_folded.png'.format(indir, tic, tic), format='png')

		if args.noshow == False:
			plt.show()

		print ("Phase folded plot... done.")

	else:
		print ("\n Only one transit marked - therefore can't be phase folded. \n")
	# ------------

	'''
	In order to create the plots that compare the in and out of transit average flux
	we need to create TPF masks for the in and out of transit.
	This couldn't be done at the time of the extraction of the TPF arrays as the transit times
	had not yet been defined.
	'''

	oot_list = [] # out of transit
	intr_list = []  # in transit

	X1_list_n = []
	X4_list_n = []
	bkg_list_n = []
	apmask_list_n = []
	arrshape_list_n = []
	t_list_n = []

	tpf_filt_list_n = []
	tpf_list_n = []

	T0_list = []  # list of the transit times - make a new list to ensure that thet are in the same order.

	for T0 in transit_list:
		for idx,t in enumerate(t_list):
			# these times were found to give good approximations for out of transit and in transit
			# Note: this will NOT be 'perfect' for all events, as it depends on the transit duration which the code doesnt' know at this time but it's a good approximation.
			if (T0 > np.nanmin(t)) and (T0 < np.nanmax(t)): # if T0 is within the time... (should be)

				oot_list.append((abs(T0-np.array(t)) < 0.55) * (abs(T0-np.array(t)) < 0.3))
				intr_list.append(abs(T0-np.array(t)) < 0.1)

				X1_list_n.append(X1_list[idx])
				X4_list_n.append(X4_list[idx])
				bkg_list_n.append(bkg_list[idx])
				apmask_list_n.append(apmask_list[idx])
				arrshape_list_n.append(arrshape_list[idx])
				t_list_n.append(t)

				tpf_filt_list_n.append(tpf_filt_list[idx])
				tpf_list_n.append(tpf_list[idx])

				T0_list.append(T0)

	X1_list	 		= 	X1_list_n
	X4_list	 		= 	X4_list_n
	bkg_list		= 	bkg_list_n
	apmask_list 	= 	apmask_list_n
	arrshape_list   =   arrshape_list_n
	t_list 			=   t_list_n
	tpf_filt_list 	= 	tpf_filt_list_n
	tpf_list 		=   tpf_list_n

	# ------------


	# Plot the in and out of transit flux comparison
	# By default the images are NOT orented north - this is because the reprojectio takes longer to run and for a simple
	# analysis to chekc whether the brightest pixel moves during the transit this is not required.
	# The orientation towards north can be defined in the command line with '--north'.

	if args.north == True:
		utils.plot_in_out_TPF_proj(tic, indir, X4_list, oot_list, t_list, intr_list, T0_list, tpf_filt_list, tpf_list, args)
		print ("In and out of aperture flux comparison with reprojection... done. ")
	else:
		utils.plot_in_out_TPF(tic, indir, X4_list, oot_list, t_list, intr_list, T0_list, tpf_filt_list, args)
		print ("In and out of aperture flux comparison... done.")
	# ------------

	# For each pixel in the TPF, extract and plot a lightcurve around the time of the marked transit event.
	utils.plot_pixel_level_LC(tic, indir, X1_list, X4_list, oot_list, intr_list, bkg_list, tpf_list, apmask_list, arrshape_list, t_list, T0_list, args)
	print ("Pixel level LCs plot... done.")
	# ------------

	# If the BLS option is chose, a BLS search is run. The LCs are first detrended and smoothed using a moving average.
	# The corrected and uncorrected LCs are saves as a single plot for comparison and to verify that the correction worked well - saved but do not feature in the DV report.
	if BLS == True:
		print ("Running BLS")
		bls_stats1, bls_stats2 = utils.data_bls_FFI(tic, indir, alltime, allflux, args)
	# ------------

	# ------------
	print ("Periodogram plot...", end =" ")
	mass_ast, radius_ast, logg_ast, numax, deltanu = utils.plot_periodogram(tic, indir, alltime, allflux, 0, -999, -999, args)

	print ("done.")

	# ------------
	print ("Evolutionary tracks plot...", end =" ")
	utils.eep_target(tic, indir, syspath, teff, srad, args)
	print ("done.")

	# ------------

	'''
	If the modelling option is selected (in the GUI), model the transit event using Pyaneti (Barragan et al 2018)
	which uses an Bayesian approach with an MCMC sampling to best fit and model the transit.
	The code runs slightly differently depending on whether one or multiple transits have been marked.
	This is because with multiple transits the code has information about the possible orbital period.
	Need to ensure that the code has compiled correctly on the users computer.

	SKIP FOR NOW - this will become available in the next version of LATTE
	'''

	# first check if Pyaneti is even installed...

	if os.path.exists("{}/pyaneti_LATTE.py".format(syspath)):

		if model == True:
			print ("Running Pyaneti modelling - this could take a while so be patient...")

			# the code is usually run through the command line so call it using the os.system function.
			transit_list_model =  ("{}".format(str(np.asarray(transit_list)))[1:-1]) # change the list into a string and get rid of the brackets
			os.system("python3 {}/pyaneti_LATTE.py {} {} {} {} {} {} {}".format(syspath, tic, indir, syspath, mstar, teff, srad, transit_list_model))

	else:
		print ("Pyaneti has not been installed so you can't model anything yet. Ask Nora or Oscar for the LATTE version of the Pyaneti code.")
		model = False

	# SKIP until HERE

	# ------------
	# Finally, create a DV report which summarises all of the plots and tables.
	if DV == True:
		from LATTE import LATTE_DV as ldv

		if BLS == True:
			ldv.LATTE_DV(tic, indir, syspath, transit_list, sectors_all, ra, dec, tessmag, teff, srad, mstar, vmag, logg, mass_ast, radius_ast, logg_ast, numax, deltanu, plx, c_id, bls_stats1, bls_stats2, False, astroquery_corrupt, FFI = True, bls = True, model = model, mpi = args.mpi)
		else:
			ldv.LATTE_DV(tic, indir, syspath, transit_list, sectors_all, ra, dec, tessmag, teff, srad, mstar, vmag, logg, mass_ast, radius_ast, logg_ast, numax, deltanu, plx, c_id, [0], [0], False, astroquery_corrupt, FFI = True, bls = False, model = model, mpi = args.mpi)

	else:
		print ("\n  Complete! \n ")
Example #5
0
def 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, upper_axis_lim_final, lower_axis_lim_final, tessmag, teff, srad, ra, dec, input_numax, input_analysis_window, url_list, args):
	'''
	This function combines all the results from LATTE and calls all the different functions -
	it makes the plots, saves them, runs the BLS model and the pyaneti model before making a PHT DV report (if this option is selected.)

	Parameters
	----------
	tic  :   str
		target TIC ID
	indir  :  str
		path to directory where all the plots and data will be saved.
	transit_list   : list
		list of the transit-like events
	simple   :   boolean
		whether or not to run the simple version
	BLS   :   boolean
		whether or not to run the BLS routine
	model   :   boolean
		whether or not to model the transit using pyaneti
	save   :	boolean
		whether or not to save the figures and data
	DV   :   boolean
		whether or not to write and save a DV report
	sectors_all  :   list
		all the sectors in which the target has been/ will be observed
	alltime  :  list
		times (not binned)
	allflux  :  list
		normalized flux (not binned)
	allflux_err  :  list
		normalized flux errors (not binned)
	all_md  :  list
		times of the momentum dumps
	alltimebinned  :  list
		binned time
	allfluxbinned  :  list
		normalized binned flux
	allx1  :  list
		CCD column position of target’s flux-weighted centroid. In x direction
	allx2  :  list
		The CCD column local motion differential velocity aberration (DVA), pointing drift, and thermal effects. In x direction
	ally1  :  list
		CCD column position of target’s flux-weighted centroid. In y direction
	ally2  :  list
		The CCD column local motion differential velocity aberration (DVA), pointing drift, and thermal effects. In y direction
	alltimel2  :  list
		time used for the x and y centroid position plottin
	allfbkg  :  list
		background flux
	start_sec  :  list
		times of the start of the sector
	end_sec  :  list
		times of the end of the sector
	in_sec  :  list
		the sectors for which data was downloaded
	tessmag  :  list
		TESS magnitude of the target star
	teff  :  float
		effective temperature of the tagret star (K)
	srad  :  float
		radius of the target star (solar radii)
	 ra	:	float
		the right ascension of the target stars
	 dec	:   float
		the declination of the target star

	'''

	# -------------------
	# SAVE THE DATA FILES
	# -------------------
	
	if (save == True) or (DV == True):
		save = True
		# if this folder doesn't exist then create it. These are the folder where the images, data and reports for each TIC ID will be stored.
		newpath = '{}/{}'.format(indir,tic)

		if not exists(newpath):
			os.makedirs(newpath)

		# save the data used as a text file - these often come in use later for a quick re-analysis.
		with open('{}/{}/{}_data.txt'.format(indir, tic, tic), "w") as f:

			# get rid of nan values first using a mask
			good_mask = np.isfinite(np.array(alltime)) * np.isfinite(np.array(allflux)) * np.isfinite(np.array(allflux_err))
			alltime_ar = np.array(alltime)[good_mask]
			allflux_ar = np.array(allflux)[good_mask]
			allflux_err_ar = np.array(allflux_err)[good_mask]

			# save
			writer = csv.writer(f, delimiter='\t')
			writer.writerow(['time', 'flux', 'flux_err'])
			writer.writerows(zip(alltime_ar,allflux_ar,allflux_err_ar))

		'''
		if the modelling option was also chose, save another data file with slightly different formatting to be called by Pyaneti.
		Pyaneti requires a very specific data format.

		Furhermore, in order for Pyaneti to run more efficiently (it has a Bayesian backend which scales with number of data points)
		we create a cutout of the times around the times of the marked transit events.
		'''

		if len(transit_list) != 0:
			if model == True:
				with open('{}/{}/{}_data_pyaneti.dat'.format(indir, tic, tic), "w") as f:
					writer = csv.writer(f, delimiter='\t')
					writer.writerow(['#time', 'flux', 'flux_err'])

				# If the dip separations are too small, then don't create cut outs and save the whole dataset
				if (len(transit_list) > 1) and ((transit_list[1] - transit_list[0]) < 2): # if there are LOTS of transit events on short period (if so it's probably a TOI but let's keep it here as a condition)
					with open('{}/{}/{}_data_pyaneti.dat'.format(indir, tic, tic), "a") as f:
						writer = csv.writer(f, delimiter='\t')
						writer.writerows(zip(alltime_ar,allflux_ar,allflux_err_ar)) # save all the data

				# else create a cut out of the data around the time of the transit events
				else:
					for transit in transit_list:
						# save the data
						# get rid of nan values first - this is used for the pyaneti code
						pyaneti_mask = (alltime_ar > (transit - 1)) * (alltime_ar < (transit + 1))

						with open('{}/{}/{}_data_pyaneti.dat'.format(indir, tic, tic), "a") as f:
							writer = csv.writer(f, delimiter='\t')
							writer.writerows(zip(alltime_ar[pyaneti_mask],allflux_ar[pyaneti_mask],allflux_err_ar[pyaneti_mask]))


	# -----------------------------------
	#			START PLOTTING		  	 - calls functions from LATTEutils.py
	# -----------------------------------

	if len(transit_list) != 0: # this is always the case unless the asteroseismic only option ws chosen
		# create a plot of the fulllighcurves with the momentum dumps (MDs) marked and a zoom-in of the marked transits
		# this plit is saved but not shown (as already shown in the interact part fo the code)
		utils.plot_full_md(tic, indir, alltime,allflux,all_md,alltimebinned,allfluxbinned, transit_list, upper_axis_lim_final, lower_axis_lim_final, args)

		# Get a list of the sectors that have transit marked in them
		# this is so that we no longer have to loop through all of the sectors, and can focus on the ones which are important.
		transit_sec = utils.transit_sec(in_sec, start_sec, end_sec, transit_list)

		# -----------
		# plot how the centroids moved during the transit event
		utils.plot_centroid(tic, indir,alltime12, allx1, ally1, allx2, ally2, transit_list, args)
		# plot the background flux at the time of the transit event.
		utils.plot_background(tic, indir,alltime, allfbkg, transit_list, args)

		print ("Centroid and background plots... done.")
		# -----------

		# if the 'simple' option is chosen in the GUI, then the code will end here - this is designed to provide a quick analysis requiring no TPFs.
		if simple == True:
			print ("Simple option was selected, therefore end analysis here.")
			sys.exit('')

		# -----------

		# call function to extract the Target Pixel File information
		# this is needed in order to extract the LCs in different aperture sizes.
		# the data is extracted using the open source Lightkurve package as they a built in function to extract LCs using different aperture sizes
		#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_lightkurve(indir, transit_list, sectors, tic)

		print ("\n Start downloading of the target pixel files - this can take a little while (up to a minute) as the files are large \n")

		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, url_list)

		# if the TPF wasn't corrupt then make the TPF files (only very ocassionally corrupt but don't want code to crash if it is corrrupt)
		if (TESS_unbinned_t_l[0] != -111):

			tpf_corrupt = False
			# plot the LCs using two different aperture sizes.
			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)

			print ("Aperture size plots... done.")
			# ------------

			'''
			Plot the average pixel brightness of the cut-out around the target star and the corresponding SDSS field of view.
			Both are oriented so that North is pointing upwards.
			The former also shows the nearby stars with TESS magnitude brighter than 17. Queried from GAIA using astroquery.
			The function returns the mass of the star (also output from astroquery)- this is a useful input for the Pyaneti modelling
			'''
			if args.mpi == False:
				test_astroquery, _, _, mstar, vmag, logg, plx, c_id = utils.plot_TESS_stars(tic,indir, transit_sec, tpf_list, args)

				if test_astroquery == -111:
					tessmag, teff, srad, mstar, vmag, logg, plx, c_id = utils.plot_TESS_stars_not_proj(tic,indir, transit_list, transit_sec, tpf_list, args)
					args.mpi = True

			else:
				test_astroquery, _, _, mstar, vmag, logg, plx, c_id = utils.plot_TESS_stars_not_proj(tic,indir, transit_list, transit_sec, tpf_list, args)

			# keep track of whether astroquery is working (sometimes the site is down and we don't want this to stop us from running the code)
			astroquery_corrupt = False

			if test_astroquery == -999:
				astroquery_corrupt = True
				print ("Star Aperture plots... failed.")

			else:
				print ("Star Aperture plots... done.")

			# ------------

			# Download the Target Pixel File using the raw MAST data - this comes in a different format as the TPFs extracted using Lightkurve
			# This data is then corrected using Principal Component Analysis is orderto get rid of systematics.
			#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)

			# ------------

			'''
			plot the in and out of transit flux comparison.
			By default the images are NOT oriented north - this is because the reprojection takes longer to run and for a simple
			analysis to check whether the brightest pixel moves during the transit this is not required.
			The orientation towards north can be defined in the command line with '--north'.
			'''
			if args.north == True:
				utils.plot_in_out_TPF_proj(tic, indir, X4_list, oot_list, t_list, intr_list, T0_list, tpf_filt_list, tpf_list, args)
				print ("In and out of aperture flux comparison with reprojection... done. ")

			else:
				utils.plot_in_out_TPF(tic, indir, X4_list, oot_list, t_list, intr_list, T0_list, tpf_filt_list, args)
				print ("In and out of aperture flux comparison... done.")
			# ------------

			# For each pixel in the TPF, extract and plot a lightcurve around the time of the marked transit event.
			utils.plot_pixel_level_LC(tic, indir, X1_list, X4_list, oot_list, intr_list, bkg_list, tpf_list, apmask_list, arrshape_list, t_list, T0_list, args)
			print ("Pixel level LCs plot... done.")
			# ------------

		else:
			tpf_corrupt = True
			mstar = 1 # need to define mstar otherwise pyaneti will complain - just make it one as an approximation.
			tessmag = np.nan
			teff = np.nan
			srad = np.nan
			vmag = np.nan
			logg = np.nan
			plx = np.nan
			c_id = np.nan

			astroquery_corrupt = True

		# ------------
		# end of plots that require target pixel files
		# ------------

		# If more than one transit has been marked by the user, the LC is phase folded based on the period of the separation of the first two maarked peaks.
		# These plots are saved but do not feature in the DV report.
		if len (transit_list) > 1: # needs to know a period so can only do this if more than one transit has been marked.

			period = transit_list[1] - transit_list[0]
			t0 = transit_list[0] # time of the first marking

			# calculate the phase
			phased = np.array([-0.5+( ( t - t0-0.5*period) % period) / period for t in alltimebinned])

			fig, ax = plt.subplots(figsize=(5.55,5))
			ax.plot(phased, allfluxbinned, marker='.',color = 'k', alpha = 1, lw = 0, markersize = 4, label = 'None', markerfacecolor='k')

			#ax.plot(phased, allflux,marker='o',color = 'navy', alpha = 0.7, lw = 0, markersize = 2, label = 'binning = 7', markerfacecolor='white')
			plt.title("Phase folded LC")
			ax.set_xlabel("Phase (days)")
			ax.set_ylabel("Normalized Flux")
			plt.plot()


			if save == True:
				plt.savefig('{}/{}/{}_phase_folded.png'.format(indir, tic, tic), format='png')

			if args.noshow == False:
				plt.show()

			print ("Phase folded plot... done.")

		else:
			print ("\n Only one transit marked - therefore can't be phase folded. \n")

		# ------------

		'''
		Plot LCs of the six closest TESS target stars. This allows us to check whether the transit-like events
		also appear in other nearby LCs which would be a sign that this is caused by a background event.
		'''

		# get the tic IDs of the six nearest stars
		if args.FFI == False:
			ticids, distance, target_ra, target_dec = utils.nn_ticids(indir, transit_sec, tic)

			# download the data for these stars
			alltime_nn, allflux_nn, all_md_nn, alltimebinned_nn, allfluxbinned_nn,outtics,tessmag_list, distance = utils.download_data_neighbours(indir, transit_sec[0], ticids, distance)

			# plot the LCs
			utils.plot_nn(tic, indir,alltime_nn, allflux_nn, alltimebinned_nn, allfluxbinned_nn, transit_list, outtics, tessmag_list, distance, args)

		else:
			target_ra = ra
			target_dec = dec
			distance = None

		print ("Nearest neighbour plot... done.")
		# ------------

		# if the BLS option is chose, a BLS search is run. The LCs are first detrended and smoothed using a moving average.
		# The corrected and uncorrected LCs are saves as a single plot for comparison and to verify that the correction worked well - saved but do not feature in the DV report.
		if BLS == True:
			print ("Running BLS algorithm...", end =" ")
			bls_stats1, bls_stats2 = utils.data_bls(tic, indir, alltime, allflux, allfluxbinned, alltimebinned, args)
			print ("done.")


	else:

		from astroquery.mast import Catalogs
		#plot the main LC with only one panel and no transit events marked
		utils.plot_full_md_notransits(tic, indir, alltime, allflux, all_md, alltimebinned, allfluxbinned, upper_axis_lim_final, lower_axis_lim_final, args)
		target_ra = ra
		target_dec = dec
		tpf_corrupt = False

		# get the star information that would otherwise come from the plot_TESS_stars function
		starName = "TIC " + str(tic)
		radSearch = 5/60 #radius in degrees

		# this function depends on astroquery working, and sometimes it doesn't.
		# for when it doesn't work (or simply can't connect to it), just skip plotting the other TESS stars.
		try:
			astroquery_corrupt = False
			catalogData = Catalogs.query_object(starName, radius = radSearch, catalog = "TIC")
		except:
			astroquery_corrupt = True
			print ("Currently cannot connect to Astroquery.")
			# return values that we know aren't real so that we can tell the code that the plotting didn't work
			return -999, -999, -999, 1, -999,-999,-999,-999

		# ra and dec of the target star
		ra = catalogData[0]['ra']
		dec = catalogData[0]['dec']

		# while we have the astroquery loaded, let's collect some other information about the star
		# these paramaters can help us find out what type of star we have with just a glance

		vmag = catalogData['Vmag'][0] # v magnitude (this migth be more useful than the TESS mag for things such as osbevring)
		logg = catalogData['logg'][0] # logg of the star
		mstar = catalogData['mass'][0] # mass of the star
		plx = catalogData['plx'][0]   # parallax

		# sometimes these values aren't accessible through astroquery - so we shoudl just quickly check.
		if not np.isfinite(vmag): vmag = '--' # this is what will appear in the table of the report to indicate that it's unknown
		if not np.isfinite(logg): logg = '--'
		if not np.isfinite(mstar): mass = '--'
		if not np.isfinite(plx): plx   = '--'

		# sometimes it's useufl to know if the star has another name
		# check whether it was osberved by one of these four large surveys

		catalogs = ['HIP', 'TYC', 'TWOMASS', 'GAIA']

		for cat in catalogs:
			c_id = str(catalogData[0][cat])
			if c_id != '--':
				cat_id = "{} {}".format(cat,c_id)
				break
			else:
				continue

		tessmag = catalogData['Tmag'][0]
		teff = catalogData['Teff'][0]
		srad = catalogData['rad'][0]
		c_id = c_id

	# ------------
	# period analysis
	# always make a peridoogram? QUestion for later.
	print ("Periodogram plot...", end =" ")
	mass_ast, radius_ast, logg_ast, numax, deltanu = utils.plot_periodogram(tic, indir, alltime, allflux, teff, input_numax, input_analysis_window, args)
	print ("done.")

	# ------------
	# stellar evolutionary tracks
	print ("Evolutionary tracks plot...", end =" ")
	utils.eep_target(tic, indir, syspath, teff, srad, args)
	print ("done.")

	# ------------

	# SKIP FROM HERE....

	'''
	NOTE: CURRENTLY ONLY WORKS ON NORA'S COMPUTER - WILL BE AVAILABLE IN NEXT RELEASE SO PLEASE SKIP THIS PART OF THE CODE
	If the modelling option is selected (in the GUI), model the transit event using Pyaneti (Barragan et al 2018)
	which uses an Bayesian approach with an MCMC sampling to best fit and model the transit.
	The code runs slightly differently depending on whether one or multiple transits have been marked.
	This is because with multiple transits the code has information about the possible orbital period.
	Need to ensure that the code has compiled correctly on the users computer.

	Reason why is doesn't work else where: the priors need to be set up ver carefully, and this has not been tested enough to know
	it can be automated to work reliably. Also, this code requires a fortran backend, which has not yet been included in LATTE.
	---> we're working on implementing this as it will be very useful.
	'''

	# First check if Pyaneti is installed...
	if os.path.exists("{}/pyaneti_LATTE.py".format(syspath)):

		if model == True:
			print ("Running Pyaneti modelling - this could take a while so be patient...")

			transit_list_model =  ("{}".format(str(np.asarray(transit_list)))[1:-1]) # change the list into a string and get rid of the brackets
			# the code is usually run through the command line so call it using the os.system function.

			os.system("python3 {}/pyaneti_LATTE.py {} {} {} {} {} {} {}".format(syspath, tic, indir, syspath, mstar, teff, srad, transit_list_model))

	else:
		#print ("Pyaneti has not been installed so you can't model anything yet. Contact Nora or Oscar for the LATTE version of the Pyaneti code.")
		model = False

	# ... UNTIL HERE
	# ------------


	# Finally, create a DV report which summarises all of the plots and tables.
	if DV == True:

		from LATTE import LATTE_DV as ldv

		if BLS == True:
			ldv.LATTE_DV(tic, indir, syspath, transit_list, sectors_all, target_ra, target_dec, tessmag, teff, srad, mstar, vmag, logg, mass_ast, radius_ast, logg_ast, numax, deltanu, plx, c_id, bls_stats1, bls_stats2, tpf_corrupt, astroquery_corrupt, FFI = args.FFI,  bls = True, model = model, mpi = args.mpi)
		else:
			ldv.LATTE_DV(tic, indir, syspath, transit_list, sectors_all, target_ra, target_dec, tessmag, teff, srad, mstar, vmag, logg, mass_ast, radius_ast, logg_ast, numax, deltanu, plx, c_id, [0], [0], tpf_corrupt, astroquery_corrupt, FFI = args.FFI,  bls = False, model = model, mpi = args.mpi)
Example #6
0
    def test_LC_request_response(self):

        # Call the service, which will send a request to the server.
        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')

        #If the request is sent successfully, then I expect a response to be returned.
        self.assertAlmostEqual(float(X1_list[0][0][0]),
                               float(23.402481079101562),
                               places=5,
                               msg='TP data is not what it should be.')
        self.assertAlmostEqual(float(X4_list[0][0][0]),
                               float(22.052828),
                               places=5,
                               msg='TP data is not what it should be.')
        self.assertAlmostEqual(float(oot_list[0][0]), float(0.0))
        self.assertAlmostEqual(float(intr_list[0][0]), float(0.0))
        self.assertAlmostEqual(float(bkg_list[0][0][0]),
                               float(29.239688873291016),
                               places=5)
        self.assertAlmostEqual(float(apmask_list[0][0][0]), float(0.0))
        self.assertAlmostEqual(float(arrshape_list[0][0]), float(18944.0))
        self.assertAlmostEqual(
            float(t_list[0][0]),
            float(1437.9924102871835),
            places=5,
        )
        self.assertAlmostEqual(float(T0_list[0]), float(1454.7))
Example #7
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)
Example #8
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
Example #9
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
Example #10
0
		print ("\n Download the text files required ... " )
		print ("\n Only the manifest text files (~325 M) will be downloaded and no TESS data." )
		print ("\n This step may take a while but luckily it only has to run once... \n" )
	
		# ------------------------------------------------
		#check whether the chosen (output) directory already exists, and if it doesn't create the directory.
		if not os.path.exists("{}".format(indir)):
			os.makedirs(indir)
	
		if not os.path.exists("{}/data".format(indir)):
			os.makedirs("{}/data".format(indir))
	
		# ------------------------------------------------
	
		# ----- REFERENCE FILES DOWNLOAD -----
		LATTEutils.data_files(indir)
		LATTEutils.tp_files(indir)
		LATTEutils.TOI_TCE_files(indir)
		LATTEutils.momentum_dumps_info(indir)
		# -----
	
	# if the user chooses to redefine the path
	elif args.new_path == True: 
	
		reply = yes_or_no() # double check that they really want to do that.
	
		if reply == True:
			indir = input("\n \n Please enter a path to save the files (e.g. ./LATTE_output or /Users/yourname/Desktop/LATTE_output) : " )
	
			# SAVE the new output path
			with open("{}/_config.txt".format(syspath),'w') as f:
Example #11
0
    def test_LC_request_response(self):

        # Call the service, which will send a request to the server.
        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_lightkurve(indir, transit_list, sectors, tic, test = './LATTE/tests/tic55525572_tp.fits')
        
        print(float(TESS_unbinned_t_l[0]))
        print(float(TESS_binned_t_l[0]))
        print(float(small_binned_t_l[0]))
        print(float(TESS_unbinned_l[0]))
        print(float(TESS_binned_l[0]))
        print(float(small_binned_l[0]))

        
        # If the request is sent successfully, then I expect a response to be returned.
        self.assertAlmostEqual(float(TESS_unbinned_t_l[0]), float(1437.9924102871835), msg='TP lighkurve data is not what it should be.')
        self.assertAlmostEqual(float(TESS_binned_t_l[0]), float(1437.9972713631325), places=5)
        self.assertAlmostEqual(float(small_binned_t_l[0]), float(1437.9972713631325), places=5)
        self.assertAlmostEqual(float(TESS_unbinned_l[0]), float(0.9975904130977179), places=5)
        self.assertAlmostEqual(float(TESS_binned_l[0]), float(0.9986087992155438), places=5)
        self.assertAlmostEqual(float(small_binned_l[0]), float(0.9971978343909532), places=5)
Example #12
0
	
		# this is also the first time that the program is being run, so download all the data that is required.
		print ("\n Download the text files required ... " )
		print ("\n Only the manifest text files (~325 M) will be downloaded and no TESS data." )
		print ("\n This step may take a while but luckily it only has to run once... \n" )

		# ------------------------------------------------
		#check whether the chosen (output) directory already exists, and if it doesn't create the directory.
		
		if not os.path.exists("{}/data".format(indir)):
			os.makedirs("{}/data".format(indir))
	
		# ------------------------------------------------

		# ----- REFERENCE FILES DOWNLOAD -----
		utils.data_files(indir)
		utils.tp_files(indir)
		utils.TOI_TCE_files(indir)
		utils.momentum_dumps_info(indir)
		
		# -----

	# if the user chooses to redefine the path
	elif args.new_path == True: 
	
		reply = yes_or_no() # double check that they really want to do that.
	
		if reply == True:
			indir = input("\n \n Please enter a path to save the files (e.g. ./LATTE_output or /Users/yourname/Desktop/LATTE_output) : " )

			#try three times to find the output path
Example #13
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")
Example #14
0
        print(
            "\n This step may take a while but luckily it only has to run once... \n"
        )

        # ------------------------------------------------
        #check whether the chosen (output) directory already exists, and if it doesn't create the directory.

        if not os.path.exists("{}/data".format(indir)):
            os.makedirs("{}/data".format(indir))

        # ------------------------------------------------

        # ----- REFERENCE FILES DOWNLOAD -----
        #utils.data_files(indir)
        utils.get_data_codes(
            indir
        )  # get the codes needed to downlaod the data directly (so that we don't need the url scipts anymore)
        utils.tp_files(
            indir
        )  # downlaod the lost of all of the tic ids in that sector - this is needed to find the nearest neighbour tic ids.
        utils.TOI_TCE_files(indir)  # get a list of the TCEs and TOIs
        utils.momentum_dumps_info(
            indir
        )  # note downn the momentum dumps - we need this for the FFI's only

        # -----

    # if the user chooses to redefine the path
    elif args.new_path == True:

        reply = yes_or_no()  # double check that they really want to do that.