Skip to content

Commit

Permalink
rename self.det_distance for clarity, some formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
glass-ships committed Feb 10, 2025
1 parent 094c3f3 commit 6e78f8f
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 107 deletions.
24 changes: 12 additions & 12 deletions reduction/lr_reduction/event_reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ def extract_meta_data(self):
Extract meta data from the loaded data file.
"""
# Get instrument parameters
if self.instrument_settings is None or self.instrument_settings.apply_instrument_settings:
if self.instrument_settings is None or not self.instrument_settings.apply_instrument_settings:
settings = read_settings(self._ws_sc)
else:
settings = self.instrument_settings
Expand Down Expand Up @@ -451,13 +451,13 @@ def extract_meta_data_4A(self):
4A-specific meta data
"""
run_object = self._ws_sc.getRun()
self.det_distance = run_object["SampleDetDis"].getStatistics().mean
self.sample_detector_distance = run_object["SampleDetDis"].getStatistics().mean
source_sample_distance = run_object["ModeratorSamDis"].getStatistics().mean
if run_object["SampleDetDis"].units not in ["m", "meter"]:
self.det_distance /= 1000.0
self.sample_detector_distance /= 1000.0
if run_object["ModeratorSamDis"].units not in ["m", "meter"]:
source_sample_distance /= 1000.0
self.source_detector_distance = source_sample_distance + self.det_distance
self.source_detector_distance = source_sample_distance + self.sample_detector_distance

def extract_meta_data_4B(self):
"""
Expand All @@ -472,9 +472,9 @@ def extract_meta_data_4B(self):
settings = self.instrument_settings

if settings.apply_instrument_settings:
self.det_distance = settings.sample_detector_distance
self.sample_detector_distance = settings.sample_detector_distance
else:
self.det_distance = self.DEFAULT_4B_SAMPLE_DET_DISTANCE
self.sample_detector_distance = self.DEFAULT_4B_SAMPLE_DET_DISTANCE

# Check that we have the needed meta data for the emission delay calculation
if self.use_emission_time:
Expand Down Expand Up @@ -503,9 +503,9 @@ def __repr__(self):
String representation of the reduction settings
"""
output = "Reduction settings:\n"
output += " sample-det: %s\n" % self.det_distance
output += " sample-det: %s\n" % self.sample_detector_distance
output += " source-det: %s\n" % self.source_detector_distance
output += " pixel: %s\n" % self.pixel_width
output += " pixel-width: %s\n" % self.pixel_width
output += " WL: %s %s\n" % (self.wl_range[0], self.wl_range[1])
output += " Q: %s %s\n" % (self.q_min_meas, self.q_max_meas)
theta_degrees = self.theta * 180 / np.pi
Expand Down Expand Up @@ -887,7 +887,7 @@ def _reflectivity(
event_weights = evt_list.getWeights()

x_distance = _pixel_width * (j - peak_position)
delta_theta_f = np.arctan(x_distance / self.det_distance) / 2.0
delta_theta_f = np.arctan(x_distance / self.sample_detector_distance) / 2.0

# Sign will depend on reflect up or down
ths_value = ws.getRun()["ths"].value[-1]
Expand Down Expand Up @@ -919,8 +919,8 @@ def _reflectivity(
if q_summing:
x0 = _pixel_width * (peak_position - peak[0])
x1 = _pixel_width * (peak_position - peak[1])
delta_theta_f0 = np.arctan(x0 / self.det_distance) / 2.0
delta_theta_f1 = np.arctan(x1 / self.det_distance) / 2.0
delta_theta_f0 = np.arctan(x0 / self.sample_detector_distance) / 2.0
delta_theta_f1 = np.arctan(x1 / self.sample_detector_distance) / 2.0

qz_max = 4.0 * np.pi / self.tof_range[1] * self.constant * np.fabs(np.sin(theta + delta_theta_f0))
qz_min = 4.0 * np.pi / self.tof_range[1] * self.constant * np.fabs(np.sin(theta + delta_theta_f1))
Expand Down Expand Up @@ -1051,7 +1051,7 @@ def _off_specular(self, ws, wl_dist, wl_bins, x_bins, z_bins, peak_position, the
wl_weights = 1.0 / np.interp(wl_list, wl_bins, wl_dist, np.inf, np.inf)

x_distance = float(j - peak_position) * self.pixel_width
delta_theta_f = np.arctan(x_distance / self.det_distance)
delta_theta_f = np.arctan(x_distance / self.sample_detector_distance)
# Sign will depend on reflect up or down
ths_value = ws.getRun()["ths"].value[-1]
delta_theta_f *= np.sign(ths_value)
Expand Down
2 changes: 1 addition & 1 deletion reduction/lr_reduction/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def process_from_template_ws(
instrument_settings=instrument_settings,
use_emission_time=template_data.use_emission_time,
)
print(event_refl)
print(f"{'*'*88}\nevent_refl:\n{event_refl}\n{'*'*88}")

# R(Q)
qz, refl, d_refl = event_refl.specular(
Expand Down
24 changes: 12 additions & 12 deletions reduction/notebooks/workflow-fixed-tthd.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@
},
{
"cell_type": "code",
"execution_count": 143,
"execution_count": null,
"metadata": {
"execution": {
"iopub.execute_input": "2024-09-01T22:56:07.736455Z",
Expand All @@ -561,7 +561,7 @@
],
"source": [
"_pixel_width = 0.0007\n",
"det_distance = 1.355\n",
"sample_detector_distance = 1.355\n",
"dirpix = 261\n",
"peak_position = 85.5\n",
"#peak_position = 210\n",
Expand All @@ -571,21 +571,21 @@
"\n",
"\n",
"x0 = _pixel_width * (peak_position - dirpix)\n",
"theta = np.arctan(x0 / det_distance) / 2.0 * 180 / np.pi\n",
"theta = np.arctan(x0 / sample_detector_distance) / 2.0 * 180 / np.pi\n",
"print(theta)\n",
"\n",
"\n",
" \n",
"\n",
"if False:\n",
" for i in range(304):\n",
" x0 = _pixel_width * (i - dirpix)\n",
" theta = np.arctan(x0 / det_distance) / 2.0 * 180 / np.pi\n",
" theta = np.arctan(x0 / sample_detector_distance) / 2.0 * 180 / np.pi\n",
" print(\"Pixel:%g Theta = %g\" % (i, theta))"
]
},
{
"cell_type": "code",
"execution_count": 74,
"execution_count": null,
"metadata": {
"execution": {
"iopub.execute_input": "2024-08-30T01:39:22.045519Z",
Expand Down Expand Up @@ -628,10 +628,10 @@
"all_pix = np.arange(300)\n",
"\n",
"x0 = _pixel_width * (pix - dirpix)\n",
"calc = np.arctan(x0 / det_distance) / 2.0 * 180 / np.pi\n",
"calc = np.arctan(x0 / sample_detector_distance) / 2.0 * 180 / np.pi\n",
"\n",
"x0 = _pixel_width * (all_pix - dirpix)\n",
"all_calc = np.arctan(x0 / det_distance) / 2.0 * 180 / np.pi\n",
"all_calc = np.arctan(x0 / sample_detector_distance) / 2.0 * 180 / np.pi\n",
"\n",
"fig, ax = plt.subplots(figsize=(10,5))\n",
"plt.plot(pix, ths, 'o', label='ths')\n",
Expand All @@ -656,9 +656,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "sans",
"language": "",
"name": "sans"
"display_name": "lr_reduction",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -670,7 +670,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.14"
"version": "3.10.16"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 6e78f8f

Please sign in to comment.