Skip to content

Commit

Permalink
Merge pull request #32 from rhoxu/master
Browse files Browse the repository at this point in the history
fix for external catalogue generation
  • Loading branch information
CheerfulUser committed Jun 26, 2024
2 parents a1ee7a3 + 8570ac9 commit f4dbf92
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2,656 deletions.
34 changes: 24 additions & 10 deletions tessreduce/catalog_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def Get_Catalogue_External(ra,dec,size,Catalog = 'gaia'):

return result

def Get_Gaia_External(tpf,magnitude_limit = 18, Offset = 10):
def Get_Gaia_External(ra,dec,size,wcsObj,magnitude_limit = 18, Offset = 10):
"""
Get the coordinates and mag of all gaia sources in the field of view.
Expand All @@ -146,31 +146,31 @@ def Get_Gaia_External(tpf,magnitude_limit = 18, Offset = 10):

#result = Get_Catalogue_External(ra,dec,size,Catalog = 'gaia')

result = Get_Catalogue(tpf,Catalog='gaia')
result = Get_Catalogue_External(ra,dec,size,Catalog='gaia')

result = result[result.Gmag < magnitude_limit]
if len(result) == 0:
raise no_targets_found_message
radecs = np.vstack([result['RA_ICRS'], result['DE_ICRS']]).T
try:
coords = tpf.wcs.all_world2pix(radecs, 0) ## TODO, is origin supposed to be zero or one?
coords = wcsObj.all_world2pix(radecs, 0) ## TODO, is origin supposed to be zero or one?
except:
good_coords = []
for i,radec in enumerate(radecs):
try:
c = tpf.wcs.all_world2pix(radec[0],radec[1], 0)
c = wcsObj.all_world2pix(radec[0],radec[1], 0)
good_coords.append(i)
except:
pass
radecs = radecs[good_coords]
result = result.iloc[good_coords]
coords = tpf.wcs.all_world2pix(radecs, 0) ## TODO, is origin supposed to be zero or one?
coords = wcsObj.all_world2pix(radecs, 0) ## TODO, is origin supposed to be zero or one?

source = result['Source'].values
Gmag = result['Gmag'].values
#Jmag = result['Jmag']
ind = (((coords[:,0] >= -10) & (coords[:,1] >= -10)) &
((coords[:,0] < (tpf.shape[2] + 10)) & (coords[:,1] < (tpf.shape[1] + 10))))
((coords[:,0] < (size + 10)) & (coords[:,1] < (size + 10))))
coords = coords[ind]
radecs = radecs[ind]
Gmag = Gmag[ind]
Expand Down Expand Up @@ -223,8 +223,6 @@ def mag2flux(mag,zp):
f = 10**(2/5*(zp-mag))
return f



def PS1_to_TESS_mag(PS1,ebv = 0):
zp = 25
gr = (PS1.gmag - PS1.rmag).values
Expand Down Expand Up @@ -485,10 +483,26 @@ def Reformat_df(df):

# gaia.to_csv(f'{save_path}/local_gaia_cat.csv',index=False)

# def external_save_cat(tpf,save_path,maglim):

# tpf = lk.TessTargetPixelFile(tpf)
# gp,gm, source = Get_Gaia_External(tpf,magnitude_limit=maglim)
# gaia = pd.DataFrame(np.array([gp[:,0],gp[:,1],gm,source]).T,columns=['ra','dec','mag','Source'])

# gaia.to_csv(f'{save_path}/local_gaia_cat.csv',index=False)

def external_save_cat(tpf,save_path,maglim):

tpfFits = fits.open(tpf)

ra = tpfFits[1].header['RA_OBJ']
dec = tpfFits[1].header['DEC_OBJ']
size = eval(tpfFits[1].header['TDIM8'])[0]

wcsObj = WCS(tpfFits[2].header)

gp,gm, source = Get_Gaia_External(ra,dec,size,wcsObj,magnitude_limit=maglim)

tpf = lk.TessTargetPixelFile(tpf)
gp,gm, source = Get_Gaia_External(tpf,magnitude_limit=maglim)
gaia = pd.DataFrame(np.array([gp[:,0],gp[:,1],gm,source]).T,columns=['ra','dec','mag','Source'])

gaia.to_csv(f'{save_path}/local_gaia_cat.csv',index=False)
Expand Down
Loading

0 comments on commit f4dbf92

Please sign in to comment.