Skip to content

Commit

Permalink
Merge pull request #26 from zemogle/main
Browse files Browse the repository at this point in the history
Dev is 24 commits behind main
  • Loading branch information
mfitzasp authored Oct 17, 2023
2 parents cb9f35f + cf2ee22 commit 57cc034
Show file tree
Hide file tree
Showing 35 changed files with 207 additions and 115 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/publish-to-test-pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Publish 🚀 astrosource distributions 📦 to PyPI and TestPyPI

on: push

jobs:
build-n-publish:
name: Build and publish astrosource package 📦 to PyPI and TestPyPI
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@main
- name: Set up Python 3.7
uses: actions/setup-python@v1
with:
python-version: 3.7
- name: Install pep517
run: >-
python -m
pip install
pep517
--user
- name: Build a binary wheel and a source tarball
run: >-
python -m
pep517.build
--source
--binary
--out-dir dist/
.
- name: Publish distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.pypi_password }}
33 changes: 0 additions & 33 deletions .github/workflows/pythonpackage.yml

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ checkplots/
outputcats/
outputplots/
__pycache__/
astrosource/test/__pycache__/
.pytest_cache/
.cache/
*.egg-info
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ There are a few input options when running the scripts. You can either run the w

`--indir` [parameter] Path of directory containing LCO data files. If none is given, astrosource assumes the current directory

`--format` [parameter] input file format. If not `fz`, `fits`, or `fit` assumes the input files are photometry files with correct headers. If image files given, code will extra photometry from FITS extension. Defaults to `fz`.
`--format` [parameter] input file format. If not `fz`, `fits`, or `fit` assumes the input files are photometry files with correct headers. If image files given, code will extract photometry from FITS extension. Defaults to `fz`.

`--stars` [boolean flag] Step 1: Identify and match stars from each data file

Expand Down Expand Up @@ -83,17 +83,17 @@ There are a few input options when running the scripts. You can either run the w

`--calib` [boolean flag] Perform calibrated

`--lowcounts` [int] Countrate above which to accept a comparison star as a candidate. Defaults to 1000. (Note: This may seem like a low number but realistically stars at this low rate will be highly variable and rejected anyway)
`--lowcounts` [int] Count rate above which to accept a comparison star as a candidate. Defaults to 1000. (Note: This may seem like a low number but realistically stars at this low rate will be highly variable and rejected anyway)

`--hicounts` [int] Countrate above which to reject a comparison star as a candidate. Defaults to 1000000. (Note: This will vary from camera to camera, but it should be representative of a typical value that would have a peak pixel value significantly below the full range of the ccd, preferably lower rather than higher. )
`--hicounts` [int] Count rate above which to reject a comparison star as a candidate. Defaults to 1000000. (Note: This will vary from camera to camera, but it should be representative of a typical value that would have a peak pixel value significantly below the full range of the ccd, preferably lower rather than higher. )

`--thresholdcounts` [int] the number of counts at which to stop adding identified comparison stars to the ensemble. Default 1000000.

`--closerejectd` [float] astrosource will reject potential comparison calibration stars if there are nearby stars to it. Closerejectd is the limiting distance in arcseconds. For crowded fields, this value may need to be lowered. Default 5.0. While the primary function here is to identify stars that are not in crowded situations, it also has the side-effect of removing false detections in sky surveys due to image artifacts or diffraction spikes which tend to cluster together.

`--nopanstarrs` [boolean flag] Do not use the PanSTARRS catalogue for calibration. Some regions of the sky in PanSTARRS have poorer quality photometry than SDSS.

`--sdss` [boolean flag] Do not use the SDSS catalogue for calibration. Some regions of the sky in SDSS have poorer quality photometry than PanSTARRS.
`--nosdss` [boolean flag] Do not use the SDSS catalogue for calibration. Some regions of the sky in SDSS have poorer quality photometry than PanSTARRS.

`--bjd` [boolean flag] Convert the MJD time into BJD time for LCO images.

Expand Down
3 changes: 0 additions & 3 deletions astrosource/analyse.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ def find_variable_stars(targets, matchRadius, errorReject=0.05, parentPath=None,
if diffMagHolder.shape[0] == sizeBefore:
break


if (diffMagHolder.shape[0] > minimumNoOfObs):
outputVariableHolder.append( [target[0],target[1],median(diffMagHolder), std(diffMagHolder), diffMagHolder.shape[0]])

Expand Down Expand Up @@ -446,8 +445,6 @@ def photometric_calculations(targets, paths, targetRadius, errorReject=0.1, file
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
4 changes: 2 additions & 2 deletions astrosource/astrosource.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(self, targets, indir, **kwargs):
self.format = kwargs.get('format', 'fz')
self.imgreject = kwargs.get('imgreject', 0.05)
self.periodupper = kwargs.get('periodupper', -99.9)
self.periodlower = kwargs.get('periodlower', -99.9)
self.periodlower = kwargs.get('periodlower', 0.05)
self.periodtests = kwargs.get('periodtests', -99)

self.racut = kwargs.get('racut', -99.9)
Expand Down Expand Up @@ -168,6 +168,7 @@ def analyse(self, calib=True, usescreenedcomps=False, usecompsused=False, usecom
#Check stars are in images

# 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 usecompletedcalib == False:
self.calibrated = False
if calib and self.filtercode in ['B', 'V', 'up', 'gp', 'rp', 'ip', 'zs', 'CV', 'w']:
Expand Down Expand Up @@ -201,7 +202,6 @@ def analyse(self, calib=True, usescreenedcomps=False, usecompsused=False, usecom
self.calibrated = True
return


def find_variables(self):
find_variable_stars(targets=self.targets, parentPath=self.paths['parent'], matchRadius=self.matchradius, varsearchglobalstdev=self.varsearchglobalstdev, varsearchthresh=self.varsearchthresh, varsearchstdev=self.varsearchstdev, varsearchmagwidth=self.varsearchmagwidth, varsearchminimages=self.varsearchminimages, photCoords=self.photCoords, photFileHolder=self.photFileHolder, fileList=self.usedimages)

Expand Down
31 changes: 5 additions & 26 deletions astrosource/comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,19 +348,18 @@ def calculate_comparison_variation(compFile, photFileArray, fileCount, parentPat
stdCompDiffMags=std(compDiffMags[:,z])
medCompDiffMags=np.nanmedian(compDiffMags[:,z])
medInstrMags=np.nanmedian(instrMags[:,z])

if np.isnan(stdCompDiffMags) :
logger.error("Star Variability non rejected")
stdCompDiffMags=99
stdCompStar.append(stdCompDiffMags)

sortStars.append([compFile[z,0],compFile[z,1],stdCompDiffMags,medCompDiffMags,medInstrMags,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0])

return stdCompStar, sortStars

def remove_stars_targets(parentPath, compFile, acceptDistance, targetFile, removeTargets):
max_sep=acceptDistance * arcsecond
logger.info("Removing Target Stars from potential Comparisons")
tableFound=False

if not (compFile.shape[0] == 2 and compFile.size ==2):
fileRaDec = SkyCoord(ra=compFile[:,0]*degree, dec=compFile[:,1]*degree)
Expand Down Expand Up @@ -398,7 +397,6 @@ def remove_stars_targets(parentPath, compFile, acceptDistance, targetFile, remov
else:
avgCoord=SkyCoord(ra=(average(compFile[:,0])*degree), dec=((average(compFile[:,1])*degree)))


# Get search Radius
radius= 0.5 * pow( pow(max(compFile[:,0])-min(compFile[:,0]),2) + pow(max((compFile[:,1])-min(compFile[:,1]))*cos((min(compFile[:,1])+max(compFile[:,1]))/2),2) , 0.5)
if radius > 120:
Expand Down Expand Up @@ -435,7 +433,6 @@ def remove_stars_targets(parentPath, compFile, acceptDistance, targetFile, remov
tableFound=True

except (ConnectionError , requests.exceptions.ConnectionError , http.client.RemoteDisconnected , urllib3.exceptions.ProtocolError) :

connected=False
logger.info("Connection failed, waiting and trying again")
cycler=0
Expand Down Expand Up @@ -614,6 +611,7 @@ def catalogue_call(avgCoord, radius, opt, cat_name, targets, closerejectd):
logger.info("Looks like your catalogue has too many sources next to nearby sources. ABORTING.")

# Remove any star that has invalid values for mag or magerror

if len(resp) != 0:
catReject=[]

Expand Down Expand Up @@ -771,7 +769,6 @@ def find_comparisons_calibrated(targets, paths, filterCode, nopanstarrs=False, n
coords=[]
raise AstrosourceException("Empty catalogue produced from catalogue call")


if coords.cat_name == 'PanSTARRS' or coords.cat_name == 'APASS':
max_sep=2.5 * arcsecond
else:
Expand Down Expand Up @@ -1095,7 +1092,6 @@ def find_comparisons_calibrated(targets, paths, filterCode, nopanstarrs=False, n
colourPath = paths['parent'] / 'colourplots'
if not colourPath.exists():
os.makedirs(colourPath)

for qert in range(len(photFileHolder)):


Expand Down Expand Up @@ -1215,11 +1211,6 @@ def find_comparisons_calibrated(targets, paths, filterCode, nopanstarrs=False, n
else:
logger.info("Skipping Colour Correction Estimation")






# Get rid of higher variability stars from calibration list
varimin=(min(asarray(calibStands)[:,2])) * variabilityMultiplier
calibStandsReject=[]
Expand Down Expand Up @@ -1302,7 +1293,6 @@ def find_comparisons_calibrated(targets, paths, filterCode, nopanstarrs=False, n
#Replace undetected colours with average colour of the field
photFile[:,8]=np.nan_to_num(photFile[:,8],nan=np.nanmedian(photFile[:,8]))
photFile[:,9]=np.nan_to_num(photFile[:,9],nan=np.nanmedian(photFile[:,9]))

# If the colour detection routine was run, this was calculated already
#if not colourdetect:
# photFile[:,5]=1.0857 * (photFile[:,5]/photFile[:,4])
Expand Down Expand Up @@ -1365,11 +1355,7 @@ def find_comparisons_calibrated(targets, paths, filterCode, nopanstarrs=False, n
else:
calibOut[:,5]=calibOut[:,4]-tempZP # Speedup
for r in range(len(calibOut[:,0])):

calibOverlord.append([calibOut[r,0],calibOut[r,1],calibOut[r,2],calibOut[r,3],calibOut[r,4],calibOut[r,5],float(file.split("_")[2].replace("d",".")),tempZP,calibOut[r,6],calibOut[r,7],calibOut[r,8]])

#breakpoint()

calibOut=asarray(calibOut)

#Save the calibrated photfiles to the calib directory
Expand All @@ -1391,6 +1377,7 @@ def find_comparisons_calibrated(targets, paths, filterCode, nopanstarrs=False, n
weights=1/(calibOut[:,1])
linA = np.vstack([outplotx,np.ones(len(outplotx))]).T * np.sqrt(weights[:,np.newaxis])
linB = outploty * np.sqrt(weights)

#breakpoint()


Expand All @@ -1415,17 +1402,10 @@ def find_comparisons_calibrated(targets, paths, filterCode, nopanstarrs=False, n

except:
logger.info("\nFailed linear fit on a postcolour plot: ")




z=z+1






#Look within photfile for ACTUAL usedcomps.csv and pull them out
#Look within photfile for ACTUAL usedcomps.csv and pull them out
lineCompUsed=[]
if compUsedFile.shape[0] ==3 and compUsedFile.size == 3:
lenloop=1
Expand Down Expand Up @@ -1629,7 +1609,6 @@ def find_comparisons_calibrated(targets, paths, filterCode, nopanstarrs=False, n
nonlinearZero=c
nonlinearError=residuals[0] / pow(len(fileList), 0.5)


with open(parentPath / "results/CalibrationSanityPlotCoefficients.txt", "a+") as f:
f.write("Corrected Magnitude slope : " + str(m)+"\n")
f.write("Corrected Magnitude zeropoint : " + str(c) +"\n")
Expand Down
1 change: 1 addition & 0 deletions astrosource/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
@click.option('--phot', is_flag=True, help='Step 4: Photometry calculations for either differential or calibrated')
@click.option('--plot', is_flag=True, help='Step 5: Produce lightcurve plots')


@click.option('--indir', default=None, type=str, required=True, help='Path of directory containing LCO data files. If none is given, astrosource assumes the current directory')
@click.option('--ra', type=str, help='Right Ascension of the target (in decimal or H:M:S)')
@click.option('--dec', type=str, help='Declination of the target (in decimal or D:M:S)')
Expand Down
2 changes: 0 additions & 2 deletions astrosource/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ def output_files(paths, photometrydata, mode='diff'):
magColumn=outputPhot[:,10]
magerrColumn=outputPhot[:,11]

#breakpoint()

outputPeransoCalib = [x for x in zip(outputPhot[:,6],magColumn,magerrColumn)]
outputPeransoCalib = asarray(outputPeransoCalib)

Expand Down
Binary file removed astrosource/test/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file removed astrosource/test/__pycache__/mocks.cpython-38.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion astrosource/test/test_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def test_remove_targets_calibrated(setup):
@patch('astrosource.comparison.Vizier',mock_vizier_apass_b)
def test_find_comparisons_calibrated_b(setup):
compFile = find_comparisons_calibrated(filterCode='B', paths=TEST_PATHS, targets=setup.targets)

assert asarray(compFile).shape == (3,)

@patch('astrosource.comparison.Vizier',mock_vizier_apass_v)
Expand Down
Binary file removed astrosource/test/test_files/comparison.zip
Binary file not shown.
1 change: 0 additions & 1 deletion astrosource/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from os import getcwd, makedirs, remove
import shutil
import logging
import sys
import time

from numpy import asarray, genfromtxt, load, isnan, delete
Expand Down
10 changes: 5 additions & 5 deletions docs/source/api_usage.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Library Usage
=============
To take advantage of some of the more advance options in AstroSource, you want to import the library as part of a larger code base.
To take advantage of some of the more advance options in ``astrosource``, you want to import the library as part of a larger code base.

Getting Started
---------------
The fundamental role of AstroSource is the analysis of time-series data. So, the basic class in AstroSource is called `TimeSeries`.
The fundamental role of ``astrosource`` is the analysis of time-series data. So, the basic class in ``astrosource`` is called `TimeSeries`.

There are only *2* required inputs: a list of targets and a directory where the input files can be found.

Expand Down Expand Up @@ -34,7 +34,7 @@ Optional Inputs
**format** `str`
A file extension for the files in `indir` which contain the photometry data.
**imgreject** `float`
Image fraction rejection allowance. Defaults to `0.0`. Increasing this will allow AstroSource to reject some of your data files if there are not enough comparison stars.
Image fraction rejection allowance. Defaults to `0.0`. Increasing this will allow ``astrosource`` to reject some of your data files if there are not enough comparison stars.


Analysis
Expand All @@ -55,5 +55,5 @@ This is an example of the full analysis code using the input directory `indir` a
The `plot` stage has 3 optional inputs:

* detrend: detrend exoplanet data
* period: recursively attempt to find a period (for periodic sources like variable stars or binaries)
* eebls: Edge Enhanced Box-fitting Least Squares analysis for an exoplanet transit curve
* :ref:`period<Period Folding>`: recursively attempt to find a period (for periodic sources like variable stars or binaries)
* eebls: Edge Enhanced Box-fitting Least Squares analysis for an exoplanet transit curve
Loading

0 comments on commit 57cc034

Please sign in to comment.