Web API for Sasview

SHIP Student: Ting (Xael) Shan Mentors: Jeff Krzywon, Elizabeth Kelley

WHAT IS SASVIEW? BENEFITS OF AN API FOR SASVIEW USER SIDE

DEVELOPING AN API FROM SCRATCH

NIST Center of Neutron Research is a user facility that uses 

neutron scattering to observe particle elements. One subdivision 

is Small Angle Neutron Scattering (SANS):

Sasview is analysis software that takes the data collected and 

analyzes it into derivable data.

Two category of tools:

• Analysis Tools: Fit, Inversion, Invarient, Corfunc

• Calculation Tools

WHAT IS AN API

An API is an application 

programming interface. It 

acts as a “translator” so 

the user can 

“communicate” with the 

server. The user and server 

do not send the same data 

format, so translation is 

necessary.

• Instrument shoots neutron through 

a sample

• Neutron scatters after collision 

with sample particles and hit 

detector

• Scattering pattern, scattering 

length density, intensity, and more 

elements are measured 

Web Framework: Django

- Modular layout - Pre-included features and tools - Easy to develop frontend

Modularity: Set up for future success. Allow future developers to pick up developing this API easier

Only Backend: the part that is responsible for storing and manipulating data

FUTURE

<File_obj> Data.txt True

Petfinder is an example of a user-friendly API:

Currently, Sasview has a Graphic User Interface (GUI) – allows 

user to interact using icons, buttons, and text. 

The API act parallel to GUI as second way to communicate to the 

server. 

Alleviate 

Resources

Experimental 

benefits

Operating System 

Deployment

Automation! 

The API allows experimenters to 

continuously ask the server to update 

their analysis with code. 

Overcomes Window, Linux, Mac 

Requirements as the computation is being 

done elsewhere.

Analysis tools can take weeks with too 

much data.

Calculations are done remotely, does not 

use user’s GPU/CPU

User user info ->

<- pet info

Animal 

shelter 

servers

NEW APP

models.py -> 

databases

views.py -> functions

Main files

URL 

linking

NEW APP

models.py -> databases

views.py -> functions

Main files

URL 

linking

NEW APP

models.py -> databases

views.py -> functions

Main files

URL 

linking

NEW APP

models.py -> databases

views.py -> functions

Main files

URL 

linking

• Links everything 

together!

• Allows the user to 

get to all functions

path(“”)

re_path(“data/”)

re_path(“analyze/”) path(“info/”)

path(“upload/”)

path(“download/”)

path(“start/”)

path(“models/”)

path(“optimizers/”)

path(“login/”)

path(“get token/”)

Base URLs ->

Spec URLs -

> API 

functions

path(“fit/”)

<File_obj> Data.txt True Inputted data

“is_public” : False

“file”:file_obj

“file_name” : 

“hello.txt”

<File_obj> Hello.txt False

• Database structure

• Define what the user 

inputs

• Make sure user can’t 

put in malicious data

• Translator

• Puts into databases

• Defines how user’s 

data looks

JSON format:

URL data:

SQLite Database format is like a table:

Field: we define

Data: user inputs

RESTFUL 

API

Sasview

Server

DATA SCRIPT

New request

There are multiple ways to be a user. The primarily ones are:

Script

Terminal/Command 

pallet

Development 

Server: API view

This demonstration of the working model is using the 

development server, as it is the most readable

WHAT WILL HAPPEN TO THIS AFTER THIS SUMMER?

This will continue to live as 

an in-progress project for 

Remote fitting interface in 

Sasview GitHub

NEXT STEPS:

WHAT WILL I CONTRIBUTE AFTER?

- Add constraints to Fit

- Implement other analysis 

tools

- Use API to analyze bicelle data

- Get API approved to merge into Sasview package

TRANSLATES

user info ->

<- pet info

COMPUTATION

{ "model":"cylinder",

"data_id":22,

"optimizer":"amoeba",

"parameters" : 

[

{

"name":"radius",

"value":35,

"data_type":"int",

"lower_limit":1,

"upper_limit":50,

"analyze":true,

},

{

"name":"length",

"value":350,

"data_type":"int",

"lower_limit":1,

"upper_limit":500

"analyze":true,

}......}

POST –

Insert Data

GET –

Read Data

No Inputted 

Data

Inputted Data:

- Implement calculation tools

- Wrap and create frontend 

URL

Response:

Response:

URL