6.53

DEVELOPING AN 

ANALYSIS 

SOFTWARE’S API

EXTENSION

Xael Shan

Poolesville Highschool

Mentor - Jeff Krzywon, Elizabeth Kelley
SASVIEW OVERVIEW

What is SANS?

NCNR is a user facility that uses neutron scattering: Small Angle Neutron Scattering (SANS)

• Shoots neutron through a sample

What is SasView?

SasView is an analysis software that takes the data from SANS:

• Analysis Tools

• Fit

• SasCalc Tools

2
PROJECT OVERVIEW

The Project

Create a website-based application to give more control and 

flexibility to extend Sasview functions

Goals

• Create a working model of a website-based application

• Use application to analyze bicelle data

• Future Publish API

3
4

User/Scientist/Person 

Using the program

Graphic User Interface 

(GUI) Backend

Sasview/Local Computer

Current Layout
5

User Backend

Remote

Proposed Layout

New RESTful API
6

GET –

Read Data

POST –

Insert Data

DELETE –

Delete Data

PUT –

Update/Insert

User Sasview

Server

RESTful 

API

WHAT IS AN API

RESTful Framework Inputs
WHY DO MORE?

7

Accessible Experimental 

benefits

Operating 

System 

Deployment

Non-Equilibrium 

(Structure of Materials) 

Initiative

Automation! 

Overcomes Window, 

Linux, Mac 

Requirements

Alleviate Resources

Why create “another” Sasview
MAKING THE API

8
DJANGO

Modularity!

9

NEW APP

models.py -> databases

views.py -> functions

Main files

URL linking
NEW APP

models.py -> databases

views.py -> functions

Main files

URL 

NEW APP linking

models.py -> databases

views.py -> functions

Main files

URL 

linking

Urls Models.py Views.py

• Links everything together!

• Allows the user to get to 

function

WHAT I IMPLEMENTED

How this was made from scratch

• 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

10

<File_obj> Data.txt True

NEW APP

models.py -> databases

views.py -> functions

Main files

URL 

linking

<File_obj> Data.txt True Inputted data

“is_public” : False

“file”:file_obj

“file_name” : “hello.txt”

<File_obj> Hello.txt False

NEW APP

models.py -> databases

views.py -> functions

Main files

URL 

linking

Website.com/homepage/

Website.com/homepage/login
WHERE ARE WE NOW!

11

1 2 3

Written! The working model

Database

Created!

Views Let’s show it 

working!
MULTIPLE WAYS TO BE A USER

Script

12

Development Server: API view Terminal/Command pallet
13

GET –

Read Data

POST –

Insert Data

DELETE –

Delete Data

PUT –

Update/Insert

User Sasview

Server

RESTFUL 

API

RESTful Framework Inputs

Scientist: 

Jeff 

Krzywon
14
15
16
17
18

GET –

Read Data

POST –

Insert Data

DELETE –

Delete Data

PUT –

Update/Insert

User Sasview

Server

RESTFUL 

API

RESTful Framework Inputs

Scientist: 

Jeff 

Krzywon
19

{

"model":"cylinder",

"data_id":22,

"optimizer":"amoeba",

"parameters" : 

[

{

"name":"radius",

"value":35,

"data_type":"int",

"lower_limit":1,

"upper_limit":50

},

{

"name":"length",

"value":350,

"data_type":"int",

"lower_limit":1,

"upper_limit":500

},

{

"name":"background",

"value":0.0,

"data_type":"float"

},

{

"name":"scale",

"value":1.0,

"data_type":"float"

},

{

"name":"sld",

"value":4.0,

"data_type":"float"

},

{

"name":"sld_solvent",

"value":1.0,

"data_type":"float"

}

]

}

https://github.com/SasView/documents/blob/master/Presentations/LINX

S_2020/LINXS_SasView.pptx
20
THANK YOU

Especially to my mentors and 

other NCNR scientists that 

helped me!

21
FUTURE WORK

- In Sasview repository

- Parallel to the qtGUI

Where is this living

- Any Sasview developer 

Who will pick this back up

- Working with Elizabeth Kelley to reanalyze bicelle data

- New tools

My future work

22
URL PATHING

• Links everything together!

• Allows the user to get to 

function

• Modular

• Add in new paths easy

Ref: Django Rest Framework Versioning

path(“”)

re_path(“data/”)

re_path(“analyze/”)

path(“list/”)

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/”)
SETTING UP 

DATABASES

• Define what the user inputs

• Make sure user can’t put in 

malicious data

Models for Django

Data

24

Data id user file file_name is_public

1 None

2 None

3... None

<File_obj> Data.txt True

NEW APP

models.py -> databases

views.py -> functions

Main files

Url linking
SETTING UP 

DATABASES

• Data – holds imported data for 

users

• Analysis – holds data for analysis 

• Fit – extends analysis, specific data 

for fit

Models for Django

Data AnalysisBase

AnalysisModelBase

AnalysisParameterBase

Fit

FitModel

FitParameter

UserProfile

25

Connected!

Connected! Connected!

Inheritance

Data id user file file_name is_public

1 None

2 None

3... None

<File_obj> Data.txt True

NEW APP

models.py -> databases

views.py -> functions
VIEWS

• Views hold the meat of the code:

• Takes user request <- holds data

• Returns response <- specified by 

function

26

(“data/”)

“upload/”

“download/”

“info/”

NEW APP “list/”

models.py -> databases

views.py -> functions
VIEWS

• Views hold the meat of the code:

• Takes user request <- holds data

• Returns response <- specified by 

function

27

request.user request.data request.FILES

“id” : 1

“username” : “Harry”

“password” : “123?”

“is_logged_in” : True

“is_public” : False

“file_name” : “hello.txt”

Data

“file” : file object

NEW APP

models.py -> databases

views.py -> functions
VIEWS

28

request.user request.data request.FILES

“id” : 1

“username” : “Harry”

“password” : “123?”

“is_logged_in” : True

“is_public” : False

“file_name” : “hello.txt”

Data

“file” : file object

NEW APP

models.py -> 

databases

views.py -> functions

• Translator

• Puts into databases

• Defines how user’s data looks

Main files

Url linking
29

User

Serializer

Backend

Remote

Proposed Layout

Serializer

New 

RESTful API New RESTful API
UPLOADING DATA

30

Example 

Data

->

example_data

L 1d_data

L file1

L file2

Data
OTHER FACTORS

31

- Users all over the world!

- Different wants

- Need something to define 

“public”

- Save Data and Fits

International

- Web framework 

- Batteries Included

- DRY (Don’t Repeat 

Yourself)

- Database backend

- Future View integration

Why Django?
OTHER FACTORS

32

- Users all over the world!

- Different wants

- Need something to define 

“public”

International

- Django

- Flask

- What’s the best?

What web framework?

- Defined database backend

- Allows for the future 

development of web 

application rather than just 

interface

Why Django?
BACKEND?

7/1/20XX Pitch deck title 33

terminal