Changes between Initial Version and Version 1 of DevNotes/Projects/sesans/SESANSCodeCampIIIStatusReport


Ignore:
Timestamp:
Mar 15, 2016 1:33:47 PM (9 years ago)
Author:
krzywon
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • DevNotes/Projects/sesans/SESANSCodeCampIIIStatusReport

    v1 v1  
     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 
     8The 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 
     10graphical visualization and model fitting in reciprocal (Fourier) space. We will 
     11extend this ability by allowing fitting in real space using Hankel transformation 
     12of existing SANS models and direct programming of real space scattering 
     13models. 
     14 
     15The long-term goal is to enable co-analysis of SANS and SESANS data. 
     16SESANS can be used to increase the accuracy of low-Q data in a SANS experiment; 
     17conversely, SANS data can be used to decrease experimental error at 
     18low length scales in a SESANS experiment. If structural models could be fitted 
     19in both real space and Fourier space simultaneously, SANS and SESANS data 
     20would provide structural information at complementary length scales. 
     21The work was divided into several stages: 
     22 
     231. Definition of data format (Section 2). 
     242. Enable dataloader package to read SESANS data and represent it in a suitable structure. 
     253. Wrap SANS models into a SESANS data analysis wrapper to calculate the projected correlation functions numerically from model parameters. 
     264. Combine the dataloader and SESANS data analysis wrapper with BUMPS in fitting scripts. 
     275. Enable fitting of SESANS data through !SasView GUI 
     28 
     29The first four tasks have been completed to some extent: a data format is 
     30proposed and a dataloader was created for this format (Section 2). Further 
     31scripts will need to be written to convert instrument output data into this data 
     32format. SESANS wrapper is able to combine with BUMPS to fit SESANS data 
     33read in by the dataloader with some tweaks (Section 6). It was decided that 
     34inclusion of SESANS analysis into the Sasview GUI would be too early at this 
     35stage, since the Sasview GUI will undergo heavy rewriting to clean up the code 
     36and create a more user-friendly interface. 
     37 
     38So in conclusion: we have now the possibility to use the models available in 
     39sasmodels to analyse SESANS-measurements in the command line in a developers 
     40environment. It is good for the experts, but not yet for users. 
     41 
     42== 2. Data format == 
     43 
     44The current file extension is .ses or .sesans (not case sensitive). 
     45Our preliminary suggestion for the file format is to have a list of name-value 
     46pairs as a header at the top of the file, detailing general experimental parameters 
     47necessary for fitting and analyzing data. This list should contain all information 
     48necessary for the file to be ’portable’ between users. 
     49 
     50Following 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 
     59The neutron wavelength appears in both scattering power (Σ) and spin echo 
     60length (δ), making data analysis more complicated for Time-of-Flight SESANS 
     61than for Monochromatic SESANS. 
     62 
     63  Σ = λ^2^t(∆ρ0)^2^φ(1 − φ)ξ  (1) 
     64 
     65  δ = cλ^2^BL/(2π tan (θ0))  (2) 
     66 
     67After discussion with partners (DUT/ISIS/ESS/ORNL, etc.), we might add 
     68more items to the header. Extending the header will not be a problem, since 
     69the dataloader has been written to allow for a 2-column header of arbitrary 
     70length. 
     71 
     72=== 2.1 Example Data File === 
     73 
     74At the moment, the data file is a tab-separated text file. Using tab as a separator 
     75elegantly avoids problems with whitespaces and special characters when parsing 
     76the 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 
     114The data loader uses the data file and parses it for use in Sasview (plotting 
     115only for now) and loading into BUMPS (for data fitting). Future changes to 
     116the Sasview source code should have minimal or no impact on the code of the 
     117dataloader. 
     118 
     119One 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 
     124Three 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 
     137The conversion from SANS into SESANS in absolute units is a simple Hankel 
     138transformation when all the small-angle scattered neutrons are detected. First 
     139we calculate the Hankel transform including the absolute intensities by 
     140{{{ 
     141#!html 
     142<math>Ge(δ) = 2π &int;_0_&infinity; J0(Qδ)*dΣ/dΩ(Q)*QdQ</math>, (3) 
     143}}} 
     144 
     145in which J0 is the zeroth order Bessel function, δ the spin-echo length, Q the 
     146wave vector transfer and dΣ/dΩ(Q) the scattering cross section in absolute units. 
     147This is a 1-dimensional integral, which can be rather fast. In the numerical 
     148calculation we integrate from Qmin = 0.1 × 2π/Rmax in which Rmax will be 
     149model dependent. We determined the factor 0.1 by varying its value until the 
     150value of the integral was stable. This happened at a value of 0.3. The have a 
     151safety margin of a factor of three we have choosen the value 0.1. For the solid 
     152sphere we took 3 times the radius for Rmax. The real integration is performed to 
     153Qmax which is an instrumental parameter that is read in from the measurement 
     154file. From 3 we can calculate the polarisation that we measure in a SESANS 
     155experiment: 
     156 
     157  P(δ) = e^t(λπ )^2^(Ge(δ)−Ge(0)), (4) 
     158 
     159in which t is the thickness of the sample and λ is the wavelength of the neutrons. 
     160For collimation by a supermirror analyser the Qmax will be fixed. 
     161 
     162Two 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 
     172Install the sasview and sasmodels source code (description in Section 6 Make 
     173sure you have a Git Bash prompt open and that your path is in the sasmodels 
     174folder. 
     175 
     176Now it’s time to use BUMPS for SESANS fitting: Place the .ses (or .sesans) 
     177file that you wish to fit into the ’sasmodels/example/’ folder and enter the 
     178following 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 
     182Figure 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 
     188Note that you can also call up a help menu using the -help option, we give 
     189no guarantees that any of the options given by help, other than those listed 
     190above, will work though: BUMPS is still a work in progress. Best of luck with 
     191your SESANS fitting! 
     192 
     193== Appendix 1: Installation Guide == 
     194 
     195For the moment, Sasview, and with it, the SESANS fitting module can only be 
     196used on Windows operating systems. Firstly, follow the [AnacondaSetup]. Be sure 
     197to create a Github account if you have none. After completing the installation 
     198of sasview, perform the following steps: 
     199 
     200Clone the sasmodels package from github by entering the following into the 
     201command-line: 
     202 
     203  git clone !https://github.com/Sasview/sasmodels.git sasmodels 
     204 
     205Download Intel Opencl drivers from: [https://software.intel.com/en-us/articles/opencldrivers#win64] 
     206and install it (this is to make the BUMPS package work). 
     207 
     208From [http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyopencl], Download pyopencl- 
     2092015.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 
     213For the moment, you will need to perform a small hack of Anaconda. You 
     214need to modify [Anaconda directory]/Lib/site-packages/bumps/gui/fit_thread.py, 
     215line 153: Change line to If False to turn off multi-core support (There is no 
     216multi-core support in the current implementation) 
     217 
     218In Git Bash (Unix prompt from Git, comes with the Git installation) , 
     219navigate to sasmodels folder. 
     220 
     221Create file bumps.sh in the sasmodels main directory (easiest method is to open 
     222compare.sh and adjust the appropriate lines, then save as bumps.sh)) to easily 
     223use BUMPS fitting system (this is simply a text file). 
     224 
     225Contents are: 
     226 
     227{{{ 
     228#!/bin/sh 
     229 
     230SASVIEW=$PWD/../sasview-code/src 
     231PYTHONPATH=$PWD:$PWD/../bumps:$PWD/../periodictable:$SASVIEW 
     232export PYOPENCL_CTX PYTHONPATH 
     233 
     234echo PYTHONPATH=$PYTHONPATH 
     235set -x 
     236 
     237python -m bumps.cli $* 
     238}}} 
     239 
     240 
     241== Acknowledgements == 
     242 
     243We would like to thank everybody of the SASVIEW team for their patient help 
     244with introducing us to this great project. This report is the product of a very 
     245intensive collaboration during the code camp 2015 in Copenhagen.