Metadata-Version: 2.4
Name: sasview
Version: 6.2.0a1
Summary: SasView application
Project-URL: Homepage, http://sasview.org
Project-URL: Documentation, https://www.sasview.org/docs/
Project-URL: Repository, https://github.com/SasView/sasview/
Project-URL: Issues, https://github.com/SasView/sasview/issues
Project-URL: Changelog, https://github.com/SasView/sasview/releases
Author-email: SasView Team <developers@sasview.org>
License: BSD-3-Clause
License-File: LICENSE.TXT
Keywords: X-ray,data analysis,neutron,scattering,small-angle
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: BSD License
Classifier: Programming Language :: Python
Requires-Python: >=3.12
Requires-Dist: bumps
Requires-Dist: cffi
Requires-Dist: docutils
Requires-Dist: dominate
Requires-Dist: h5py
Requires-Dist: html2text
Requires-Dist: html5lib
Requires-Dist: ipython
Requires-Dist: jsonschema
Requires-Dist: lxml
Requires-Dist: mako
Requires-Dist: matplotlib
Requires-Dist: numba
Requires-Dist: numpy
Requires-Dist: packaging
Requires-Dist: periodictable
Requires-Dist: platformdirs
Requires-Dist: pyausaxs
Requires-Dist: pybind11
Requires-Dist: pylint
Requires-Dist: pyopencl
Requires-Dist: pyopengl
Requires-Dist: pyparsing
Requires-Dist: pyside6
Requires-Dist: pytools
Requires-Dist: pywin32; platform_system == 'Windows'
Requires-Dist: qtconsole
Requires-Dist: requests
Requires-Dist: sasdata
Requires-Dist: sasmodels
Requires-Dist: scipy
Requires-Dist: siphash24
Requires-Dist: superqt
Requires-Dist: tccbox
Requires-Dist: twisted
Requires-Dist: uncertainties
Requires-Dist: xhtml2pdf
Requires-Dist: zope
Provides-Extra: dev
Requires-Dist: build; extra == 'dev'
Requires-Dist: bumps; extra == 'dev'
Requires-Dist: dominate; extra == 'dev'
Requires-Dist: hatch-build-scripts; extra == 'dev'
Requires-Dist: hatch-requirements-txt; extra == 'dev'
Requires-Dist: hatch-sphinx; extra == 'dev'
Requires-Dist: hatch-vcs; extra == 'dev'
Requires-Dist: hatchling; extra == 'dev'
Requires-Dist: html2text; extra == 'dev'
Requires-Dist: numpy; extra == 'dev'
Requires-Dist: periodictable; extra == 'dev'
Requires-Dist: pip-licenses; extra == 'dev'
Requires-Dist: pre-commit; extra == 'dev'
Requires-Dist: pyopengl; extra == 'dev'
Requires-Dist: pyside6; extra == 'dev'
Requires-Dist: qtconsole; extra == 'dev'
Requires-Dist: scipy; extra == 'dev'
Requires-Dist: superqt; extra == 'dev'
Requires-Dist: twisted; extra == 'dev'
Requires-Dist: uncertainties; extra == 'dev'
Provides-Extra: test
Requires-Dist: pytest; extra == 'test'
Requires-Dist: pytest-mock; extra == 'test'
Requires-Dist: pytest-qt; extra == 'test'
Requires-Dist: unittest-xml-reporting; extra == 'test'
Description-Content-Type: text/markdown

![Logo](https://github.com/SasView/sasview.github.io/blob/master/img/sasview_logo.png)

<div align='center'>
    <a href="https://github.com/SasView/sasview/releases/latest"><img src="https://img.shields.io/github/v/release/SasView/sasview" alt="Latest Release" /></a>
    <a href="https://github.com/SasView/sasview/commits/main"><img src="https://img.shields.io/github/last-commit/SasView/sasview" alt="Last Commit" /></a>
    <a href="https://sasview.org"><img src="https://img.shields.io/website-up-down-green-red/http/sasview.org.svg" alt="Website Status" /></a>
    <a href="https://opensource.org/licenses/bsd-3-clause"><img src="https://img.shields.io/badge/License-BSD-brightgreen" alt="License"></a>
</div>

---

# General

[SasView](http://www.sasview.org) is a Small Angle Scattering (SAS) analysis package for the analysis of 1D and 2D scattering data directly in inverse space.
The focus was originally on neutron data (SANS) but has been used for X-rays as well and includes a tool for determining a slit resolution for the SAXSess instrument.
SasView also includes PrView to invert SAS data to P(r), a resolution calculator, and a scattering length density calculator among others tools.
A simple plugin mechanism is available for users to add custom models.

# Citing and Acknowledging SasView

If you found this software useful to your work please cite and/or acknowledge its use in your publications.
The latest instructions for citing and acknowledging are available on our website.

[Citing SasView](http://www.sasview.org/cite/)

# Install instructions

## Users

Users can install SasView either from the installers listed on the [SasView website](http://www.sasview.org),
or directly from the packages distributed by `pip`.

### Install using `pip` inside a virtual environment in the current directory:


```shell
python -m venv .venv # create the environment
. .venv/bin/activate # activate the environment on linux and MacOS
# .venv\Scripts\activate & REM Windows: activate environment

python -m pip install sasview

python -m sas   # launch the gui
```

### Install using `uv` for your user:

```shell
uv tool install sasview

uvx sasview   # launch the gui
```

**Note:** To launch SasView, it needs to be installed.
Running SasView from a source directory is not supported.

## Developers

The installation instructions for developers can be found [here](INSTALL.md).
Installing the development-version of SasView with conda is currently not supported.
`NOTE:` In case you want to contribute, please also checkout the [DevelopersNotes](https://github.com/SasView/sasview/wiki/DevNotes_DevGuide_GettingStarted).

## Getting Started

### Scripting

This section is a small scripting example in SasView to check your installation.
We will fit a simple sphere model. For this first lets synthesize input data.

```python
import numpy as np
from sasmodels.bumps_model import Model
from sasmodels.core import load_model
from sasmodels.direct_model import call_kernel

# define q vector
q = np.logspace(-3, -0.1, 200)

# define the model
exp_model = load_model("sphere")
exp_pars = {
    "radius": 50,
    "sld": 1,
    "sld_solvent": 6,
    "scale": 1,
    "background": 0.001,
}

# calculate intensities
Iq = call_kernel(exp_model.make_kernel([q]), exp_pars)

# calculate errors and normalize data
max_counts = 1e7  # approximate number of counts at first q values
norm = Iq[0] / max_counts
counts = np.random.poisson((Iq / norm).astype(int))
errors = np.sqrt(counts) * norm
data = counts * norm
dataset = np.array([q, data, errors]).T

# saving the data
header = (
    "Neutron-like data generated for model "
    + exp_model.info.name
    + " with parameters:\n"
)
for key in exp_pars.keys():
    header += key + " = " + str(exp_pars[key]) + "\n"
header += "Q\t counts\t error"

np.savetxt("scattering.txt", dataset, fmt="%12.6e", delimiter="\t", header=header)
```

...and now let's do the fitting. We will optimize the scale, radius and background starting from an inital values close to the ground truth.

```python
import matplotlib.pyplot as plt
from sasmodels.bumps_model import Model, Experiment
from sasmodels.core import load_model
from sasmodels.data import load_data
from bumps.fitters import fit
from bumps.names import FitProblem

# defining the  model to fit
fit_pars = {
    "radius": 80,
    "sld": 1,
    "sld_solvent": 6,
    "scale": 0.900,
    "background": 0.05,
}
fit_kernel = load_model("sphere")
fit_model = Model(fit_kernel, **fit_pars)

## setting fitting ranges
fit_model.radius.range(10, 1000)
fit_model.scale.range(1e-3, 10)
fit_model.background.range(1e-9, 0.1)

# load the data we synthesized above
exp_data = load_data("scattering.txt")

# Setup the experiments, sharing the same model across all datasets.
M = Experiment(data=exp_data, model=fit_model, name="MyAwsomeFit")

problem = FitProblem(M)

plt.figure()
problem.plot(view=True)

# fit the results
result = fit(problem, method="dream")

print(f"Final chisq {problem.chisq()}\n")
problem.plot()
for k, v, dv in zip(problem.labels(), result.x, result.dx):
    print(f"{k} : {v:.4f} +- {dv:.4f}")
plt.show()
```

This simple fit should results in a $\chi^2$ close to one.

![image](./simpleexample.png)

# Resources

In case you are just getting started or you want to contribute please checkout some selected [resources](/RESOURCES.md).
