Skip to content

Commit

Permalink
Revert "[WIP] Add frequency channel masking capability. Issue #125."
Browse files Browse the repository at this point in the history
  • Loading branch information
texadactyl authored Dec 31, 2020
1 parent 29f01f0 commit 3611cd2
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 90 deletions.
10 changes: 0 additions & 10 deletions mask.yml

This file was deleted.

1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ blimpy>=2.0.0
pandas
toolz
fsspec
pyyaml
dask
dask[bag]
numba
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import numpy
from setuptools.extension import Extension

__version__ = "2.1.0"
__version__ = "2.0.4.1"

with open("README.md", "r") as fh:
long_description = fh.read()
Expand Down
71 changes: 1 addition & 70 deletions turbo_seti/find_doppler/data_handler.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python

import os
import yaml
import math
import logging

Expand Down Expand Up @@ -36,8 +35,6 @@ class DATAHandle:
Number of coarse channels.
coarse_chans : list or None
List of course channels.
mask : str, optional
Used to specify the frequency masking file-path.
kernels : Kernels, optional
Pre-configured class of Kernels.
gpu_backend : bool, optional
Expand All @@ -47,7 +44,7 @@ class DATAHandle:
"""
def __init__(self, filename=None, out_dir='./', n_coarse_chan=None, coarse_chans=None,
kernels=None, gpu_backend=False, precision=2, mask=None):
kernels=None, gpu_backend=False, precision=2):
if not kernels:
self.kernels = Kernels(gpu_backend, precision)
else:
Expand All @@ -58,7 +55,6 @@ def __init__(self, filename=None, out_dir='./', n_coarse_chan=None, coarse_chans
self.out_dir = out_dir
self.n_coarse_chan = n_coarse_chan
self.coarse_chans = coarse_chans
self.mask = []

if not h5py.is_hdf5(filename):
if not sigproc.is_filterbank(filename):
Expand All @@ -83,9 +79,6 @@ def __init__(self, filename=None, out_dir='./', n_coarse_chan=None, coarse_chans
self.header = dobj_master.header
dobj_master.close()

# Load mask file from disk
self.__parse_mask_file(mask)

# Split the file
self.data_list = self.__split_h5()
self.status = True
Expand All @@ -109,68 +102,6 @@ def get_info(self):
fil_file = Waterfall(self.filename, load_data=False)
return fil_file.header

def __parse_mask_file(self, mask_path):
r"""
Loads mask file from disk and creates the masking plan.
"""
# Check if user specified a mask file
if not mask_path:
self.freq_mask = None
return

# Check if mask file exists and load data
if not os.path.isfile(mask_path):
error = f"Masking file ({mask_path}) not found."
logger.error(error)
raise RuntimeError(error)

with open(mask_path) as f:
mask_data = yaml.load(f, Loader=yaml.FullLoader)

# Verify if data from file is valid
if not "blacklist" in mask_data:
error = "Can't file blacklist key. Check mask file."
raise RuntimeError(error)

for r in mask_data["blacklist"]:
if not "range" in r:
error = "Invalid key inside blacklist. Check mask file."
raise RuntimeError(error)

start_keys = ["start"]
end_keys = ["end"]
keys = r["range"]

if len(keys) != 2:
error = "Invalid number of keys inside blacklist range item. Check mask file."
raise RuntimeError(error)

for s in keys:
if not any(n in s for n in (start_keys + end_keys)):
error = "Invalid key inside blacklist range item. Check mask file"
raise RuntimeError(error)

for a, b in [(start_keys, end_keys), (end_keys, start_keys)]:
for key in a:
if any(key in n for n in keys) and not any(n in x for n in b for x in keys):
error = f"The key `{key}` requires the `{b[0]}` key. Check mask file."
raise RuntimeError(error)

def __get_by_key(d, key):
for k in d:
if key in k:
return float(k[key])

# Generate mask tuple
for r in mask_data["blacklist"]:
f_start = __get_by_key(r["range"], "start")
f_end = __get_by_key(r["range"], "end")

self.mask.append((f_start, f_end))

print(self.mask)

def __make_h5_file(self):
r"""
Converts file to h5 format, saved in current directory.
Expand Down
7 changes: 2 additions & 5 deletions turbo_seti/find_doppler/find_doppler.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ class FindDoppler:
Flags the edges of the PFF for BL data (with 3Hz res per channel).
n_coarse_chan : int
Number of coarse channels in file.
mask : str, optional
Used to specify the frequency masking file-path.
kernels : Kernels, optional
Pre-configured class of Kernels.
gpu_backend : bool, optional
Expand All @@ -71,8 +69,8 @@ class FindDoppler:
"""
def __init__(self, datafile, max_drift, min_drift=0, snr=25.0, out_dir='./', coarse_chans=None,
obs_info=None, mask=None, flagging=False, n_coarse_chan=None, kernels=None,
gpu_backend=False, precision=2, append_output=False, log_level_int=logging.INFO):
obs_info=None, flagging=False, n_coarse_chan=None, kernels=None, gpu_backend=False,
precision=2, append_output=False, log_level_int=logging.INFO):
if not kernels:
self.kernels = Kernels(gpu_backend, precision)
else:
Expand All @@ -89,7 +87,6 @@ def __init__(self, datafile, max_drift, min_drift=0, snr=25.0, out_dir='./', coa
out_dir=out_dir,
n_coarse_chan=n_coarse_chan,
coarse_chans=coarse_chans,
mask=mask,
kernels=self.kernels)
if (self.data_handle is None) or (self.data_handle.status is False):
raise IOError("File error, aborting...")
Expand Down
3 changes: 0 additions & 3 deletions turbo_seti/find_doppler/seti_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ def main(args=None):
p.add_argument('filename', type=str, help='Name of filename to open (h5 or fil)')
p.add_argument('-M', '--max_drift', dest='max_drift', type=float, default=10.0,
help='Set the drift rate to search. Unit: Hz/sec. Default: 10.0')
p.add_argument('-m', '--mask', dest='mask', type=str, default=None,
help='Set the frequency masking file path.')
p.add_argument('-s', '--snr', dest='snr', type=float, default=25.0,
help='SNR threshold. Default: 25.0')
p.add_argument('-o', '--out_dir', dest='out_dir', type=str, default='./',
Expand Down Expand Up @@ -106,7 +104,6 @@ def exec(args):
append_output=(args.flag_append_output == "y"),
coarse_chans=coarse_chans,
obs_info=None,
mask=args.mask,
n_coarse_chan=args.n_coarse_chan,
gpu_backend=(args.flag_gpu == "y"),
precision=1 if args.flag_single_precision == "y" else 2,
Expand Down

0 comments on commit 3611cd2

Please sign in to comment.