diff --git a/.github/workflows/publish_package.yml b/.github/workflows/publish_package.yml index a605e1c..0a81b8f 100644 --- a/.github/workflows/publish_package.yml +++ b/.github/workflows/publish_package.yml @@ -1,11 +1,19 @@ -# 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: @@ -13,19 +21,21 @@ jobs: 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/poetry-publish@v1.16 + with: + pypi_token: ${{ secrets.PYPI_API_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/test_installation.yml b/.github/workflows/test_installation.yml index b0c2927..ce7041f 100644 --- a/.github/workflows/test_installation.yml +++ b/.github/workflows/test_installation.yml @@ -23,23 +23,26 @@ 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 @@ -47,27 +50,27 @@ jobs: 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 diff --git a/.travis/py3.docker b/.travis/py3.docker index fe1be67..8e8c5a4 100644 --- a/.travis/py3.docker +++ b/.travis/py3.docker @@ -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"] diff --git a/Tigger/bin/__init__.py b/Tigger/bin/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Tigger/bin/tigger-convert b/Tigger/bin/tigger_convert.py old mode 100755 new mode 100644 similarity index 99% rename from Tigger/bin/tigger-convert rename to Tigger/bin/tigger_convert.py index 701014b..feed4b1 --- a/Tigger/bin/tigger-convert +++ b/Tigger/bin/tigger_convert.py @@ -34,6 +34,7 @@ import numpy import os.path +import Cattery.Siamese.OMS.Utils as Utils DEG = math.pi / 180 @@ -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") @@ -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 @@ -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 @@ -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): @@ -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): diff --git a/Tigger/bin/tigger-make-brick b/Tigger/bin/tigger_make_brick.py old mode 100755 new mode 100644 similarity index 99% rename from Tigger/bin/tigger-make-brick rename to Tigger/bin/tigger_make_brick.py index a982628..6ddb866 --- a/Tigger/bin/tigger-make-brick +++ b/Tigger/bin/tigger_make_brick.py @@ -41,7 +41,7 @@ NATIVE = "Tigger" -if __name__ == '__main__': +def main(): import Kittens.utils _verbosity = Kittens.utils.verbosity(name="convert-model") @@ -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: diff --git a/Tigger/bin/tigger-restore b/Tigger/bin/tigger_restore.py old mode 100755 new mode 100644 similarity index 98% rename from Tigger/bin/tigger-restore rename to Tigger/bin/tigger_restore.py index f1ab844..0bf07e3 --- a/Tigger/bin/tigger-restore +++ b/Tigger/bin/tigger_restore.py @@ -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 @@ -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.") diff --git a/Tigger/bin/tigger-tag b/Tigger/bin/tigger_tag.py old mode 100755 new mode 100644 similarity index 99% rename from Tigger/bin/tigger-tag rename to Tigger/bin/tigger_tag.py index 03ffe55..dabbfba --- a/Tigger/bin/tigger-tag +++ b/Tigger/bin/tigger_tag.py @@ -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") @@ -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 @@ -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) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..3e46ad4 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,43 @@ +[tool.poetry] +name = "astro-tigger-lsm" +version = "1.7.4" +description = "Python libraries and command-line tools for manipulating Tigger LSMs" +authors = ["Oleg Smirnov "] +readme = "README.rst" +packages = [ + {include = "Tigger"}, +] + + +[tool.poetry.dependencies] +python = "^3.8" +astro-kittens = "^1.4.6" +numpy = "*" +scipy = "*" +astlib = [ + { version = "<=0.11.10", python = ">=3.8"}, + { version = "<=0.11.8", python = "<=3.8"} +] +astropy = "*" +future = "*" +python-casacore = "*" +meqtrees-cattery = "^1.7.9" + +[tool.poetry.scripts] +tigger-convert = "Tigger.bin.tigger_convert:main" +tigger-tag = "Tigger.bin.tigger_tag:main" +tigger-restore = "Tigger.bin.tigger_restore:main" +tigger-make-brick = "Tigger.bin.tigger_make_brick:main" + + +[tool.poetry.group.tests] +optional = true +[tool.poetry.group.tests.dependencies] +pytest = "^7.1.3" +flake8 = "*" + + + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" diff --git a/setup.py b/setup.py deleted file mode 100644 index 2db7f52..0000000 --- a/setup.py +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env python3 - - -from setuptools import setup, find_packages - -__version__ = "1.7.3" - -# PyQt 5 has not been added here are. It needs to be installed via apt-get which is a Tigger v1.6.0 requirement. -requirements = ['astro_kittens', - 'numpy', - 'scipy', - 'astlib<=0.11.10; python_version >="3.8"', - 'astlib<=0.11.8; python_version <"3.8"', - 'astropy', - 'future', - 'python-casacore' -] - -scripts = [ - 'Tigger/bin/tigger-convert', - 'Tigger/bin/tigger-make-brick', - 'Tigger/bin/tigger-restore', - 'Tigger/bin/tigger-tag', -] - -package_data = { -} - -extras_require = { -} - - -setup( - name="astro-tigger-lsm", - version=__version__, - packages=find_packages(), - extras_require=extras_require, - scripts=scripts, - package_data=package_data, - python_requires='>=3.6', - description="Python libraries and command-line tools for manipulating Tigger-format LSMs", - author="Oleg Smirnov", - author_email="osmirnov@gmail.com", - url="https://github.com/ska-sa/tigger-lsm", - install_requires=requirements, -) -