Skip to content

Commit

Permalink
Merge pull request #21 from kadrlica/actions
Browse files Browse the repository at this point in the history
Add GitHub Actions
  • Loading branch information
kadrlica authored Feb 5, 2023
2 parents 65af937 + a8b8cbd commit ddab4ec
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 45 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
# For more information on conda actions see: https://autobencoder.com/2020-08-24-conda-actions/
# Starter workflow for conda: https://github.com/actions/starter-workflows/blob/main/ci/python-package-conda.yml

name: build

on:
push:
branches: [ main, actions ]
pull_request:
branches: [ main ]

defaults:
run:
shell: bash -l {0}


jobs:
build:
runs-on: ubuntu-latest
strategy:
max-parallel: 3
matrix:
python-version: [3.8]
env:
OBZTAK_SURVEY: obztak
steps:
- uses: actions/checkout@v3
- name: Install Environment with Micromamba
uses: mamba-org/provision-with-micromamba@main
with:
environment-name: obztak
extra-specs: |
python=${{ matrix.python-version }}
- name: Install Package
if: ${{ true }}
run: |
pip install -e .
- name: Run Python
if: ${{ true }}
run: |
python -c "import obztak; print(obztak)"
- name: Lint with flake8
if: ${{ false }}
run: |
mamba install -q flake8 -c conda-forge
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with nose
if: ${{ true }}
run: |
export MPLBACKEND=Agg
nosetests -v tests
28 changes: 0 additions & 28 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Bizarro Observation Tactician (obztak)

[![Build](https://img.shields.io/travis/kadrlica/obztak.svg)](https://travis-ci.org/kadrlica/obztak)
[![Build](https://github.com/kadrlica/obztak/actions/workflows/build.yml/badge.svg)](https://github.com/kadrlica/obztak/actions)
[![PyPI](https://img.shields.io/pypi/v/obztak.svg)](https://pypi.python.org/pypi/obztak)
[![Release](https://img.shields.io/github/release/kadrlica/obztak.svg)](../../releases)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](../../)
Expand Down
18 changes: 18 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: obztak
channels:
- conda-forge
dependencies:
- numpy
- scipy
- pandas
- pyyaml
- matplotlib
- basemap
- ephem
- astropy
- fitsio
- healpy
- psycopg2
- nose
#variables:
# OBZTAK_SURVEY: obztak
2 changes: 1 addition & 1 deletion obztak/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def comment(self):

def from_unique_id(self,string):
try:
hex,tiling = map(int,string.split('-')[:2])
hex,tiling = list(map(int,string.split('-')[:2]))
self['HEX'] = hex
self['TILING'] = tiling
return True
Expand Down
2 changes: 1 addition & 1 deletion obztak/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def schedule_field(self, hex, tiling, band=None, date=None, plot=False, mode=Non

field = self.target_fields[select]
nfields = select.sum()
field['DATE'] = map(datestring,nfields*[date])
field['DATE'] = list(map(datestring,nfields*[date]))
return field

def schedule_chunk(self,tstart=None,chunk=60,clip=False,plot=False,mode=None):
Expand Down
21 changes: 13 additions & 8 deletions tests/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,21 @@ def test_database_fields():
# No database connection
if len(fields) == 0: return

# Used to explicitly test dtype; now just use the fields
#dtype=[('HEX','<i8'),('RA','<f8'),('DEC','<f8'),('FILTER',(np.str_,1)),
# ('EXPTIME','<f8'),('TILING','<i8'),('PRIORITY','<i8'),
# ('DATE',(np.str_,30)), ('AIRMASS','<f8'),('SLEW','<f8'),
# ('MOONANGLE','<f8'),('HOURANGLE','<f8'),('PROGRAM',(np.str_,30))]
#dtype = list(obztak.field.DEFAULTS.items())
dtype = fields.dtype
idx = [0,17,357,1703]
test = np.rec.array([
(5143,101.331075,-55.618165,'g',90.0,1,1,'2016/02/11 04:56:51.972',1.29,87.4149,97.1638, 42.6655 , ''),
(5345,106.011075,-58.41872, 'r',90.0,1,1,'2016/02/11 05:30:32.472',1.35,0.0015, 98.7751, 46.357625, ''),
(6062,157.487654,-76.852859,'g',90.0,1,1,'2016/02/13 09:00:12.732',1.62,1.4089, 106.6357,49.368042, ''),
(2206,345.810525,-70.197803,'g',90.0,2,1,'2016/06/30 08:37:52.759',1.31,1.6166, 91.3154, -8.633625, '')],
dtype=[('HEX','<i8'),('RA','<f8'),('DEC','<f8'),('FILTER','S1'),
('EXPTIME','<f8'),('TILING','<i8'),('PRIORITY','<i8'),
('DATE','S30'), ('AIRMASS','<f8'),('SLEW','<f8'),
('MOONANGLE','<f8'),('HOURANGLE','<f8'),('PROGRAM','S30')])
(5143,101.331075,-55.618165,'g',90.0,1,1,'2016/02/11 04:56:51.936',1.29,87.4149,97.1638, 42.6655 , ''),
(5345,106.011075,-58.41872, 'r',90.0,1,1,'2016/02/11 05:30:32.436',1.35,0.0015, 98.7751, 46.357625, ''),
(6062,157.487654,-76.852859,'g',90.0,1,1,'2016/02/13 09:00:12.684',1.62,1.4089, 106.6357,49.368042, ''),
(2206,345.810525,-70.197803,'g',90.0,2,1,'2016/06/30 08:37:52.702',1.31,1.6166, 91.3154, -8.633625, '')],
dtype=dtype
)

np.testing.assert_equal(fields[idx],test)

Expand Down
9 changes: 5 additions & 4 deletions tests/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ def test_schedule_field():
assert len(out)==1

index = 0
value = {u'count': 1, u'program': u'maglites', u'seqtot': 2, u'seqnum': 1, u'expType': u'object', u'object': u'MAGLITES field: 6679-01-g', u'filter': u'g', u'seqid': u'MAGLITES scheduled: 2017/02/22 06:00:00.0000', u'RA': 121.083, u'propid': u'2016A-0366', u'dec': -57.0986, u'expTime': 90.0, u'wait': u'False'}
value = {u'count': 1, u'program': u'maglites', u'seqtot': 1, u'seqnum': 1, u'expType': u'object', u'object': u'MAGLITES field: 6679-01-g', u'filter': u'g', u'seqid': u'MAGLITES scheduled: 2017/02/22 06:00:00.0000', u'RA': 121.083, u'propid': u'2016A-0366', u'dec': -57.0986, u'expTime': 90.0, u'wait': u'False'}
check_dict(value,out[index])


def test_schedule_chunk():
kwargs = dict(utc='2017-02-22T06:00:00',chunk=60,outfile='chunk_test.json',
complete='None',mode='coverage')
Expand All @@ -36,7 +37,7 @@ def test_schedule_chunk():
assert len(out)==30

index = 17
value = {u'count': 1, u'program': u'maglites', u'seqtot': 2, u'seqnum': 2, u'expType': u'object', u'object': u'MAGLITES field: 6679-01-r', u'filter': u'r', u'seqid': u'MAGLITES scheduled: 2017/02/22 06:34:00.0000', u'RA': 121.083, u'propid': u'2016A-0366', u'dec': -57.0986, u'expTime': 90.0, u'wait': u'False'}
value = {u'count': 1, u'program': u'maglites', u'seqtot': 1, u'seqnum': 1, u'expType': u'object', u'object': u'MAGLITES field: 6679-01-r', u'filter': u'r', u'seqid': u'MAGLITES scheduled: 2017/02/22 06:34:00.0000', u'RA': 121.083, u'propid': u'2016A-0366', u'dec': -57.0986, u'expTime': 90.0, u'wait': u'False'}
check_dict(value,out[index])

def test_schedule_night():
Expand All @@ -54,7 +55,7 @@ def test_schedule_night():
assert len(out)==30

index = 17
value = {u'count': 1, u'program': u'maglites', u'seqtot': 2, u'seqnum': 2, u'expType': u'object', u'object': u'MAGLITES field: 6575-01-r', u'filter': u'r', u'seqid': u'MAGLITES scheduled: 2016/02/12 07:41:00.0000', u'RA': 127.941, u'proposer': u'Bechtol', u'propid': u'2016A-0366', u'dec': -60.8294, u'expTime': 90.0, u'wait': u'False'}
value = {u'count': 1, u'program': u'maglites', u'seqtot': 1, u'seqnum': 1, u'expType': u'object', u'object': u'MAGLITES field: 6575-01-r', u'filter': u'r', u'seqid': u'MAGLITES scheduled: 2016/02/12 07:41:00.0000', u'RA': 127.941, u'proposer': u'Bechtol', u'propid': u'2016A-0366', u'dec': -60.8294, u'expTime': 90.0, u'wait': u'False'}

check_dict(value,out[index])

Expand All @@ -75,7 +76,7 @@ def NOTEST_schedule_survey():
assert len(out) == 30

index = 17
value = {u'count': 1, u'program': u'maglites', u'seqtot': 2, u'seqnum': 2, u'expType': u'object', u'object': u'MAGLITES field: 6687-01-r', u'filter': u'r', u'seqid': u'MAGLITES scheduled: 2016/02/14 08:46:30.0000', u'RA': 176.263, u'propid': u'2016A-0366', u'dec': -74.1112, u'expTime': 90.0, u'wait': u'False'}
value = {u'count': 1, u'program': u'maglites', u'seqtot': 1, u'seqnum': 1, u'expType': u'object', u'object': u'MAGLITES field: 6687-01-r', u'filter': u'r', u'seqid': u'MAGLITES scheduled: 2016/02/14 08:46:30.0000', u'RA': 176.263, u'propid': u'2016A-0366', u'dec': -74.1112, u'expTime': 90.0, u'wait': u'False'}
check_dict(value,out[index])

if __name__ == "__main__":
Expand Down
8 changes: 6 additions & 2 deletions tests/test_tactician.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,16 @@ def test_calculate_moon():
test_moon_angle = np.array([108.9487001, 97.8196126, 70.7322332, 51.6236834, 64.0174593, 93.9227775, 116.3650182, 111.7185502, 88.2697742, 71.4721274])
# With topocentric correction
test_moon_angle = np.array([109.6670211, 98.396651, 71.3473021, 52.4287292, 64.6183409, 94.124153, 116.0532799, 111.0075416, 87.4853729, 70.7408394])
# Newer version of ephem (2023)
test_moon_angle = np.array([109.6670216, 98.3966407, 71.3472944, 52.4287432, 64.6183752, 94.1241885, 116.0533029, 111.0075417, 87.4853641, 70.7408376])

np.testing.assert_almost_equal(tac.moon_angle,test_moon_angle,
np.testing.assert_almost_equal(tac.moon_angle,test_moon_angle,decimal=5,
err_msg='moon_angle')

test_moon_phase = 89.82009887695312
np.testing.assert_almost_equal(tac.moon_phase,test_moon_phase,
# Newer version of ephem (2023)
test_moon_phase = 89.82008361816406
np.testing.assert_almost_equal(tac.moon_phase,test_moon_phase, decimal=4,
err_msg='moon_phase')

def test_calculate_slew():
Expand Down

0 comments on commit ddab4ec

Please sign in to comment.