From a091c73d58f78958b93760a3d07f916929574a35 Mon Sep 17 00:00:00 2001 From: Erin Sheldon Date: Tue, 13 May 2025 12:27:20 -0400 Subject: [PATCH 1/7] use longdouble rather than 'f16' 'f16' is no longer supported --- pymangle/mangle.py | 34 +++++++++++++++++----------------- pymangle/version.py | 2 +- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/pymangle/mangle.py b/pymangle/mangle.py index f20d3ea..53d477b 100644 --- a/pymangle/mangle.py +++ b/pymangle/mangle.py @@ -18,7 +18,7 @@ from __future__ import print_function, absolute_import -from numpy import array +from numpy import array, longdouble from . import _mangle @@ -91,8 +91,8 @@ def polyid_and_weight(self, ra, dec): ------ polyd,weight tuple of arrays """ - ra = array(ra, ndmin=1, dtype='f16', copy=False, order='C') - dec = array(dec, ndmin=1, dtype='f16', copy=False, order='C') + ra = array(ra, ndmin=1, dtype=longdouble, copy=False, order='C') + dec = array(dec, ndmin=1, dtype=longdouble, copy=False, order='C') return super(Mangle, self).polyid_and_weight(ra, dec) def polyid(self, ra, dec): @@ -110,8 +110,8 @@ def polyid(self, ra, dec): ------ Array of poly ids """ - ra = array(ra, ndmin=1, dtype='f16', copy=False, order='C') - dec = array(dec, ndmin=1, dtype='f16', copy=False, order='C') + ra = array(ra, ndmin=1, dtype=longdouble, copy=False, order='C') + dec = array(dec, ndmin=1, dtype=longdouble, copy=False, order='C') return super(Mangle, self).polyid(ra, dec) def weight(self, ra, dec): @@ -129,8 +129,8 @@ def weight(self, ra, dec): ------ Array of weights """ - ra = array(ra, ndmin=1, dtype='f16', copy=False, order='C') - dec = array(dec, ndmin=1, dtype='f16', copy=False, order='C') + ra = array(ra, ndmin=1, dtype=longdouble, copy=False, order='C') + dec = array(dec, ndmin=1, dtype=longdouble, copy=False, order='C') return super(Mangle, self).weight(ra, dec) def contains(self, ra, dec): @@ -149,8 +149,8 @@ def contains(self, ra, dec): Array of zeros or ones """ # we specify order to force contiguous - ra = array(ra, ndmin=1, dtype='f16', copy=False, order='C') - dec = array(dec, ndmin=1, dtype='f16', copy=False, order='C') + ra = array(ra, ndmin=1, dtype=longdouble, copy=False, order='C') + dec = array(dec, ndmin=1, dtype=longdouble, copy=False, order='C') return super(Mangle, self).contains(ra, dec) def check_quadrants(self, @@ -194,10 +194,10 @@ def check_quadrants(self, 2**4 is set if fourth quadrant is OK """ # we specify order to force contiguous - ra = array(ra, ndmin=1, dtype='f16', copy=False, order='C') - dec = array(dec, ndmin=1, dtype='f16', copy=False, order='C') + ra = array(ra, ndmin=1, dtype=longdouble, copy=False, order='C') + dec = array(dec, ndmin=1, dtype=longdouble, copy=False, order='C') angle_degrees = array( - angle_degrees, ndmin=1, dtype='f16', copy=False, order='C' + angle_degrees, ndmin=1, dtype=longdouble, copy=False, order='C' ) return super(Mangle, self).check_quadrants( ra, dec, angle_degrees, @@ -219,8 +219,8 @@ def calc_simplepix(self, ra, dec): ------ Array of zeros or ones """ - ra = array(ra, ndmin=1, dtype='f16', copy=False) - dec = array(dec, ndmin=1, dtype='f16', copy=False) + ra = array(ra, ndmin=1, dtype=longdouble, copy=False) + dec = array(dec, ndmin=1, dtype=longdouble, copy=False) return super(Mangle, self).calc_simplepix(ra, dec) def _set_weights(self, weights): @@ -232,7 +232,7 @@ def _set_weights(self, weights): ) # make long doubles - weights = array(weights, ndmin=1, dtype='f16', copy=False) + weights = array(weights, ndmin=1, dtype=longdouble, copy=False) super(Mangle, self).set_weights(weights) @@ -299,7 +299,7 @@ def set(self, data): data: array or sequence An length 4 array of 128 bit floats, or convertable to that. """ - data = array(data, ndmin=1, dtype='f16', copy=False) + data = array(data, ndmin=1, dtype=longdouble, copy=False) if data.size != 4: raise ValueError( "capdata must be an array of length 4, got %d" % data.size @@ -414,7 +414,7 @@ def __init__(self, poly_id, pixel_id, weight, cap_vec): raise ValueError("cap_vec must be of " "type CapVec, got %s" % type(cap_vec)) - wtarr = array(weight, ndmin=1, dtype='f16', copy=False) + wtarr = array(weight, ndmin=1, dtype=longdouble, copy=False) super(Polygon, self).__init__( poly_id, diff --git a/pymangle/version.py b/pymangle/version.py index 7582adb..dd0b676 100644 --- a/pymangle/version.py +++ b/pymangle/version.py @@ -2,4 +2,4 @@ # 1) we don't load dependencies by storing it in __init__.py # 2) we can import it in setup.py for the same reason # 3) we can import it into the module -__version__ = '0.9.2' +__version__ = '0.9.3' From a3326dd052a9d3fe7363535262224ac35dc895f0 Mon Sep 17 00:00:00 2001 From: Erin Sheldon Date: Tue, 13 May 2025 12:42:53 -0400 Subject: [PATCH 2/7] remove extra noqa --- tests/testmangle.py | 259 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 259 insertions(+) create mode 100644 tests/testmangle.py diff --git a/tests/testmangle.py b/tests/testmangle.py new file mode 100644 index 0000000..b4db071 --- /dev/null +++ b/tests/testmangle.py @@ -0,0 +1,259 @@ +import os +import tempfile +import numpy as np + +from pymangle import Mangle + + +def test_standard_unpixelized(): + + """ + a basic mask with standard header, no pixelization + """ + + text = """3 polygons +snapped +polygon 0 ( 4 caps, 1 weight, 0 pixel, 0.101732020850849 str): +0.0871557427476579 -0.9961946980917455 0.0000000000000001 -0.2568551745226059 +0.0871557427476579 -0.9961946980917455 0.0000000000000001 1.422618261740699 +0.2367814257465403 0.0207156904863277 -0.9713420698132612 1 +0.1515445107781580 0.0132584267126710 -0.9883615104677608 -1 +polygon 1 ( 4 caps, 1 weight, 0 pixel, 0.054242425709277 str): +0.0871557427476579 -0.9961946980917455 0.0000000000000001 -0.2568551745226059 +0.0871557427476579 -0.9961946980917455 0.0000000000000001 1.5 +0.1515445107781580 0.0132584267126710 -0.9883615104677608 1 +0.1084526035253447 0.0094883733383393 -0.9940563382223196 -1 +polygon 2 ( 4 caps, 1 weight, 0 pixel, 0.302363552547417 str): +0.0871557427476579 -0.9961946980917455 0.0000000000000001 -0.2568551745226059 +0.0871557427476579 -0.9961946980917455 0.0000000000000001 1.642787609686539 +0.1084526035253447 0.0094883733383393 -0.9940563382223196 1 +-0.1084526035253447 -0.0094883733383393 -0.9940563382223196 -1\n""" + + with tempfile.TemporaryDirectory() as tmpdir: + fname = os.path.join(tmpdir, 'test.ply') + + with open(fname, 'w') as fobj: + fobj.write(text) + + m = Mangle(fname) + ra, dec = m.genrand(3) + + +def test_standard_pixelized(): + """ + standard header with pixel + """ + + text = """3 polygons +pixelization 9s +snapped +balkanized +polygon 0 ( 4 caps, 1 weight, 87381 pixel, 0.000000000129178 str): + 0.9999999991588143 0.0000410152374105 0.0000003490658505 0.998159921767887 + 0.9659041924494473 -0.2588997625991339 -0.0000627271332757 -0.9982831417433783 + -0.0000000000000000 1.0000000000000000 0.0000000000000000 1 + -0.0122715382857199 0.9999247018391445 0.0000000000000000 -1 +polygon 1 ( 4 caps, 1 weight, 87381 pixel, 0.000000067701897 str): + -0.9647577286061684 -0.2584481766449109 0.0494678186661570 -1 + 0.2587637821532441 -0.9659406319340194 -0.0000249931148859 -0.9872370563678581 + -0.0122715382857199 0.9999247018391445 0.0000000000000000 -1 + 0.0000000000000000 0.0000000000000000 1.0000000000000000 0.00390625 +polygon 2 ( 5 caps, 1 weight, 87381 pixel, 0.000000311118396 str): + -0.9647577286061684 -0.2584481766449109 0.0494678186661570 1 + 0.2587637821532441 -0.9659406319340194 -0.0000249931148859 -0.9872370563678581 + -0.9987456407765712 0.0000501504038277 0.0500713742045613 -1 + -0.0122715382857199 0.9999247018391445 0.0000000000000000 -1 + 0.0000000000000000 0.0000000000000000 1.0000000000000000 0.00390625\n""" # noqa + + with tempfile.TemporaryDirectory() as tmpdir: + fname = os.path.join(tmpdir, 'test.ply') + with open(fname, 'w') as fobj: + fobj.write(text) + + _ = Mangle(fname) + + +def test_nopixel(): + """ + standard header with no pixels in the header + """ + + text = """3 polygons +polygon 0 ( 4 caps, 1.0000000 weight, 0.0074088006084970 str): +-0.06081623141086969775 -0.00532073080682029988 0.99813479842186692004 -1.00000000000000000000 +0.08715574274765790219 -0.99619469809174554520 0.00000000000000010000 -0.21198924639327809682 +0.08715574274765790219 -0.99619469809174554520 0.00000000000000010000 1.90996127087654299359 +-0.06515425057767830486 -0.00570025830607420042 0.99785892323860347908 1.00000000000000000000 +polygon 1 ( 4 caps, 1.0000000 weight, 0.0116826109771030 str): +0.08715574274765790219 -0.99619469809174554520 0.00000000000000010000 1.88539361956466899883 +-0.06081623141086969775 -0.00532073080682029988 0.99813479842186692004 1.00000000000000000000 +-0.05387300028307989708 -0.00471327679489840033 0.99853667176641747183 -1.00000000000000000000 +0.08715574274765790219 -0.99619469809174554520 0.00000000000000010000 -0.21198924639327809682 +polygon 2 ( 4 caps, 1.0000000 weight, 0.0022611252679780 str): +0.08715574274765790219 -0.99619469809174554520 0.00000000000000010000 1.50753836296070398149 +-0.05387300028307989708 -0.00471327679489840033 0.99853667176641747183 1.00000000000000000000 +-0.05213680212878300108 -0.00456137913876279982 0.99862953475457394426 -1.00000000000000000000 +0.08715574274765790219 -0.99619469809174554520 0.00000000000000010000 -0.21198924639327809682\n""" # noqa + + with tempfile.TemporaryDirectory() as tmpdir: + fname = os.path.join(tmpdir, 'test.ply') + + with open(fname, 'w') as fobj: + fobj.write(text) + + m = Mangle(fname) + + n = 100 + ra, dec = m.genrand(n) + assert np.all(m.contains(ra, dec)) + + ra, dec = m.genrand_range(n, 180, 190, -3.5, -3.2) + assert np.all(m.contains(ra, dec)) + + ra, dec = m.genrand_range(n, 100, 250, -4, 0) + assert np.all(m.contains(ra, dec)) + + +def test_weight_only(): + """ + standard header with only weight in addition to caps + """ + + text = """4 polygons +polygon 1 ( 4 caps, 1 weight ): +0.0000000000 0.0000000000 1.0000000000 1.0174524064 +0.0000000000 0.0000000000 1.0000000000 -0.8781306566 +0.5000000000 0.8660254038 0.0000000000 1.0000000000 +-0.6427876097 0.7660444431 0.0000000000 -1.0000000000 +polygon 2 ( 4 caps, 1 weight ): +0.0000000000 0.0000000000 1.0000000000 1.1218693434 +0.0000000000 0.0000000000 1.0000000000 -1.0174524064 +-0.4617486132 0.8870108332 0.0000000000 1.0000000000 +-0.6427876097 0.7660444431 0.0000000000 -1.0000000000 +polygon 3 ( 4 caps, 1 weight ): +0.0000000000 0.0000000000 1.0000000000 1.0348994967 +0.0000000000 0.0000000000 1.0000000000 -0.9128442573 +-0.7933533403 -0.6087614290 0.0000000000 1.0000000000 +0.7071067812 -0.7071067812 0.0000000000 -1.0000000000 +polygon 4 ( 4 caps, 1 weight ): +0.0000000000 0.0000000000 1.0000000000 0.3244097924 +0.0000000000 0.0000000000 1.0000000000 -0.3053416295 +0.3420201433 -0.9396926208 0.0000000000 1.0000000000 +0.9396926208 -0.3420201433 0.0000000000 -1.0000000000\n""" + + with tempfile.TemporaryDirectory() as tmpdir: + fname = os.path.join(tmpdir, 'test.ply') + with open(fname, 'w') as fobj: + fobj.write(text) + + m = Mangle(fname) + ra, dec = m.genrand(3) + + +def test_minimal_non_standard(): + """ + absolutely minimal header, non standard + """ + + text = """4 polygons +polygon 1 4 +0.0000000000 0.0000000000 1.0000000000 1.0174524064 +0.0000000000 0.0000000000 1.0000000000 -0.8781306566 +0.5000000000 0.8660254038 0.0000000000 1.0000000000 +-0.6427876097 0.7660444431 0.0000000000 -1.0000000000 +polygon 2 4 +0.0000000000 0.0000000000 1.0000000000 1.1218693434 +0.0000000000 0.0000000000 1.0000000000 -1.0174524064 +-0.4617486132 0.8870108332 0.0000000000 1.0000000000 +-0.6427876097 0.7660444431 0.0000000000 -1.0000000000 +polygon 3 4 +0.0000000000 0.0000000000 1.0000000000 1.0348994967 +0.0000000000 0.0000000000 1.0000000000 -0.9128442573 +-0.7933533403 -0.6087614290 0.0000000000 1.0000000000 +0.7071067812 -0.7071067812 0.0000000000 -1.0000000000 +polygon 4 4 +0.0000000000 0.0000000000 1.0000000000 0.3244097924 +0.0000000000 0.0000000000 1.0000000000 -0.3053416295 +0.3420201433 -0.9396926208 0.0000000000 1.0000000000 +0.9396926208 -0.3420201433 0.0000000000 -1.0000000000\n""" + + with tempfile.TemporaryDirectory() as tmpdir: + fname = os.path.join(tmpdir, 'test.ply') + with open(fname, 'w') as fobj: + fobj.write(text) + + m = Mangle(fname) + ra, dec = m.genrand(3) + + +def test_minimal_non_standard_nopolycount(): + """ + absolutely minimal header, non standard, without even + the polygon count + """ + + text = """polygon 1 4 +0.0000000000 0.0000000000 1.0000000000 1.0174524064 +0.0000000000 0.0000000000 1.0000000000 -0.8781306566 +0.5000000000 0.8660254038 0.0000000000 1.0000000000 +-0.6427876097 0.7660444431 0.0000000000 -1.0000000000 +polygon 2 4 +0.0000000000 0.0000000000 1.0000000000 1.1218693434 +0.0000000000 0.0000000000 1.0000000000 -1.0174524064 +-0.4617486132 0.8870108332 0.0000000000 1.0000000000 +-0.6427876097 0.7660444431 0.0000000000 -1.0000000000 +polygon 3 4 +0.0000000000 0.0000000000 1.0000000000 1.0348994967 +0.0000000000 0.0000000000 1.0000000000 -0.9128442573 +-0.7933533403 -0.6087614290 0.0000000000 1.0000000000 +0.7071067812 -0.7071067812 0.0000000000 -1.0000000000 +polygon 4 4 +0.0000000000 0.0000000000 1.0000000000 0.3244097924 +0.0000000000 0.0000000000 1.0000000000 -0.3053416295 +0.3420201433 -0.9396926208 0.0000000000 1.0000000000 +0.9396926208 -0.3420201433 0.0000000000 -1.0000000000\n""" + + with tempfile.TemporaryDirectory() as tmpdir: + fname = os.path.join(tmpdir, 'test.ply') + + with open(fname, 'w') as fobj: + fobj.write(text) + + m = Mangle(fname) + ra, dec = m.genrand(3) + + +def test_extra_lines(): + """ + extra line at the end + """ + + text = """polygon 1 4 +0.0000000000 0.0000000000 1.0000000000 1.0174524064 +0.0000000000 0.0000000000 1.0000000000 -0.8781306566 +0.5000000000 0.8660254038 0.0000000000 1.0000000000 +-0.6427876097 0.7660444431 0.0000000000 -1.0000000000 +polygon 2 4 +0.0000000000 0.0000000000 1.0000000000 1.1218693434 +0.0000000000 0.0000000000 1.0000000000 -1.0174524064 +-0.4617486132 0.8870108332 0.0000000000 1.0000000000 +-0.6427876097 0.7660444431 0.0000000000 -1.0000000000 +polygon 3 4 +0.0000000000 0.0000000000 1.0000000000 1.0348994967 +0.0000000000 0.0000000000 1.0000000000 -0.9128442573 +-0.7933533403 -0.6087614290 0.0000000000 1.0000000000 +0.7071067812 -0.7071067812 0.0000000000 -1.0000000000 +polygon 4 4 +0.0000000000 0.0000000000 1.0000000000 0.3244097924 +0.0000000000 0.0000000000 1.0000000000 -0.3053416295 +0.3420201433 -0.9396926208 0.0000000000 1.0000000000 +0.9396926208 -0.3420201433 0.0000000000 -1.0000000000\n + \n""" + + with tempfile.TemporaryDirectory() as tmpdir: + fname = os.path.join(tmpdir, 'test.ply') + with open(fname, 'w') as fobj: + fobj.write(text) + + m = Mangle(fname) + ra, dec = m.genrand(3) From 245cdda44cd0f06c6b22181b14cab5c3acc2223b Mon Sep 17 00:00:00 2001 From: Erin Sheldon Date: Tue, 13 May 2025 12:43:23 -0400 Subject: [PATCH 3/7] flake8 --- register.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/register.py b/register.py index fc1c834..b2fb1ba 100644 --- a/register.py +++ b/register.py @@ -1,20 +1,24 @@ import os -rname='README.md' -rstname='README.rst' +rname = 'README.md' +rstname = 'README.rst' + def clear(): if os.path.exists(rstname): os.remove(rstname) + def try_make_rst(): - cmd="pandoc --from=markdown --to=rst {readme} -o {rst}" - cmd=cmd.format(readme=rname, rst=rstname) + cmd = "pandoc --from=markdown --to=rst {readme} -o {rst}" + cmd = cmd.format(readme=rname, rst=rstname) os.system(cmd) + def register(): os.system("python setup.py register") + clear() try_make_rst() From 38e4466e9aad51ab32f5d1b56f8de53511474487 Mon Sep 17 00:00:00 2001 From: Erin Sheldon Date: Tue, 13 May 2025 12:43:57 -0400 Subject: [PATCH 4/7] define version before read --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 469aedd..3070f40 100644 --- a/setup.py +++ b/setup.py @@ -26,6 +26,7 @@ def finalize_options(self): self.include_dirs.extend(glob.glob("pymangle/*h")) +__version__ = None exec(open('pymangle/version.py').read()) description = "A python code to read and work with Mangle masks." From 1e302e7ffc75716badc08ac8e50943b623d6b857 Mon Sep 17 00:00:00 2001 From: Erin Sheldon Date: Tue, 13 May 2025 12:44:21 -0400 Subject: [PATCH 5/7] update CI --- .github/workflows/test.yml | 87 ++++++----- pymangle/test.py | 287 ------------------------------------- tests/test_import.py | 9 -- 3 files changed, 48 insertions(+), 335 deletions(-) delete mode 100644 pymangle/test.py delete mode 100644 tests/test_import.py diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f805d34..6bb02d4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,43 +1,52 @@ -name: tests +name: pymangle CI on: - push: - branches: - - master - pull_request: null + push: + branches: + - master + pull_request: + branches: + - master + - releases/* jobs: - tests: - name: tests - strategy: - matrix: - pyver: [3.6, 3.7, 3.8] - - runs-on: 'ubuntu-latest' - - steps: - - uses: actions/checkout@v2 - - - uses: conda-incubator/setup-miniconda@v2 - with: - python-version: ${{ matrix.pyver }} - channels: conda-forge,defaults - channel-priority: strict - show-channel-urls: true - - - name: configure conda and install code - shell: bash -l {0} - run: | - conda config --set always_yes yes - conda install --quiet setuptools flake8 - - python -m pip install -e . - - - name: lint - shell: bash -l {0} - run: | - flake8 pymangle - - name: test - shell: bash -l {0} - run: | - python -c 'import pymangle; pymangle.test.test()' + tests: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ ubuntu-latest ] + py: [ "3.11" ] + CC: [ gcc ] + CXX: [ g++ ] + + defaults: + run: + # cf. https://github.com/conda-incubator/setup-miniconda#important + shell: bash -l {0} + + steps: + - uses: actions/checkout@v2 + - uses: conda-incubator/setup-miniconda@v2 + with: + python-version: ${{ matrix.pyver }} + channels: conda-forge,defaults + channel-priority: strict + show-channel-urls: true + miniforge-version: latest + + - name: Install deps + run: | + conda config --set always_yes yes + conda install numpy pytest flake8 + + - name: Install pymangle + run: + pip install . + + - name: lint + run: | + flake8 pymangle + + - name: Run tests + run: | + pytest -vv tests/ diff --git a/pymangle/test.py b/pymangle/test.py deleted file mode 100644 index d2dd347..0000000 --- a/pymangle/test.py +++ /dev/null @@ -1,287 +0,0 @@ -from __future__ import with_statement, print_function -import sys -import os -import tempfile -import numpy as np - -from .mangle import Mangle - -import unittest - - -def test(): - suite = unittest.TestLoader().loadTestsFromTestCase(TestRead) - res = unittest.TextTestRunner(verbosity=2).run(suite).wasSuccessful() - - if not res: - sys.exit(1) - - -class TestRead(unittest.TestCase): - - def testStandardUnpixelized(self): - """ - a basic mask with standard header, no pixelization - """ - - text = """3 polygons -snapped -polygon 0 ( 4 caps, 1 weight, 0 pixel, 0.101732020850849 str): - 0.0871557427476579 -0.9961946980917455 0.0000000000000001 -0.2568551745226059 - 0.0871557427476579 -0.9961946980917455 0.0000000000000001 1.422618261740699 - 0.2367814257465403 0.0207156904863277 -0.9713420698132612 1 - 0.1515445107781580 0.0132584267126710 -0.9883615104677608 -1 -polygon 1 ( 4 caps, 1 weight, 0 pixel, 0.054242425709277 str): - 0.0871557427476579 -0.9961946980917455 0.0000000000000001 -0.2568551745226059 - 0.0871557427476579 -0.9961946980917455 0.0000000000000001 1.5 - 0.1515445107781580 0.0132584267126710 -0.9883615104677608 1 - 0.1084526035253447 0.0094883733383393 -0.9940563382223196 -1 -polygon 2 ( 4 caps, 1 weight, 0 pixel, 0.302363552547417 str): - 0.0871557427476579 -0.9961946980917455 0.0000000000000001 -0.2568551745226059 - 0.0871557427476579 -0.9961946980917455 0.0000000000000001 1.642787609686539 - 0.1084526035253447 0.0094883733383393 -0.9940563382223196 1 - -0.1084526035253447 -0.0094883733383393 -0.9940563382223196 -1\n""" # noqa - - fname = tempfile.mktemp( - prefix='mangle-StandardUnpixelized-', suffix='.ply', - ) - with open(fname, 'w') as fobj: - fobj.write(text) - - m = Mangle(fname) - ra, dec = m.genrand(3) - if os.path.exists(fname): - os.remove(fname) - - def testStandardPixelized(self): - """ - standard header with pixel - """ - - text="""3 polygons -pixelization 9s -snapped -balkanized -polygon 0 ( 4 caps, 1 weight, 87381 pixel, 0.000000000129178 str): - 0.9999999991588143 0.0000410152374105 0.0000003490658505 0.998159921767887 - 0.9659041924494473 -0.2588997625991339 -0.0000627271332757 -0.9982831417433783 - -0.0000000000000000 1.0000000000000000 0.0000000000000000 1 - -0.0122715382857199 0.9999247018391445 0.0000000000000000 -1 -polygon 1 ( 4 caps, 1 weight, 87381 pixel, 0.000000067701897 str): - -0.9647577286061684 -0.2584481766449109 0.0494678186661570 -1 - 0.2587637821532441 -0.9659406319340194 -0.0000249931148859 -0.9872370563678581 - -0.0122715382857199 0.9999247018391445 0.0000000000000000 -1 - 0.0000000000000000 0.0000000000000000 1.0000000000000000 0.00390625 -polygon 2 ( 5 caps, 1 weight, 87381 pixel, 0.000000311118396 str): - -0.9647577286061684 -0.2584481766449109 0.0494678186661570 1 - 0.2587637821532441 -0.9659406319340194 -0.0000249931148859 -0.9872370563678581 - -0.9987456407765712 0.0000501504038277 0.0500713742045613 -1 - -0.0122715382857199 0.9999247018391445 0.0000000000000000 -1 - 0.0000000000000000 0.0000000000000000 1.0000000000000000 0.00390625\n""" # noqa - - fname = tempfile.mktemp(prefix='mangle-Pixelized-', suffix='.ply') - with open(fname, 'w') as fobj: - fobj.write(text) - - _ = Mangle(fname) - if os.path.exists(fname): - os.remove(fname) - - def testNopixel(self): - """ - standard header with no pixels in the header - """ - - text = """3 polygons -polygon 0 ( 4 caps, 1.0000000 weight, 0.0074088006084970 str): - -0.06081623141086969775 -0.00532073080682029988 0.99813479842186692004 -1.00000000000000000000 - 0.08715574274765790219 -0.99619469809174554520 0.00000000000000010000 -0.21198924639327809682 - 0.08715574274765790219 -0.99619469809174554520 0.00000000000000010000 1.90996127087654299359 - -0.06515425057767830486 -0.00570025830607420042 0.99785892323860347908 1.00000000000000000000 -polygon 1 ( 4 caps, 1.0000000 weight, 0.0116826109771030 str): - 0.08715574274765790219 -0.99619469809174554520 0.00000000000000010000 1.88539361956466899883 - -0.06081623141086969775 -0.00532073080682029988 0.99813479842186692004 1.00000000000000000000 - -0.05387300028307989708 -0.00471327679489840033 0.99853667176641747183 -1.00000000000000000000 - 0.08715574274765790219 -0.99619469809174554520 0.00000000000000010000 -0.21198924639327809682 -polygon 2 ( 4 caps, 1.0000000 weight, 0.0022611252679780 str): - 0.08715574274765790219 -0.99619469809174554520 0.00000000000000010000 1.50753836296070398149 - -0.05387300028307989708 -0.00471327679489840033 0.99853667176641747183 1.00000000000000000000 - -0.05213680212878300108 -0.00456137913876279982 0.99862953475457394426 -1.00000000000000000000 - 0.08715574274765790219 -0.99619469809174554520 0.00000000000000010000 -0.21198924639327809682\n""" # noqa - - fname = tempfile.mktemp( - prefix='mangle-Nopixel-', suffix='.ply', - ) - with open(fname, 'w') as fobj: - fobj.write(text) - - m = Mangle(fname) - - n = 100 - ra, dec = m.genrand(n) - assert np.all(m.contains(ra, dec)) - - ra, dec = m.genrand_range(n, 180, 190, -3.5, -3.2) - assert np.all(m.contains(ra, dec)) - - ra, dec = m.genrand_range(n, 100, 250, -4, 0) - assert np.all(m.contains(ra, dec)) - - if os.path.exists(fname): - os.remove(fname) - - def testWeightOnly(self): - """ - standard header with only weight in addition to caps - """ - - text="""4 polygons -polygon 1 ( 4 caps, 1 weight ): -0.0000000000 0.0000000000 1.0000000000 1.0174524064 -0.0000000000 0.0000000000 1.0000000000 -0.8781306566 -0.5000000000 0.8660254038 0.0000000000 1.0000000000 --0.6427876097 0.7660444431 0.0000000000 -1.0000000000 -polygon 2 ( 4 caps, 1 weight ): -0.0000000000 0.0000000000 1.0000000000 1.1218693434 -0.0000000000 0.0000000000 1.0000000000 -1.0174524064 --0.4617486132 0.8870108332 0.0000000000 1.0000000000 --0.6427876097 0.7660444431 0.0000000000 -1.0000000000 -polygon 3 ( 4 caps, 1 weight ): -0.0000000000 0.0000000000 1.0000000000 1.0348994967 -0.0000000000 0.0000000000 1.0000000000 -0.9128442573 --0.7933533403 -0.6087614290 0.0000000000 1.0000000000 -0.7071067812 -0.7071067812 0.0000000000 -1.0000000000 -polygon 4 ( 4 caps, 1 weight ): -0.0000000000 0.0000000000 1.0000000000 0.3244097924 -0.0000000000 0.0000000000 1.0000000000 -0.3053416295 -0.3420201433 -0.9396926208 0.0000000000 1.0000000000 -0.9396926208 -0.3420201433 0.0000000000 -1.0000000000\n""" # noqa - - fname = tempfile.mktemp( - prefix='mangle-Weight-', suffix='.ply', - ) - with open(fname, 'w') as fobj: - fobj.write(text) - - m = Mangle(fname) - ra, dec = m.genrand(3) - if os.path.exists(fname): - os.remove(fname) - - def testMinimalNonStandard(self): - """ - absolutely minimal header, non standard - """ - - text = """4 polygons -polygon 1 4 -0.0000000000 0.0000000000 1.0000000000 1.0174524064 -0.0000000000 0.0000000000 1.0000000000 -0.8781306566 -0.5000000000 0.8660254038 0.0000000000 1.0000000000 --0.6427876097 0.7660444431 0.0000000000 -1.0000000000 -polygon 2 4 -0.0000000000 0.0000000000 1.0000000000 1.1218693434 -0.0000000000 0.0000000000 1.0000000000 -1.0174524064 --0.4617486132 0.8870108332 0.0000000000 1.0000000000 --0.6427876097 0.7660444431 0.0000000000 -1.0000000000 -polygon 3 4 -0.0000000000 0.0000000000 1.0000000000 1.0348994967 -0.0000000000 0.0000000000 1.0000000000 -0.9128442573 --0.7933533403 -0.6087614290 0.0000000000 1.0000000000 -0.7071067812 -0.7071067812 0.0000000000 -1.0000000000 -polygon 4 4 -0.0000000000 0.0000000000 1.0000000000 0.3244097924 -0.0000000000 0.0000000000 1.0000000000 -0.3053416295 -0.3420201433 -0.9396926208 0.0000000000 1.0000000000 -0.9396926208 -0.3420201433 0.0000000000 -1.0000000000\n""" # noqa - - fname = tempfile.mktemp( - prefix='mangle-MinimalNonStandard-', suffix='.ply', - ) - with open(fname, 'w') as fobj: - fobj.write(text) - - m = Mangle(fname) - ra, dec = m.genrand(3) - if os.path.exists(fname): - os.remove(fname) - - def testMinimalNonStandardNopolycount(self): - """ - absolutely minimal header, non standard, without even - the polygon count - """ - - text="""polygon 1 4 -0.0000000000 0.0000000000 1.0000000000 1.0174524064 -0.0000000000 0.0000000000 1.0000000000 -0.8781306566 -0.5000000000 0.8660254038 0.0000000000 1.0000000000 --0.6427876097 0.7660444431 0.0000000000 -1.0000000000 -polygon 2 4 -0.0000000000 0.0000000000 1.0000000000 1.1218693434 -0.0000000000 0.0000000000 1.0000000000 -1.0174524064 --0.4617486132 0.8870108332 0.0000000000 1.0000000000 --0.6427876097 0.7660444431 0.0000000000 -1.0000000000 -polygon 3 4 -0.0000000000 0.0000000000 1.0000000000 1.0348994967 -0.0000000000 0.0000000000 1.0000000000 -0.9128442573 --0.7933533403 -0.6087614290 0.0000000000 1.0000000000 -0.7071067812 -0.7071067812 0.0000000000 -1.0000000000 -polygon 4 4 -0.0000000000 0.0000000000 1.0000000000 0.3244097924 -0.0000000000 0.0000000000 1.0000000000 -0.3053416295 -0.3420201433 -0.9396926208 0.0000000000 1.0000000000 -0.9396926208 -0.3420201433 0.0000000000 -1.0000000000\n""" # noqa - - fname = tempfile.mktemp( - prefix='mangle-MinimalNonStandard-', suffix='.ply', - ) - with open(fname, 'w') as fobj: - fobj.write(text) - - m = Mangle(fname) - ra, dec = m.genrand(3) - if os.path.exists(fname): - os.remove(fname) - - def testExtraLines(self): - """ - extra line at the end - """ - - text = """polygon 1 4 -0.0000000000 0.0000000000 1.0000000000 1.0174524064 -0.0000000000 0.0000000000 1.0000000000 -0.8781306566 -0.5000000000 0.8660254038 0.0000000000 1.0000000000 --0.6427876097 0.7660444431 0.0000000000 -1.0000000000 -polygon 2 4 -0.0000000000 0.0000000000 1.0000000000 1.1218693434 -0.0000000000 0.0000000000 1.0000000000 -1.0174524064 --0.4617486132 0.8870108332 0.0000000000 1.0000000000 --0.6427876097 0.7660444431 0.0000000000 -1.0000000000 -polygon 3 4 -0.0000000000 0.0000000000 1.0000000000 1.0348994967 -0.0000000000 0.0000000000 1.0000000000 -0.9128442573 --0.7933533403 -0.6087614290 0.0000000000 1.0000000000 -0.7071067812 -0.7071067812 0.0000000000 -1.0000000000 -polygon 4 4 -0.0000000000 0.0000000000 1.0000000000 0.3244097924 -0.0000000000 0.0000000000 1.0000000000 -0.3053416295 -0.3420201433 -0.9396926208 0.0000000000 1.0000000000 -0.9396926208 -0.3420201433 0.0000000000 -1.0000000000\n - \n""" - - fname = tempfile.mktemp( - prefix='mangle-MinimalNonStandard-', suffix='.ply', - ) - with open(fname, 'w') as fobj: - fobj.write(text) - - m = Mangle(fname) - ra, dec = m.genrand(3) - if os.path.exists(fname): - os.remove(fname) - - -if __name__ == '__main__': - test() diff --git a/tests/test_import.py b/tests/test_import.py deleted file mode 100644 index 6427412..0000000 --- a/tests/test_import.py +++ /dev/null @@ -1,9 +0,0 @@ -"test that pymangle is correctly imported" - -import pymangle - - -def test_Mangle(): - '''Check that is imported and that the Mangle class exists''' - pymangle.Mangle - pymangle.__version__ From 0b8ac491e2d0e73a14f06399a006b66ddd06063f Mon Sep 17 00:00:00 2001 From: Erin Sheldon Date: Tue, 13 May 2025 12:50:41 -0400 Subject: [PATCH 6/7] rename so pytest picks up file --- tests/{testmangle.py => test_pymangle.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/{testmangle.py => test_pymangle.py} (100%) diff --git a/tests/testmangle.py b/tests/test_pymangle.py similarity index 100% rename from tests/testmangle.py rename to tests/test_pymangle.py From 56e73be42a692634197083966d5760d1abf84cb1 Mon Sep 17 00:00:00 2001 From: Erin Sheldon Date: Tue, 13 May 2025 12:51:12 -0400 Subject: [PATCH 7/7] remove import --- pymangle/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pymangle/__init__.py b/pymangle/__init__.py index c2dee55..4b93c04 100644 --- a/pymangle/__init__.py +++ b/pymangle/__init__.py @@ -3,6 +3,5 @@ from . import mangle from .mangle import Mangle, genrand_cap from .version import __version__ -from . import test __doc__ = mangle.__doc__