| 1 | = Status report on inclusion of SESANS data analysis in SASVIEW during Sasview Code Camp III (February 2015) = |
| 2 | Jurrian Bakker (j.h.bakker@tudelft.nl), Wim Bouwman (w.g.bouwman@tudelft.nl) |
| 3 | |
| 4 | April 10, 2015 |
| 5 | |
| 6 | == 1. The aim of the code camp == |
| 7 | |
| 8 | The aim of this work package is to add the ability to analyse SESANS data using |
| 9 | !SasView. !SasView is a software package designed to analyze scattering data by |
| 10 | graphical visualization and model fitting in reciprocal (Fourier) space. We will |
| 11 | extend this ability by allowing fitting in real space using Hankel transformation |
| 12 | of existing SANS models and direct programming of real space scattering |
| 13 | models. |
| 14 | |
| 15 | The long-term goal is to enable co-analysis of SANS and SESANS data. |
| 16 | SESANS can be used to increase the accuracy of low-Q data in a SANS experiment; |
| 17 | conversely, SANS data can be used to decrease experimental error at |
| 18 | low length scales in a SESANS experiment. If structural models could be fitted |
| 19 | in both real space and Fourier space simultaneously, SANS and SESANS data |
| 20 | would provide structural information at complementary length scales. |
| 21 | The work was divided into several stages: |
| 22 | |
| 23 | 1. Definition of data format (Section 2). |
| 24 | 2. Enable dataloader package to read SESANS data and represent it in a suitable structure. |
| 25 | 3. Wrap SANS models into a SESANS data analysis wrapper to calculate the projected correlation functions numerically from model parameters. |
| 26 | 4. Combine the dataloader and SESANS data analysis wrapper with BUMPS in fitting scripts. |
| 27 | 5. Enable fitting of SESANS data through !SasView GUI |
| 28 | |
| 29 | The first four tasks have been completed to some extent: a data format is |
| 30 | proposed and a dataloader was created for this format (Section 2). Further |
| 31 | scripts will need to be written to convert instrument output data into this data |
| 32 | format. SESANS wrapper is able to combine with BUMPS to fit SESANS data |
| 33 | read in by the dataloader with some tweaks (Section 6). It was decided that |
| 34 | inclusion of SESANS analysis into the Sasview GUI would be too early at this |
| 35 | stage, since the Sasview GUI will undergo heavy rewriting to clean up the code |
| 36 | and create a more user-friendly interface. |
| 37 | |
| 38 | So in conclusion: we have now the possibility to use the models available in |
| 39 | sasmodels to analyse SESANS-measurements in the command line in a developers |
| 40 | environment. It is good for the experts, but not yet for users. |
| 41 | |
| 42 | == 2. Data format == |
| 43 | |
| 44 | The current file extension is .ses or .sesans (not case sensitive). |
| 45 | Our preliminary suggestion for the file format is to have a list of name-value |
| 46 | pairs as a header at the top of the file, detailing general experimental parameters |
| 47 | necessary for fitting and analyzing data. This list should contain all information |
| 48 | necessary for the file to be ’portable’ between users. |
| 49 | |
| 50 | Following that is a 6 column list of instrument experimental variables: |
| 51 | |
| 52 | * Spin echo length (δ, in Angstroms) |
| 53 | * Spin echo length error (∆δ, in Angstroms) (experimental resolution) |
| 54 | * neutron wavelength (λ, in Angstroms) (essential for ToF instruments) |
| 55 | * neutron wavelength error (∆λ, in Angstroms) |
| 56 | * Normalized polarization (P/P0, unitless) |
| 57 | * Normalized polarization error (∆(P/P0), unitless) (measurement error) |
| 58 | |
| 59 | The neutron wavelength appears in both scattering power (Σ) and spin echo |
| 60 | length (δ), making data analysis more complicated for Time-of-Flight SESANS |
| 61 | than for Monochromatic SESANS. |
| 62 | |
| 63 | Σ = λ^2^t(∆ρ0)^2^φ(1 − φ)ξ (1) |
| 64 | |
| 65 | δ = cλ^2^BL/(2π tan (θ0)) (2) |
| 66 | |
| 67 | After discussion with partners (DUT/ISIS/ESS/ORNL, etc.), we might add |
| 68 | more items to the header. Extending the header will not be a problem, since |
| 69 | the dataloader has been written to allow for a 2-column header of arbitrary |
| 70 | length. |
| 71 | |
| 72 | === 2.1 Example Data File === |
| 73 | |
| 74 | At the moment, the data file is a tab-separated text file. Using tab as a separator |
| 75 | elegantly avoids problems with whitespaces and special characters when parsing |
| 76 | the data (keeps the dataloader code short, simple and flexible). |
| 77 | |
| 78 | DataFileTitle Polystyrene of Markus Strobl, Full Sine, ++ only |
| 79 | |
| 80 | Sample Polystyrene 2 um in 53% H2O, 47% D2O |
| 81 | |
| 82 | Settings D1=D2=20x8 mm,Ds = 16x10 mm (WxH), GF1 =scanning, GF2 = 2.5 A. 2 um polystyrene in 53% H2O, 47% D2O; 8.55% contrast |
| 83 | |
| 84 | Operator CPD |
| 85 | |
| 86 | Date ma 7 jul 2014 18:54:43 |
| 87 | |
| 88 | ScanType sine one element scan |
| 89 | |
| 90 | Thickness [mm] 2 |
| 91 | |
| 92 | Q_zmax [\AA^-1] 0.05 |
| 93 | |
| 94 | Q_ymax [\AA^-1] 0.05 |
| 95 | |
| 96 | spin echo length [nm] error SEL wavelength [nm] error wavelength polarisation error pol |
| 97 | |
| 98 | 49.778 2.4889 0.211 0.01055 0.99782 0.0044367 |
| 99 | |
| 100 | 63.041 3.152 0.211 0.01055 1.0026 0.0047862 |
| 101 | |
| 102 | 76.487 3.8244 0.211 0.01055 0.99601 0.0060598 |
| 103 | |
| 104 | 89.847 4.4924 0.211 0.01055 0.99175 0.0058257 |
| 105 | |
| 106 | 103.41 5.1705 0.211 0.01055 0.99543 0.0060966 |
| 107 | |
| 108 | 116.95 5.8475 0.211 0.01055 0.99512 0.0048106 |
| 109 | |
| 110 | etc.... |
| 111 | |
| 112 | == 3. Dataloader == |
| 113 | |
| 114 | The data loader uses the data file and parses it for use in Sasview (plotting |
| 115 | only for now) and loading into BUMPS (for data fitting). Future changes to |
| 116 | the Sasview source code should have minimal or no impact on the code of the |
| 117 | dataloader. |
| 118 | |
| 119 | One new file was created in the Sasview source code to load in data: |
| 120 | |
| 121 | * [https://github.com/SasView/sasview/blob/master/src/sas/sascalc/dataloader/readers/sesans_reader.py sesans_reader.py]:: |
| 122 | The code for this file has been added to this document in Appendix 7 |
| 123 | |
| 124 | Three existing files of the source code were modified: |
| 125 | |
| 126 | * [https://github.com/SasView/sasview/blob/master/src/sas/sascalc/dataloader/data_info.py data_info.py]:: |
| 127 | added the SESANSData1D class to handle SESANS data as opposed to Data1D or Data2D for SANS/SAXS data. Added the plottable sesans1D class to handle SESANS plots. |
| 128 | |
| 129 | * [https://github.com/SasView/sasview/blob/master/src/sas/sascalc/dataloader/readers/associations.py associations.py]:: |
| 130 | added sesans reader to the registry to allow use in Sasview. |
| 131 | |
| 132 | * [https://github.com/SasView/sasview/blob/master/src/sas/sascalc/dataloader/readers/defaults.json defaults.json]:: |
| 133 | added default file extension .ses to allow automatic detection of SESANS data files; this is not yet working as intended. |
| 134 | |
| 135 | == 4. Wrapper from SAS model to SESANS in absolute units == |
| 136 | |
| 137 | The conversion from SANS into SESANS in absolute units is a simple Hankel |
| 138 | transformation when all the small-angle scattered neutrons are detected. First |
| 139 | we calculate the Hankel transform including the absolute intensities by |
| 140 | {{{ |
| 141 | #!html |
| 142 | <math>Ge(δ) = 2π ∫_0_&infinity; J0(Qδ)*dΣ/dΩ(Q)*QdQ</math>, (3) |
| 143 | }}} |
| 144 | |
| 145 | in which J0 is the zeroth order Bessel function, δ the spin-echo length, Q the |
| 146 | wave vector transfer and dΣ/dΩ(Q) the scattering cross section in absolute units. |
| 147 | This is a 1-dimensional integral, which can be rather fast. In the numerical |
| 148 | calculation we integrate from Qmin = 0.1 × 2π/Rmax in which Rmax will be |
| 149 | model dependent. We determined the factor 0.1 by varying its value until the |
| 150 | value of the integral was stable. This happened at a value of 0.3. The have a |
| 151 | safety margin of a factor of three we have choosen the value 0.1. For the solid |
| 152 | sphere we took 3 times the radius for Rmax. The real integration is performed to |
| 153 | Qmax which is an instrumental parameter that is read in from the measurement |
| 154 | file. From 3 we can calculate the polarisation that we measure in a SESANS |
| 155 | experiment: |
| 156 | |
| 157 | P(δ) = e^t(λπ )^2^(Ge(δ)−Ge(0)), (4) |
| 158 | |
| 159 | in which t is the thickness of the sample and λ is the wavelength of the neutrons. |
| 160 | For collimation by a supermirror analyser the Qmax will be fixed. |
| 161 | |
| 162 | Two new files were created for fitting the SESANS data: |
| 163 | |
| 164 | [https://github.com/SasView/sasmodels/blob/master/example/sesansfit.py sesansfit.py]:: |
| 165 | The file containing the fit model and parameter boundaries to be used in the fitting |
| 166 | |
| 167 | [https://github.com/SasView/sasmodels/blob/master/sasmodels/sesans.py sesans.py]:: |
| 168 | The file containing the Hankel transform |
| 169 | |
| 170 | == 5. Combination of dataloader with wrapper to fit in command line with bumps == |
| 171 | |
| 172 | Install the sasview and sasmodels source code (description in Section 6 Make |
| 173 | sure you have a Git Bash prompt open and that your path is in the sasmodels |
| 174 | folder. |
| 175 | |
| 176 | Now it’s time to use BUMPS for SESANS fitting: Place the .ses (or .sesans) |
| 177 | file that you wish to fit into the ’sasmodels/example/’ folder and enter the |
| 178 | following into the command-line: |
| 179 | |
| 180 | ./bumps.sh example/sesansfit.py --preview (for a quick preview of the fit) (something should appear on your screen if the installation was successful) |
| 181 | |
| 182 | Figure 1: a window showing a plot of SESANS data in the current version of Sasview |
| 183 | |
| 184 | ./bumps.sh example/sesansfit.py --edit (for interactive GUI mode). |
| 185 | |
| 186 | ./bumps.sh example/sesansfit.py --fit=amoeba -edit (a very good fitting algorithm). |
| 187 | |
| 188 | Note that you can also call up a help menu using the -help option, we give |
| 189 | no guarantees that any of the options given by help, other than those listed |
| 190 | above, will work though: BUMPS is still a work in progress. Best of luck with |
| 191 | your SESANS fitting! |
| 192 | |
| 193 | == Appendix 1: Installation Guide == |
| 194 | |
| 195 | For the moment, Sasview, and with it, the SESANS fitting module can only be |
| 196 | used on Windows operating systems. Firstly, follow the [AnacondaSetup]. Be sure |
| 197 | to create a Github account if you have none. After completing the installation |
| 198 | of sasview, perform the following steps: |
| 199 | |
| 200 | Clone the sasmodels package from github by entering the following into the |
| 201 | command-line: |
| 202 | |
| 203 | git clone !https://github.com/Sasview/sasmodels.git sasmodels |
| 204 | |
| 205 | Download Intel Opencl drivers from: [https://software.intel.com/en-us/articles/opencldrivers#win64] |
| 206 | and install it (this is to make the BUMPS package work). |
| 207 | |
| 208 | From [http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyopencl], Download pyopencl- |
| 209 | 2015.1-cp27-none-win32.whl Enter the following into the command-line: |
| 210 | |
| 211 | pip install pyopencl- 2015.1-cp27-none-win32.whl (make sure to be in the correct directrory, otherwise you need to enter the entire path to it). |
| 212 | |
| 213 | For the moment, you will need to perform a small hack of Anaconda. You |
| 214 | need to modify [Anaconda directory]/Lib/site-packages/bumps/gui/fit_thread.py, |
| 215 | line 153: Change line to If False to turn off multi-core support (There is no |
| 216 | multi-core support in the current implementation) |
| 217 | |
| 218 | In Git Bash (Unix prompt from Git, comes with the Git installation) , |
| 219 | navigate to sasmodels folder. |
| 220 | |
| 221 | Create file bumps.sh in the sasmodels main directory (easiest method is to open |
| 222 | compare.sh and adjust the appropriate lines, then save as bumps.sh)) to easily |
| 223 | use BUMPS fitting system (this is simply a text file). |
| 224 | |
| 225 | Contents are: |
| 226 | |
| 227 | {{{ |
| 228 | #!/bin/sh |
| 229 | |
| 230 | SASVIEW=$PWD/../sasview-code/src |
| 231 | PYTHONPATH=$PWD:$PWD/../bumps:$PWD/../periodictable:$SASVIEW |
| 232 | export PYOPENCL_CTX PYTHONPATH |
| 233 | |
| 234 | echo PYTHONPATH=$PYTHONPATH |
| 235 | set -x |
| 236 | |
| 237 | python -m bumps.cli $* |
| 238 | }}} |
| 239 | |
| 240 | |
| 241 | == Acknowledgements == |
| 242 | |
| 243 | We would like to thank everybody of the SASVIEW team for their patient help |
| 244 | with introducing us to this great project. This report is the product of a very |
| 245 | intensive collaboration during the code camp 2015 in Copenhagen. |