...
 
Commits (4)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created by schaffer at 12/10/19
"""
from kis_tools.interface import BasicArgParser
from kis_tools.interface.commandline_interface import add_arg_outputfolder
parser = BasicArgParser()
add_arg_outputfolder(parser)
args = parser.parse_args()
from chroquest.image_metrics import calculate_and_save_metrics_for_folder
calculate_and_save_metrics_for_folder(args.folder_in, args.folder_out)
\ No newline at end of file
......@@ -19,7 +19,7 @@ from scipy.ndimage import center_of_mass
from tqdm import tqdm
class ChrotelFileWrapper(ChrotelFitsFile):
class FileWrapper(ChrotelFitsFile):
"""Simple wrapper for extracting quality metrics from a fits file"""
def __init__(self, filename):
......@@ -36,7 +36,6 @@ class ChrotelFileWrapper(ChrotelFitsFile):
mean=self.data_mean(),
max_val=self.data.max(),
min_val=self.data.min(),
filter=self.FILTER,
variance=self.data_variance(),
center_of_mass_x=center_of_mass_x,
center_of_mass_y=center_of_mass_y,
......@@ -88,12 +87,12 @@ def get_chrotel_quality_predictors(filename):
:param filename: path to chrotel FITS file
:return predictors: dictionary of metric names and metric values
"""
cfw = ChrotelFileWrapper(filename)
cfw = FileWrapper(filename)
predictors = cfw.image_quality_predictors()
return predictors
def calculate_and_save_metrics_for_folder(folder):
def calculate_and_save_metrics_for_folder(folder,outpath_prefix=None):
"""
Loop over files in folder and store all quality metrics, metrics are stored at /dat/sdc/chrotel/image_quality_data
:param folder:
......@@ -109,7 +108,7 @@ def calculate_and_save_metrics_for_folder(folder):
for f in progress_bar:
progress_bar.set_description(f)
try:
pred = ChrotelFileWrapper(f).image_quality_predictors()
pred = FileWrapper(f).image_quality_predictors()
predictors.append(pred)
except:
warn(f"File {f} could not be processed!")
......@@ -117,8 +116,12 @@ def calculate_and_save_metrics_for_folder(folder):
df = pd.DataFrame(predictors)
df = df.set_index("filename")
filename = ChrotelFileWrapper(files[0]).obs_time.strftime("chrotel_quality_%Y%m%d.csv")
save_path = join('/dat', 'sdc', 'chrotel', 'image_quality_data', filename)
filename = FileWrapper(files[0]).obs_time.strftime("summary_statistics_%Y%m%d.csv")
if outpath_prefix is None:
save_path = join('/dat', 'sdc', 'chrotel', 'image_quality_data', filename)
else:
save_path = join(outpath_prefix,filename)
print(f"Saving to {save_path}")
df.to_csv(save_path)
print(f"Saved to {save_path}")
......
......@@ -16,7 +16,7 @@ from matplotlib import colors
from matplotlib.patches import Circle
from tqdm import tqdm
from .image_metrics import ChrotelFileWrapper
from .image_metrics import FileWrapper
def center_of_mass_plot(df, kind='scatter'):
......@@ -101,7 +101,7 @@ def ecdf_plot(data):
def plot_chrotel(filename, ax: plt.axes):
f = ChrotelFileWrapper(filename)
f = FileWrapper(filename)
d = f.data
if len(d.shape) > 2:
d = np.sum(d, axis=0)
......