-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add extract autos script #393
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/usr/bin/env python | ||
""" | ||
Pipeline script to extract autocorrelations from chunked files into waterfall. | ||
""" | ||
from hera_pspec import utils | ||
from pyuvdata import UVData | ||
from hera_cal._cli_tools import parse_args, run_with_profiling | ||
import warnings | ||
|
||
def main(args): | ||
def check_for_sumdiff(file): | ||
if not args.sumdiff in file: | ||
raise ValueError(f"Supposedly processing {args.sumdiff} files but " | ||
f"{args.sumdiff} not in the filename.") | ||
return | ||
|
||
# In case there are files without autos | ||
found_autos = False | ||
for file_ind, file in enumerate(args.flist): | ||
check_for_sumdiff(file) | ||
try: | ||
main_uvd = UVData() | ||
main_uvd.read(file, ant_str="auto") | ||
found_autos = True | ||
break | ||
except ValueError: # There were no autos in that file | ||
continue | ||
|
||
if found_autos: | ||
start_ind = file_ind + 1 | ||
if start_ind < len(args.flist): | ||
for file in args.flist[file_ind + 1:]: | ||
Comment on lines
+30
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure how important it is to track whether only one file had autocorrelations in it, but if it's not that important to do, then you can replace this block with: |
||
check_for_sumdiff(file) | ||
try: | ||
new_uvd = UVData() | ||
new_uvd.read(file, ant_str="auto") | ||
main_uvd.__add__(new_uvd, inplace=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd suggest adding an |
||
except ValueError: | ||
continue | ||
Comment on lines
+38
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This worries me. Are you certain the only way a |
||
else: | ||
warnings.warn("Only one file had autocorrelatons. Inputs are almost " | ||
"certainly incorrect.") | ||
|
||
outfile = f"zen.LST.0.00000.{args.sumdiff}.{args.label}.foreground_filled.xtalk_filtered.chunked.waterfall.autos.uvh5" | ||
main_uvd.write_uvh5(outfile, clobber=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think for best practice, |
||
else: | ||
raise ValueError("No autocorrelations found in any files. Check inputs.") | ||
|
||
parser = utils.extract_autos_post_lstbin_parser() | ||
args = parse_args(parser) | ||
run_with_profiling(main, args, args) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found this block of code a little difficult to parse at first--it took me a few reads to wrap my head around it. I would maybe instead add a comment to the effect of "Find the first file that has autos."