Skip to content

Data correction documentary #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 31, 2024
Merged

Data correction documentary #26

merged 7 commits into from
Jan 31, 2024

Conversation

astellhorn
Copy link
Collaborator

  • Documentary for functions and dependencies.
  • Some notes are added that can be deleted later.
  • Changes to previously discussed issues: The empty-glass-transmission $T^{g,p|a}$ of polarizer/analyzer we previously assumed as constant. That is not precisely true (though never any wavelength dependence was able to be measured on 3He-cells so far). To keep a wavelength-dependence as an option, the new proposition is to insert it as wavelength-dependent function $T^{g,p|a}(\lambda)$, instead of a scalar. This function will be pre-determined during cell-fabrication and hence this will not change anything in the workflow, except for reading in a pre-known function of $T^{g,p|a}$ instead of the scalar variable.

Documentary for functions and dependencies
Copy link
Member

@SimonHeybrock SimonHeybrock left a comment

Choose a reason for hiding this comment

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

Not a real review, just brief comments about formatting (problems and readability).

Copy link
Member

Choose a reason for hiding this comment

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

Use lowercase and now spaces in filenames.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

True!! I am very sorry, I need to get rid of this windows habit

"| $l^{p|a}$ | length of $^3$He-polarizer/analyzer | scalar, 1-dim | from metadata |Row 1 |\n",
"| $T^{g, p|a}(\\lambda)$ | transmission of empty glass of polarizer/analyzer | scalar, 1-dim | from metadata |Row 1 |\n",
"| $O^{p|a}(\\lambda)=O^{0, p|a}*\\lambda$ | wavelength-dependent opacity of $^3$He-polarizer/analyzer | continuous function of $\\lambda$ | $O^{0, p|a}$ fit to data |Row 1 |\n",
"| $O^{0, p|a}$ | wavelength-independent pre-factor of opacity of $^3$He-polarizer/analyzer | scalar, 1-dim | fit to data |Row 1 |\n",
Copy link
Member

Choose a reason for hiding this comment

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

The He3 also is not rendered.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

thanks, its also not in the rest of the text I just see!

"\n",
"| Value | Meaning | shape | How acquired? | How named in current main branch? |\n",
"|:--------:|:--------:|:--------:|:--------:|:--------:|\n",
"| $I^{++}_{t,\\lambda}$ | uncorrected sample data of ++ channel | data array with columns for $I$, $\\lambda$, $t$ | neutron data |Row 1 |\n",
Copy link
Member

Choose a reason for hiding this comment

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

I don't think the notation like $I^{++}_{t,\\lambda}$ makes sense when talking about event data. This looks like a 2-D array (for any given $t$ there can be multiple $\lambda$ and vice versa), which would be fine if we planned to histogram, but maybe need to come up with a better notation for event data? Maybe an event index?

On the other hand, maybe we can keep it, and just clarify in the beginning that the notation is for histogrammed data?

Copy link
Collaborator Author

@astellhorn astellhorn Jan 12, 2024

Choose a reason for hiding this comment

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

Are there any other workflows (e.g. unpol SANS or other instruments) who use a notation for event data already? I will ask around here.
But other question: the test-data we create binned, not histogrammed, but the data we use for calculating O and P(t) were histogrammed in the direct-beam data in the function "compute_direct_beam"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So for that part we use histogrammed, but for sample-correction in the end the not histogrammed data?

Copy link
Member

Choose a reason for hiding this comment

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

Let use keep histogrammed notation everywhere (at least for now). One can always think of event data as an extremely sparse histogram, so conceptually it is ok (and this document is not about the way Scipp handles event data).

"\n",
"From the neutron measurement, this again can be retrieved by measuring the transmission through each cell (i.e., for an unpolarized incoming beam into the polarized cell):\n",
"\n",
"$$\\hat{T}^{unpol-in}(\\lambda, t) = T^{g, p|a}(\\lambda)e^{-O_0^{p|a}*\\lambda}\\cosh({P_{3He}(t)*O^{0, p|a}*\\lambda})$$<br>\n",
Copy link
Member

Choose a reason for hiding this comment

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

Avoid all the $*$? I think they don't help with readability.

"\n",
"\n",
"Both $\\hat{T^p}$ and $\\hat{T^a}$ can be derived from their cell parameters (the transmission of the empty cell $T_g$, and the cell opacity $O$), and the time-dependent nuclear polarization of the cell $P_{^3He}(t)$.<br>\n",
"This general method for time-dependent $^3$He-cells can be adapted for other use-cases such as using supermirrors or in-situ polarized ^3He-cells, see \"Note\" at the end of the page. \n",
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't render properly: $^3$He

"O^{cell}(\\lambda)= (0.0733 \\cdot p^{cell} \\cdot l^{cell} )\\lambda\n",
"$$\n",
"\n",
"with a factor 0.0733 arising from the number density of $^3$He gas and the absorption cross section of 1$\\mathring A$ neutrons by $^3$He. It can be seen that the opacity depends linearly on the neutron wavelength $\\lambda$. To calculate one value of $O(\\lambda)$ that fits to all wavelength from the depolarized direct-beam data $I^{DB, depol, cell}$, we will fit the wavelength-independent part $O^{0, cell}$ of $O(\\lambda)=O^{0, cell}\\cdot\\lambda$ in above equation. Afterwards, the wavelength-dependence can be retrieved by setting \n",
Copy link
Member

Choose a reason for hiding this comment

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

What do you mean by 'we will fit the wavelength-independent part'? Can't you just measure l and p and compute O^0?

EDIT: After reading on, it seems that everything up to here is the same for both workflows. So why is it in the 'Workflow 1' section?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

  1. we did not divide the workflows 1 and 2 into parts defined in the beginning of the script and end of the script, but into how they are physically derived.
    In workflow 1, the opacity will be acquired by setting O=p l lambda = O_0 lambda, whereas in workflow 2 it will be acquired by the direct beam through the depolarized cell and fitting O_0 to the given function.
    --> the workflows are the same everywhere except for how to derive O_0

  2. for workflow 1 with setting O=p l lambda = O_0 lambda:
    --> yes, O_0 is set by predefined p and l, that can be inserted by the sample environemtn team prior to the user measurement and will be just read-in values. still, O = O_0 lambda is wavelength dependent, and the lambda-dependency in how its written here is then treated the same as for workflow 2.
    --> but for workflow 2, this does not work, O_0 has to be fit to the given function in workflow 2

Copy link
Member

Choose a reason for hiding this comment

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

So $O(\lambda)=O^{0, cell}\cdot\lambda$ is used in both workflows? Then why is it listed in the 'workflow 1' section? Can you move the common equations and text out of the workflow sections and cleanly separate the workflows into sections? This would make it easier to understand how things relate to each other.

Also, 'workflow 2' says

A more precise data correction is based on a measure of $p$ by a direct-beam measurement through the depolarized cell

Do you really measure $p$? It sounds more like you don't use the parametrisation with $p$ and $l$ in workflow 2 but treat $O^0$ as a fundamental parameter.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for this comment, it is a good idea to divide these information in a better way! I will upload a new version. I am also sorry for confusion, I meant $P(t)$ here, not p (pressure of cell). I have rewritten it.

"\n",
"- Note: Workflow 2 should overwrite workflow 1 opacity after the experiment\n",
"- Note: Different to the sample data, $I^{DB,depol,cell}$ and $I^{DB,no-cell}$ are not time-dependent\n",
"- Note: It is important to fit $I_{depol}/I_0$ instead of $I_{depol}$, such that all the parameters in the fit-functions are scalars.\n"
Copy link
Member

Choose a reason for hiding this comment

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

What is I_0? I can't find a definition.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I forgot to change the name of this in the note, sorry. I_0 is now I^{DB, no-cell}_{\lambda}, I will change it

"source": [
"#### Calculation of time-dependent $^3$He-polarization\n",
" \n",
"Now $O^{cell}(\\lambda)=)O^{0, cell}\\cdot\\lambda$ is known. <br>\n",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"Now $O^{cell}(\\lambda)=)O^{0, cell}\\cdot\\lambda$ is known. <br>\n",
"Now $O^{cell}(\\lambda)=O^{0, cell}\\cdot\\lambda$ is known. <br>\n",

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

thanks

"source": [
"#### Spin-dependent transmission values\n",
"\n",
"Now both $O^{cell}(\\lambda)=)O^{0, cell}\\cdot\\lambda$ and $P^{^3He, cell}(t)$ are known. <br>\n",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"Now both $O^{cell}(\\lambda)=)O^{0, cell}\\cdot\\lambda$ and $P^{^3He, cell}(t)$ are known. <br>\n",
"Now both $O^{cell}(\\lambda)=O^{0, cell}\\cdot\\lambda$ and $P^{^3He, cell}(t)$ are known. <br>\n",

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

thanks

@SimonHeybrock
Copy link
Member

@astellhorn Can you fix the formatting or static analysis problems? This should actually happen locally when you commit (unless you bypass the check). You can run again using pre-commit run --all-files.

Comment on lines 114 to 131
"$\\mathbf{Workflow 2}$:<br>\n",
"A more precise data correction is based on a direct-beam measurement through the depolarized cell (i.e., $P_{^3He}(t) \\rightarrow 0$)(Ref. 2). For such a depolarized cell and an unpolarized incident beam (i.e., $\\hat{T}^{depol} = (\\hat{T}^++\\hat{T}^-)/2$), the neutron transmission becomes:\n",
"\n",
"$$\n",
"T^{depol, cell}(\\lambda)=T^{g, cell}(\\lambda)e^{-O^{0, cell}\\cdot\\lambda}\n",
"$$\n",
"\n",
"This leads to following direct beam intensity $I^{DB,depol,cell}_{\\lambda}$ measured on a depolarized cell:\n",
"\n",
"$$\n",
"\\frac{I^{DB,depol,cell}_{\\lambda}}{I^{DB,no-cell}_{\\lambda}}=T^{g, cell}(\\lambda)e^{-O^{0, cell}\\cdot\\lambda}\n",
"$$\n",
"\n",
"where $I^{DB,no-cell}_{\\lambda}$ is the intensity of a direct beam through an open neutron path (without cell and sample) and acts as a background measurement. For a measurement of $I^{DB,depol,cell}_{\\lambda}$, the <sup>3</sup>He cell needs to be depolarized at the end of its lifetime and $I^{DB,depol,cell}_{\\lambda}$ has to be acquired for each cell (and the other cell and sample out of beam). \n",
"\n",
"- Note: Workflow 2 should overwrite workflow 1 opacity after the experiment\n",
"- Note: Different to the sample data, $I^{DB,depol,cell}$ and $I^{DB,no-cell}$ are not time-dependent\n",
"- Note: It is important to fit $I_{depol}/I^{DB, no-cell}_{\\lambda}$ instead of $I_{depol}$, such that all the parameters in the fit-functions are scalars.\n"
Copy link
Member

Choose a reason for hiding this comment

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

The fact that we need to do a fit is hidden in a note. Can the procedure be explained more explicitly?

"O^{0, cell}= 0.0733 \\cdot p^{cell} \\cdot l^{cell}\n",
"$$\n",
"\n",
"with a factor 0.0733 arising from the number density of <sup>3</sup>He gas, the path length $l$ of neutron through the cell, and the absorption cross section of 1$\\mathring A$ neutrons by <sup>3</sup>He. However, a measurement of the opacity by neutron transmission in a depolarized cell condition yields more precise values and can be performed at the end of the cell-lifetime during the user's neutron experiments, i.e., leading to \"workflow 2\". \n",
Copy link
Member

Choose a reason for hiding this comment

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

Is this 0.0733 missing a unit? I can't get the opacity math to work otherwise.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, it has. To get this pre-factor according to the pressure [bar], cell length [cm] and wavelength [Angstrom] it is 0.0733[1/(kg/s2)] pro Angstrom. I mentioned it in the code of the branch calculating O, but yes of course I should better insert that here in the documentary: O is calculated from O=nsigmalambda*l ("n is the number density of 3He gas in the cell. σ0 is the absorption cross section of 1 Å neutron by 3He, σ0 = 2966 × 10−24 cm2. λ is the neutron wavelength. l is the path length through the cell. " - from Hals paper of the ECNS proceedings). Then exchanging with p = nk_BT. I thought its ok as its reported in other papers but its a quick copy-paste!

Copy link
Member

Choose a reason for hiding this comment

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

Yes, please update!

Copy link
Member

Choose a reason for hiding this comment

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

0.0733[1/(kg/s2)] pro Angstrom

Where is the Angstrom in that fraction, exactly?

Copy link
Member

Choose a reason for hiding this comment

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

If we can define things in terms of other constants that would be even better, avoiding magic numbers.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

0.0733[1/(kg*Angstrom/s2)]

Copy link
Member

Choose a reason for hiding this comment

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

Please see my updates in #27.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sorry about confusion. yes it is actually 0.0733 with units s2/kg per neutron wavelength - so 0.0733 (s2/kg*Angstrom) for 1Angstrom neutrons (which is typically done)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes I am having a look on the changes now - trying to keep track after coming back from USA! If I forget anything there please dont hesitate to remind me again.

"\\begin{pmatrix} S^{++}_{t,\\lambda} \\\\ S^{+-}_{t,\\lambda} \\\\ S^{-+}_{t,\\lambda} \\\\ S^{--}_{t,\\lambda}\\end{pmatrix}\n",
"$$\n",
"\n",
"- Note: probably easier to first put functions into the matrix product $T^a$ $\\cdot$ $T^p$, then numerically get the inverse of that matrix product.\n",
Copy link
Member

Choose a reason for hiding this comment

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

If done numerically this will be wasteful, since the matrices have a very special structure and many zeros. Therefore, it should be done analytically.

"| $O^{0, cell}$ | wavelength-independent pre-factor of opacity of <sup>3</sup>He-polarizer/analyzer | scalar, 1-dim | fit to data |\n",
"| $P^{^3He, cell}(t) = C^{cell}e^{-t/T^{1, cell}}$ | time-dependent nuclear polarization of <sup>3</sup>He-polarizer/analyzer | continuous function of $t$ | $C^{cell}, T^{1, cell}$ fit to data |\n",
"| $C^{cell}$ | Pre-factor of nuclear polarization exponential decay of <sup>3</sup>He-polarizer/analyzer | scalar, 1-dim | fit to data | $P_{He0}$ |\n",
"| $T^{1, cell}$ | Decay constant of nuclear polarization exponential decay of <sup>3</sup>He-polarizer/analyzer | scalar, 1-dim | fit to data |\n",
Copy link
Member

Choose a reason for hiding this comment

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

This appears to be a time-scale, can we use $t$ instead of $T$? As it is it is also easily confused with the other uses of $T$ for transmission.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hm. Its a commonly used "T", as its not varying in time, its a fix constant. I feel it can be dangerous to exchange with 't' as well. I see the point of confusion with Transmission. Sometims these time-decays are also called "Gamma" (large greek character). I have no objection calling it "Gamma_1". But I believe I had called it "Gamma" before Hal said that for 3He cell neutron polarization its commonly "T_1". That may be a group decision here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hal recommends changing the Transmission from "T" to "Tr" instead, and leaving "T_1" as it is. Fine with me

@astellhorn
Copy link
Collaborator Author

have let check run using pre-commit, but after it still complained about "Tung" to be changed to "tongue" (see Wai Tung Lees paper reference), I have used commit -n -m to commit it anyhow. How can I go around such an error message in a better way?

"O(\\lambda)=n\\cdot \\sigma_0\\cdot l \\cdot\\lambda\n",
"$$\n",
"\n",
"with n being the number density of <sup>3</sup>He gas in the cell, $\\sigma_0$ the absorption cross section of 1 $\\mathring A$ neutrons by <sup>3</sup>He ($\\sigma_0 = 2966 \\cdot 10^{−24} cm^2$), and the path length through the cell $l$ [Ref. 1]. As <sup>3</sup>He can be considered to follow the ideal gas law, $n$ can be replaced via $p=n\\cdot k_B\\cdot T$:\n",
Copy link
Member

Choose a reason for hiding this comment

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

Do we have an error bar for the 2966? Then we could include it in the propagation of uncertainties.

@SimonHeybrock
Copy link
Member

have let check run using pre-commit, but after it still complained about "Tung" to be changed to "tongue" (see Wai Tung Lees paper reference), I have used commit -n -m to commit it anyhow. How can I go around such an error message in a better way?

I added it to the spell checker's ignore list for you. Run git pull to update your local branch.

@SimonHeybrock SimonHeybrock merged commit 648383b into main Jan 31, 2024
@SimonHeybrock SimonHeybrock deleted the astellhorn-patch-2 branch January 31, 2024 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants