Skip to content

Commit

Permalink
Merge dev into main
Browse files Browse the repository at this point in the history
  • Loading branch information
zemogle committed Jun 30, 2024
2 parents de708c8 + 38387e6 commit d631536
Show file tree
Hide file tree
Showing 7 changed files with 343 additions and 194 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*.pyc
run.py

stdComps.csv
compsUsed.csv
Expand Down
106 changes: 65 additions & 41 deletions astrosource/analyse.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import math
import os
from tqdm import tqdm

#import traceback
import logging

#from astrosource.utils import photometry_files_to_array, AstrosourceException
Expand Down Expand Up @@ -122,34 +122,23 @@ def find_variable_stars(targets, matchRadius, errorReject=0.05, parentPath=None,
outputVariableHolder=[]

logger.info("Measuring variability of stars...... ")
taketime=time.time()

q=0
for target in targetFile:
q=q+1
#logger.debug("*********************")
#logger.debug("Processing Target {}".format(str(q)))
#logger.debug("RA {}".format(target[0]))
#logger.debug("DEC {}".format(target[1]))
varCoord = SkyCoord(target[0],(target[1]), frame='icrs', unit=degree) # Need to remove target stars from consideration


diffMagHolder=[]

allcountscount=0

r=0

for photFile in photFileArray:
#compList=[]
fileRaDec = photFileCoords[r]
r=r+1
idx, d2d, _ = varCoord.match_to_catalog_sky(fileRaDec)
# A bit rougher than using SkyCoord, but way faster
# The amount of calculations is too slow for SkyCoord
idx=(np.abs(photFile[:,0] - target[0]) + np.abs(photFile[:,1] - target[1])).argmin()
d2d=pow(pow(photFile[idx,0] - target[0],2) + pow(photFile[idx,1] - target[1],2),0.5) * 3600
multTemp=(multiply(-2.5,log10(divide(photFile[idx][11],allCountsArray[allcountscount][0]))))
if less(d2d.arcsecond, matchRadius) and (multTemp != inf) :
if less(d2d, matchRadius) and (multTemp != inf) :
diffMagHolder=append(diffMagHolder,multTemp)
allcountscount=add(allcountscount,1)

#breakpoint()


## REMOVE MAJOR OUTLIERS FROM CONSIDERATION
diffMagHolder=np.array(diffMagHolder)
while True:
Expand All @@ -169,9 +158,9 @@ def find_variable_stars(targets, matchRadius, errorReject=0.05, parentPath=None,
if (diffMagHolder.shape[0] > minimumNoOfObs):
outputVariableHolder.append( [target[0],target[1],median(diffMagHolder), std(diffMagHolder), diffMagHolder.shape[0]])

print ("Star Variability done in " + str(time.time()-taketime))


savetxt(parentPath / "results/starVariability.csv", outputVariableHolder, delimiter=",", fmt='%0.8f')
savetxt(parentPath / "results/starVariability.csv", outputVariableHolder, delimiter=",", fmt='%0.8f', header='RA,DEC,DiffMag,Variability,No_of_images_used')

## Routine that actually pops out potential variables.
starVar = np.asarray(outputVariableHolder)
Expand Down Expand Up @@ -215,7 +204,7 @@ def find_variable_stars(targets, matchRadius, errorReject=0.05, parentPath=None,
if potentialVariables.shape[0] == 0:
logger.info("No Potential Variables identified in this set of data using the parameters requested.")
else:
savetxt(parentPath / "results/potentialVariables.csv", potentialVariables , delimiter=",", fmt='%0.8f')
savetxt(parentPath / "results/potentialVariables.csv", potentialVariables , delimiter=",", fmt='%0.8f', header='RA,DEC,DiffMag,Variability')

plot_variability(outputVariableHolder, potentialVariables, parentPath, compFile)

Expand Down Expand Up @@ -288,22 +277,42 @@ def photometric_calculations(targets, paths, targetRadius, errorReject=0.1, file
else:
logger.debug("Dec {}".format(targets[q][1]))
if int(len(targets)) == 4 and targets.size==4:
varCoord = SkyCoord(targets[0],(targets[1]), frame='icrs', unit=degree) # Need to remove target stars from consideration
#varCoord = SkyCoord(targets[0],(targets[1]), frame='icrs', unit=degree) # Need to remove target stars from consideration
singleCoordRA=targets[0]
singleCoordDEC=targets[1]
else:
varCoord = SkyCoord(targets[q][0],(targets[q][1]), frame='icrs', unit=degree) # Need to remove target stars from consideration
#varCoord = SkyCoord(targets[q][0],(targets[q][1]), frame='icrs', unit=degree) # Need to remove target stars from consideration
singleCoordRA=targets[q][0]
singleCoordDEC=targets[q][1]

# Grabbing variable rows
logger.debug("Extracting and Measuring Differential Magnitude in each Photometry File")
outputPhot=[] # new
allcountscount=0

for imgs, photFile in enumerate(tqdm(photFileArray)):
fileRaDec = photCoordsFile[imgs]
idx, d2d, _ = varCoord.match_to_catalog_sky(fileRaDec)
#fileRaDec = photCoordsFile[imgs]
#idx, d2d, _ = varCoord.match_to_catalog_sky(fileRaDec)
#breakpoint()
idx=(np.abs(photFile[:,0] - singleCoordRA) + np.abs(photFile[:,1] - singleCoordDEC)).argmin()
d2d=pow(pow(photFile[idx,0] - singleCoordRA,2) + pow(photFile[idx,1] - singleCoordDEC,2),0.5) * 3600

#print (d2d)

starRejected=0
if (less(d2d.arcsecond, targetRadius)):
if (less(d2d, targetRadius)):
#magErrVar = 1.0857 * (photFile[idx][5]/photFile[idx][4])
magErrVar = photFile[idx][5]



# If the file hasn't been calibrated, then it still contains the countrate in it.
# So convert these to mags, otherwise use the calibrated error.
if photFile[idx][4] > 50:
magErrVar = 1.0857 * (photFile[idx][5]/photFile[idx][4])
else:
magErrVar = photFile[idx][5]


if magErrVar < errorReject:

magErrEns = 1.0857 * (allCountsArray[allcountscount][1]/allCountsArray[allcountscount][0])
Expand All @@ -329,10 +338,16 @@ def photometric_calculations(targets, paths, targetRadius, errorReject=0.1, file
loopLength=compFile.shape[0]
for j in range(loopLength):
if compFile.size == 2 or (compFile.shape[0]== 3 and compFile.size ==3) or (compFile.shape[0]== 5 and compFile.size ==5):
matchCoord=SkyCoord(ra=compFile[0]*degree, dec=compFile[1]*degree)
#matchCoord=SkyCoord(ra=compFile[0]*degree, dec=compFile[1]*degree)
matchRA=compFile[0]
matchDEC=compFile[1]
else:
matchCoord=SkyCoord(ra=compFile[j][0]*degree, dec=compFile[j][1]*degree)
idx, d2d, d3d = matchCoord.match_to_catalog_sky(fileRaDec)
#matchCoord=SkyCoord(ra=compFile[j][0]*degree, dec=compFile[j][1]*degree)
matchRA=compFile[j][0]
matchDEC=compFile[j][1]
#idx, d2d, _ = matchCoord.match_to_catalog_sky(fileRaDec)
idx=(np.abs(photFile[:,0] - matchRA) + np.abs(photFile[:,1] - matchDEC)).argmin()
d2d=pow(pow(photFile[idx,0] - matchRA,2) + pow(photFile[idx,1] - matchDEC,2),0.5) * 3600
tempList=append(tempList, photFileArray[imgs][idx][11])
outputPhot.append(tempList)

Expand Down Expand Up @@ -370,15 +385,23 @@ def photometric_calculations(targets, paths, targetRadius, errorReject=0.1, file

for j in range(loopLength):
if compFile.size == 2 or (compFile.shape[0]== 3 and compFile.size ==3) or (compFile.shape[0]== 5 and compFile.size ==5):
matchCoord=SkyCoord(ra=compFile[0]*degree, dec=compFile[1]*degree)
# matchCoord=SkyCoord(ra=compFile[0]*degree, dec=compFile[1]*degree)
matchRA=compFile[0]
matchDEC=compFile[1]
else:
matchCoord=SkyCoord(ra=compFile[j][0]*degree, dec=compFile[j][1]*degree)
idx, d2d, d3d = matchCoord.match_to_catalog_sky(fileRaDec)
# matchCoord=SkyCoord(ra=compFile[j][0]*degree, dec=compFile[j][1]*degree)
matchRA=compFile[j][0]
matchDEC=compFile[j][1]
#idx, d2d, d3d = matchCoord.match_to_catalog_sky(fileRaDec)
idx=(np.abs(photFile[:,0] - matchRA) + np.abs(photFile[:,1] - matchDEC)).argmin()
d2d=pow(pow(photFile[idx,0] - matchRA,2) + pow(photFile[idx,1] - matchDEC,2),0.5) * 3600
tempList=append(tempList, photFileArray[imgs][idx][11])
outputPhot.append(tempList)
fileCount.append(allCountsArray[allcountscount][0])
allcountscount=allcountscount+1

#breakpoint()

# Check for dud images
imageReject=[]
for j in range(asarray(outputPhot).shape[0]):
Expand All @@ -403,7 +426,7 @@ def photometric_calculations(targets, paths, targetRadius, errorReject=0.1, file
starReject.append(j)
stdevReject=stdevReject+1

if starReject != []:
if len(starReject) != 0:
outputPhot=delete(outputPhot, starReject, axis=0)
else:
break
Expand All @@ -423,7 +446,7 @@ def photometric_calculations(targets, paths, targetRadius, errorReject=0.1, file
starReject.append(j)
starErrorRejCount=starErrorRejCount+1

if starReject != []:
if len(starReject) != 0:
outputPhot=delete(outputPhot, starReject, axis=0)
else:
break
Expand All @@ -440,10 +463,11 @@ def photometric_calculations(targets, paths, targetRadius, errorReject=0.1, file

except ValueError:
#raise AstrosourceException("No target stars were detected in your dataset. Check your input target(s) RA/Dec")
import traceback; logger.error(traceback.print_exc())
logger.error("This target star was not detected in your dataset. Check your input target(s) RA/Dec")
logger.info("Rejected Stdev Measurements: : {}".format(stdevReject))
logger.error("Rejected Error Measurements: : {}".format(starErrorRejCount))
logger.error("Rejected Distance Measurements: : {}".format(starDistanceRejCount))
#logger.info("Rejected Stdev Measurements: : {}".format(stdevReject))
#logger.error("Rejected Error Measurements: : {}".format(starErrorRejCount))
#logger.error("Rejected Distance Measurements: : {}".format(starDistanceRejCount))

# Add calibration columns
outputPhot= np.c_[outputPhot, np.ones(outputPhot.shape[0]),np.ones(outputPhot.shape[0])]
Expand Down Expand Up @@ -526,4 +550,4 @@ def calibrated_photometry(paths, photometrydata, colourterm, colourerror, colour
logger.info("then consider providing an appropriate colour for this filter using the --targetcolour option")
logger.info("as well as an appropriate colour term for this filter (using --colourdetect or --colourterm).")

return pdata
return pdata
16 changes: 13 additions & 3 deletions astrosource/astrosource.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ def __init__(self, targets, indir, **kwargs):
self.starreject = kwargs.get('starreject', 0.3)
self.nopanstarrs = kwargs.get('nopanstarrs', False)
self.nosdss = kwargs.get('nosdss', False)
self.noskymapper = kwargs.get('noskymapper', False)

self.nocalib = kwargs.get('nocalib', False)
self.closerejectd = kwargs.get('closerejectd', 5.0)
self.targetradius = kwargs.get('targetradius', 1.5)
self.matchradius = kwargs.get('matchradius', 1.0)
Expand Down Expand Up @@ -123,7 +126,8 @@ def analyse(self, calib=True, usescreenedcomps=False, usecompsused=False, usecom
paths=self.paths,
fileList=self.files,
nopanstarrs=self.nopanstarrs,
nosdss=self.nosdss,
nosdss=self.nosdss,
noskymapper=self.noskymapper,
closerejectd=self.closerejectd,
photCoords=self.photCoords,
photFileHolder=self.photFileHolder,
Expand Down Expand Up @@ -169,16 +173,22 @@ def analyse(self, calib=True, usescreenedcomps=False, usecompsused=False, usecom

# Check that it is a filter that can actually be calibrated - in the future I am considering calibrating w against V to give a 'rough V' calibration, but not for now.

if self.nocalib==True:
calib=False

print ("calib: " + str(calib))

if usecompletedcalib == False:
self.calibrated = False
if calib and self.filtercode in ['B', 'V', 'up', 'gp', 'rp', 'ip', 'zs', 'CV', 'w']:
if calib and self.filtercode in ['B', 'V', 'up', 'gp', 'rp', 'ip', 'zs', 'CV', 'w', 'PB', 'PG','PR']:
try:

self.colourterm, self.colourerror, self.calibcompsused = find_comparisons_calibrated(targets=self.targets,
filterCode=self.filtercode,
paths=self.paths,
nopanstarrs=self.nopanstarrs,
nosdss=self.nosdss,
nosdss=self.nosdss,
noskymapper=self.noskymapper,
closerejectd=self.closerejectd,
colourdetect=self.colourdetect,
linearise=self.linearise,
Expand Down
Loading

0 comments on commit d631536

Please sign in to comment.