diff --git a/docs/user_docs/conf.py b/docs/user_docs/conf.py index 9c12860..e44b78b 100644 --- a/docs/user_docs/conf.py +++ b/docs/user_docs/conf.py @@ -18,7 +18,7 @@ # -- Project information ----------------------------------------------------- project = 'PACE' -copyright = "2021 PACE Authors" +copyright = "2021-2026 PACE Authors" author = ['A. Buts','T.G. Perring','N. Battam','H. Saunders','M.D. Le','C. Marooney','J. Wilkins', 'R.A. Ewings', 'J. van Duijn', 'I. Bustinduy', 'G. Tucker', 'R. Fair','A. Jackson', 'S. Ward', 'S. Toth'] author = ', '.join(sorted(author, key = lambda x: x.split()[-1])) # Authors by surname diff --git a/docs/user_docs/examples.rst b/docs/user_docs/examples.rst index 5f92cad..8580ecb 100644 --- a/docs/user_docs/examples.rst +++ b/docs/user_docs/examples.rst @@ -19,34 +19,32 @@ You can obtain a zip of this repository The follow examples will use the data contained in this repository. +More examples can be found in the course materials for a `recent training course `__ +particularly the IPython notebooks in the ``solutions`` folder. -Starting ``pace_neutrons`` --------------------------- -There are three options to start ``pace_neutrons``: - -* ``pace_neutrons`` - starts with an IPython console +Initialisation +-------------- -* ``pace_neutrons -s`` or ``pace_neutrons --spyder`` - starts with the `Spyder IDE `__ +``pace_neutrons`` is compatible with both jupyter notebooks and the Spyder IDE. +If you prefer to use either of you can start these as usual, +or just start python normally to use the standard Python console. +We recommend to use jupyter notebooks. -* ``pace_neutrons -j`` or ``pace_neutrons --jupyter`` - starts a Jupyter Notebook server. +.. code-block:: sh -(The option to start with ``spyder`` or ``jupyter`` only work if you have already installed Spyder or Jupyter). + jupyter notebook -The following examples will work with all modes. -Note that for the Jupyter notebooks, by default figures are rendered in the notebook as images (``inline`` mode). -If you are running the Jupyter server on a local machine, and want to have the actual plot windows, +Note that for Jupyter notebooks, by default figures are rendered in the notebook as images (``inline`` mode). +If you are running the Jupyter server on a local machine, and want to have the interactive plot windows, please run the following in a Notebook cell before making any plots: .. code-block:: python - %pace windowed + %matlab_plot_mode windowed -Initialisation --------------- - After starting ``pace_neutrons`` but defore running any of the Matlab derived programs (``horace`` and ``spinw``), we must initialise the Matlab interpreter using: @@ -66,14 +64,33 @@ but there are a few differences you should bear in mind: * Matlab functions like ``diag`` must be preceded by ``m.`` and array elements needs ``,`` comma separators. * Array indexing uses square brackets ``[]`` instead of round brackets ``()`` and are indexed from zero. * ``.T`` is used for transposed in ``numpy`` instead of the ``'`` operator. -* Keyword arguments for *Matlab functions* must be speficied as pairs ``'arg_name', arg_val`` - in the old-style Matlab fashion rather than in Python style ``arg_name=arg_val``. For vectors and arrays, ``pace_neutrons`` will try to convert lists of numeric values into Matlab arrays automatically. It will convert non-numeric or mixed lists into Matlab cell arrays, so you should not use the braces ``{}`` constructor for this (this is used for a Python dictionary which is converted to a Matlab structure). +Multi-dimensional arrays are constructed as nested list in the Python manner, e.g. + +.. code-block:: python + + m.sum([[8, 1, 6], [3, 5, 7], [4, 9, 2]]) + + +Will yield ``15 15 15`` summing over the columns of the :math:`3 \times 3` magic square. + +If you need to specify a Matlab cell arrays of numeric values, arrays or vectors, +(such as required by the ``multifit`` class in Horace in order to pass extra parameters to a model function) +you should use a Python tuple, e.g. + +.. code-block:: python + + mf.set_fun(my_function, ([fitpar1, fitpar2], [nonfitpar1, nonfitpar2])) + +where the argument is equivalent to the Matlab syntax: ``{[fitpar1 fitpar2] [nonfitpar1 nonfitpar2]}``. +If you used ``[[fitpar1, fitpar2], [nonfitpar1, nonfitpar2]]`` in Python, ``pace_neutrons`` +will convert this into :math:`2 \times 2` array, but the rounded brackets (a tuple constructor operator) +tells it to treat the variable as a Matlab cell array. Using Horace to look at INS data @@ -158,14 +175,14 @@ We can now plot a dispersion and INS spectrum along high symmetry directions: .. code-block:: - Qlist = [[3/4, 1/4, 1], [1/2, 1/2, 1], [1/2, 0, 1], [3/4, 1/4, 1], \ - [1, 0, 1], [1/2, 0, 1], 100] - Qlab = ['P', 'M', 'X', 'P', '\Gamma', 'X']; + Qlist = ([3/4, 1/4, 1], [1/2, 1/2, 1], [1/2, 0, 1], [3/4, 1/4, 1], \ + [1, 0, 1], [1/2, 0, 1], 100) + Qlab = ('P', 'M', 'X', 'P', '\Gamma', 'X') feSpec = fe.spinwave(Qlist,'hermit',False) feSpec = m.sw_egrid(m.sw_neutron(feSpec), 'component', 'Sperp'); m.figure() - m.sw_plotspec(feSpec, 'dE', 30, 'qlabel', Qlab) + m.sw_plotspec(feSpec, 'dE', 0.3, 'qlabel', Qlab) m.legend('off') .. image:: images/example_spinw_fe_disp.png @@ -333,26 +350,36 @@ defining the instrument and experimental parameters on the workspace and then re .. code-block:: python - # Set up instrument and experiment parameters - xgeom = [0,0,1]; ygeom = [0,1,0]; shape = 'cuboid'; shape_pars = [0.01,0.05,0.01]; - w_fe = m.set_sample(w_fe, m.IX_sample(xgeom, ygeom, shape, shape_pars)); - ei = 70; freq = 250; chopper = 's'; - w_fe = m.set_instrument(w_fe, m.maps_instrument(ei, freq, chopper)); - - # Set up resolution convolution model - gam = 0.1 # set intrinsic width to minimum - kk = m.multifit_sqw(w_fe) - kk = kk.set_fun (py_fe_sqw, [J, D, gam, temp, amp]) - kk = kk.set_free ([1, 0, 1, 0, 1]) - kk = kk.set_bfun (linear_bg, [0.3,0]) - kk = kk.set_bfree ([1,0]) + # Define sample parameters + xgeom = [0,0,1] + ygeom = [0,1,0] + shape = 'cuboid' + shape_pars = [0.01,0.05,0.01] + + # Define instrument parameters + ei = 400 # Incident energy in meV + freq = 600 # Chopper frequency in Hz + chop = 's' # Chopper rotor identifier (ask instrument scientist) + + # Sets the sample and instrument on the workspace + w_fe = w_fe.set_sample(m.IX_sample(xgeom, ygeom, shape, shape_pars)) + w_fe = w_fe.set_instrument(m.maps_instrument(ei, freq, chop)) + + tbfobj = m.tobyfit(w_fe) + tbfobj = tbfobj.set_fun(py_fe_sqw, [J, D, gam, temp, amp]) + tbfobj = tbfobj.set_bfun(linear_bg, [0.3, 0]) + w_tbf = tbfobj.simulate() + + m.acolor('black') + m.plot(my_cuts[0]) + m.acolor('red') + m.pl(w_tbf) + m.acolor('blue') + m.pl(w_cal) - # Calculate the model spectrum - w_res = kk.simulate() - # Plots the data and model together - m.plot(w_fe) - m.pl(w_res) +.. image:: images/example_tobyfit.png + :width: 500px Modelling Horace data with SpinW or Euphonic @@ -369,13 +396,13 @@ so can be used directly. # Constant parameters for SpinW model # Note that we use the damped harmonic oscillator resolution model ('sho') - cpars = ['mat', ['J1', 'D(3,3)'], 'hermit', False, 'optmem', 1, - 'useFast', True, 'resfun', 'sho', 'formfact', True]; + cpars = ('mat', ['J1', 'D(3,3)'], 'hermit', False, 'optmem', 1, + 'useFast', True, 'resfun', 'sho', 'formfact', True); kk = m.multifit_sqw(w_fe) # The spinw object "fe" is previous defined above # We need to pass the "horace_sqw" method of the "fe" object: - kk = kk.set_fun (fe.horace_sqw, [[J, D, gam, temp, amp]]+cpars) + kk = kk.set_fun (fe.horace_sqw, ([J, D, gam, temp, amp], *cpars)) kk = kk.set_free ([1, 0, 1, 0, 1]); kk = kk.set_bfun (linear_bg, [0.1,0]); kk = kk.set_bfree ([1,0]); @@ -392,6 +419,10 @@ so can be used directly. m.pl(wsim['fore']) +.. image:: images/example_horace_spinw.png + :width: 500px + + For Euphonic, the gateway function is ``horace_disp`` and returns two cell arrays :math:`E_n(\mathbf{Q}), S_n(\mathbf{Q})`, so must be wrapped in another function ``disp2sqw`` first. In addition, ``horace_disp`` is a method of a helper class ``CoherentCrystal`` @@ -422,3 +453,7 @@ from the ``euphonic_sqw_models`` module which should be constructed from the ``F hf = m.plot(wsc); m.pl(wsim) +.. image:: images/example_horace_euphonic.png + :width: 500px + + diff --git a/docs/user_docs/images/example_horace_euphonic.png b/docs/user_docs/images/example_horace_euphonic.png new file mode 100644 index 0000000..28bd419 Binary files /dev/null and b/docs/user_docs/images/example_horace_euphonic.png differ diff --git a/docs/user_docs/images/example_horace_spinw.png b/docs/user_docs/images/example_horace_spinw.png new file mode 100644 index 0000000..3617df3 Binary files /dev/null and b/docs/user_docs/images/example_horace_spinw.png differ diff --git a/docs/user_docs/images/example_pyfun_spectrum.png b/docs/user_docs/images/example_pyfun_spectrum.png index 0cd479e..000ed11 100644 Binary files a/docs/user_docs/images/example_pyfun_spectrum.png and b/docs/user_docs/images/example_pyfun_spectrum.png differ diff --git a/docs/user_docs/images/example_tobyfit.png b/docs/user_docs/images/example_tobyfit.png new file mode 100644 index 0000000..5c2bc3b Binary files /dev/null and b/docs/user_docs/images/example_tobyfit.png differ diff --git a/docs/user_docs/installation.rst b/docs/user_docs/installation.rst index f85c631..0134ea8 100644 --- a/docs/user_docs/installation.rst +++ b/docs/user_docs/installation.rst @@ -8,79 +8,45 @@ Installation ``pace_neutrons`` is available on the Python Package Index `(PyPI) `__, and can in principle be installed with any (CPython) distributions. -However, due to :ref:`restrictions ` detailed below we recommend that you use the -`conda `__ system. -You can install a minimal conda system using `miniconda `__. -Once you have installed ``conda``, run it and type: +We highly recommend to use an isolated Python virtual environment rather than to install ``pace_neutrons`` +into a common Python environment with your other software - in particular, ``pace_neutrons`` is currently +not compatible with Mantid due to clashing library dependencies. -.. code-block:: sh - - conda create -n pace python=3.7 - conda activate pace - pip install pace_neutrons spyder jupyter - -Alternatively, you can download and run one of the installers from the -`github page `__ -(either for `Windows `__ -or `Linux `__). - -The installer will first install the Matlab Compiler Runtime (MCR) needed by ``pace_neutrons``, -and install a small GUI application called ``Pace Neutrons Installer``, -which you should then run to install a conda environment and the ``pace_neutrons`` package. - - -Matlab Compiler Runtime ------------------------ - -``pace_neutrons`` relies on the Matlab Compiler Runtime (MCR). -If you did not use the installer, then the MCR also needs to be installed. -When you first run ``pace_neutrons`` after installing it using ``pip``, -and the program detects that the MCR has not been installed, -it will prompt you to ask if you want to install it (and to accept the MCR license). -Note that you do not need a full Matlab license to install the MCR or to run ``pace_neutrons``. - -Alternatively, if you have the MCR or a full version of Matlab with the Compiler SDK toolbox -(but note that ``pace_neutrons`` specifically needs R2020a on Linux and R2020b on Windows) -installed but in a non-standard location, you can tell ``pace_neutrons`` this using: +If you use the conda/mamba system, one way to install is: .. code-block:: sh - pace_neutrons -d - - -This location will be cached for future use, so you do not need to specify it again. + conda create -n pace python=3.11 + conda activate pace + python -m pip install pace_neutrons jupyter -You can also tell the program to install the MCR manually using: +Where you can replace ``conda`` with ``mamba`` if you use the later. +Alternatively, you can use the ``venv`` package: .. code-block:: sh - pace_neutrons --install-mcr + python -m venv /path/to/where/you/want/pace + /path/to/where/you/want/pace/env/Scripts/activate + python -m pip install pace_neutrons jupyter +We currently support Python 3.8 to 3.13. -In this case it will assume that you consent to the MCR license and will not prompt. +Matlab Compiler Runtime +----------------------- -Restrictions ------------- - -Because of the dependence on the MCR, which bundles its own version of many common libraries, -``pace_neutrons`` has a number of restrictions: - -* On Linux, only Python 3.6 and 3.7 are supported, requiring Matlab 2020a. - This is to be compatible with the IDAaaS system. -* On Windows, only Python 3.7 and 3.8 are supported, requiring Matlab 2020b. - This is to support the most common versions of Python in the Windows app store. -* At present, Mac OS is not supported. -* ``pace_neutrons`` is not compatible with Mantid Workbench. - This is because of incompatibilities between the versions of the Qt and HDF5 libraries - bundled by the MCR and those which Mantid is compiled with. +``pace_neutrons`` relies on the Matlab Compiler Runtime (MCR), which needs to be installed separately. +You can find versions at `the Mathworks page `__. +We currently support Matlab versions from R2021b to R2024b (R2025a and R2025b are currently not supported). -We are working to remove some of these restrictions. +Alternatively you can download an older installer for `Linux `__ or `Windows `__ +which will install a stripped down version of the R2021b MCR and a small GUI application to create +a conda environment and install ``pace_neutrons``. +This approach is no longer supported, but the MCR installed by the installer will still work and require +a smaller download than the full MCR from the `official Mathworks webpage `__. -In addition, to avoid incompatiblities with system libraries or those of other Python modules, -we recommend that you install ``pace_neutrons`` in a Python virtual environment such as -`venv `__/`virtualenv `__ -or `conda `__. +Finally, ``pace_neutrons`` will also work if you have a full (licensed) version of Matlab, as long as +the Compiler SDK toolbox is installed. Parallization @@ -114,13 +80,13 @@ on certain versions of the IDAaaS system.) IDAaaS Installation ------------------- -An installation of ``pace_neutrons`` is available on the `IDAaaS `__ system. +An installation of ``pace_neutrons`` is available on the `Ada `__ system. To run it, open a terminal and type: .. code-block:: sh - /mnt/nomachine/isis_direct_soft/pace_neutrons --spyder + /mnt/ceph/auxiliary/excitations/pace_neutrons Note that because the distribution is stored on a CEPH shared network drive, -there may be a delay of ~15-30s the first time it is run whilst the data is retrieved and cached. +there may be a delay of ~10s the first time it is run whilst the data is retrieved and cached. Subsequent start-up time should be faster.