5.1. server.py
The inclinet server side in Python
This package uses Flask
to implement the API functionalities in Python.
Visit the online GUI at http://edd.ifa.hawaii.edu/inclinet/
- For documentations check:
- server.IM_upload()
An image uploader
API
for the use in the online GUI This API is called from the online application, throughAJAX
calls. The uploaded image is stored on the server for further analysis.- Returns
the status of the process, and the public address of the images path for the online GUI
- Return type
json
- class server.NpEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)
Bases:
json.encoder.JSONEncoder
- default(obj)
Implement this method in a subclass such that it returns a serializable object for
o
, or calls the base implementation (to raise aTypeError
).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return JSONEncoder.default(self, o)
- server.addGalaxyInfo(Leda, pgc, response=None, objname=None)
Exctracting the information of a galaxy from the LEDA catalog given the corresponsing PGC ID
- Parameters
Leda (
Pandas dataFrame
) – Leda catalogpgc (
int
) – pgc IDresponse (python
dictionary
, optional) – response to be modified, defaults to Noneobjname (
str
, optional) – galaxy name, defaults to None
- Returns
response dictionary that holds the requested galaxy information
- Return type
python dictionary
- server.addUnits(params)
adding units to the parameters of the provided dictionary
- Parameters
params (
dict
) – a dictionary that holds galaxy information- Returns
revised dictionary
- Return type
dict
- server.allowedFile(fileName, suffixes=['PNG', 'JPG', 'JPEG', 'GIF'])
Determining is the provided input file is acceptable
- Parameters
fileName (
str
) – name of the input filesuffixes (
list
, optional) – valid file extensions, defaults to['PNG', 'JPG', 'JPEG', 'GIF']
- Returns
True if acceptable, False if invalid
- Return type
boolean
- server.arg_parser()
Parsing the command line arguments
- Returns
parsed arguments
(opts, args)
opts: the
- Return type
tuple
- server.createDir(folderPath)
generating a directory/folder if it doesn’t exist
- Parameters
folderPath (
str
) – path to the desired folder- Returns
True is created, False if the folder already exists
- Return type
str
- server.evaluate()
An
API
rule that accepts galaxy images and returns a summary of all results- Returns
evaluated inclination(s) and other evaluations/predictions
- Return type
json
- server.expand2square(pil_img, background_color)
transforms images to square shapes If a rectangular image is provided, the output image is square in size. Note: image is NOT stretched, just the smaller dimension is padded
- Parameters
pil_img (
PIL
image object) – input imagebackground_color (tuple
(R, G, B)
) – background color of the augmented part
- Returns
an square image
- Return type
PIL
image object
- server.file_api()
API
function, evaluating the inclination by providing the galaxy image- Returns
summary of the results, inclinations, statistics
- Return type
json
$ curl -F 'file=@/path/to/image/NGC_4579.jpg' <inclinet_url>/api/file { "status": "success", "filename": "NGC_4579.jpg", "inclinations": { "Group_0": { "model4": 47.0, "model41": 51.0, "model42": 50.0, "model43": 47.0 }, "Group_1": { "model5": 49.0, "model51": 49.0, "model52": 51.0, "model53": 52.0 }, "Group_2": { "model6": 50.0, "model61": 49.0, "model62": 49.0, "model63": 48.0 }, "summary": { "mean": 49.333333333333336, "median": 49.0, "stdev": 1.49071198499986 } }, "rejection_likelihood": { "model4-binary": 84.28281545639038, "model5-binary": 94.24970746040344, "model6-binary": 88.11054229736328, "summary": { "mean": 88.88102173805237, "median": 88.11054229736328, "stdev": 4.105278145778375 } } }
- server.getObj()
API
getObj rule Object name is provided injson
format and it returns the information about the galaxy injason
- Returns
galaxy information
ra, dec
: galaxy coordinatesfov
: field of viewpa
: position angleobjname
: galaxy namestatus
: success/fail depending on the status of the query
- Return type
json
Example:
$ curl -X POST <inclinet_url>/getObj -d '{"objname":"M31"}' -H 'Content-Type: application/json' { "dec": "41.2689", "fov": "266.74", "objname": "M31", "pa": "35.0", "pgc": 2557, "ra": "10.6848", "status": "success" }
- server.getPGC()
API
getPGC rule The PGC number of galaxy is provided injson
format and it returns the information about the galaxy injson
- Returns
galaxy information
ra, dec
: galaxy coordinatesfov
: field of viewpa
: position angleobjname
: galaxy namestatus
: success/fail depending on the status of the query
- Return type
json
Example:
$ curl -X POST <inclinet_url>/getPGC -d '{"pgc":"2557"}' -H 'Content-Type: application/json' { "dec": "41.2689", "fov": "266.74", "objname": "NGC0224", "pa": "35.0", "pgc": "2557", "ra": "10.6848", "status": "success" }
- server.getPGCid(objname)
extracting the PGC ID of a galaxy given its name
- Parameters
objname (str) – galaxy name
- Returns
PGC ID
- Return type
int
- server.get_docs()
- server.home()
mounting the server home
- Returns
the rendered template
index.html
- server.imSquarify(imPath, outPath=None)
padding an image to square shape
- Parameters
imPath (
str
) – image pathoutPath (
str
, optional) – output path, defaults to None
- Returns
output path, if the``outPath`` is not given the output is stored in the same locations
as that of the input image :rtype:
str
- server.loadLeda()
Loading the HyperLeda catalog: - http://leda.univ-lyon1.fr/ - This catalog tabulates the proper information on local galaxies
- Returns
the Leda catalog in the Pandas dataFrame format
- Return type
Pandas
dataFrame
- server.loadModels()
Loading all ML models (deployment versions)
- Returns
a Python dictionary that holds all models in groups
- Return type
python
Dictionary
- server.modelParams(params)
an auxillary function for additional book keepings The conventional extracted galaxy information from the LEDA catalog need to be revised to be compatible with the API of the SDSS image server
- Parameters
params (
dict
) – input parameters- Returns
augmented/adjusted information
- Return type
dict
- server.mySoup(url)
Loading an online webpage using the Beautiful soup client, in order to parse the html contents
- Parameters
url (str) – url of the online page
- Returns
the parsed html text of the requested url
- Return type
<class ‘bs4.BeautifulSoup’>
>>> mySoup("https://edd.ifa.hawaii.edu")
- server.obj_api(objname)
the URL
API
that evaluates inclinations by providing thePGC ID
in the URL- Parameters
objname (
string
) – galaxy name- Returns
the summary of all evaluated inclinations
- Return type
json
The following example shows the output
JSON
that contains the detailed evaluation of the available models. Thesummary
fields hold the statistical summary of the outputs of all models.$ curl <inclinet_url>/api/objname/M33 { "status": "success", "galaxy": { "pgc": 5818, "ra": "23.4621 deg", "dec": "30.6599 deg", "fov": "92.49 arcmin", "pa": "22.5 deg", "objname": "M33" }, "inclinations": { "Group_0": { "model4": 54.0, "model41": 58.0, "model42": 54.0, "model43": 52.0 }, "Group_1": { "model5": 54.0, "model51": 55.0, "model52": 52.0, "model53": 55.0 }, "Group_2": { "model6": 56.0, "model61": 57.0, "model62": 55.0, "model63": 53.0 }, "summary": { "mean": 54.583333333333336, "median": 54.5, "stdev": 1.753963764987432 } }, "rejection_likelihood": { "model4-binary": 41.287994384765625, "model5-binary": 4.068142548203468, "model6-binary": 55.70455193519592, "summary": { "mean": 33.686896289388336, "median": 41.287994384765625, "stdev": 21.754880108256657 } } }
- server.pgc_api(pgcID)
the URL
API
that evaluates inclinations by providing thePGC ID
in the URL- Parameters
pgcID (
int
) – PGC ID- Returns
the summary of all evaluated inclinations
- Return type
json
The following example shows that the output
JSON
contains the detailed evaluation of the available models. Thesummary
fields hold the statistical summary of the outputs of all models.$ curl <inclinet_url>/api/pgc/2557' { "status": "success", "galaxy": { "pgc": "2557", "ra": "10.6848 deg", "dec": "41.2689 deg", "fov": "266.74 arcmin", "pa": "35.0 deg", "objname": "NGC0224" }, "inclinations": { "Group_0": { "model4": 69.0, "model41": 72.0, "model42": 76.0, "model43": 71.0 }, "Group_1": { "model5": 73.0, "model51": 73.0, "model52": 74.0, "model53": 74.0 }, "Group_2": { "model6": 73.0, "model61": 76.0, "model62": 76.0, "model63": 67.0 }, "summary": { "mean": 72.83333333333333, "median": 73.0, "stdev": 2.6718699236468995 } }, "rejection_likelihood": { "model4-binary": 50.396937131881714, "model5-binary": 20.49814760684967, "model6-binary": 65.37048816680908, "summary": { "mean": 45.42185763518015, "median": 50.396937131881714, "stdev": 18.65378065042258 } } }
- server.xcmd(cmd, verbose=True)
Runs an OS command
- Parameters
cmd (
str
) – terminal commandverbose (
boolean
) – printing the details, default True
- Returns
OS outputs
- Return type
str