Skip to content

Commit

Permalink
Re #4048 Clean up data table and add tags
Browse files Browse the repository at this point in the history
  • Loading branch information
mdoucet committed Nov 9, 2011
1 parent 7e35456 commit ec83ea5
Show file tree
Hide file tree
Showing 12 changed files with 184 additions and 26 deletions.
4 changes: 4 additions & 0 deletions Code/Mantid/scripts/Interface/reduction_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ def reduce_clicked(self):
self.reduce_button.setEnabled(False)
self.export_button.setEnabled(False)
self.save_button.setEnabled(False)
self.interface_chk.setEnabled(False)
if IS_IN_MANTIDPLOT:
qti.app.mantidUI.setIsRunning(True)
self._interface.reduce()
Expand All @@ -352,6 +353,7 @@ def reduce_clicked(self):
self.reduce_button.setEnabled(True)
self.export_button.setEnabled(True)
self.save_button.setEnabled(True)
self.interface_chk.setEnabled(True)

def open_file(self, file_path=None):
"""
Expand All @@ -372,10 +374,12 @@ def open_file(self, file_path=None):
self.reduce_button.setEnabled(False)
self.export_button.setEnabled(False)
self.save_button.setEnabled(False)
self.interface_chk.setEnabled(False)
self._interface.load_file(file_path)
self.reduce_button.setEnabled(True)
self.export_button.setEnabled(True)
self.save_button.setEnabled(True)
self.interface_chk.setEnabled(True)

self._filename = file_path
self._update_file_menu()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ def reduce(self):
print "Could not save last reduction\n %s" % str(traceback.format_exc())

try:
self.set_running(True)
self.scripter.apply()
self.set_running(False)
except RuntimeError, e:
if self._settings.debug:
msg = "Reduction could not be executed:\n\n%s" % unicode(traceback.format_exc())
Expand Down Expand Up @@ -181,6 +183,13 @@ def get_tabs(self):
tab_list.append([item.name, item])
return tab_list

def set_running(self, is_running=True):
"""
Tell the widgets whether they are running or not
"""
for widget in self.widgets:
widget.is_running(is_running)

def reset(self):
"""
Reset the interface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import re
import time
import sys
import traceback

# Check whether Mantid is available
try:
Expand All @@ -18,14 +19,55 @@
except:
HAS_MANTID = False

class DataType(object):
TABLE_NAME = "datatype"

# Data type names
DATA_TYPES = {"FLOOD_FIELD":"Flood Field",
"DARK_CURRENT":"Dark Current",
"TRANS_SAMPLE":"Transmission Sample",
"TRANS_BCK":"Transmission Background",
"TRANS_DIRECT":"Transmission Empty"}

@classmethod
def create_table(cls, cursor, data_set_table):
cursor.execute("""create table if not exists %s (
id integer primary key,
type_id integer,
dataset_id integer,
foreign key(dataset_id) references %s(id))""" % (cls.TABLE_NAME, data_set_table))

@classmethod
def add(cls, dataset_id, type_id, cursor):
"""
Add a data type entry to the datatype table
"""
if not type_id in cls.DATA_TYPES.keys():
raise RuntimeError, "DataType got an unknown type ID: %s" % type_id

t = (type_id, dataset_id,)
cursor.execute("insert into %s(type_id, dataset_id) values (?,?)" % cls.TABLE_NAME, t)

@classmethod
def get_likely_type(cls, dataset_id, cursor):
t = (dataset_id,)
cursor.execute("select type_id from %s where dataset_id=?" % cls.TABLE_NAME, t)
rows = cursor.fetchall()
if len(rows)>1:
return cls.DATA_TYPES[rows[len(rows)-1][0]]
return None

class DataSet(object):
TABLE_NAME = "dataset"
def __init__(self, run_number, title, run_start, duration, sdd):
data_type_cls = DataType

def __init__(self, run_number, title, run_start, duration, sdd, id=None):
self.run_number = run_number
self.title = title
self.run_start = run_start
self.duration = duration
self.sdd = sdd
self.id = id

@classmethod
def header(cls):
Expand Down Expand Up @@ -70,6 +112,16 @@ def as_string_list(self):
"""
return (str(self.run_number), self.title, self.run_start, "%-g"%self.duration, "%-10.0f"%self.sdd)

@classmethod
def get_data_set_id(cls, run, cursor):
t = (run,)
cursor.execute('select * from %s where run=?'% cls.TABLE_NAME, t)
rows = cursor.fetchall()
if len(rows) == 0:
return -1
else:
return rows[0][0]

@classmethod
def find(cls, file_path, cursor, process_files=True):
"""
Expand All @@ -94,7 +146,7 @@ def find(cls, file_path, cursor, process_files=True):
return None
else:
row = rows[0]
return DataSet(row[1], row[2], row[3], row[4], row[5])
return DataSet(row[1], row[2], row[3], row[4], row[5], id=row[0])

@classmethod
def create_table(cls, cursor):
Expand All @@ -104,10 +156,13 @@ def create_table(cls, cursor):
title text,
start text,
duration real, sdd real)""" % cls.TABLE_NAME)

cls.data_type_cls.create_table(cursor, cls.TABLE_NAME)

def insert_in_db(self, cursor):
t = (self.run_number, self.title, self.run_start, self.duration, self.sdd)
t = (self.run_number, self.title, self.run_start, self.duration, self.sdd,)
cursor.execute('insert into %s(run, title, start, duration,sdd) values (?,?,?,?,?)'%self.TABLE_NAME, t)
return cursor.lastrowid

class DataCatalog(object):
"""
Expand Down Expand Up @@ -182,6 +237,20 @@ def get_string_list(self, data_dir=None):
output.append(r.as_string_list())
return output

def add_type(self, run, type):
if self.db is None:
if HAS_MANTID:
mtd.sendLogMessage("DataCatalog: Could not access local data catalog")
return

c = self.db.cursor()
id = self.data_set_cls.get_data_set_id(run, c)
if id>0:
self.data_set_cls.data_type_cls.add(id, type, c)

self.db.commit()
c.close()

def list_data_sets(self, data_dir=None, call_back=None, process_files=True):
"""
Process a data directory
Expand All @@ -205,13 +274,16 @@ def list_data_sets(self, data_dir=None, call_back=None, process_files=True):
d = self.data_set_cls.find(path, c, process_files=process_files)
if d is not None:
if call_back is not None:
call_back(d.as_string_list())
attr_list = d.as_string_list()
type_id = self.data_set_cls.data_type_cls.get_likely_type(d.id, c)
attr_list += (type_id,)
call_back(attr_list)
self.catalog.append(d)

self.db.commit()
c.close()
except:
if HAS_MANTID:
mtd.sendLogMessage("DataCatalog: Error working with the local data catalog\n%s" % sys.exc_value)
mtd.sendLogMessage("DataCatalog: Error working with the local data catalog\n%s" % str(traceback.format_exc()))
else:
raise
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
Data catalog for EQSANS
"""
from reduction_gui.reduction.sans.data_cat import DataCatalog as BaseCatalog
from reduction_gui.reduction.sans.data_cat import DataSet as BaseDataSet
from reduction_gui.reduction.sans.data_cat import DataSet
from data_cat import DataType
import re
import time

Expand All @@ -15,8 +16,13 @@
except:
HAS_MANTID = False

class EQSANSDataSet(BaseDataSet):
class EQSANSDataType(DataType):
TABLE_NAME="eqsans_datatype"

class EQSANSDataSet(DataSet):
TABLE_NAME="eqsans_dataset"
data_type_cls = EQSANSDataType

def __init__(self, run_number, title, run_start, duration, sdd):
super(EQSANSDataSet, self).__init__(run_number, title, run_start, duration, sdd)

Expand All @@ -33,11 +39,18 @@ def handle(cls, file_path):
"""
Return a DB handle for the given file, such as a run number
"""
file_path = file_path.strip()
r_re = re.search("EQSANS_([0-9]+)_event", file_path)
if r_re is None:
return None

return r_re.group(1)
if r_re is not None:
return r_re.group(1)
else:
# Check whether we simply have a run number
try:
run = int(file_path)
return file_path
except:
return None
return None

@classmethod
def read_properties(cls, ws, run, cursor):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
Data catalog for HFIR SANS
"""
from data_cat import DataCatalog as BaseCatalog
from data_cat import DataSet as BaseDataSet
from data_cat import DataSet
from data_cat import DataType
import os
import time

Expand All @@ -15,8 +16,13 @@
except:
HAS_MANTID = False

class HFIRDataSet(BaseDataSet):
class HFIRDataType(DataType):
TABLE_NAME="hfir_datatype"

class HFIRDataSet(DataSet):
TABLE_NAME="hfir_dataset"
data_type_cls = HFIRDataType

def __init__(self, run_number, title, run_start, duration, sdd):
super(HFIRDataSet, self).__init__(run_number, title, run_start, duration, sdd)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ def __init__(self, parent=None, state=None, settings=None, data_type=None, ui_cl
self._data_proxy = data_proxy
self._in_mantidplot = IS_IN_MANTIDPLOT and self._data_proxy is not None

self._is_running = True

def is_running(self, is_running):
"""
Change running state
"""
self._is_running = is_running

def initialize_content(self):
"""
Declare the validators and event connections for the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
from reduction_gui.widgets.base_widget import BaseWidget
import ui.sans.ui_eqsans_sample_data

from hfir_sample_data import DirectBeam

class DataSetsWidget(BaseWidget):
"""
Widget that presents the transmission options to the user
Expand Down Expand Up @@ -260,6 +258,10 @@ def get_state(self):
d.sample_file = unicode(self._content.bck_sample_edit.text())
d.direct_beam = unicode(self._content.bck_empty_edit.text())

self._settings.emit_key_value("TRANS_SAMPLE", QtCore.QString(str(self._content.sample_edit.text())))
self._settings.emit_key_value("TRANS_DIRECT", QtCore.QString(str(self._content.empty_edit.text())))
self._settings.emit_key_value("TRANS_BCK", QtCore.QString(str(self._content.bck_sample_edit.text())))
self._settings.emit_key_value("TRANS_DIRECT", QtCore.QString(str(self._content.bck_empty_edit.text())))
return m

def _background_clicked(self, is_checked):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ def get_state(self):
m.use_data_directory = self._summary.use_data_dir_radio.isChecked()
m.output_directory = str(self._summary.output_dir_edit.text())

self._settings.emit_key_value("DARK_CURRENT", QtCore.QString(str(self._summary.dark_file_edit.text())))
return m

def _show_help(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ def get_state(self):
m.flood_use_finder = self._content.use_beam_finder_checkbox_2.isChecked()
m.flood_beam_file = unicode(self._content.beam_data_file_edit_2.text())
m.flood_use_direct_beam = self._content.direct_beam_2.isChecked()

self._settings.emit_key_value("FLOOD_FIELD", QtCore.QString(str(self._content.sensitivity_file_edit.text())))
return m

def _use_sample_center_changed(self, is_checked):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,4 +413,5 @@ def get_state(self):
ids_str = masked_detectors.getPropertyValue("DetectorList")
m.detector_ids = map(int, ids_str.split(','))

return m
self._settings.emit_key_value("DARK_CURRENT", QtCore.QString(str(self._summary.dark_file_edit.text())))
return m
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ def get_state(self):
m.beam_radius = util._check_and_get_float_line_edit(self._content.beam_radius_edit)
m.sample_file = unicode(self._content.sample_edit.text())
m.direct_beam = unicode(self._content.direct_edit.text())
self._settings.emit_key_value("TRANS_SAMPLE", QtCore.QString(str(self._content.sample_edit.text())))
self._settings.emit_key_value("TRANS_DIRECT", QtCore.QString(str(self._content.direct_edit.text())))
return m

def _sample_browse(self):
Expand Down

0 comments on commit ec83ea5

Please sign in to comment.