Skip to content

Commit

Permalink
Merge branch 'devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhandberg committed Jun 29, 2021
2 parents 5199951 + 0e3798a commit f25abe5
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 75 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tests/input/** filter=lfs diff=lfs merge=lfs -text
62 changes: 0 additions & 62 deletions .github/workflows/deploy.yml

This file was deleted.

134 changes: 123 additions & 11 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,57 @@ on:
- cron: '0 6 1 * *' # once a month in the morning

jobs:
# Use the `flake8` tool to check for syntax errors
flake8:
name: Flake8
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup Python 3.7
uses: actions/setup-python@v2
with:
python-version: 3.7

- name: Cache pip
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-py3.7-${{ hashFiles('requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-py3.7-
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip wheel
grep "numpy" requirements.txt | xargs -I {} pip install "{}"
pip install -r requirements.txt
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
# For some reason we have to specifically ignore G001 as well
flake8 --select=E9,F63,F7,F82 --ignore=G001 --show-source
# exit-zero treats all errors as warnings.
flake8 --exit-zero
# Run unit tests on Linux, OSX and Windows
pytest:
needs: flake8
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: [3.6, 3.7, 3.8]
include:
- os: ubuntu-latest
pippath: ~/.cache/pip
- os: macos-latest
pippath: ~/Library/Caches/pip
- os: windows-latest
pippath: ~\AppData\Local\pip\Cache

name: Python ${{ matrix.python-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
Expand All @@ -33,11 +77,33 @@ jobs:
with:
fetch-depth: 0

- name: Create LFS file list
run: git lfs ls-files -l | cut -d' ' -f1 | sort > .lfs-assets-id

- name: Restore LFS cache
uses: actions/cache@v2
id: lfs-cache
with:
path: .git/lfs
key: ${{ runner.os }}-lfs-${{ hashFiles('.lfs-assets-id') }}-v1

- name: Git LFS Pull
run: git lfs pull

- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Cache pip
uses: actions/cache@v2
with:
path: ${{ matrix.pippath }}
key: ${{ runner.os }}-pip-py${{ matrix.python-version }}-${{ hashFiles('requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-py${{ matrix.python-version }}-
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip wheel
Expand All @@ -53,30 +119,76 @@ jobs:
with:
env_vars: OS,PYTHON


# Use the `flake8` tool to check for syntax errors
flake8:
name: Flake8
# Release tagged commits to:
release:
name: Create release
if: startsWith( github.ref, 'refs/tags/v' )
needs: pytest
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Create LFS file list
run: git lfs ls-files -l | cut -d' ' -f1 | sort > .lfs-assets-id

- name: Restore LFS cache
uses: actions/cache@v2
id: lfs-cache
with:
path: .git/lfs
key: ${{ runner.os }}-lfs-${{ hashFiles('.lfs-assets-id') }}-v1

- name: Git LFS Pull
run: git lfs pull

- name: Setup Python 3.7
uses: actions/setup-python@v2
with:
python-version: 3.7

- name: Cache pip
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-py3.7-${{ hashFiles('requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-py3.7-
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip wheel
grep "numpy" requirements.txt | xargs -I {} pip install "{}"
pip install -r requirements.txt
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
# For some reason we have to specifically ignore G001 as well
flake8 --select=E9,F63,F7,F82 --ignore=G001 --show-source
# exit-zero treats all errors as warnings.
flake8 --exit-zero
- name: Update VERSION file
run: python -c "from flows import version; version.update_release_version();"

- name: Set env
id: vars
run: echo ::set-output name=tag::${GITHUB_REF#refs/tags/v}

- name: Generate changelog
id: changelog
uses: metcalfc/changelog-generator@v1.0.0
with:
myToken: ${{ secrets.GITHUB_TOKEN }}

- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Version ${{ steps.vars.outputs.tag }}
body: |
Version ${{ steps.vars.outputs.tag }}
Changelog
---------
${{ steps.changelog.outputs.changelog }}
draft: true
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
master-v0.7.8
master-v0.7.9
2 changes: 1 addition & 1 deletion flows/load_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def load_image(FILENAME):
elif telescope == 'SAI-2.5' and instrument == 'ASTRONIRCAM':
image.site = api.get_site(13) # Hard-coded the siteid for Caucasus Mountain Observatory
if 'MIDPOINT' in hdr:
image.obstime = Time(hdr['MIDPOINT'], format='mjd', scale='utc', location=image.site['EarthLocation'])
image.obstime = Time(hdr['MIDPOINT'], format='isot', scale='utc', location=image.site['EarthLocation'])
else:
image.obstime = Time(hdr['MJD-AVG'], format='mjd', scale='utc', location=image.site['EarthLocation'])
image.photfilter = {
Expand Down
3 changes: 3 additions & 0 deletions tests/input/SN2020aatc_K_20201213_495s.fits.gz
Git LFS file not shown
42 changes: 42 additions & 0 deletions tests/test_load_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Test loading of images.
.. codeauthor:: Rasmus Handberg <rasmush@phys.au.dk>
"""

import pytest
import numpy as np
from astropy.time import Time
from astropy.wcs import WCS
import os.path
import conftest
from flows.load_image import load_image

#--------------------------------------------------------------------------------------------------
@pytest.mark.parametrize('fpath', ['SN2020aatc_K_20201213_495s.fits.gz'])
def test_load_image(fpath):

# The test input directory containing the test-images:
INPUT_DIR = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'input')

# Load the image from the test-set:
img = load_image(os.path.join(INPUT_DIR, fpath))

# Check the attributes of the image object:
assert isinstance(img.image, np.ndarray)
assert img.image.dtype in ('float32', 'float64')
assert isinstance(img.mask, np.ndarray)
assert img.mask.dtype == 'bool'
assert isinstance(img.clean, np.ma.MaskedArray)
assert img.clean.dtype == img.image.dtype
assert isinstance(img.obstime, Time)
assert isinstance(img.exptime, float)
assert img.exptime > 0
assert isinstance(img.photfilter, str)
assert isinstance(img.wcs, WCS)

#--------------------------------------------------------------------------------------------------
if __name__ == '__main__':
pytest.main([__file__])

0 comments on commit f25abe5

Please sign in to comment.