Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: fix major bugs in PyKE #5

Merged
merged 80 commits into from
Apr 27, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
95830c0
[BUG]: fix major bugs in PyKE
mirca Mar 24, 2017
92e96fd
fix typo
mirca Mar 24, 2017
4f38157
'update' method has changed
mirca Mar 28, 2017
e61f8f0
update gitignore; update kepkey.py
mirca Mar 28, 2017
9e5994e
fix kepoutlier
mirca Mar 28, 2017
a431225
fix kepclip
mirca Mar 28, 2017
7084131
fix kepcotrend
mirca Mar 29, 2017
8ecb14d
fix kepdetrend
mirca Mar 30, 2017
fe9c508
fix kepdiffim
mirca Mar 30, 2017
7add742
fix kepextract
mirca Mar 30, 2017
1345d2d
fix kepft
mirca Mar 31, 2017
0b6111f
fix kepmask
mirca Apr 2, 2017
50a505a
fix kepflatten
mirca Apr 2, 2017
b847f50
fix kepfit
mirca Apr 2, 2017
f8afb19
fix kepdraw
mirca Apr 2, 2017
34ae6d0
fix kepfunc
mirca Apr 2, 2017
386f7ca
fix kepsmooth
mirca Apr 2, 2017
9f38dd5
kepfit: do not compare to None
mirca Apr 3, 2017
0a2e49b
fix kepstddev
mirca Apr 3, 2017
75d6592
update test_imports
mirca Apr 3, 2017
d177e9a
copy is from copy library not from numpy
mirca Apr 4, 2017
5ec86a9
fix kepfold
mirca Apr 4, 2017
eeac4af
fix keptrim
mirca Apr 4, 2017
4a9a5d9
update kepfourier
mirca Apr 5, 2017
1c4a09a
update kepfunc
mirca Apr 5, 2017
dce9201
fix keptrial
mirca Apr 5, 2017
6a0462e
remove keparith
mirca Apr 5, 2017
027bacc
remove kepbls
mirca Apr 5, 2017
0c3b5fe
remove keptransit
mirca Apr 5, 2017
5e8de4d
fix kepdynamic
mirca Apr 5, 2017
ddae0ef
fix kepfilter
mirca Apr 5, 2017
8c2c67c
fix keppixseries
mirca Apr 6, 2017
2342d74
update test_imports
mirca Apr 6, 2017
d55c01c
fix keppprfphot
mirca Apr 6, 2017
f2b2318
fix kepprf
mirca Apr 6, 2017
fefbf36
fix kepconvert
mirca Apr 7, 2017
461d4a5
enable interactive plotting
mirca Apr 10, 2017
5fc83d3
remove block=True from plt.show
mirca Apr 10, 2017
55c7bfa
add import os to kepmask
mirca Apr 10, 2017
8c75158
remove ploting style in kepdraw
mirca Apr 11, 2017
2bb7bfb
uses axisbg instead of facecolor in keppixseries
mirca Apr 11, 2017
6a2f74e
fix identation and style in kepcotrend
mirca Apr 12, 2017
7e53d1b
fix kepstitch
mirca Apr 13, 2017
6291450
fix keparray
mirca Apr 13, 2017
822319e
add kepbls back
mirca Apr 15, 2017
67af790
remove kepbin
mirca Apr 18, 2017
24c1566
refactor kepclip
mirca Apr 18, 2017
b9a74d8
refactor kepcotrend
mirca Apr 18, 2017
dc0330f
remove kepcotrend_cl.py
mirca Apr 18, 2017
dd90122
refactor kepdetrend
mirca Apr 18, 2017
3d92220
refactor kepdiffim
mirca Apr 18, 2017
efa8594
add keptransit back
mirca Apr 19, 2017
6a474d3
fix keparith
mirca Apr 20, 2017
be81038
update kepconvert
mirca Apr 20, 2017
d938209
fix kepffi
mirca Apr 20, 2017
88ed393
style changes kepft.py
mirca Apr 20, 2017
d8c9b5c
fix kephead
mirca Apr 21, 2017
fafe4e9
rm kepfield and kepfoldimg
mirca Apr 21, 2017
1e1faef
fix kepimages
mirca Apr 24, 2017
e26e80f
fix keppca
mirca Apr 25, 2017
465f0eb
fix keprange
mirca Apr 25, 2017
fe71987
update kepwindow
mirca Apr 25, 2017
a75b0f0
small bug in kepft
mirca Apr 25, 2017
3c28519
add test imports
mirca Apr 25, 2017
db981e4
fix identation in keptrial
mirca Apr 25, 2017
c4bbbfb
keppixseries now saves the output
mirca Apr 25, 2017
4c69abd
update log filename
mirca Apr 26, 2017
38b9092
fix tabs in kepbls
mirca Apr 26, 2017
82de75c
fix indentations in many files
mirca Apr 26, 2017
21f384d
fix indentation
mirca Apr 26, 2017
fe67683
fix indentation of kepstitch
mirca Apr 26, 2017
4eaf79e
fix keptrial indentation
mirca Apr 26, 2017
27967fa
fix identations
mirca Apr 26, 2017
5e27226
update kepler.cl
mirca Apr 27, 2017
53109a5
fix logfile
mirca Apr 27, 2017
6ae6974
fix logfile default values
mirca Apr 27, 2017
8d22e60
update requirements
mirca Apr 27, 2017
d4865ed
update requirements
mirca Apr 27, 2017
cea9f98
Add travis
mirca Mar 29, 2017
3f8a7f3
Merge branch 'master' into major-bug-fix
mirca Apr 27, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,6 @@ target/

# Custom additions
pyraf

# Mac OSX
.DS_Store
74 changes: 28 additions & 46 deletions keparith.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,29 @@


import sys
import pyfits
from astropy.io import fits as pyfits
import matplotlib.pyplot as plt
import kepio, kepmsg, kepkey, kepfit, kepstat
from numpy import median,subtract,maximum,ones,multiply,float32,shape,absolute,mean,std,isfinite,where,nan
from numpy import median, subtract, maximum, ones, multiply, float32, shape
from numpy import absolute, mean, std, isfinite, where, nan

__svnid__ = "$Id: keparith.py 4326 2012-07-02 21:49:01Z tsbarcl2 $"
__url__ = "$URL: svn+ssh://mstill@murzim.amn.nasa.gov/data-repo/trunk/data/flight/go/PyKE/kepler/keparith.py $"


def MAD(xx,minSd=1E-16):
"""Median Absolute Deviation
"""
med=median(xx,0)
absdev=absolute(subtract(xx,med))
mad=median(absdev,0)
mad=maximum(mad,multiply(ones(mad.shape,float32),
(minSd/1.48)))
return mad
def MAD(xx,minSd=1E-16):
"""Median Absolute Deviation
"""
med = median(xx,0)
absdev = absolute(subtract(xx, med))
mad=median(absdev, 0)
mad=maximum(mad, multiply(ones(mad.shape, float32),(minSd / 1.48)))
return mad


def kepaddconstant(infile,outfile,datacol,constant,constantval,sign
,clobber,verbose,logfile,status):
# log the call
# log the call

hashline = '----------------------------------------------------------------------------'
kepmsg.log(logfile,hashline,verbose)
Expand Down Expand Up @@ -65,33 +65,23 @@ def kepaddconstant(infile,outfile,datacol,constant,constantval,sign
# clobber output file

if clobber: status = kepio.clobber(outfile,logfile,verbose)
if kepio.fileexists(outfile):
if kepio.fileexists(outfile):
message = 'ERROR -- KEPARITH: ' + outfile + ' exists. Use clobber=yes'
status = kepmsg.err(logfile,message,verbose)

## open input file

instr, status = kepio.openfits(infile,'readonly',logfile,verbose)

if status == 0:
try:
test = str(instr[0].header['FILEVER'])
version = 2
except KeyError:
version = 1


# if version == 1:
# #lc_flux = instr[1].data.field(datacol) + constant
# lc_flux = instr[1].data.field(datacol)
# instr[1].data.field(datacol)[:] = (lc_flux - median(lc_flux)) / MAD(lc_flux)
# elif version == 2:
# #lc_flux = instr[1].data.field(datacol) + constant
# lc_flux = instr[1].data.field(datacol)
# instr[1].data.field(datacol)[:] = (lc_flux - median(lc_flux)) / MAD(lc_flux)


lc_flux = instr[1].data.field(datacol)

if datacol == 'SAP_FLUX':
errcol = 'SAP_FLUX_ERR'
try:
Expand All @@ -118,7 +108,6 @@ def kepaddconstant(infile,outfile,datacol,constant,constantval,sign
haveerr = True
except:
haveerr = False

#subtractor he just refers to the number that will be added/subtracted
#divided or multiplied
if isinstance(constantval,(long,int,float)) and constant == 'None':
Expand All @@ -142,14 +131,12 @@ def kepaddconstant(infile,outfile,datacol,constant,constantval,sign
else:
message = 'Your constant term is not in the list of possible functions'
status = kepmsg.err(logfile,message,verbose)

if subtractor == 0. and sign == 'divide' and status == 0:
message = 'You are trying to divide by zero: not a good idea.'
status = kepmsg.err(logfile,message,verbose)



if status == 0:
if status == 0:
if sign.lower() == 'add':
instr[1].data.field(datacol)[:] = where(isfinite(instr[1].data.field(datacol)[:]),(lc_flux + subtractor),nan)
elif sign.lower() == 'subtract':
Expand All @@ -165,14 +152,11 @@ def kepaddconstant(infile,outfile,datacol,constant,constantval,sign
else:
message = 'Your operation need to be one of: add, subtract, divide or multiply'
status = kepmsg.err(logfile,message,verbose)

if status == 0:
instr.writeto(outfile)


if status == 0:
status = kepio.closefits(instr,logfile,verbose)

status = kepio.closefits(instr,logfile,verbose)
## end time

if (status == 0):
Expand All @@ -185,34 +169,32 @@ def kepaddconstant(infile,outfile,datacol,constant,constantval,sign

if '--shell' in sys.argv:
import argparse

parser = argparse.ArgumentParser(description='Time invariant algebra on light curve data')
parser.add_argument('--shell', action='store_true', help='Are we running from the shell?')

parser = argparse.ArgumentParser(description='Time invariant algebra '
'on light curve data')
parser.add_argument('--shell', action='store_true',
help='Are we running from the shell?')

parser.add_argument('infile', help='Name of input file', type=str)
parser.add_argument('outfile', help='Name of FITS file to output', type=str)

parser.add_argument('--datacol', '-d', default='SAP_FLUX', dest='datacol', help='Name of the column containing the flux time series', type=str)
parser.add_argument('--datacol', '-d', default='SAP_FLUX',
dest='datacol',
help='Name of the column containing the flux time series', type=str)
parser.add_argument('--constantfunc', '-f', default='None', dest='constantfunc', help='A value calculated from a function to be used in operation', type=str,
choices=['None','median','mean','MAD','std','max','range'])
parser.add_argument('--constantval', '-v', default='None', dest='constantval', help='Use a given number in operation', type=str)
parser.add_argument('--operation', '-o', default='add', dest='operation', help='Add, subtract, multiply, divide flux by a constant', type=str,
choices=['add','','subtract','multiply','divide'])

parser.add_argument('--clobber', action='store_true', help='Overwrite output file?')
parser.add_argument('--verbose', action='store_true', help='Write to a log file?')
parser.add_argument('--logfile', '-l', help='Name of ascii log file', default='kepcotrend.log', dest='logfile', type=str)
parser.add_argument('--status', '-e', help='Exit status (0=good)', default=0, dest='status', type=int)


args = parser.parse_args()

kepaddconstant(args.infile,args.outfile,args.datacol,args.constantfunc,args.constantval,args.operation,args.clobber,args.verbose,args.logfile,args.status)


else:
from pyraf import iraf
parfile = iraf.osfn("kepler$keparith.par")
t = iraf.IrafTaskFactory(taskname="keparith", value=parfile, function=kepaddconstant)


Loading