Skip to content

Synthesize stellar spectrum through a REST API.

License

Notifications You must be signed in to change notification settings

gabraganca/quickstar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

80 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

QuickStar

CI codecov Code style: black

QuickStar provides the Synspec software built by Dr. Ivan Hubeny and Dr. Thierry Lanz as a web app, which can be use through the browser or as an API.

Click in the image below to see a quick demo.

Watch the video

Example of using the API

This is an example of how one can consume the API using Python but, since it is an API, it is language agnostic allowing you to use the tool of your choice (as long it makes web request available).

asciicast

The API runs asynchronously, so we need to send a POST request first with the stellar parameters to trigger the Synspec calculation. We will assume that QuickStar is running locally:

import json
import requests

stellar_parameters = {"teff":20000, "logg":4.0, "wstart":4460, "wend":4500}
post_response = requests.post(
    'http://localhost:8000/synspec',
    data=json.dumps(stellar_parameters)
)

if post_response.ok:
    print(post_response.text)
# {"id":"046f8aa4-d25f-4dec-b7b1-9b1c6025e2da"}

With the request id, we can get the results:

result_id = json.loads(post_response.text)['id']
get_response = requests.get(f'http://localhost:8000/synspec/{result_id}')

if get_response.ok:
    print(get_response.text)

Which will return, by default, only the twenty first wavelength-flux pairs.

{
    "id": "e5d0b55a-52f7-4c83-953e-aec86f155288",
    "status": "SUCCESS",
    "results": [
        {
            "wavelength": 4460.0,
            "flux": 33390000.0
        },
        ...
        {
            "wavelength": 4460.185,
            "flux": 33500000.0
        }
    ],
    "finished_at": "2020-06-11T23:08:36.314996",
    "total_count": 4097
}

To get the full spectrum, it's necessary to paginate the results. The example below shows how to paginate the results

# Get the ID in the response and send a request
result_id = json.loads(post_response.text)["id"]
get_response = requests.get(f"http://localhost:8000/synspec/{result_id}")

# Get the fist part of the spectrum
spectrum = []
if get_response.ok:
    spectrum.extend(json.loads(get_response.text).get("results", []))

# Paginate to get the rest of the spectrum
while "next" in get_response.links:
    get_response = requests.get(get_response.links["next"]["url"])
    if get_response.ok:
        spectrum.extend(json.loads(get_response.text).get("results", []))

API Documentation

The API documentation can be accessed in:

Requirements

The API and Synspec are containerized so all you will need is:

Deploying the services

The API is configured to run with Docker Compose. In your terminal, run.

docker-compose up

The command above will start the API with just one worker, which will not allow you to calculate multiple spectra in parallel. To start multiple workers, for example two, we need to use the following command:

docker-compose up --scale worker=2

This set up will allow to calculate two spectra in parallel.

Depending of how you have installed Docker and Docker Compose, it is possible that you will need to run the docker commands above with sudo.

After booting the services, the frontend can be accessed at localhost.