Skip to content

Commit

Permalink
Merge pull request #45 from ratt-ru/chaos
Browse files Browse the repository at this point in the history
Chaos
  • Loading branch information
o-smirnov authored Jun 10, 2024
2 parents 76f06d9 + 976c81a commit 6d65b43
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 170 deletions.
42 changes: 26 additions & 16 deletions .github/workflows/publish_package.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,41 @@
# This workflows will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
# This workflow will upload a Python Package using Twine when a release is created
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Upload Python Package

on:
release:
types: [created]
types: [published]

permissions:
contents: read

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v1
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.4.0
virtualenvs-create: true
installer-parallel: false
- name: Install package
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
poetry install --with docs --no-interaction
- name: Build and publish to pypi
uses: JRubics/[email protected]
with:
pypi_token: ${{ secrets.PYPI_API_TOKEN }}
39 changes: 21 additions & 18 deletions .github/workflows/test_installation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,51 +23,54 @@ jobs:
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.4.0
virtualenvs-create: true
installer-parallel: false
- name: Install package
run: |
python -m pip install --upgrade pip
pip install --upgrade setuptools wheel
pip install flake8 pytest
pip install .
poetry install --with tests --no-interaction
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
poetry run 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
poetry run flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test conversion to .txt models
run: |
tigger-convert $GITHUB_WORKSPACE/test/3C147-HI6.refmodel.lsm.html /tmp/output.txt -f \
poetry run tigger-convert $GITHUB_WORKSPACE/test/3C147-HI6.refmodel.lsm.html /tmp/output.txt -f \
--output-format "name ra_d dec_d i q u v i q u v spi rm emaj_s emin_s pa_d freq0"
tigger-convert $GITHUB_WORKSPACE/test/3C147-HI6.refmodel.lsm.html /tmp/output.recentred.txt -f --center 85.5deg,49.9deg --rename \
poetry run tigger-convert $GITHUB_WORKSPACE/test/3C147-HI6.refmodel.lsm.html /tmp/output.recentred.txt -f --center 85.5deg,49.9deg --rename \
--output-format "name ra_d dec_d i q u v i q u v spi rm emaj_s emin_s pa_d freq0"
echo "Checking reference LSM"
diff $GITHUB_WORKSPACE/test/3C147-HI6.refmodel.reference.txt /tmp/output.txt
echo "Checking recentred reference LSM"
diff $GITHUB_WORKSPACE/test/3C147-HI6.refmodel.recentred.reference.txt /tmp/output.recentred.txt
- name: Test reverse conversion to .lsm.html models
run: |
tigger-convert /tmp/output.txt /tmp/output.lsm.html -f
poetry run tigger-convert /tmp/output.txt /tmp/output.lsm.html -f
- name: Test .gaul conversions
run: |
tigger-convert $GITHUB_WORKSPACE/test/deep4.gaul /tmp/deep4.lsm.html -f
tigger-convert $GITHUB_WORKSPACE/test/deep4.gaul /tmp/deep4.txt -f --output-format "name ra_d dec_d i q u v spi rm emaj_s emin_s pa_d freq0"
poetry run tigger-convert $GITHUB_WORKSPACE/test/deep4.gaul /tmp/deep4.lsm.html -f
poetry run tigger-convert $GITHUB_WORKSPACE/test/deep4.gaul /tmp/deep4.txt -f --output-format "name ra_d dec_d i q u v spi rm emaj_s emin_s pa_d freq0"
diff $GITHUB_WORKSPACE/test/deep4.reference.txt /tmp/deep4.txt
- name: Test .AIPSCC conversions
run: |
gunzip <$GITHUB_WORKSPACE/test/3C147-L-A-CLEAN.fits.gz >/tmp/3C147-L-A-CLEAN.fits
tigger-convert /tmp/3C147-L-A-CLEAN.fits /tmp/3C147-L-A-CLEAN.fits.lsm.html -f
tigger-convert /tmp/3C147-L-A-CLEAN.fits.lsm.html /tmp/3C147-L-A-CLEAN.txt -f --output-format "name ra_d dec_d i q u v"
poetry run tigger-convert /tmp/3C147-L-A-CLEAN.fits /tmp/3C147-L-A-CLEAN.fits.lsm.html -f
poetry run tigger-convert /tmp/3C147-L-A-CLEAN.fits.lsm.html /tmp/3C147-L-A-CLEAN.txt -f --output-format "name ra_d dec_d i q u v"
zdiff $GITHUB_WORKSPACE/test/3C147-L-A-CLEAN.txt.gz /tmp/3C147-L-A-CLEAN.txt
- name: Testing tigger-restore and tigger-make-brick
run: |
cp $GITHUB_WORKSPACE/test/3C147tmp.fits /tmp
tigger-make-brick $GITHUB_WORKSPACE/test/3C147-HI6.refmodel.lsm.html /tmp/3C147tmp.fits
tigger-restore -f $GITHUB_WORKSPACE/test/3C147tmp.fits $GITHUB_WORKSPACE/test/3C147-HI6.refmodel.lsm.html /tmp/restored.fits
poetry run tigger-make-brick $GITHUB_WORKSPACE/test/3C147-HI6.refmodel.lsm.html /tmp/3C147tmp.fits
poetry run tigger-restore -f $GITHUB_WORKSPACE/test/3C147tmp.fits $GITHUB_WORKSPACE/test/3C147-HI6.refmodel.lsm.html /tmp/restored.fits
- name: Test tigger-tag
run: |
tigger-tag $GITHUB_WORKSPACE/test/3C147-HI6.refmodel.lsm.html 'r<0.5d' inner=1 -o /tmp/tmp.lsm.html -f
poetry run tigger-tag $GITHUB_WORKSPACE/test/3C147-HI6.refmodel.lsm.html 'r<0.5d' inner=1 -o /tmp/tmp.lsm.html -f
- name: Test .lsm to ds9 region file conversion
run: |
echo "Checking lsm.html to .reg conversion"
tigger-convert $GITHUB_WORKSPACE/test/3C147-HI6.refmodel.lsm.html /tmp/3C147-HI6.refmodel.lsm.reg -f
poetry run tigger-convert $GITHUB_WORKSPACE/test/3C147-HI6.refmodel.lsm.html /tmp/3C147-HI6.refmodel.lsm.reg -f
80 changes: 9 additions & 71 deletions .travis/py3.docker
Original file line number Diff line number Diff line change
@@ -1,100 +1,38 @@
FROM kernsuite/base:6
FROM kernsuite/base:9

RUN docker-apt-install python3-casacore casacore-dev casacore-data makems casarest \
python3-pip git wget cmake libblitz0-dev libqdbm-dev \
libfftw3-dev wcslib-dev libcfitsio-dev \
'libcasa-*' liblapack-dev libatlas-base-dev
'libcasa-*' liblapack-dev libatlas-base-dev 2to3

RUN pip3 install -U pip setuptools wheel
RUN pip install -U pip setuptools wheel
#######################################
# Install python 3 meqtrees
#######################################

WORKDIR /code
ADD . /code/tigger-lsm
RUN pip3 install ./tigger-lsm

# add additional Timba dependencies
RUN docker-apt-install python3-pyqt4 python3-pyqt5
RUN docker-apt-install meqtrees-timba
WORKDIR /src
RUN wget https://codeload.github.com/ska-sa/meqtrees-cattery/tar.gz/refs/tags/v1.7.1 && \
tar zxvf v1.7.1 && \
rm v1.7.1
RUN wget https://codeload.github.com/ska-sa/purr/tar.gz/refs/tags/v1.5.0 && \
tar zxvf v1.5.0 && \
rm v1.5.0
RUN wget https://codeload.github.com/ska-sa/owlcat/tar.gz/refs/tags/v1.6.0 && \
tar zxvf v1.6.0 && \
rm v1.6.0
RUN wget https://codeload.github.com/ska-sa/kittens/tar.gz/refs/tags/v1.4.3 && \
tar zxvf v1.4.3 && \
rm v1.4.3
RUN wget https://codeload.github.com/ska-sa/pyxis/tar.gz/refs/tags/v1.7.1 && \
tar zxvf v1.7.1 && \
rm v1.7.1

RUN pip3 install ./meqtrees-cattery-1.7.1 ./purr-1.5.0 ./owlcat-1.6.0 ./kittens-1.4.3
RUN pip3 install -e ./pyxis-1.7.1

WORKDIR /src
RUN wget https://codeload.github.com/ska-sa/meqtrees-timba/tar.gz/refs/tags/v1.8.0 && \
tar zxvf v1.8.0 && \
rm v1.8.0
RUN mkdir /src/meqtrees-timba-1.8.0/build
WORKDIR /src/meqtrees-timba-1.8.0/build
RUN cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release -DENABLE_PYTHON_3=ON ..
RUN make
RUN make install
RUN ldconfig
WORKDIR /code
ADD . /code/tigger-lsm
RUN pip install ./tigger-lsm

RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.6 2
# basic install tests
RUN pip install pynose owlcat
RUN flag-ms.py --help
RUN meqtree-pipeliner.py --help
RUN pyxis --help

#######################################
# run oleg's new tests
#######################################
ENV GITHUB_WORKSPACE=/code/tigger-lsm
# Test conversion to .txt models
RUN tigger-convert $GITHUB_WORKSPACE/test/3C147-HI6.refmodel.lsm.html /tmp/output.txt -f \
--output-format "name ra_d dec_d i q u v i q u v spi rm emaj_s emin_s pa_d freq0"
RUN tigger-convert $GITHUB_WORKSPACE/test/3C147-HI6.refmodel.lsm.html /tmp/output.recentred.txt -f --center 85.5deg,49.9deg --rename \
--output-format "name ra_d dec_d i q u v i q u v spi rm emaj_s emin_s pa_d freq0"
RUN echo "Checking reference LSM"
RUN diff $GITHUB_WORKSPACE/test/3C147-HI6.refmodel.reference.txt /tmp/output.txt
RUN echo "Checking recentred reference LSM"
RUN diff $GITHUB_WORKSPACE/test/3C147-HI6.refmodel.recentred.reference.txt /tmp/output.recentred.txt

#Test reverse conversion to .lsm.html models
RUN tigger-convert /tmp/output.txt /tmp/output.lsm.html -f

#Test .gaul conversions
RUN tigger-convert $GITHUB_WORKSPACE/test/deep4.gaul /tmp/deep4.lsm.html -f
RUN tigger-convert $GITHUB_WORKSPACE/test/deep4.gaul /tmp/deep4.txt -f --output-format "name ra_d dec_d i q u v spi rm emaj_s emin_s pa_d freq0"
RUN diff $GITHUB_WORKSPACE/test/deep4.reference.txt /tmp/deep4.txt

# Test .AIPSCC conversions
RUN gunzip <$GITHUB_WORKSPACE/test/3C147-L-A-CLEAN.fits.gz >/tmp/3C147-L-A-CLEAN.fits
RUN tigger-convert /tmp/3C147-L-A-CLEAN.fits /tmp/3C147-L-A-CLEAN.fits.lsm.html -f
RUN tigger-convert /tmp/3C147-L-A-CLEAN.fits.lsm.html /tmp/3C147-L-A-CLEAN.txt -f --output-format "name ra_d dec_d i q u v"
RUN zdiff $GITHUB_WORKSPACE/test/3C147-L-A-CLEAN.txt.gz /tmp/3C147-L-A-CLEAN.txt

# Testing tigger-restore and tigger-make-brick
RUN cp $GITHUB_WORKSPACE/test/3C147tmp.fits /tmp
RUN tigger-make-brick $GITHUB_WORKSPACE/test/3C147-HI6.refmodel.lsm.html /tmp/3C147tmp.fits
RUN tigger-restore -f $GITHUB_WORKSPACE/test/3C147tmp.fits $GITHUB_WORKSPACE/test/3C147-HI6.refmodel.lsm.html /tmp/restored.fits

#Test tigger-tag
RUN tigger-tag $GITHUB_WORKSPACE/test/3C147-HI6.refmodel.lsm.html 'r<0.5d' inner=1 -o /tmp/tmp.lsm.html -f

#######################################
# end to end test
#######################################
RUN pip3 install nose
WORKDIR /src/pyxis-1.7.1/Pyxis/recipes/meqtrees-batch-test
RUN python3 -m "nose"
RUN pynose

ENTRYPOINT ["meqtree-pipeliner.py"]
CMD ["--help"]
Empty file added Tigger/bin/__init__.py
Empty file.
17 changes: 6 additions & 11 deletions Tigger/bin/tigger-convert → Tigger/bin/tigger_convert.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import numpy
import os.path
import Cattery.Siamese.OMS.Utils as Utils

DEG = math.pi / 180

Expand Down Expand Up @@ -81,7 +82,7 @@ def rotatelm(l0, m0, rotangle):
return l, m


if __name__ == '__main__':
def main():
import Kittens.utils

_verbosity = Kittens.utils.verbosity(name="convert-model")
Expand Down Expand Up @@ -460,7 +461,7 @@ def convert_coordinates(coords):
# recompute 'r' attribute (unless --center is in effect, in which case it's going to be done anyway below)
if options.refresh_r:
for src in model2.sources:
src.setAttribute('r', Coordinates.angular_dist_pos_angle(ra0, dec0, *model.fieldCenter())[0])
src.setAttribute('r', Coordinates.angular_dist_pos_angle(src.pos.ra, src.pos.dec, *model.fieldCenter())[0])
print("Appended %d sources from %s (%s)" % (len(model2.sources), filename, append_doc))

# apply center, if specified
Expand Down Expand Up @@ -514,8 +515,8 @@ def convert_coordinates(coords):
tags = ff[3:] if len(ff) > 3 else []
except:
parser.error("Invalid --add-brick setting %s" % brickspec)
if [src.name for src in sources if src.name == name]:
print("Error: model already contains a source named '%s'" % name)
if [src.name for src in sources if src.name == srcname]:
print("Error: model already contains a source named '%s'" % srcname)
# add brick
from astropy.io import fits as pyfits
from astLib.astWCS import WCS
Expand Down Expand Up @@ -660,12 +661,6 @@ def getTagValue(src, tag):
REIM = "re", "im"
REALIMAG = dict(re="real", im="imag")

# get the Cattery
for varname in 'CATTERY_PATH', "MEQTREES_CATTERY_PATH":
if varname in os.environ:
sys.path.append(os.environ[varname])

import Siamese.OMS.Utils as Utils


def make_beam_filename(filename_pattern, corr, reim):
Expand All @@ -681,7 +676,7 @@ def make_beam_filename(filename_pattern, corr, reim):
filename_real = []
filename_imag = []
# load beam interpolator
import Siamese.OMS.InterpolatedBeams as InterpolatedBeams
import Cattery.Siamese.OMS.InterpolatedBeams as InterpolatedBeams

vbs = []
for icorr, corr in enumerate(CORRS_XY if options.linear_pol else CORRS_RL):
Expand Down
4 changes: 2 additions & 2 deletions Tigger/bin/tigger-make-brick → Tigger/bin/tigger_make_brick.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

NATIVE = "Tigger"

if __name__ == '__main__':
def main():
import Kittens.utils

_verbosity = Kittens.utils.verbosity(name="convert-model")
Expand Down Expand Up @@ -221,7 +221,7 @@
src.flux.I = max_flux
src.shape.ex, src.shape.ey = sx, sy
src.shape.nx, src.shape.ny = nx, ny
src.shape.pad = pad
src.shape.pad = options.pad
break
# not contained, make new source object
else:
Expand Down
4 changes: 2 additions & 2 deletions Tigger/bin/tigger-restore → Tigger/bin/tigger_restore.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from astropy.io import fits as pyfits
from past.builtins import cmp

if __name__ == '__main__':
def main():

import Tigger.Models.Formats
from Tigger.Models.Formats import ASCII
Expand Down Expand Up @@ -196,7 +196,7 @@
if not isinstance(dum, float):
raise TypeError("Primary beam expression does not evaluate to a float")
except Exception as exc:
print("Bad primary beam expression '%s': %s" % (pb, str(exc)))
print("Bad primary beam expression '%s': %s" % (options.pb, str(exc)))
sys.exit(1)
if not freq:
print("Model must contain a reference requency, or else specify one with --freq.")
Expand Down
8 changes: 5 additions & 3 deletions Tigger/bin/tigger-tag → Tigger/bin/tigger_tag.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def transfer_tags(fromlsm, lsm, output, tags, tolerance, tigger):
model.save(output)


if __name__ == '__main__':
def main():
import Kittens.utils

_verbosity = Kittens.utils.verbosity(name="convert-model")
Expand Down Expand Up @@ -172,13 +172,15 @@ def transfer_tags(fromlsm, lsm, output, tags, tolerance, tigger):

# This is where we accumulate the result of selection arguments, until we hit the first tagging argument.
# Initially None, meaning no explicit selection
global selected_ids
selected_ids = None

# This is where we put the selection when we hit the first tagging argument.
global selection
selection = None

# this is set to true when the selection is listed
listed = False
global listed
# set to true when the model is modified
modified = False

Expand Down Expand Up @@ -300,7 +302,7 @@ def lookupObject(src, tagname):
# else some other type is specified -- use it to convert the value
elif typename:
try:
newval = getattr(__builtin__, typename)(value)
newval = getattr(globals()["__builtin__"], typename)(value)
except:
print("Can't parse \"%s\" as a value of type %s" % (value, typename))
sys.exit(2)
Expand Down
Loading

0 comments on commit 6d65b43

Please sign in to comment.