Skip to content

Commit 9fdb654

Browse files
authored
Merge pull request #283 from ISISComputingGroup/proof_read_docs
Docs: proof read & improve rendering
2 parents def10be + 9fb722a commit 9fdb654

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+2079
-1045
lines changed

.github/workflows/documentation.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@ name: sphinx
33
on: [push, pull_request, workflow_call]
44

55
jobs:
6+
spellcheck:
7+
runs-on: "windows-latest"
8+
steps:
9+
- uses: actions/checkout@v4
10+
with:
11+
fetch-depth: 0
12+
- uses: actions/setup-python@v5
13+
with:
14+
python-version: "3.13"
15+
- name: install requirements
16+
run: pip install -e .[dev]
17+
- name: run spellcheck
18+
run: sphinx-build -E -a -W --keep-going -b spelling doc _build
619
call_sphinx_builder:
720
uses: ISISComputingGroup/reusable-workflows/.github/workflows/sphinx.yml@main
821
secrets: inherit

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ Core bluesky plan stubs & devices for use at ISIS.
88
| [CI (nightly)](https://github.com/ISISComputingGroup/ibex_bluesky_core/actions/workflows/lint-and-test-nightly.yml) | [<img src="https://github.com/ISISComputingGroup/ibex_bluesky_core/actions/workflows/lint-and-test-nightly.yml/badge.svg">](https://github.com/ISISComputingGroup/ibex_bluesky_core/actions/workflows/lint-and-test-nightly.yml) |
99
| [CI (`bluesky` & `ophyd-async` main)](https://github.com/ISISComputingGroup/ibex_bluesky_core/actions/workflows/test-against-main.yml) | [<img src="https://github.com/ISISComputingGroup/ibex_bluesky_core/actions/workflows/test-against-main.yml/badge.svg">](https://github.com/ISISComputingGroup/ibex_bluesky_core/actions/workflows/test-against-main.yml) |
1010
| [PyPI](https://pypi.org/project/ibex-bluesky-core/) | ![PyPI - Version](https://img.shields.io/pypi/v/ibex_bluesky_core) |
11-
| [Github](https://github.com/ISISComputingGroup/ibex_bluesky_core) | ![GitHub Release](https://img.shields.io/github/v/release/IsisComputingGroup/ibex_bluesky_core) |
11+
| [GitHub](https://github.com/ISISComputingGroup/ibex_bluesky_core) | ![GitHub Release](https://img.shields.io/github/v/release/IsisComputingGroup/ibex_bluesky_core) |
1212
| [License](https://github.com/ISISComputingGroup/ibex_bluesky_core/blob/main/LICENSE) | ![GitHub License](https://img.shields.io/github/license/ISISComputingGroup/ibex_bluesky_core) |

doc/architectural_decisions/003-run-in-process.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Current
88

99
`bluesky` code can be run in several ways:
1010
- By the user at an interactive shell, directly calling the run engine in-process.
11-
- Underneath {py:obj}`run_plan()<ibex_bluesky_core.run_engine.run_plan>` if a plan/plan stub is to be run programmatically, which in turn calls the run engine.
11+
- Underneath {py:obj}`~ibex_bluesky_core.run_engine.run_plan` if a plan/plan stub is to be run programmatically, which in turn calls the run engine.
1212
- By a central worker process, to which the user would "submit" plans to run.
1313
- See DLS's `blueapi` for an example of a REST API for submitting plans to the run engine.
1414

doc/architectural_decisions/005-variance-addition.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ Current
66

77
## Context
88

9-
For counts data, the uncertainty on counts is typically defined by poisson counting statistics, i.e. the standard
10-
deviation on `N` counts is `sqrt(N)`.
9+
For counts data, the uncertainty on counts is typically defined by Poisson counting statistics, i.e. the standard
10+
deviation on {math}`N` counts is {math}`\sqrt{N}`.
1111

1212
This can be problematic in cases where zero counts have been collected, as the standard deviation will then be zero,
1313
which will subsequently lead to "infinite" point weightings in downstream fitting routines for example.
@@ -24,17 +24,17 @@ Use a standard deviation of `NaN` for points with zero counts.
2424

2525
### Option C
2626

27-
Define the standard deviation of `N` counts as `1` if counts are zero, otherwise `sqrt(N)`. This is one of the
27+
Define the standard deviation of {math}`N` counts as {math}`1` if counts are zero, otherwise {math}`\sqrt{N}`. This is one of the
2828
approaches [available in mantid](https://github.com/mantidproject/mantid/blob/bbbb86edc2c3fa554499770463aa25c2b46984e5/docs/source/algorithms/SetUncertainties-v1.rst#L16) for example.
2929

3030
### Option D
3131

32-
Define the standard deviation of `N` counts as `sqrt(N+0.5)` unconditionally - on the basis that "half a count" is
32+
Define the standard deviation of {math}`N` counts as {math}`\sqrt{N+0.5}` unconditionally - on the basis that "half a count" is
3333
smaller than the smallest possible actual measurement which can be taken.
3434

3535
### Option E
3636

37-
No special handling, calculate std. dev. as `sqrt(N)`.
37+
No special handling, calculate std. dev. as {math}`\sqrt{N}`.
3838

3939
---
4040

doc/architectural_decisions/006-where-to-put-code.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Examples of devices and where we would put them under this model:
3434
Examples of plans and where we would put them under this model:
3535
### `ibex_bluesky_core` plans
3636
- Scanning one block against DAE with a common set of callbacks
37-
- Optimizing an axis against a readback (e.g. consituent parts of reflectometry auto-align)
37+
- Optimizing an axis against a readback (e.g. constituent parts of reflectometry auto-align)
3838
- Very common plans
3939
- `scan_motor_against_dae`:
4040
* Always assumes a "motor" - i.e. sets up a block with `use_completion_callback=True` and `use_global_moving_flag=True`

doc/architectural_decisions/007-output-file-archiving.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ Accepted
77
## Context
88

99
Our bluesky implementation contains bluesky callbacks which produce scientist-facing output files, for example:
10-
- [Human-readable scan result files](/callbacks/file_writing): {py:obj}`HumanReadableFileCallback <ibex_bluesky_core.callbacks.HumanReadableFileCallback>`
11-
- [Fitting results](/callbacks/fitting/livefit_logger): {py:obj}`LiveFitLogger <ibex_bluesky_core.callbacks.LiveFitLogger>`
12-
- [Plot PNGs](#plot_png_saver): {py:obj}`PlotPNGSaver <ibex_bluesky_core.callbacks.PlotPNGSaver>`
10+
- [Human-readable scan result files](/callbacks/file_writing): {py:obj}`~ibex_bluesky_core.callbacks.HumanReadableFileCallback`
11+
- [Fitting results](/callbacks/fitting/livefit_logger): {py:obj}`~ibex_bluesky_core.callbacks.LiveFitLogger`
12+
- [Plot PNGs](#plot_png_saver): {py:obj}`~ibex_bluesky_core.callbacks.PlotPNGSaver`
1313

1414
In addition, we have a {ref}`developer-facing callback for diagnostics <event_doc_cb>`,
15-
{py:obj}`DocLoggingCallback <ibex_bluesky_core.callbacks.DocLoggingCallback>`.
15+
{py:obj}`~ibex_bluesky_core.callbacks.DocLoggingCallback`.
1616

1717
The above callbacks produce files on disk in response to a bluesky scan. These files contain valuable data and so we
1818
need to consider how these files are archived for the long term. This must align with the
@@ -268,7 +268,7 @@ unachievable - it would require too much work relative to using the existing `au
268268

269269
At present, our scan file output format is explicitly designed to be "human-readable" (and, in fact, the callback which
270270
generates these files is explicitly called
271-
{py:obj}`HumanReadableFileCallback <ibex_bluesky_core.callbacks.HumanReadableFileCallback>`).
271+
{py:obj}`~ibex_bluesky_core.callbacks.HumanReadableFileCallback`).
272272

273273
We have [issue 26](https://github.com/ISISComputingGroup/ibex_bluesky_core/issues/26) which will implement
274274
machine-readable files, using a format such as `.hdf5` or `.nxs`. These files will sit alongside the existing

doc/architectural_decisions/008-centre-of-mass.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ A decision needs to be made about whether to make changes to upstream Bluesky so
1010

1111
## Decision
1212

13-
We will be making our own {py:obj}`CentreOfMass <ibex_bluesky_core.callbacks.CentreOfMass>` callback.
13+
We will be making our own {py:obj}`~ibex_bluesky_core.callbacks.CentreOfMass` callback.
1414

1515
## Justification & Consequences
1616

1717
[We attempted to make changes to upstream Bluesky which were rejected](https://github.com/bluesky/bluesky/pull/1878), as it adds limits to the functionality of the callback. We also found other limitations with using their callback, such as not being able to have disordered and non-continuous data sent to it without it skewing the calculated value - we need it to work with disordered and non-continuous data as we need to be able to run continuous scans.
1818

19-
We currently only need to support positive peaks, but in future a toggle could be added to {py:obj}`CentreOfMass <ibex_bluesky_core.callbacks.CentreOfMass>` to allow for negative peaks.
19+
We currently only need to support positive peaks, but in future a toggle could be added to {py:obj}`~ibex_bluesky_core.callbacks.CentreOfMass` to allow for negative peaks.
2020

2121
This will mean that...
2222
- Our version of the callback will not be supported by Bluesky and may need changes as Bluesky updates.
23-
- We can have a version of the callback that is made bespokely for our use cases.
23+
- We can have a version of the callback that is made specifically for our use cases.

doc/callbacks/centre_of_mass.md

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,44 @@
11
# Centre of Mass
22

3-
{py:obj}`ibex_bluesky_core.callbacks.CentreOfMass` is a callback that provides functionality for calculating our definition of Centre of Mass. We calculate centre of mass from the 2D region bounded by min(y), min(x), max(x), and straight-line segments joining (x, y) data points with their nearest neighbours along the x axis.
3+
{py:obj}`ibex_bluesky_core.callbacks.CentreOfMass` provides functionality for calculating a specific definition of a "centre of mass": it computes the centre of mass of a 2-dimensional region bounded by:
4+
- `min(x)`
5+
- `max(x)`
6+
- `min(y)`
7+
- Straight-line segments joining `(x, y)` data points with their nearest neighbours along the x axis
48

5-
{py:obj}`ibex_bluesky_core.callbacks.CentreOfMass` has a property, {py:obj}`result <ibex_bluesky_core.callbacks.CentreOfMass.result>`, which stores the centre of mass value once the callback has finished.
9+
{py:obj}`~ibex_bluesky_core.callbacks.CentreOfMass` stores its result in the {py:obj}`~ibex_bluesky_core.callbacks.CentreOfMass.result` property.
610

7-
## Our CoM Algorithm
11+
:::{note}
12+
This will return **different** results from the `com` property available from {py:obj}`bluesky.callbacks.fitting.PeakStats` in the following cases:
13+
- Points irregularly sampled along the x-axis
14+
- Points with negative y-values
15+
- x data which does not monotonically increase
816

9-
Given non-continuous arrays of collected data `x` and `y`, ({py:obj}`ibex_bluesky_core.callbacks.CentreOfMass`) returns the `x` value of the centre of mass.
17+
For a detailed comparison of the two implementations, see [unit tests written to expose tricky cases](https://github.com/bluesky/bluesky/blob/2d6fecd45e8de3a7d53d1c16dcd1a7b8f6f88d69/src/bluesky/tests/test_scientific.py#L142).
18+
:::
1019

11-
Our use cases require that our algorithm abides to the following rules:
12-
- Any background on data does not skew the centre of mass
13-
- The order in which data is received does not skew the centre of mass
20+
Given non-continuous arrays of collected data `x` and `y`, {py:obj}`~ibex_bluesky_core.callbacks.CentreOfMass` returns the `x` value of the centre of mass.
21+
22+
Many of our use cases require that our algorithm follows the following rules:
23+
- Any background on data should not change the centre of mass.
24+
- The order in which data is received should not change the centre of mass
1425
- Should support non-constant point spacing without skewing the centre of mass
1526

1627
```{note}
1728
Note that this is designed for only **positive** peaks.
1829
```
1930

20-
### Step-by-step
31+
{py:obj}`ibex_bluesky_core.callbacks.CentreOfMass` is included in {doc}`our callbacks collection <isiscallbacks>`.
32+
33+
---
34+
35+
**Implementation details**
2136

2237
1) Sort `x` and `y` arrays in respect of `x` ascending. This is so that data can be received in any order.
23-
2) From each `y` element, subtract `min(y)`. This means that any constant background over data is ignored. (Does not work for negative peaks)
24-
3) Calculate weight/widths for each point; based on it's `x` distances from neighbouring points. This ensures non-constant point spacing is accounted for in our calculation.
25-
4) For each decomposed shape that makes up the total area under the curve, `CoM` is calculated as the following:
38+
2) From each `y` element, subtract `min(y)`. This means that any constant background over data is ignored.
39+
3) Decompose the curve into a series of trapezoidal regions, and then further decompose those
40+
trapezoidal regions into rectangular and triangular regions.
41+
4) Compute centre of mass of the overall shape by composition of each region:
2642
```{math}
27-
com_x = \frac{\sum_{}^{}x * y * \text{weight}}{\sum_{}^{}y * \text{weight}}
28-
```
29-
30-
{py:obj}`ibex_bluesky_core.callbacks.CentreOfMass` can be used from our callbacks collection. See {doc}`isiscallbacks`.
43+
C_x = \frac{\sum_{i}^{} C_{ix} * A_i}{\sum_{i}^{} A_i}
44+
```

doc/callbacks/file_writing.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
{#hr_file_cb}
44
## Human readable files
55

6-
A callback ([`HumanReadableFileCallback`](ibex_bluesky_core.callbacks.HumanReadableFileCallback)) exists to write all documents to a separate human-readable file which contains the specified fields.
6+
{py:obj}`~ibex_bluesky_core.callbacks.HumanReadableFileCallback` can be configured to write all documents to a human-readable file which contains the specified fields.
77

8-
This callback will add units and honour precision for each field as well as add some metadata ie. the `uid` of each scan as well as the RB number, which is injected using the {doc}`/dev/rbnumberpp`
8+
This callback will add units and honour precision for each field as well as add some metadata, for example the RB number, which is injected using the {doc}`/dev/rbnumberpp`.
99

10-
### Example
1110
An example of using this could be:
1211

1312
```{code} python
@@ -47,17 +46,17 @@ RE(some_plan())
4746
```
4847

4948
This will put the `block` and `dae.good_frames` data collected over the run into a `.txt` file, named after the `uid`
50-
of the scan, in `C:\instrument\var\logs\bluesky\output_files\`.
49+
of the scan, in `\\isis\inst$\ndx<inst>\user\bluesky_scans\<rbnumber>`.
5150

5251
Optional parameters, not shown above, include:
53-
- `output_dir` parameter is optional, if not input the file will by default be placed in
52+
- `output_dir` parameter is optional; if not provided, the file will by default be placed in
5453
`\\isis\inst$\ndx<inst>\user\bluesky_scans\<rbnumber>`.
5554
- `postfix` an optional suffix to append to the end of the file name, to disambiguate scans. Default is no suffix.
5655

5756
The data is prepended on the first event with the names and units of each logged field, and then subsequently the data
58-
for each scan separated by a newline. All of this is separated by commas, though the metadata is not.
57+
for each scan separated by a newline. The data is separated by commas, though the metadata is not.
5958

60-
The file also contains metadata such as the bluesky version, plan type, and rb number.
59+
The file also contains metadata such as the bluesky version, plan type, and RB number.
6160

6261
## Fit outputs
6362

@@ -74,6 +73,6 @@ See {ref}`plot_png_saver`
7473
This callback is added automatically and is not intended to be user-facing - it is primarily for developer diagnostics.
7574
```
7675

77-
The [`DocLoggingCallback`](ibex_bluesky_core.callbacks.DocLoggingCallback) is a callback that the BlueSky RunEngine subscribes to unconditionally in {py:obj}`RunEngine import level<ibex_bluesky_core.run_engine.get_run_engine>`. After receiving each document, if they share the same start document (in the same run) then it will write them to the same file. These logs are stored under `C:/instrument/var/logs/bluesky/raw_documents` and are handled by the log rotation.
76+
The {py:obj}`~ibex_bluesky_core.callbacks.DocLoggingCallback` is a callback that the BlueSky RunEngine subscribes to unconditionally during {py:obj}`~ibex_bluesky_core.run_engine.get_run_engine`. It logs all documents it receives into files grouped by unique scan identifier. These logs are stored under `C:/instrument/var/logs/bluesky/raw_documents`; older logs are moved to long-term storage by a log rotation script.
7877

79-
Each document is stored in a JSON format so can be both machine and human readable. It is in the format `{"type": name, "document": document}` whereby `name` is the type of the document, e.g start, stop, event, descriptor and the `document` is the [document from BlueSky in JSON format](https://blueskyproject.io/bluesky/main/documents.html). As these files are produced per BlueSky run, these will be useful for debugging.
78+
Each document is stored in a JSON format so can be both machine and human-readable. The format is line-delimited JSON, `{"type": name, "document": document}` whereby `name` is the type of the document, e.g start, stop, event, descriptor and the `document` is the {external+bluesky:doc}`document from bluesky in JSON format <documents>`.

0 commit comments

Comments
 (0)