Skip to content

Commit

Permalink
Merge pull request #17 from neutrons/from_sample_to_peak_suffix
Browse files Browse the repository at this point in the history
substitute "sample" with "peak"
  • Loading branch information
jmborr authored Oct 30, 2024
2 parents bc09361 + 00263ff commit f80fafc
Show file tree
Hide file tree
Showing 26 changed files with 495 additions and 520 deletions.
17 changes: 0 additions & 17 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ Check all that apply:
- [ ] Source added/refactored
- [ ] Added unit tests
- [ ] Added integration tests
- [ ] Verified that tests requiring the /SNS and /HFIR filesystems pass without fail

**References:**
- Links to IBM EWM items:
Expand All @@ -25,19 +24,3 @@ updated, or an explanation is provided as to why release notes are unnecessary
- [ ] All the tests are passing
- [ ] The documentation is up to date
- [ ] code comments added when explaining intent

### Execution of tests requiring the /SNS and /HFIR filesystems
It is strongly encouraged that the reviewer runs the following tests in their local machine
because these tests are not run by the GitLab CI. It is assumed that the reviewer has the /SNS and /HFIR filesystems
remotely mounted in their machine.

```bash
cd /path/to/my/local/mr_reduction/repo/
git fetch origin merge-requests/<MERGE_REQUEST_NUMBER>/head:mr<MERGE_REQUEST_NUMBER>
git switch mr<MERGE_REQUEST_NUMBER>
conda activate <my_mr_reduction_environment>
pytest -m mount_eqsans ./tests/unit/ ./tests/integration/
```
In the above code snippet, substitute `<MERGE_REQUEST_NUMBER>` for the actual merge request number. Also substitute
`<my_mr_reduction_environment>` with the name of the conda environment you use for development. It is critical that
you have installed the repo in editable mode with `pip install -e .` or `conda develop .`
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ User Guide
.. toctree::
:titlesonly:

/user/multiple_samples
/user/multiple_peaks
/user/conda_environments
/user/reduce
/releases
Expand Down
2 changes: 1 addition & 1 deletion docs/releases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Notes for major and minor releases. Notes for patch releases are referred.

**Of interest to the User**:

- PR #9 Add the capability to autoreduce two samples from the same run
- PR #9 Add the capability to autoreduce two peaks from the same run

**Of interest to the Developer:**

Expand Down
File renamed without changes
22 changes: 22 additions & 0 deletions docs/user/multiple_peaks.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.. multiple_peaks
Multiple Peaks in a single Run
================================

The Magnetism Reflectometer can stack several (usually 2, rarely 3) peaks on top of each other.
The beam is wide enough to cover all the peaks.
To measure reflectivity, the beam is very narrow in the other direction (so it’s like a thin ribbon).
Because we are sensitive to tiny angles,
the reflection from each peak will appear in different sports on the detector.
With one peak, there will be one spot on the detector.
With two, there will be two if (1) the peaks are not exactly parallel
(in which case it will still look like one spot) and
(2) the peaks are parallel enough so that both spots are on the detector
(otherwise one of the spots may be outside the detector surface.

.. figure:: ./media/two_peaks_stacked.png
:alt: Reflectometry from two peaks stacked.
:align: center
:width: 900

Reflectometry from two peaks stacked.
22 changes: 0 additions & 22 deletions docs/user/multiple_samples.rst

This file was deleted.

22 changes: 11 additions & 11 deletions docs/user/reduce.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,27 @@ Notice how the report shows the superposition of reflectivity curves for runs 41
will happen if reduced files for runs 41446 and 41447 are found either in the output directory `/tmp/test_webform`
or the canonical output directory for autoreduction of runs corresponding to run 41445 which in this
case is `/SNS/REF_M/IPTS-21391/shared/autoreduce/`. Runs 41445, 41446, and 41447 correspond to experiments
taken on the same sample but with a different incidence angle.
taken on the same peak but with a different incidence angle.

The webapp supports reduction of up to three samples for the scenarios when the run contains more than one sample.
In the following screenshot we selected `Sample Count=2`, causing reduction taking into account options
from `Sample #1` and `Sample #2`.
The webapp supports reduction of up to three peaks for the scenarios when the run contains more than one peak.
In the following screenshot we selected `Peak Count=2`, causing reduction taking into account options
from `Peak #1` and `Peak #2`.

.. figure:: ./media/manual_reduction_two_samples.GIF
:alt: Reduction of two samples.
.. figure:: ./media/manual_reduction_two_peaks.GIF
:alt: Reduction of two peaks.
:align: center
:width: 900

Reduction of two samples.
Reduction of two peaks.

The below excerpt from the corresponding report show the reflectivity curves for the two samples (41445_1 and 41445_2).
The below excerpt from the corresponding report show the reflectivity curves for the two peaks (41445_1 and 41445_2).

.. figure:: ./media/manual_reduction_two_samples_report.GIF
:alt: Report for two samples.
.. figure:: ./media/manual_reduction_two_peaks_report.GIF
:alt: Report for two peaks.
:align: center
:width: 700

Report for two samples.
Report for two peaks.


Automated Reduction
Expand Down
36 changes: 18 additions & 18 deletions src/mr_autoreduce/reduce_REF_M.py.template
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def _as_bool(value):

def reduction_user_options():
r"""Collects all values defined by the user in https://monitor.sns.gov/reduction/ref_m/"""
# Options common to all samples:
# Options common to all peaks:
kwargs_common = dict(
plot_2d=_as_bool(${plot_in_2D}),
const_q_binning=_as_bool(${use_const_q}),
Expand All @@ -55,8 +55,8 @@ def reduction_user_options():
publish = False # uploading to livedata server to be done later by `upload_html_report()`
)

# Options for Sample 1
kwargs_sample_1 = dict(
# Options for Peak 1
kwargs_peak_1 = dict(
use_roi=True,
force_peak_roi=_as_bool(${force_peak}),
peak_roi=[int(${peak_min}), int(${peak_max})],
Expand All @@ -67,8 +67,8 @@ def reduction_user_options():
bck_offset=int(${bck_width})
)

# Options for Sample 2
kwargs_sample_2 = dict(
# Options for Peak 2
kwargs_peak_2 = dict(
use_roi=True,
force_peak_roi=_as_bool(${force_peak_s2}),
peak_roi=[int(${peak_min_s2}), int(${peak_max_s2})],
Expand All @@ -79,8 +79,8 @@ def reduction_user_options():
bck_offset=int(${bck_width_s2})
)

# Options for Sample 3
kwargs_sample_3 = dict(
# Options for Peak 3
kwargs_peak_3 = dict(
use_roi=True,
force_peak_roi=_as_bool(${force_peak_s3}),
peak_roi=[int(${peak_min_s3}), int(${peak_max_s3})],
Expand All @@ -91,22 +91,22 @@ def reduction_user_options():
bck_offset=int(${bck_width_s3}),
)

# Do we have more than one sample in this run?
sample_count = int(${sample_count})
ReductionOptions = namedtuple('ReductionOptions', 'common, sample_count, sample1, sample2, sample3')
return ReductionOptions(kwargs_common, sample_count, kwargs_sample_1, kwargs_sample_2, kwargs_sample_3)
# Do we have more than one peak in this run?
peak_count = int(${peak_count})
ReductionOptions = namedtuple('ReductionOptions', 'common, peak_count, peak1, peak2, peak3')
return ReductionOptions(kwargs_common, peak_count, kwargs_peak_1, kwargs_peak_2, kwargs_peak_3)


def reduce_events_file(event_file_path, outdir):
event_file = os.path.split(event_file_path)[-1] # file name
reports = list() # autoreduction reports for each sample in the run, in HTML format
reports = list() # autoreduction reports for each peak in the run, in HTML format
opts = reduction_user_options()
assert opts.sample_count <= 3, "Sample count must be <= 3"
kwargs_samples = [opts.sample1, opts.sample2, opts.sample3]
sample_numbers = [None, ] if opts.sample_count == 1 else range(1, opts.sample_count + 1) # numbers start at 1, not 0
for i, sample_number in enumerate(sample_numbers):
d = dict(data_run=event_file, output_dir=outdir, sample_number=sample_number)
kwargs = {**d, **opts.common, **kwargs_samples[i]} # merge all partial dicts
assert opts.peak_count <= 3, "Peak count must be <= 3"
kwargs_peaks = [opts.peak1, opts.peak2, opts.peak3]
peak_numbers = [None, ] if opts.peak_count == 1 else range(1, opts.peak_count + 1) # numbers start at 1, not 0
for i, peak_number in enumerate(peak_numbers):
d = dict(data_run=event_file, output_dir=outdir, peak_number=peak_number)
kwargs = {**d, **opts.common, **kwargs_peaks[i]} # merge all partial dicts
reports.append(ReductionProcess(**kwargs).reduce())
return reports

Expand Down
28 changes: 14 additions & 14 deletions src/mr_autoreduce/templates/reduction_options.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
padding: 5px;
margin-bottom: 10px;
}
.samples-container {
.peaks-container {
display: flex;
justify-content: space-between;
}
.sample {
.peak {
width: 30%;
padding: 10px;
box-sizing: border-box;
Expand All @@ -53,7 +53,7 @@ <h2 title="Output directory path for reduced and reports files">Output Directory
</div>

<div class="form-section">
<h2>Options for all samples</h2>
<h2>Options for all peaks</h2>

<label title="Check the following box to see 2D plots on the monitor.
Loading the page for each run will take much longer when this option is turned on.">
Expand All @@ -66,19 +66,19 @@ <h2>Options for all samples</h2>
<label title="Check the following box if you want to use SANGLE,
otherwise DANGLE will be used."><input type="checkbox" id="use_sangle" checked> Use SANGLE</label>

<label title="Once the reflected peak ROI is selected for each sample below,
<label title="Once the reflected peak ROI is selected for each peak below,
you can try to fine tune this ROI by fitting for a peak within that
region and updating the ROI [both center and width] according to the
location found. Check the box if you want to find a peak within the
ROI and redefine the ROI afterwards."><input type="checkbox" id="fit_peak_in_roi" checked> Automated ROI</label>

<label title="Number of samples in the run" style="font-weight:bold; font-size:1.2em;">
Sample count <input type="number" id="sample_count" style="width: 25px;" value="1"></label>
<label title="Number of peaks in the run" style="font-weight:bold; font-size:1.2em;">
Peak count <input type="number" id="peak_count" style="width: 25px;" value="1"></label>
</div>

<div class="samples-container">
<div class="form-section sample" id="sample1">
<h2>Sample #1</h2>
<div class="peaks-container">
<div class="form-section peak" id="peak1">
<h2>Peak #1</h2>

<label title="You can choose to replace the ROI in the data by your own range.
Check the following box if you want to define your own ROI and
Expand Down Expand Up @@ -109,8 +109,8 @@ <h2>Sample #1</h2>
<label>Pixels on each side <input type="number" style="width: 40px;" id="bck_width"></label>
</div>

<div class="form-section sample" id="sample2">
<h2 title="Sample 2 options ignored if Sample count is 1">Sample #2</h2>
<div class="form-section peak" id="peak2">
<h2 title="Peak 2 options ignored if Peak count is 1">Peak #2</h2>

<label title="You can choose to replace the ROI in the data by your own range.
Check the following box if you want to define your own ROI and
Expand Down Expand Up @@ -141,8 +141,8 @@ <h2 title="Sample 2 options ignored if Sample count is 1">Sample #2</h2>
<label>Pixels on each side <input type="number" style="width: 40px;" id="bck_width_s2"></label>
</div>

<div class="form-section sample" id="sample3">
<h2 title="Sample 3 options ignored if Sample count is smaller than three">Sample #3</h2>
<div class="form-section peak" id="peak3">
<h2 title="Peak 3 options ignored if Peak count is smaller than three">Peak #3</h2>

<label title="You can choose to replace the ROI in the data by your own range.
Check the following box if you want to define your own ROI and
Expand Down Expand Up @@ -228,7 +228,7 @@ <h2 title="Sample 3 options ignored if Sample count is smaller than three">Sampl
q_step: document.getElementById('q_step').value,
use_sangle: document.getElementById('use_sangle').checked,
fit_peak_in_roi: document.getElementById('fit_peak_in_roi').checked,
sample_count: document.getElementById('sample_count').value,
peak_count: document.getElementById('peak_count').value,

force_peak: document.getElementById('force_peak').checked,
peak_min: document.getElementById('peak_min').value,
Expand Down
Loading

0 comments on commit f80fafc

Please sign in to comment.