Skip to content

Commit

Permalink
workflow fix (hopefully)
Browse files Browse the repository at this point in the history
  • Loading branch information
danmoser committed Apr 11, 2024
1 parent 94cd504 commit 55e5ffd
Show file tree
Hide file tree
Showing 10 changed files with 298 additions and 205 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ on:

jobs:
build:

runs-on: ubuntu-latest


steps:
- uses: actions/checkout@v4
- name: Set up Python
Expand All @@ -30,4 +27,6 @@ jobs:
- name: Test with pytest
run: |
pip install pytest pytest-cov
pytest --doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html
pytest --junitxml=junit/test-results.xml
# pip install pytest-cov
# pytest --doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,4 @@ target/
.DS_Store
**/.idea/*
pyhdust/.*
junit/*
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Welcome to **pyhdust** documentation!
=============================================================
**Analysis tools for multi-technique astronomical data and** *hdust* **models**. About the *hdust* code, see Carciofi & Bjorkman (`2006 <http://adsabs.harvard.edu/abs/2006ApJ...639.1081C>`_, `2008 <http://adsabs.harvard.edu/abs/2008ApJ...684.1374C>`_).

Pyhdust is currently at **version 1.5.12**.
Pyhdust is currently at **version 1.5.12-1**.

**pyhdust** should be independent of plataform (Linux, Mac, Windows) and compatible with any version of Python (3.6+).

Expand Down
23 changes: 13 additions & 10 deletions scripts/extract3Dfits.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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))
76 changes: 40 additions & 36 deletions scripts/extract_ms_opera.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand All @@ -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
Expand All @@ -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)
60 changes: 37 additions & 23 deletions scripts/hdcompact.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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!")
Loading

0 comments on commit 55e5ffd

Please sign in to comment.