Skip to content

Commit

Permalink
Merge pull request #5 from Small-Bodies-Node/infrastructure-update-20…
Browse files Browse the repository at this point in the history
…24.02

Infrastructure update 2024.02
  • Loading branch information
mkelley authored Mar 1, 2024
2 parents 5963759 + c995fbc commit 3f5bc51
Show file tree
Hide file tree
Showing 20 changed files with 671 additions and 432 deletions.
11 changes: 11 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Copyright 2021-2024 SBN Survey Image Service Developers

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
91 changes: 61 additions & 30 deletions _initial_setup.sh
Original file line number Diff line number Diff line change
@@ -1,57 +1,88 @@
#!/usr/bin/env false
#!/bin/bash

### 0. Load vars defined in .env
if [ ! -f $PWD/.env ]; then
echo -e "No .env file found. Generate with '_sbnsis env' then edit."
return 1
set -e

reset_color="\033[00m"
black="\033[30m"
red="\033[31m"
green="\033[32m"
yellow="\033[33m"
blue="\033[34m"
magenta="\033[35m"
cyan="\033[36m"
white="\033[37m"

if [[ -z $PYTHON ]]; then
PYTHON=python3
fi
source .env

### 1. Message user
clear
echo -e """${GRE}
=======================================
Initializing Python Virtual Environment
=======================================
${WHI}"""
echo -e """${green}
==========================
Python Virtual Environment
==========================
${reset_color}"""

sleep 1

### 2. Get rid of caches NOT in .venv
### Get rid of caches NOT in .venv
echo -e """${cyan}
Cleaning cached pyc files
${reset_color}"""
find . -type d ! -path './.venv/*' -name '__pycache__' -exec rm -rf {} +
find . -type d ! -path './.venv/*' -name '.pytest_cache' -exec rm -rf {} +
find . -type d ! -path './.venv/*' -name '.mypy_cache' -exec rm -rf {} +

### 3. Check for existence of `.venv` dir
### Check for existence of `.venv` dir
if [[ ! -d $PWD/.venv ]]; then
echo -e """${BLU}
virtual Environment Not Found -- Creating '.venv'
"""
$PYTHON_3_6_OR_HIGHER -m venv .venv --prompt=$APP_NAME
echo -e """${cyan}
Virtual environment not found -- Creating ".venv"
${reset_color}"""
$PYTHON -m venv .venv --prompt=sbn-survey-image-service
else
echo -e """${cyan}
Virtual environment found in ".venv"
${reset_color}"""
fi

### 4. Activate VENV
### Activate VENV
source ./.venv/bin/activate

### 5. Install package dependencies for project
### Install package dependencies for project

echo -e """${green}
===========================
Setup dependencies and code
===========================
${reset_color}"""

pip install --upgrade -q -q -q pip setuptools wheel
pip install -q -r requirements.vscode.txt
pip install -q -r requirements.txt
pip install -e .
pip install -e .[recommended,dev]

if [[ ! -e $VIRTUAL_ENV/bin/fitscut ]]; then
echo -e """${BLU}
installing fitscut
${WHI}
echo -e """${cyan}
Installing fitscut
${reset_color}
"""
./_install_fitscut
fi

### 6. Link git pre-commit-hook script
### Link git pre-commit-hook script
ln -fs $PWD/_precommit_hook $PWD/.git/hooks/pre-commit

if [ ! -f $PWD/.env ]; then
echo -e """${red}
To create a .env file:
source .venv/bin/activate
_sbnsis env
Then edit .env
${reset_color}"""
fi

### 7. Final Message
echo -e """${BLU}
echo -e """${cyan}
Done. Bon courage!
${WHI}
"""
${reset_color}
"""
5 changes: 3 additions & 2 deletions _sbnsis
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#!/bin/bash
./.venv/bin/python3 -m sbn_survey_image_service.scripts.sbnsis $*
#!/usr/bin/env python3
from sbn_survey_image_service.scripts.sbnsis import SBNSISService
SBNSISService()
47 changes: 47 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[project]
name = "sbn-survey-image-service"
description = "Serves images and cutouts via REST API."
readme = "readme.md"
authors = [
{ name = "Michael S. P. Kelley", email = "[email protected]" }
]
license = { text = "BSD 3-Clause License" }
dependencies = [
"Flask>=3.0",
"Flask-Cors>=4.0",
"gunicorn>=21",
"connexion>=3.0",
"swagger-ui-bundle>1.0",
"astropy>=6.0",
"pds4_tools==1.3",
"SQLAlchemy>=2.0",
"python-dotenv>1.0",
"pytest-remotedata>=0.4",
]
dynamic = ["version"]

[project.urls]
homepage = "https://github.com/Small-Bodies-Node/sbn-survey-image-service"

[build-system]
requires = ["setuptools>=45", "wheel", "setuptools_scm[toml]>=6.2"]
build-backend = 'setuptools.build_meta'

[tool.setuptools_scm]

[tool.setuptools]
zip-safe = false

[tool.setuptools.packages.find]

[project.optional-dependencies]
recommended = [
"psycopg2-binary>=2.8",
]
dev = [
"autopep8",
"mypy",
"pycodestyle",
"pytest>=7.0",
"pytest-cov>=3.0",
]
16 changes: 7 additions & 9 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@ Live at the PDS [Small Bodies Node](https://sbnsurveys.astro.umd.edu/api/ui)

The SBN Survey Image Service is a REST API that enables a user to retrieve archive images and cutouts thereof from the Planetary Data System's Small-Bodies Node (PDS SBN). For example, a user may request a full-frame image from the ATLAS survey archive, or a small cutout around their object of interest. The returned data may be in FITS, JPEG, or PNG formats. The service can also return the image's PDS label.

The data model is partially compatible with the IVOA's [Simple Image Access protocol](https://www.ivoa.net/documents/SIA/), which is based on the [ObsCore Data Model](https://www.ivoa.net/documents/ObsCore/20111028/). However, this functionality is deprecated.

![SBN Survey Image Service workflow](docs/SBNSIS-workflow.png)

## Code Features

- Uses [fitscut](https://github.com/spacetelescope/fitscut) for image cutouts and JPEG/PNG generation
- Flask API layer
- Connexion used to generate swagger interface
- Gunicorn/Apache used for production deployment
- OpenAPI spec with Connexion and Swagger
- Gunicorn for production deployment
- Backed by Postgresql or Sqlite3

## Development
Expand All @@ -33,7 +31,7 @@ The data model is partially compatible with the IVOA's [Simple Image Access prot

This repo has code for:

- Running a flask-connexion API
- Running the API
- Testing

Most day-to-day tasks can be accomplished with the `_sbnsis` command.
Expand All @@ -53,11 +51,11 @@ The following steps are needed to set up the code base:
cd sbn-survey-image-service
```

- Create a new environment variable file and edit to suit your needs: `_sbnsis env`.
- Initialize your installation with `source _initial_setup.sh`. This will:
- Initialize your installation with `bash _initial_setup.sh`. This will:
- Create and activate a python virtual environment.
- Install dependencies (e.g., `fitscut`) to the virtual env, if needed.
- Make available to your shell the variables `.env`.
- To use a specific Python interpreter, set the PYTHON environment variable: `PYTHON=/path/to/python3 bash _install_setup.sh`
- Install dependencies, including `fitscut`, to the virtual env.
- Create a new environment variable file and edit to suit your needs: `_sbnsis env`.
- Optionally test your set up:
- Be aware that the testing suite will use the database parameters specified in the `.env` file.
- The database user must have write permissions for testing.
Expand Down
14 changes: 0 additions & 14 deletions requirements.txt

This file was deleted.

22 changes: 0 additions & 22 deletions requirements.vscode.txt

This file was deleted.

14 changes: 11 additions & 3 deletions sbn_survey_image_service/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
"""SBN Survey Image Service"""

import os
from importlib.metadata import version as _version, PackageNotFoundError

# make cache directory set umask
from . import exceptions
from . import env
from . import services
from . import models
import os
os.system(f'mkdir -p {env.ENV.SBNSIS_CUTOUT_CACHE}')
del os

try:
__version__ = _version(__name__)
except PackageNotFoundError:
pass

os.system(f"mkdir -p {env.ENV.SBNSIS_CUTOUT_CACHE}")
del os, PackageNotFoundError, _version
2 changes: 1 addition & 1 deletion sbn_survey_image_service/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ paths:
parameters:
- name: id
in: path
description: Unique image data product ID (PDS3) or logical identifier (PDS4)
description: Unique image data logical identifier (PDS4)
example: urn:nasa:pds:gbo.ast.neat.survey:data_tricam:p20020222_obsdata_20020222120052c
required: true
allowEmptyValue: false
Expand Down
Loading

0 comments on commit 3f5bc51

Please sign in to comment.