Skip to content

Commit 17aecd5

Browse files
Eliminate empty log files forever
1 parent 3ae5edd commit 17aecd5

18 files changed

Lines changed: 483 additions & 508 deletions

hendrics/binary.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -278,25 +278,25 @@ def main_presto(args=None):
278278

279279
if args.energy_interval is None:
280280
args.energy_interval = [None, None]
281-
with log.log_to_file("HENbinary.log"):
282-
for f in args.files:
283-
print(f)
284-
outfile = f.replace(HEN_FILE_EXTENSION, ".dat")
285-
ftype, contents = get_file_type(f)
286-
if ftype == "lc":
287-
lcinfo = save_lc_to_binary(contents, outfile)
288-
elif ftype == "events":
289-
if args.deorbit_par is not None:
290-
contents = deorbit_events(contents, args.deorbit_par)
291-
lcinfo = save_events_to_binary(
292-
contents,
293-
outfile,
294-
bin_time=bintime,
295-
emin=args.energy_interval[0],
296-
emax=args.energy_interval[1],
297-
)
298-
else:
299-
raise ValueError("File type not recognized")
300-
301-
info = get_header_info(contents)
302-
save_inf(lcinfo, info, f.replace(HEN_FILE_EXTENSION, ".inf"))
281+
282+
for f in args.files:
283+
print(f)
284+
outfile = f.replace(HEN_FILE_EXTENSION, ".dat")
285+
ftype, contents = get_file_type(f)
286+
if ftype == "lc":
287+
lcinfo = save_lc_to_binary(contents, outfile)
288+
elif ftype == "events":
289+
if args.deorbit_par is not None:
290+
contents = deorbit_events(contents, args.deorbit_par)
291+
lcinfo = save_events_to_binary(
292+
contents,
293+
outfile,
294+
bin_time=bintime,
295+
emin=args.energy_interval[0],
296+
emax=args.energy_interval[1],
297+
)
298+
else:
299+
raise ValueError("File type not recognized")
300+
301+
info = get_header_info(contents)
302+
save_inf(lcinfo, info, f.replace(HEN_FILE_EXTENSION, ".inf"))

hendrics/calibrate.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -219,21 +219,20 @@ def main(args=None):
219219
args.loglevel = "DEBUG"
220220

221221
log.setLevel(args.loglevel)
222-
with log.log_to_file("HENcalibrate.log"):
223-
funcargs = []
224-
for i_f, f in enumerate(files):
225-
outname = f
226-
if args.overwrite is False:
227-
label = "_calib"
228-
if args.rough:
229-
label = "_rough_calib"
230-
outname = f.replace(get_file_extension(f), label + HEN_FILE_EXTENSION)
231-
funcargs.append([f, outname, args.rmf, args.rough])
232-
233-
if os.name == "nt" or args.nproc == 1:
234-
[_calib_wrap(fa) for fa in funcargs]
235-
else:
236-
pool = Pool(processes=args.nproc)
237-
for i in pool.imap_unordered(_calib_wrap, funcargs):
238-
pass
239-
pool.close()
222+
funcargs = []
223+
for i_f, f in enumerate(files):
224+
outname = f
225+
if args.overwrite is False:
226+
label = "_calib"
227+
if args.rough:
228+
label = "_rough_calib"
229+
outname = f.replace(get_file_extension(f), label + HEN_FILE_EXTENSION)
230+
funcargs.append([f, outname, args.rmf, args.rough])
231+
232+
if os.name == "nt" or args.nproc == 1:
233+
[_calib_wrap(fa) for fa in funcargs]
234+
else:
235+
pool = Pool(processes=args.nproc)
236+
for i in pool.imap_unordered(_calib_wrap, funcargs):
237+
pass
238+
pool.close()

hendrics/colors.py

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -45,45 +45,44 @@ def main(args=None):
4545

4646
log.setLevel(args.loglevel)
4747

48-
with log.log_to_file("HENcolors.log"):
49-
energies = [
50-
[args.energies[0], args.energies[1]],
51-
[args.energies[2], args.energies[3]],
52-
]
53-
if args.outfile is not None and len(files) > 1:
54-
raise ValueError("Specify --output only when processing " "a single file")
55-
for f in files:
56-
events = load_events(f)
57-
if not args.use_pi and events.energy is None:
58-
raise ValueError(
59-
f"Energy information not found in file {f}. "
60-
"Use --use-pi if you want to use PI channels "
61-
"instead."
62-
)
63-
h_starts, h_stops, colors, color_errs = events.get_color_evolution(
64-
energy_ranges=energies, segment_size=args.bintime, use_pi=args.use_pi
48+
energies = [
49+
[args.energies[0], args.energies[1]],
50+
[args.energies[2], args.energies[3]],
51+
]
52+
if args.outfile is not None and len(files) > 1:
53+
raise ValueError("Specify --output only when processing " "a single file")
54+
for f in files:
55+
events = load_events(f)
56+
if not args.use_pi and events.energy is None:
57+
raise ValueError(
58+
f"Energy information not found in file {f}. "
59+
"Use --use-pi if you want to use PI channels "
60+
"instead."
6561
)
62+
h_starts, h_stops, colors, color_errs = events.get_color_evolution(
63+
energy_ranges=energies, segment_size=args.bintime, use_pi=args.use_pi
64+
)
6665

67-
time = (h_starts + h_stops) / 2
66+
time = (h_starts + h_stops) / 2
6867

69-
scolor = Lightcurve(
70-
time=time,
71-
counts=colors,
72-
err=color_errs,
73-
input_counts=False,
74-
err_dist="gauss",
75-
gti=events.gti,
76-
dt=args.bintime,
77-
skip_checks=True,
78-
)
68+
scolor = Lightcurve(
69+
time=time,
70+
counts=colors,
71+
err=color_errs,
72+
input_counts=False,
73+
err_dist="gauss",
74+
gti=events.gti,
75+
dt=args.bintime,
76+
skip_checks=True,
77+
)
7978

80-
if args.outfile is None:
81-
label = "_E_"
82-
if args.use_pi:
83-
label = "_PI_"
84-
label += "{3:g}-{2:g}_over_{1:g}-{0:g}".format(*args.energies)
85-
args.outfile = hen_root(f) + label + HEN_FILE_EXTENSION
86-
scolor.e_intervals = np.asarray([float(k) for k in args.energies])
87-
scolor.use_pi = args.use_pi
88-
save_lcurve(scolor, args.outfile, lctype="Color")
89-
print(args.outfile)
79+
if args.outfile is None:
80+
label = "_E_"
81+
if args.use_pi:
82+
label = "_PI_"
83+
label += "{3:g}-{2:g}_over_{1:g}-{0:g}".format(*args.energies)
84+
args.outfile = hen_root(f) + label + HEN_FILE_EXTENSION
85+
scolor.e_intervals = np.asarray([float(k) for k in args.energies])
86+
scolor.use_pi = args.use_pi
87+
save_lcurve(scolor, args.outfile, lctype="Color")
88+
print(args.outfile)

hendrics/create_gti.py

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -188,34 +188,31 @@ def main(args=None):
188188
args.loglevel = "DEBUG"
189189

190190
log.setLevel(args.loglevel)
191-
with log.log_to_file("HENcreategti.log"):
192-
filter_expr = args.filter
193-
if filter_expr is None and args.apply_gti is None:
194-
sys.exit(
195-
"Please specify filter expression (-f option) or input " "GTI file (-a option)"
196-
)
197-
198-
for fname in files:
199-
if args.apply_gti is not None:
200-
data = load_data(args.apply_gti)
201-
gti = data["gti"]
202-
else:
203-
gti = create_gti(
204-
fname,
205-
filter_expr,
206-
safe_interval=args.safe_interval,
207-
minimum_length=args.minimum_length,
208-
)
209-
if args.create_only:
210-
continue
211-
if args.overwrite:
212-
outname = fname
213-
else:
214-
# Use default
215-
outname = None
216-
apply_gti(
191+
filter_expr = args.filter
192+
if filter_expr is None and args.apply_gti is None:
193+
sys.exit("Please specify filter expression (-f option) or input " "GTI file (-a option)")
194+
195+
for fname in files:
196+
if args.apply_gti is not None:
197+
data = load_data(args.apply_gti)
198+
gti = data["gti"]
199+
else:
200+
gti = create_gti(
217201
fname,
218-
gti,
219-
outname=outname,
202+
filter_expr,
203+
safe_interval=args.safe_interval,
220204
minimum_length=args.minimum_length,
221205
)
206+
if args.create_only:
207+
continue
208+
if args.overwrite:
209+
outname = fname
210+
else:
211+
# Use default
212+
outname = None
213+
apply_gti(
214+
fname,
215+
gti,
216+
outname=outname,
217+
minimum_length=args.minimum_length,
218+
)

hendrics/efsearch.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,14 +1875,12 @@ def _common_main(args, func):
18751875

18761876
def main_efsearch(args=None):
18771877
"""Main function called by the `HENefsearch` command line script."""
1878-
with log.log_to_file("HENefsearch.log"):
1879-
return _common_main(args, epoch_folding_search)
1878+
return _common_main(args, epoch_folding_search)
18801879

18811880

18821881
def main_zsearch(args=None):
18831882
"""Main function called by the `HENzsearch` command line script."""
1884-
with log.log_to_file("HENzsearch.log"):
1885-
return _common_main(args, z_n_search)
1883+
return _common_main(args, z_n_search)
18861884

18871885

18881886
def z2_vs_pf(event_list, deadtime=0.0, ntrials=100, outfile=None, N=2):

hendrics/exposure.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -353,30 +353,29 @@ def main(args=None):
353353
args.loglevel = "DEBUG"
354354

355355
log.setLevel(args.loglevel)
356-
with log.log_to_file("HENexposure.log"):
357-
lc_file = args.lcfile
358-
uf_file = args.uffile
356+
lc_file = args.lcfile
357+
uf_file = args.uffile
359358

360-
outroot = _assign_value_if_none(args.outroot, hen_root(lc_file))
359+
outroot = _assign_value_if_none(args.outroot, hen_root(lc_file))
361360

362-
outname = outroot + "_lccorr" + HEN_FILE_EXTENSION
361+
outname = outroot + "_lccorr" + HEN_FILE_EXTENSION
363362

364-
outfile = correct_lightcurve(lc_file, uf_file, outname)
363+
outfile = correct_lightcurve(lc_file, uf_file, outname)
365364

366-
# outdata = load_data(outfile)
367-
_, outdata = get_file_type(outfile, raw_data=False)
368-
time = outdata.time
369-
lc = outdata.counts
370-
expo = outdata.expo
371-
gti = outdata.gti
365+
# outdata = load_data(outfile)
366+
_, outdata = get_file_type(outfile, raw_data=False)
367+
time = outdata.time
368+
lc = outdata.counts
369+
expo = outdata.expo
370+
gti = outdata.gti
372371

373-
try:
374-
_plot_corrected_light_curve(time, lc * expo, expo, gti, outroot)
375-
_plot_dead_time_from_uf(uf_file, outroot)
376-
except Exception as e:
377-
warnings.warn(str(e))
372+
try:
373+
_plot_corrected_light_curve(time, lc * expo, expo, gti, outroot)
374+
_plot_dead_time_from_uf(uf_file, outroot)
375+
except Exception as e:
376+
warnings.warn(str(e))
378377

379-
if args.plot:
380-
import matplotlib.pyplot as plt
378+
if args.plot:
379+
import matplotlib.pyplot as plt
381380

382-
plt.show()
381+
plt.show()

hendrics/exvar.py

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -66,31 +66,28 @@ def main(args=None):
6666
args.loglevel = "DEBUG"
6767

6868
log.setLevel(args.loglevel)
69-
with log.log_to_file("HENexcvar.log"):
70-
filelist = []
71-
for fname in args.files:
72-
lcurve = load_lcurve(fname)
73-
if args.norm == "fvar":
74-
start, stop, res = lcurve.analyze_segments(
75-
fvar, args.chunk_length, args.fraction_step
76-
)
77-
elif args.norm == "excvar":
78-
start, stop, res = lcurve.analyze_segments(
79-
excvar_none, args.chunk_length, args.fraction_step
80-
)
81-
elif args.norm == "norm_excvar":
82-
start, stop, res = lcurve.analyze_segments(
83-
excvar_norm, args.chunk_length, args.fraction_step
84-
)
85-
else:
86-
raise ValueError("Normalization must be fvar, norm_excvar " "or excvar")
87-
var, var_err = res
88-
out = hen_root(fname) + "_" + args.norm + ".qdp"
89-
save_as_qdp(
90-
[(start + stop) / 2, var],
91-
[(stop - start) / 2, var_err],
92-
filename=out,
69+
filelist = []
70+
for fname in args.files:
71+
lcurve = load_lcurve(fname)
72+
if args.norm == "fvar":
73+
start, stop, res = lcurve.analyze_segments(fvar, args.chunk_length, args.fraction_step)
74+
elif args.norm == "excvar":
75+
start, stop, res = lcurve.analyze_segments(
76+
excvar_none, args.chunk_length, args.fraction_step
9377
)
94-
filelist.append(out)
78+
elif args.norm == "norm_excvar":
79+
start, stop, res = lcurve.analyze_segments(
80+
excvar_norm, args.chunk_length, args.fraction_step
81+
)
82+
else:
83+
raise ValueError("Normalization must be fvar, norm_excvar " "or excvar")
84+
var, var_err = res
85+
out = hen_root(fname) + "_" + args.norm + ".qdp"
86+
save_as_qdp(
87+
[(start + stop) / 2, var],
88+
[(stop - start) / 2, var_err],
89+
filename=out,
90+
)
91+
filelist.append(out)
9592

9693
return filelist

0 commit comments

Comments
 (0)