-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
298 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,3 +61,4 @@ target/ | |
.DS_Store | ||
**/.idea/* | ||
pyhdust/.* | ||
junit/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,28 +7,30 @@ | |
import sys | ||
from argparse import ArgumentParser | ||
import os | ||
import pyfits as pf | ||
import astropy.io.fits as pf | ||
|
||
__version__ = "0.91" | ||
__version__ = "0.92" | ||
__author__ = "Daniel Moser" | ||
__email__ = "[email protected]" | ||
|
||
|
||
class MyParser(ArgumentParser): | ||
class MyParser(ArgumentParser): | ||
def error(self, message): | ||
sys.stderr.write('# ERROR! %s\n' % message) | ||
sys.stderr.write("# ERROR! %s\n" % message) | ||
self.print_help() | ||
sys.exit(2) | ||
|
||
|
||
parser = MyParser(description=__doc__) | ||
parser.add_argument('--version', action='version', | ||
version='%(prog)s {0}'.format(__version__)) | ||
parser.add_argument( | ||
"--version", action="version", version="%(prog)s {0}".format(__version__) | ||
) | ||
parser.add_argument("INPUT", help=("Filename of the 3D FITS cube"), type=str) | ||
|
||
args = parser.parse_args() | ||
|
||
|
||
if __name__ == '__main__': | ||
if __name__ == "__main__": | ||
|
||
fname = args.INPUT | ||
fits = pf.open(fname) | ||
|
@@ -39,6 +41,7 @@ def error(self, message): | |
hdulist[0].header = fits[0].header | ||
path, oname = os.path.split(fname) | ||
pref, ext = os.path.splitext(oname) | ||
hdu.writeto(os.path.join(path, pref+"_{0:04d}".format(i)+ext), | ||
overwrite=True) | ||
print('# Saved {0} 2D images from {1}'.format(nimgs, oname)) | ||
hdu.writeto( | ||
os.path.join(path, pref + "_{0:04d}".format(i) + ext), overwrite=True | ||
) | ||
print("# Saved {0} 2D images from {1}".format(nimgs, oname)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,12 +13,12 @@ | |
import matplotlib.pyplot as plt | ||
from scipy.signal import savgol_filter | ||
|
||
__version__ = "0.9" | ||
__version__ = "0.91" | ||
__author__ = "Daniel Moser" | ||
__email__ = "[email protected]" | ||
|
||
|
||
def plot_orders(ax, fwl, fflx, mode='o'): | ||
def plot_orders(ax, fwl, fflx, mode="o"): | ||
for i in range(len(fwl)): | ||
ax.plot(fwl[i], fflx[i], mode, ms=1) | ||
return ax | ||
|
@@ -28,22 +28,22 @@ def do_norm(wl, flx): | |
xout, yout = spt.max_func_pts(wl, flx, ws=0.01, avgbox=5) | ||
tck = interpolate.splrep(xout, yout) | ||
ynew = interpolate.splev(xout, tck, der=1) | ||
dmed = np.median( np.abs(ynew) ) | ||
dmed = np.median(np.abs(ynew)) | ||
l = len(wl) | ||
# ConditionA: small derivative | ||
conda = ( np.abs(ynew) < dmed ) | ||
# ConditionA: small derivative | ||
conda = np.abs(ynew) < dmed | ||
# ConditionB: in the limits | ||
condb = ( wl[int(l*0.15)] > xout ) | ( xout > wl[int(l*(1-.15))] ) | ||
condb = (wl[int(l * 0.15)] > xout) | (xout > wl[int(l * (1 - 0.15))]) | ||
# xmax = phc.find_nearest(yout, np.max(yout), idx=True) | ||
# xmax = xout[xmax] | ||
# xmax = wl[l/2] | ||
# ConditionC: xout < max(flx) AND ynew > 0 | ||
# condc = ( xout <= xmax ) & ( ynew >= 0 ) | ||
# ConditionD: xout > max(flx) AND ynew < 0 | ||
# condd = ( xout >= xmax ) & ( ynew <= 0 ) | ||
conde = ( ( xout > 658.45 ) | ( xout < 654.1 ) ) | ||
# idx = np.where( (( conda & (condd | condc) ) | condb) & (conde) ) | ||
idx = np.where( (conda | condb) & (conde) ) | ||
conde = (xout > 658.45) | (xout < 654.1) | ||
# idx = np.where( (( conda & (condd | condc) ) | condb) & (conde) ) | ||
idx = np.where((conda | condb) & (conde)) | ||
# & (condd | condc)) | ||
xout = xout[idx] | ||
yout = yout[idx] | ||
|
@@ -54,20 +54,20 @@ def do_norm(wl, flx): | |
return wl, flx, ynew | ||
|
||
|
||
path = '.' | ||
opsps = glob('*.spc.gz') | ||
print opsps | ||
path = "." | ||
opsps = glob("*.spc.gz") | ||
print(opsps) | ||
|
||
avgspecs = [] | ||
for sp in opsps: | ||
os.system('gunzip -c {0} > tmp.txt'.format(sp)) | ||
spec = np.loadtxt('tmp.txt', skiprows=11) | ||
os.system("gunzip -c {0} > tmp.txt".format(sp)) | ||
spec = np.loadtxt("tmp.txt", skiprows=11) | ||
|
||
fig, ax = plt.subplots() | ||
ax.plot(spec[:, 5], spec[:, 10], label='Leg.') | ||
ax.plot(spec[:, 5], spec[:, 10], label="Leg.") | ||
# ax.set_title('Title') | ||
# ax.legend() | ||
plt.savefig(sp.replace('.spc.gz', '_ori')) | ||
plt.savefig(sp.replace(".spc.gz", "_ori")) | ||
plt.close(fig) | ||
|
||
# i = 0 | ||
|
@@ -83,46 +83,50 @@ def do_norm(wl, flx): | |
try: | ||
wl, flx, ynew = do_norm(wl, flx) | ||
fwl.append(wl) | ||
onorm.append(flx/ynew) | ||
onorm.append(flx / ynew) | ||
ocont.append(ynew) | ||
oflx.append(flx) | ||
oflx.append(flx) | ||
except: | ||
print('# Error in order {0}'.format(o)) | ||
print("# Error in order {0}".format(o)) | ||
|
||
fig, ax = plt.subplots() | ||
ax = plot_orders(ax, fwl, oflx, 'o') | ||
ax = plot_orders(ax, fwl, ocont, '-') | ||
plt.savefig(sp.replace('.spc.gz', '.orders')) | ||
ax = plot_orders(ax, fwl, oflx, "o") | ||
ax = plot_orders(ax, fwl, ocont, "-") | ||
plt.savefig(sp.replace(".spc.gz", ".orders")) | ||
plt.close(fig) | ||
|
||
swl, sflx = spt.sum_ec(fwl, oflx) | ||
swl, scont = spt.sum_ec(fwl, ocont) | ||
swl, snorm = spt.sum_ec(fwl, onorm) | ||
|
||
avgspecs.append(sp.replace('.spc.gz', '.rv.fits')) | ||
avgspecs.append(sp.replace(".spc.gz", ".rv.fits")) | ||
nans, x = (np.isnan(scont), lambda z: z.nonzero()[0]) | ||
sflx[nans] = 1. | ||
scont[nans] = 1. | ||
sflx[nans] = 1.0 | ||
scont[nans] = 1.0 | ||
idx = np.where(scont <= 1e-3) | ||
scont[idx] = 1. | ||
sflx[idx] = 1. | ||
final = sflx/scont | ||
scont[idx] = 1.0 | ||
sflx[idx] = 1.0 | ||
final = sflx / scont | ||
idx = np.where((final > 0.986) & (final < 1.014)) | ||
pflx = final[idx] | ||
pwl = swl[idx] | ||
pflx = np.interp(swl, pwl, savgol_filter(pflx, 3, 1, mode='nearest')) | ||
final = final/pflx | ||
spt.writeFits(final, swl*10, | ||
savename=sp.replace('.spc.gz', '.rv.fits'), quiet=False, | ||
externhd='../../{0}'.format(sp.replace('.spc.gz', '.fits')) ) | ||
pflx = np.interp(swl, pwl, savgol_filter(pflx, 3, 1, mode="nearest")) | ||
final = final / pflx | ||
spt.writeFits( | ||
final, | ||
swl * 10, | ||
savename=sp.replace(".spc.gz", ".rv.fits"), | ||
quiet=False, | ||
externhd="../../{0}".format(sp.replace(".spc.gz", ".fits")), | ||
) | ||
|
||
fig, ax = plt.subplots() | ||
ax.plot(swl, final) | ||
ax.set_ylim([0, 3]) | ||
plt.savefig(figname=sp.replace('.spc.gz', '')) | ||
plt.savefig(figname=sp.replace(".spc.gz", "")) | ||
plt.close(fig) | ||
|
||
if os.path.exists('tmp.txt'): | ||
os.system('rm tmp.txt') | ||
if os.path.exists("tmp.txt"): | ||
os.system("rm tmp.txt") | ||
|
||
spt.averagespecs(avgspecs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,49 +18,63 @@ | |
__email__ = "[email protected]" | ||
|
||
|
||
class MyParser(ArgumentParser): | ||
class MyParser(ArgumentParser): | ||
def error(self, message): | ||
sys.stderr.write('# ERROR! %s\n' % message) | ||
sys.stderr.write("# ERROR! %s\n" % message) | ||
self.print_help() | ||
sys.exit(2) | ||
|
||
|
||
parser = MyParser(description=__doc__) | ||
parser.add_argument('--version', action='version', | ||
version='%(prog)s {0}'.format(__version__)) | ||
parser.add_argument("-n", action="store", dest="n", | ||
help=("Number of cores to be used [default: %(default)s]"), | ||
type=int, default=2) | ||
|
||
group2 = parser.add_argument_group('other arguments') | ||
group2.add_argument("-c", "--check", action="store_true", dest="chk", | ||
help=("If this flag is enabled, it does not make new compressed files. It " | ||
parser.add_argument( | ||
"--version", action="version", version="%(prog)s {0}".format(__version__) | ||
) | ||
parser.add_argument( | ||
"-n", | ||
action="store", | ||
dest="n", | ||
help=("Number of cores to be used [default: %(default)s]"), | ||
type=int, | ||
default=2, | ||
) | ||
|
||
group2 = parser.add_argument_group("other arguments") | ||
group2.add_argument( | ||
"-c", | ||
"--check", | ||
action="store_true", | ||
dest="chk", | ||
help=( | ||
"If this flag is enabled, it does not make new compressed files. It " | ||
"will only removed the *.map* file if the " | ||
"*.map.bz2 file exists"), default=False) | ||
"*.map.bz2 file exists" | ||
), | ||
default=False, | ||
) | ||
|
||
args = parser.parse_args() | ||
|
||
|
||
def compact(fp): | ||
if os.path.exists(fp): | ||
# print('# Creating '+fpnew) | ||
fpnew = fp+'.bz2' | ||
fpnew = fp + ".bz2" | ||
# fpnew = fp+'.gz' | ||
# with gzip.open(fpnew, 'wb') as fout: | ||
with bz2.BZ2File(fpnew, 'wb', compresslevel=1) as fout: | ||
fout.write(open(fp, 'rb').read()) | ||
with bz2.BZ2File(fpnew, "wb", compresslevel=1) as fout: | ||
fout.write(open(fp, "rb").read()) | ||
if os.path.exists(fpnew): | ||
if os.path.getsize(fpnew) > 40000: | ||
os.remove(fp) | ||
print('# Processed '+fp) | ||
print("# Processed " + fp) | ||
return 0 | ||
else: | ||
print('# {0} was not found!'.format(fp)) | ||
print("# {0} was not found!".format(fp)) | ||
return 1 | ||
|
||
|
||
if __name__ == '__main__': | ||
extensions = ['.tau', '.map'] | ||
if __name__ == "__main__": | ||
extensions = [".tau", ".map"] | ||
|
||
path = "." | ||
if len(sys.argv) == 2: | ||
|
@@ -75,18 +89,18 @@ def compact(fp): | |
if not args.chk: | ||
clist.append(fp) | ||
else: | ||
fpnew = fp+'.bz2' | ||
fpnew = fp + ".bz2" | ||
if os.path.exists(fpnew): | ||
if os.path.getsize(fpnew) > 40000: | ||
os.remove(fp) | ||
print('# Removing '+fp) | ||
print("# Removing " + fp) | ||
|
||
if not args.chk and args.n > 1: | ||
pool = Pool(processes=args.n) | ||
# for result in pool.imap_unordered(compact, clist): | ||
result = pool.map(compact, clist) | ||
print('# DONE!') | ||
print("# DONE!") | ||
if not args.chk and args.n == 1: | ||
for c in clist: | ||
compact(c) | ||
print('# DONE!') | ||
print("# DONE!") |
Oops, something went wrong.