Skip to content

Commit

Permalink
Improved workflow. this refs #211
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanBilheux committed Jun 20, 2024
1 parent 847f27a commit e2b6b52
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 80 deletions.
53 changes: 34 additions & 19 deletions notebooks/__code/venus_monitor_hdf5/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ def __init__(self, working_dir=None):
logging.info("*** Starting a new session ***")

def select_event_nexus(self):

start_dir = os.path.join(self.working_dir, 'nexus')

self.nexus_ui = fileselector.FileSelectorPanel(instruction='Select NeXus file ...',
start_dir=self.working_dir,
start_dir=start_dir,
next=self.load_data,
filters={'NeXus': ".h5"},
multiple=False)
Expand Down Expand Up @@ -103,17 +106,13 @@ def record_settings(self):
self.distance_source_detector_m = self.distance_source_detector_ui.value
self.detector_offset_micros = self.monitor_offset_ui.value

def display_data_tof(self):
def calculate_data_tof(self):

nbr_bins = self.nbr_bins
self.histo_tof, self.bins_tof = np.histogram(self.time_offset, bins=np.arange(0, 16666, nbr_bins))

fig, ax = plt.subplots(num='histogram2')
plt.plot(self.bins_tof[:-1], self.histo_tof)
ax.set_xlabel(u"TOF (\u00B5s)")
ax.set_ylabel("Counts")

def display_data_lambda(self):
def calculate_data_lambda(self):

tof_axis = self.bins_tof[:-1]
detector_offset_micros = self.detector_offset_micros
Expand All @@ -123,20 +122,36 @@ def display_data_lambda(self):
distance_source_detector_cm=distance_source_detector_cm,
detector_offset_micros=detector_offset_micros)

fig, ax = plt.subplots(num='histogram3')
plt.plot(self.lambda_axis_angstroms, self.histo_tof)
ax.set_xlabel(u"Lambda (\u212B)")
ax.set_ylabel("Total counts")

def display_data_energy(self):
def calculate_data_energy(self):
lambda_axis_angstroms = self.lambda_axis_angstroms
self.energy_axis_ev = 1000 * (ENERGY_CONVERSION_FACTOR / (lambda_axis_angstroms**2))

fig, ax = plt.subplots(num='counts vs energy')
plt.plot(self.energy_axis_ev, self.histo_tof, '*')
ax.set_xlabel("Energy (eV)")
ax.set_ylabel("Total counts")
self.energy_axis_ev = 1000 * (ENERGY_CONVERSION_FACTOR / (lambda_axis_angstroms*lambda_axis_angstroms))

@staticmethod
def from_micros_to_lambda(tof_axis_micros, detector_offset_micros=0, distance_source_detector_cm=2372.6):
return 0.3954 * (tof_axis_micros + detector_offset_micros) / distance_source_detector_cm

def display_all_at_once(self):

self.calculate_data_tof()
self.calculate_data_lambda()
self.calculate_data_energy()

plt.rcParams['figure.constrained_layout.use'] = True
fig, ax = plt.subplots(nrows=3, ncols=1, num='Monitor',
figsize=(10, 15),
)

ax[0].plot(self.bins_tof[:-1], self.histo_tof)
ax[0].set_xlabel(u"TOF (\u00B5s)")
ax[0].set_ylabel("Counts")
ax[0].set_title(u"Counts vs TOF(\u00B5s)")

ax[1].plot(self.lambda_axis_angstroms, self.histo_tof, 'r')
ax[1].set_xlabel(u"Lambda (\u212B)")
ax[1].set_ylabel("Total counts")
ax[1].set_title(u"Counts vs lambda (\u212B)")

ax[2].plot(self.energy_axis_ev, self.histo_tof, '*g')
ax[2].set_xlabel("Energy (eV)")
ax[2].set_ylabel("Total counts")
ax[2].set_title("Counts vs Energy (eV)")
68 changes: 7 additions & 61 deletions notebooks/venus_monitor_hdf5.ipynb

Large diffs are not rendered by default.

1 comment on commit e2b6b52

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitLab pipeline with NOTEBOOK_COLLECTION_NAME=IPTS_notebooks submitted for commit "https://code.ornl.gov/sns-hfir-scse/deployments/jupyter-notebooks-deploy/-/pipelines/583800"

Please sign in to comment.