Skip to content

Commit

Permalink
Merge pull request #826 from aaronwmorris/dev
Browse files Browse the repository at this point in the history
Aurora and Kp-index reporting
  • Loading branch information
aaronwmorris authored Jul 8, 2023
2 parents 5bbbc5f + 6e66bfb commit fb9de62
Show file tree
Hide file tree
Showing 22 changed files with 775 additions and 39 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ indi-allsky is software used to manage a Linux-based All Sky Camera using the IN
*Pictured: SpaceX Cargo Dragon (over Georgia) headed for splashdown off the coast of Florida*

## Features
* NEW: Aurora prediction and Kp-index reporting
* NEW: Docker containerization support
* NEW: Image stretching
* Multi-image stacking
Expand Down Expand Up @@ -168,6 +169,16 @@ Video of the star trails being stacked in real-time!
[YouTube](https://youtu.be/pLJbTzlyBkM)


## Aurora & Kp-index
indi-allsky utilizes data from [NOAA Space Weather Prediction Center](https://www.swpc.noaa.gov/) to predict the possibility of Aurora in your location. The SWPC provides data using the Ovation Aurora Model for aurora predictions. indi-allsky uses the Ovation data to create an aggregate score within a ~500 mile radius around your location.

The current Kp-index value is also polled from NOAA. This is the measurement of the disturbance of the Earth's magnetic field, ranging from 0-9. Values higher than 5 are good indicators of stronger solor storm activity which creates aurora.

The Kp-index data, combined with the Ovation data, gives an objective prediction of the visibility of Aurora for your location.

Data is updated every 3 hours from NOAA.


## Star Detection
indi-allsky utilizes OpenCV pattern matching to detect and count the number of stars in the view. Star counts are a good objective measurement of sky conditions.

Expand Down
8 changes: 8 additions & 0 deletions docker/Dockerfile.nginx
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@

FROM nginx:bullseye

ARG INDI_ALLSKY_IMAGE_FOLDER


ENV DEBIAN_FRONTEND noninteractive


USER root
RUN apt-get update
RUN apt-get -y upgrade
Expand All @@ -27,6 +31,10 @@ RUN chown -R allsky:allsky /home/allsky/indi-allsky

RUN rm -f /etc/nginx/conf.d/default.conf
COPY docker/nginx.local.conf /etc/nginx/conf.d/default.conf
RUN sed \
-i \
-e "s|%INDI_ALLSKY_IMAGE_FOLDER%|$INDI_ALLSKY_IMAGE_FOLDER|g" \
/etc/nginx/conf.d/default.conf
COPY docker/ssl.crt /etc/ssl/certs/nginx.crt
COPY docker/ssl.key /etc/ssl/private/nginx.key

Expand Down
2 changes: 2 additions & 0 deletions docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ services:
build:
context: ..
dockerfile: docker/Dockerfile.nginx
args:
- INDI_ALLSKY_IMAGE_FOLDER=${INDI_ALLSKY_IMAGE_FOLDER}
env_file: .env
depends_on:
- gunicorn.indi.allsky
Expand Down
8 changes: 7 additions & 1 deletion docker/env_template
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ INDIALLSKY_INDI_GPS_DRIVER=

INDIALLSKY_TIMEZONE=America/New_York

# This folder needs to be shared to the capture, gunicorn, and nginx containers
INDI_ALLSKY_IMAGE_FOLDER=/var/www/html/allsky/images

INDIALLSKY_FLASK_AUTH_ALL_VIEWS=false
INDIALLSKY_FLASK_SECRET_KEY=%INDIALLSKY_FLASK_SECRET_KEY%
INDIALLSKY_FLASK_PASSWORD_KEY=%INDIALLSKY_FLASK_PASSWORD_KEY%

# Folder for temporary files in capture process. Uncomment to activate
#CAPTURE_TMPDIR=/tmp

INDIALLSKY_WEB_USER=%WEB_USER%
INDIALLSKY_WEB_PASS=%WEB_PASS%
INDIALLSKY_WEB_NAME=%WEB_NAME%
Expand All @@ -23,7 +29,7 @@ INDIALLSKY_MOSQUITTO_PASS=%WEB_PASS%
INDIALLSKY_WEB_GENERATE_APIKEY=false

# Only used on the debian build
#INDIALLSKY_INDI_VERSION=2.0.1
#INDIALLSKY_INDI_VERSION=2.0.2

INDI_ALLSKY_MARIADB_HOST=mariadb.indi.allsky
INDI_ALLSKY_MARIADB_PORT=3306
Expand Down
4 changes: 2 additions & 2 deletions docker/nginx.local.conf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ server {


location /indi-allsky/images {
alias /var/www/html/allsky/images;
alias %INDI_ALLSKY_IMAGE_FOLDER%;
autoindex off;
}

Expand Down Expand Up @@ -61,7 +61,7 @@ server {


location /indi-allsky/images {
alias /var/www/html/allsky/images;
alias %INDI_ALLSKY_IMAGE_FOLDER%;
autoindex off;
}

Expand Down
19 changes: 12 additions & 7 deletions docker/start_gunicorn.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,25 @@ TMP_CONFIG_DUMP=$(mktemp --suffix=.json)
"${ALLSKY_DIRECTORY}/config.py" dump > "$TMP_CONFIG_DUMP"


# Detect IMAGE_FOLDER
IMAGE_FOLDER=$(jq -r '.IMAGE_FOLDER' "$TMP_CONFIG_DUMP")
echo "Detected IMAGE_FOLDER: $IMAGE_FOLDER"


# replace the flask IMAGE_FOLDER
TMP_FLASK_3=$(mktemp --suffix=.json)
jq --arg image_folder "$IMAGE_FOLDER" '.INDI_ALLSKY_IMAGE_FOLDER = $image_folder' "${ALLSKY_ETC}/flask.json" > "$TMP_FLASK_3"
jq --arg image_folder "$INDI_ALLSKY_IMAGE_FOLDER" '.INDI_ALLSKY_IMAGE_FOLDER = $image_folder' "${ALLSKY_ETC}/flask.json" > "$TMP_FLASK_3"
cp -f "$TMP_FLASK_3" "${ALLSKY_ETC}/flask.json"
[[ -f "$TMP_FLASK_3" ]] && rm -f "$TMP_FLASK_3"


# update image folder config
TMP_IMAGE_FOLDER=$(mktemp --suffix=.json)
jq \
--arg image_folder "$INDI_ALLSKY_IMAGE_FOLDER" \
'.IMAGE_FOLDER = $image_folder' \
"$TMP_CONFIG_DUMP" > "$TMP_IMAGE_FOLDER"


# load all changes
"${ALLSKY_DIRECTORY}/config.py" load -c "$TMP_CONFIG_DUMP" --force
"${ALLSKY_DIRECTORY}/config.py" load -c "$TMP_IMAGE_FOLDER" --force
[[ -f "$TMP_CONFIG_DUMP" ]] && rm -f "$TMP_CONFIG_DUMP"
[[ -f "$TMP_IMAGE_FOLDER" ]] && rm -f "$TMP_IMAGE_FOLDER"


USER_COUNT=$("${ALLSKY_DIRECTORY}/config.py" user_count)
Expand Down
32 changes: 22 additions & 10 deletions docker/start_indi_allsky.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,35 +79,39 @@ TMP_CONFIG_DUMP=$(mktemp --suffix=.json)
"${ALLSKY_DIRECTORY}/config.py" dump > "$TMP_CONFIG_DUMP"


# Detect IMAGE_FOLDER
IMAGE_FOLDER=$(jq -r '.IMAGE_FOLDER' "$TMP_CONFIG_DUMP")
echo "Detected IMAGE_FOLDER: $IMAGE_FOLDER"


# replace the flask IMAGE_FOLDER
TMP_FLASK_3=$(mktemp --suffix=.json)
jq --arg image_folder "$IMAGE_FOLDER" '.INDI_ALLSKY_IMAGE_FOLDER = $image_folder' "${ALLSKY_ETC}/flask.json" > "$TMP_FLASK_3"
jq --arg image_folder "$INDI_ALLSKY_IMAGE_FOLDER" '.INDI_ALLSKY_IMAGE_FOLDER = $image_folder' "${ALLSKY_ETC}/flask.json" > "$TMP_FLASK_3"
cp -f "$TMP_FLASK_3" "${ALLSKY_ETC}/flask.json"
[[ -f "$TMP_FLASK_3" ]] && rm -f "$TMP_FLASK_3"


# replace hosts
INDI_SERVER=$(jq -r '.INDI_SERVER' "$TMP_CONFIG_DUMP")
MQTTPUBLISH_HOST=$(jq -r '.MQTTPUBLISH.HOST' "$TMP_CONFIG_DUMP")
# update image folder config
TMP_IMAGE_FOLDER=$(mktemp --suffix=.json)
jq \
--arg image_folder "$INDI_ALLSKY_IMAGE_FOLDER" \
'.IMAGE_FOLDER = $image_folder' \
"$TMP_CONFIG_DUMP" > "$TMP_IMAGE_FOLDER"


# replace host
INDI_SERVER=$(jq -r '.INDI_SERVER' "$TMP_CONFIG_DUMP")

# fix indi server hostname for docker
if [ "$INDI_SERVER" == "localhost" ]; then
TMP_INDI_SERVER=$(mktemp --suffix=.json)
jq \
--arg indi_server "indiserver.indi.allsky" \
'.INDI_SERVER = $indi_server' \
"$TMP_CONFIG_DUMP" > "$TMP_INDI_SERVER"
"$TMP_IMAGE_FOLDER" > "$TMP_INDI_SERVER"
else
TMP_INDI_SERVER="$TMP_CONFIG_DUMP"
fi


# replace host
MQTTPUBLISH_HOST=$(jq -r '.MQTTPUBLISH.HOST' "$TMP_CONFIG_DUMP")

# fix mqtt server hostname for docker
if [ "$MQTTPUBLISH_HOST" == "localhost" ]; then
TMP_MQTTPUBLISH_HOST=$(mktemp --suffix=.json)
Expand All @@ -123,10 +127,18 @@ fi
# load all changes
"${ALLSKY_DIRECTORY}/config.py" load -c "$TMP_MQTTPUBLISH_HOST" --force
[[ -f "$TMP_CONFIG_DUMP" ]] && rm -f "$TMP_CONFIG_DUMP"
[[ -f "$TMP_IMAGE_FOLDER" ]] && rm -f "$TMP_IMAGE_FOLDER"
[[ -f "$TMP_INDI_SERVER" ]] && rm -f "$TMP_INDI_SERVER"
[[ -f "$TMP_MQTTPUBLISH_HOST" ]] && rm -f "$TMP_MQTTPUBLISH_HOST"


# tmp folder for python
if [ -n "${CAPTURE_TMPDIR:-}" ]; then
TMPDIR="$CAPTURE_TMPDIR"
export TMPDIR
fi


# start the program
./allsky.py \
--log stderr \
Expand Down
40 changes: 39 additions & 1 deletion indi_allsky/allsky.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
class IndiAllSky(object):

periodic_tasks_offset = 180.0 # 3 minutes
aurora_tasks_offset = 10800 # 3 hours


def __init__(self):
Expand Down Expand Up @@ -159,6 +160,8 @@ def __init__(self):


self.periodic_tasks_time = time.time() + self.periodic_tasks_offset
#self.periodic_tasks_time = time.time() # testing
self.aurora_tasks_time = time.time() # start immediately


if self.config['IMAGE_FOLDER']:
Expand Down Expand Up @@ -1009,6 +1012,41 @@ def periodic_tasks(self):
self.indiclient.configureCcdDevice(self.config['INDI_CONFIG_DEFAULTS'])


# aurora data update
if self.aurora_tasks_time < now:
self.aurora_tasks_time = now + self.aurora_tasks_offset

logger.info('Creating aurora update task')
self._updateAuroraData(self.camera_id)


def _updateAuroraData(self, camera_id, task_state=TaskQueueState.QUEUED):

camera = IndiAllSkyDbCameraTable.query\
.filter(IndiAllSkyDbCameraTable.id == camera_id)\
.one()


# This will delete old images from the filesystem and DB
jobdata = {
'action' : 'updateAuroraData',
'img_folder' : str(self.image_dir),
'timespec' : None, # Not needed
'night' : None, # Not needed
'camera_id' : camera.id,
}

task = IndiAllSkyDbTaskQueueTable(
queue=TaskQueueQueue.VIDEO,
state=task_state,
data=jobdata,
)
db.session.add(task)
db.session.commit()

self.video_q.put({'task_id' : task.id})


def connectOnly(self):
self._initialize(connectOnly=True)

Expand Down Expand Up @@ -1229,7 +1267,7 @@ def run(self):
# reconfigure if needed
self.reconfigureCcd()

# these tasks run every ~5 minutes
# these tasks run every ~3 minutes
self.periodic_tasks()


Expand Down
Loading

0 comments on commit fb9de62

Please sign in to comment.