diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..798ded5 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +tests/input/** filter=lfs diff=lfs merge=lfs -text diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml deleted file mode 100644 index 4c21af7..0000000 --- a/.github/workflows/deploy.yml +++ /dev/null @@ -1,62 +0,0 @@ -# GitHub Actions workflow for Flows's deployment. - -name: Deploy - -# Run this action every time a tagged push is done. -# TODO: Only run this action after testing has completed -on: - push: - # Sequence of patterns matched against refs/tags - tags: - - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 - -jobs: - release: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - - 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 - grep "numpy" requirements.txt | xargs -I {} pip install "{}" - pip install -r requirements.txt - - - name: Update VERSION file - run: python -c "from flows import version; version.update_release_version();" - - - 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 ${GITHUB_REF##*/} - body: | - Version ${GITHUB_REF##*/} - ${{ steps.changelog.outputs.changelog }} - draft: true diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 74d0130..e131cce 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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 }} @@ -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 @@ -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 diff --git a/VERSION b/VERSION index b2977ae..9e9d6da 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -master-v0.7.8 \ No newline at end of file +master-v0.7.9 \ No newline at end of file diff --git a/flows/load_image.py b/flows/load_image.py index 3e47795..cefbdeb 100644 --- a/flows/load_image.py +++ b/flows/load_image.py @@ -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 = { diff --git a/tests/input/SN2020aatc_K_20201213_495s.fits.gz b/tests/input/SN2020aatc_K_20201213_495s.fits.gz new file mode 100644 index 0000000..0b00ece --- /dev/null +++ b/tests/input/SN2020aatc_K_20201213_495s.fits.gz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:94a1bdcfbfd75da8c66f7d37271125353953acb16d087982d4241f05f9864c6a +size 2909171 diff --git a/tests/test_load_image.py b/tests/test_load_image.py new file mode 100644 index 0000000..77a8f07 --- /dev/null +++ b/tests/test_load_image.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Test loading of images. + +.. codeauthor:: Rasmus Handberg +""" + +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__])