Skip to content

Commit

Permalink
Merge branch 'feature/own-discoveries' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
talister committed Jun 30, 2015
2 parents 483bc3d + 4aeb4e6 commit ee59857
Show file tree
Hide file tree
Showing 96 changed files with 3,061 additions and 1,715 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,4 @@ ingest/static/ingest/css/admin.css
ingest/static/ingest/css/dashboard.css
neoexchange/neox/local_settings.py
*.db
docker-compose.yml
66 changes: 35 additions & 31 deletions docker/neoexchange.dockerfile → Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,57 +10,61 @@
# just default to using the nginx port only (recommended). There is no
# requirement to map all exposed container ports onto host ports.
#
# To run with nginx only:
# docker run -d -p 8200:8200 --name=neoexchange lcogtwebmaster/lcogt:neoexchange_$BRANCH
# Build with
# docker build -t docker.lcogt.net/neoexchange:latest .
#
# To run with nginx + uwsgi both exposed:
# docker run -d -p 8200:8200 -p 8201:8201 --name=neox lcogtwebmaster/lcogt:neoexchange_$BRANCH
# Push to docker registry with
# docker push docker.lcogt.net/neoexchange:latest
#
# See the notes in the code below about NFS mounts.
# To run with nginx + uwsgi both exposed:
# docker run -d -p 8200:80 --name=neox docker.lcogt.net/neoexchange:latest
# Or use the docker-compose.yml from github.com/LCOGT/docker/compose/neoexchange/
#
################################################################################
FROM centos:centos7
MAINTAINER LCOGT <webmaster@lcogt.net>

# Install package repositories
RUN yum -y install epel-release

# Install packages and update base system
RUN yum -y install nginx python-pip mysql-devel python-devel supervisor
RUN yum -y groupinstall "Development Tools"
RUN yum -y update

# Copy the LCOGT Mezzanine webapp files
COPY neoexchange /var/www/apps/neoexchange
RUN yum -y install epel-release \
&& yum -y install cronie libjpeg-devel nginx python-pip mysql-devel python-devel supervisor \
&& yum -y groupinstall "Development Tools" \
&& yum -y update

# Setup our python env now so it can be cached
COPY neoexchange/requirements.txt /var/www/apps/neoexchange/requirements.txt
# Install the LCOGT NEO exchange Python required packages
RUN pip install pip==1.3 && pip install uwsgi==2.0.8
RUN pip install -r /var/www/apps/neoexchange/pip_requirements.txt
RUN pip install pip==1.3 && pip install uwsgi==2.0.8 \
&& pip install -r /var/www/apps/neoexchange/requirements.txt

# LCOGT packages which have to be installed after the normal pip install
RUN pip install pyslalib --extra-index-url=http://buildsba.lco.gtn/python/
RUN pip install rise_set --extra-index-url=http://buildsba.lco.gtn/python/
RUN pip install pyslalib --extra-index-url=http://buildsba.lco.gtn/python/ \
&& pip install rise_set --extra-index-url=http://buildsba.lco.gtn/python/

# Ensure crond will run on all host operating systems
RUN sed -i -e 's/\(session\s*required\s*pam_loginuid.so\)/#\1/' /etc/pam.d/crond

# Setup the Python Django environment
ENV PYTHONPATH /var/www/apps
ENV DJANGO_SETTINGS_MODULE neox.settings
ENV BRANCH ${BRANCH}
#ENV BUILDDATE ${BUILDDATE}

# Setup the LCOGT Mezzanine webapp
RUN python /var/www/apps/neoexchange/manage.py validate
RUN python /var/www/apps/neoexchange/manage.py collectstatic --noinput
RUN python /var/www/apps/neoexchange/manage.py syncdb --noinput
RUN python /var/www/apps/neoexchange/manage.py migrate --noinput

# Copy configuration files
COPY config/uwsgi.ini /etc/uwsgi.ini
COPY config/nginx/* /etc/nginx/
COPY config/neoexchange.ini /etc/supervisord.d/neoexchange.ini
COPY config/processes.ini /etc/supervisord.d/processes.ini
COPY config/crontab.root /var/spool/cron/root

# nginx runs on port 8200, uwsgi runs on port 8201
EXPOSE 8200 8201
# nginx runs on port 80, uwsgi is linked in the nginx conf
EXPOSE 80

# The entry point is our init script, which runs startup tasks, then
# execs the supervisord daemon
ENTRYPOINT [ "/init" ]

# Copy configuration files
COPY config/init /init

# Copy the LCOGT Mezzanine webapp files
COPY neoexchange /var/www/apps/neoexchange

# Entry point is the supervisord daemon
ENTRYPOINT [ "/usr/bin/supervisord", "-n" ]
# Setup the LCOGT NEOx webapp
RUN python /var/www/apps/neoexchange/manage.py collectstatic --noinput
56 changes: 0 additions & 56 deletions Makefile

This file was deleted.

69 changes: 67 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
NEO Exchange
============

Portal for scheduling observations of NEOs using LCOGT (Version 0.1.0)
Portal for scheduling observations of NEOs using LCOGT (Version 1.0.1)

Setup
-----
Expand All @@ -14,6 +14,71 @@ Construct a Python Virtual Enviroment (virtualenv) by executing:
or:

`source <path to virtualenv>/bin/activate.csh # for (t)csh-shells`
`pip install -r pip-requirements.txt`

then:

`pip install -r neox/requirements.txt`

Deployment
----------

You will need to set up 3 environment variables before deploying (if you are just locally testing see instructions below).

If you are using BASH or ZSH add the following to your .profile or .zshrc files:
```
export NEOX_DB_USER='<insert your DB username>'
export NEOX_DB_PASSWORD='<insert your DB password>'
export NEOX_DB_HOST='<insert the name of your DB server>'
```

Docker
------
If you are building a Docker container use the following syntax:
```
docker build -t docker.lcogt.net/neoexchange:latest .
```
This will build a Docker image which will need to be pushed into a Docker registry with:
```
docker push docker.lcogt.net/neoexchange:latest
```
Starting a Docker container from this image can be done with a `docker run` command or using `docker-compose`.


Local Testing
-------------

For local testing you will probably want to create a
`neoexchange/neox/local_settings.py` file to point at a local test database and
to switch on `DEBUG` for easier testing. An example file would look like:
```
import sys, os
CURRENT_PATH = os.path.dirname(os.path.realpath(__file__))
BASE_DIR = os.path.dirname(CURRENT_PATH)
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'neox.db', # Or path to database file if using sqlite3.
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
DEBUG = True
# Use a different database file when testing or exploring in the shell.
if 'test' in sys.argv or 'test_coverage' in sys.argv or 'shell' in sys.argv:
DATABASES['default']['ENGINE'] = 'django.db.backends.sqlite3'
DATABASES['default']['NAME'] = 'test.db'
DATABASES['default']['USER'] = ''
DATABASES['default']['PASSWORD'] = ''
STATIC_ROOT = os.path.abspath(os.path.join(BASE_DIR, '../../static/'))
```

To prepare the local SQLite DB for use, you should follow these steps:
1. `cd neoexchange\neoexchange`
2. Run `python manage.py syncdb`. This will perform migrations as necessary.
4 changes: 2 additions & 2 deletions config/crontab.root
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Put your cron jobs here
10 5 * * * python /var/www/apps/neoexchange/manage.py fetch_goldstone_targets
10 5 * * * python /var/www/apps/neoexchange/manage.py update_neocp_data
10 5 * * * python /var/www/apps/neoexchange/manage.py update_crossids
20 5 * * * python /var/www/apps/neoexchange/manage.py update_neocp_data
30 5 * * * python /var/www/apps/neoexchange/manage.py update_crossids
8 changes: 8 additions & 0 deletions config/init
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

# Substitute the prefix into the nginx configuration
# If any schema changed have happened but not been applied
python /var/www/apps/neoexchange/manage.py migrate --noinput

# Run under supervisord
exec /usr/bin/supervisord -n -c /etc/supervisord.conf
2 changes: 1 addition & 1 deletion config/nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ http {
}

server {
listen 8200;
listen 80;
server_name dockerhost;
charset utf-8;

Expand Down
File renamed without changes.
4 changes: 0 additions & 4 deletions docker/bin/loaddata.sh

This file was deleted.

8 changes: 0 additions & 8 deletions docker/bin/nginx.sh

This file was deleted.

19 changes: 0 additions & 19 deletions docker/bin/run.sh

This file was deleted.

5 changes: 0 additions & 5 deletions docker/bin/stop.sh

This file was deleted.

4 changes: 0 additions & 4 deletions docker/bin/uwsgi.sh

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,37 @@ def normal_to_packed(obj_name, dbg=False):
packed_desig = ' ' * 12
rval = -1
return ( packed_desig, rval)

def determine_asteroid_type(perihdist, eccentricity):
'''Determines the object class from the perihelion distance <perihdist> and
the eccentricity <eccentricity> and returns it as a single character code
as defined in core/models.py.
Currently the checked types are:
1) NEO (perihelion < 1.3 AU)
2) Centaur (perihelion > 5.5 AU (orbit of Jupiter) & semi-major axis < 30.1 AU
(orbit of Neptune)
3) KBO (perihelion > 30.1 AU (orbit of Neptune)'''

jupiter_semidist = 5.5
neptune_semidist = 30.1
juptrojan_lowlimit = 5.05
juptrojan_hilimit = 5.35

obj_type = 'A'
if perihdist <= 1.3 and eccentricity < 0.999:
obj_type = 'N' # NEO
else:
# Test for eccentricity close to or greater than 1.0
if abs(eccentricity-1.0) >= 1e-3 and eccentricity < 1.0:
semi_axis = perihdist / (1.0 - eccentricity )
if perihdist >= jupiter_semidist and semi_axis >= jupiter_semidist \
and semi_axis <= neptune_semidist:
obj_type = 'E' # Centaur
elif perihdist > neptune_semidist:
obj_type = 'K'
elif semi_axis >= juptrojan_lowlimit and semi_axis <= juptrojan_hilimit:
obj_type = 'T'
else:
obj_type = 'C' # Comet
return obj_type
Loading

0 comments on commit ee59857

Please sign in to comment.