├── .coveragerc ├── .dockerignore ├── .github └── workflows │ ├── build_release.yml │ ├── linux.yml │ ├── osx.yml │ └── py3_casacore_master.docker ├── .gitignore ├── CHANGELOG.md ├── CMakeLists.txt ├── LICENSE ├── README.rst ├── casacore ├── .aipsrc ├── __init__.py ├── fitting │ ├── __init__.py │ └── fitting.py ├── functionals │ ├── __init__.py │ └── functional.py ├── images │ ├── __init__.py │ ├── coordinates.py │ └── image.py ├── measures │ └── __init__.py ├── quanta │ ├── __init__.py │ └── quantity.py ├── tables │ ├── __init__.py │ ├── msutil.py │ ├── table.py │ ├── tablecolumn.py │ ├── tablehelper.py │ ├── tableindex.py │ ├── tableiter.py │ ├── tablerow.py │ ├── tableutil.py │ └── wxtablebrowser.py └── util │ ├── __init__.py │ └── substitute.py ├── cmake ├── FindCFITSIO.cmake ├── FindCasacore.cmake └── FindWCSLIB.cmake ├── doc ├── 199.html ├── 259.css ├── 259.html ├── 259.latex ├── 259.pdf ├── Makefile ├── casacore.tex ├── casacore_fitting.rst ├── casacore_functionals.rst ├── casacore_images.rst ├── casacore_measures.rst ├── casacore_quanta.rst ├── casacore_tables.rst ├── casacore_util.rst ├── conf.py ├── index.rst └── requirements.txt ├── pyproject.toml ├── pyrap ├── __init__.py ├── fitting.py ├── functionals.py ├── images.py ├── images │ ├── __init__.py │ ├── coordinates.py │ └── image.py ├── measures.py ├── quanta.py ├── tables.py └── util.py ├── src ├── CMakeLists.txt ├── fit.cc ├── fitting.cc ├── fitting.h ├── functional.cc ├── functionals.cc ├── functionals.h ├── images.cc ├── pyimages.cc ├── pyimages.h ├── pymeas.cc ├── pymeasures.cc ├── pymeasures.h ├── pyms.cc ├── pytable.cc ├── pytableindex.cc ├── pytableiter.cc ├── pytablerow.cc ├── quanta.cc ├── quanta.h ├── quantamath.cc ├── quantity.cc ├── quantvec.cc ├── tables.cc └── tables.h └── tests ├── CMakeLists.txt ├── requirements.txt ├── tConvert.cc ├── test_convert.py ├── test_fitting.py ├── test_functionals.py ├── test_image.py ├── test_measures.py ├── test_quanta.py ├── test_table.py ├── test_unicode.py ├── test_util.py ├── timage.py.out ├── tquanta.py.out ├── ttable.py.out └── tutil.py.out /.coveragerc: -------------------------------------------------------------------------------- 1 | [report] 2 | omit = 3 | */python?.?/* 4 | */site-packages/nose/* 5 | *__init__* 6 | */tests/* 7 | -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | .venv*/ 2 | venv/ 3 | .virtualenv*/ 4 | build/ 5 | *.egg-info/ 6 | -------------------------------------------------------------------------------- /.github/workflows/build_release.yml: -------------------------------------------------------------------------------- 1 | name: Build and upload to PyPI 2 | 3 | # Only build and upload when a new release tag is created 4 | # on: 5 | # push: 6 | # tags: 7 | # - "v[0-9]+.[0-9]+.[0-9]+" 8 | # - "v[0-9]+.[0-9]+.[0-9]+[a-z]+[0-9]+" 9 | # Alternatively, build on every branch push, tag push, and pull request change 10 | on: [push] #, pull_request] 11 | 12 | jobs: 13 | 14 | build_sdist: 15 | name: Build source distribution 16 | runs-on: ubuntu-latest 17 | steps: 18 | - uses: actions/checkout@v4 19 | with: 20 | # Needed for `setuptools-scm` 21 | fetch-depth: 0 22 | 23 | - name: Build sdist 24 | run: pipx run build --sdist 25 | 26 | - uses: actions/upload-artifact@v4 27 | with: 28 | name: tarball 29 | path: dist/*.tar.gz 30 | 31 | build_wheels: 32 | name: Build wheels on ${{ matrix.os }} 33 | runs-on: ${{ matrix.os }} 34 | strategy: 35 | matrix: 36 | os: [ubuntu-latest] #, macos-latest] 37 | 38 | steps: 39 | - uses: actions/checkout@v4 40 | with: 41 | # Needed for `setuptools-scm` 42 | fetch-depth: 0 43 | 44 | - name: Build wheels 45 | uses: pypa/cibuildwheel@v2.23 46 | 47 | - name: Upload wheels 48 | uses: actions/upload-artifact@v4 49 | with: 50 | name: wheels-${{ matrix.os }} 51 | path: wheelhouse/*.whl 52 | 53 | upload_pypi: 54 | name: Upload release to PyPI 55 | runs-on: ubuntu-latest 56 | needs: [build_sdist, build_wheels] 57 | environment: 58 | name: pypi 59 | url: https://pypi.org/p/python-casacore 60 | # For testing, use TestPyPI 61 | # url: https://test.pypi.org/p/python-casacore 62 | permissions: 63 | id-token: write # IMPORTANT: this permission is mandatory for trusted publishing 64 | # Upload to PyPI on every tag starting with 'v' 65 | if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') 66 | # Alternatively, to publish when a GitHub Release is created, use the following rule: 67 | # if: github.event_name == 'release' && github.event.action == 'published' 68 | steps: 69 | - uses: actions/download-artifact@v4 70 | with: 71 | path: dist # put artifacts where next action expects them to be 72 | merge-multiple: true 73 | - uses: pypa/gh-action-pypi-publish@release/v1 74 | with: 75 | # For testing, use TestPyPI 76 | # repository-url: https://test.pypi.org/legacy/ 77 | skip-existing: true 78 | verbose: true 79 | -------------------------------------------------------------------------------- /.github/workflows/linux.yml: -------------------------------------------------------------------------------- 1 | name: Linux 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | tags: [ "*" ] 7 | pull_request: 8 | branches: [ master ] 9 | 10 | jobs: 11 | tests: 12 | runs-on: ${{ matrix.os }} 13 | strategy: 14 | matrix: 15 | os: [ubuntu-22.04, ubuntu-24.04] 16 | dist: 17 | - py3_casacore_master 18 | steps: 19 | - name: Checkout 20 | uses: actions/checkout@v4 21 | with: 22 | # Needed for `setuptools-scm` 23 | fetch-depth: 0 24 | 25 | - name: Build container 26 | run: docker build . -t ${{ matrix.dist }} -f .github/workflows/${{ matrix.dist }}.docker 27 | -------------------------------------------------------------------------------- /.github/workflows/osx.yml: -------------------------------------------------------------------------------- 1 | name: OS X 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | tags: [ "*" ] 7 | pull_request: 8 | branches: [ master ] 9 | 10 | jobs: 11 | osx: 12 | runs-on: macos-13 13 | continue-on-error: true 14 | 15 | steps: 16 | - name: checkout 17 | uses: actions/checkout@v4 18 | with: 19 | # Needed for `setuptools-scm` 20 | fetch-depth: 0 21 | 22 | - name: install homebrew packages 23 | run: | 24 | brew tap casacore/tap 25 | brew install casacore --with-python 26 | 27 | - name: make virtualenv 28 | run: python3 -m venv venv 29 | 30 | - name: Install Python dependencies 31 | run: venv/bin/pip install --upgrade pip wheel delocate pytest 32 | 33 | - name: Compile and install python-casacore 34 | run: CFLAGS="-I/usr/local/include -L/usr/local/lib" venv/bin/pip install . 35 | 36 | - name: Run pytest 37 | run: venv/bin/pytest 38 | 39 | - name: make binary wheel 40 | run: venv/bin/pip wheel -w dist . 41 | 42 | - name: Delocate binary wheel 43 | run: venv/bin/delocate-wheel -v dist/*.whl 44 | 45 | - name: Publish OS X binary wheels 46 | uses: actions/upload-artifact@v4 47 | with: 48 | path: dist/*.whl 49 | -------------------------------------------------------------------------------- /.github/workflows/py3_casacore_master.docker: -------------------------------------------------------------------------------- 1 | FROM ubuntu:latest 2 | RUN apt-get update -y 3 | RUN DEBIAN_FRONTEND=noninteractive apt-get install -y \ 4 | build-essential \ 5 | casacore-dev \ 6 | git \ 7 | libboost-python-dev \ 8 | libcfitsio-dev \ 9 | liblapack-dev \ 10 | python3-dev \ 11 | python3-venv \ 12 | wcslib-dev 13 | ADD . /src 14 | WORKDIR /src 15 | RUN python3 -m venv venv && \ 16 | . venv/bin/activate && \ 17 | pip install 'numpy<2' && \ 18 | pip install . && \ 19 | cd tests && \ 20 | pip install -r requirements.txt && \ 21 | pytest --cov-report term --cov=casacore 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | doc/.build/ 3 | build/ 4 | dist/ 5 | *.pyc 6 | .vagrant/ 7 | casacore/*/_*.so 8 | python_casacore.egg-info/ 9 | casacore.egg-info/ 10 | *~ 11 | *.bak 12 | *.log 13 | .coverage 14 | .virtualenv/ 15 | .virtualenv3/ 16 | .venv*/ 17 | venv/ 18 | wheelhouse/ 19 | htmlcov 20 | *.so 21 | .vscode/ 22 | casacore/_version.py 23 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # 3.7.1 2 | 3 | This version as a binary wheel ships with underlying casacore v3.7.1. 4 | 5 | # 3.6.1 6 | 7 | This version as a binary wheel ships with underlying casacore v3.6.1. 8 | 9 | The build system has seen a major upgrade. 10 | 11 | 12 | # 3.5.2 13 | 14 | The binary wheels have now been built with `-DPORTABLE=True`. This should fix issues with Dysco crashing on some platforms (due to missing AVX instructions). Otherwise nothing has changed. 15 | 16 | 17 | # 3.5.1 18 | 19 | The binary wheel for python 3.10 is now based on numpy 1.22.4. Otherwise nothing has changed. 20 | 21 | 22 | # 3.5.0 23 | 24 | This version as a binary wheel ships with underlying casacore v3.5.0 25 | 26 | Binary wheels are now `manylinux2014` which will only work with pip >= 19.3 27 | 28 | The license has changed to LGPL. 29 | 30 | 31 | # 3.4.0 32 | 33 | This version as a binary wheel ships with underlying casacore v3.4.0 34 | 35 | There are no changes to python-casacore itself 36 | 37 | 38 | # 3.3.0 39 | 40 | This version as a binary wheel ships with underlying casacore v3.3.0. 41 | 42 | Ony a few changes in python-casacore itself: 43 | 44 | - Expose complete MS and subtable definitions (#183) 45 | - Miminum casacore version is now 3.2.0 (#195) 46 | - Several improvements to library handling in setup.py (#194) 47 | 48 | 49 | # 3.2.0 50 | 51 | This version as a binary wheel ships with underlying casacore v3.2.0. 52 | 53 | Changes are only in the underlying casacore. 54 | 55 | 56 | # 3.1.1 57 | 58 | This is the first release that will be supplied as binary wheels 59 | (manylinux2010). Note that you need pip > 10.x to use manylinux2010 wheels. 60 | If you don't use the binary wheel and unicode is important to you, use 61 | casacore 3.1.1. Note that we skipped 3.1.0 to match the casacore version 62 | and hopefully avoid confusion. 63 | 64 | Changes: 65 | 66 | - handle unicode even better! :) (#158) 67 | - iteritems() in casacore/tables/table.py incompatible with Python 3 (#165) 68 | - Make a big binary wheel including dependencies (#145) 69 | - Use ~ instead of - to negate the mask (#179) 70 | 71 | 72 | # 3.0 73 | 74 | - Improve the setup procedure (#146) 75 | - prepare for 3.0.0 (#147) 76 | - More find_boost improvements build system (#131) 77 | - gcc failure when attempting setup.py build_ext on Red Hat EL 7.4 (quantamath.cc) (#135) 78 | - python-casacore uses hardcoded casa:: calls (#136) 79 | - quanta example not working with python 2.7.6 bug (#17) 80 | - Fix build and namespace problem (#137) 81 | - Remove deprecated has_key (#132) 82 | - Correct header guard macro definition (#156) 83 | - Avoiding TypeError deep down in setuptool (#155) 84 | 85 | 86 | # 2.2.0 87 | 88 | - Expose MeasurementSet functionality (#61) 89 | - Many improvements to documentation and test coverage 90 | Thanks to Shibasis Patel (@shibasisp) our Google summer of Code '17 student. 91 | 92 | A full list of changes can be found on the issue tracker: 93 | 94 | https://github.com/casacore/python-casacore/milestone/6?closed=1 95 | 96 | 97 | # 2.1.0 98 | 99 | 100 | - Replaced references to pyrap -> casacore (issue #16) 101 | - Experimental support for Python3 (needs python3 branch build of casacore) 102 | - Link against correct Python on OSX when using homebrew (issue #15) 103 | 104 | 105 | # 2.0.0 106 | 107 | - Renamed project from pyrap to python-casacore 108 | - Renamed modules from pyrap to casacore 109 | - Added backswards compatible module which imports casacore 110 | - Removed scons build dependency, just use setup.py 111 | - Depends on CASACORE 2.0 112 | - Cleanup of project structure 113 | - Moved development to github 114 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.15...3.26) 2 | project(python-casacore) 3 | 4 | find_package( 5 | Python 6 | COMPONENTS Interpreter Development.Module 7 | REQUIRED) 8 | 9 | # Find Casacore and its dependencies 10 | set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) 11 | find_package(Casacore REQUIRED) 12 | find_package(Boost REQUIRED COMPONENTS python3) 13 | 14 | # If environment variable CASACORE_DATA is set, assume it points to a directory 15 | # containing the cascacore data files, and install its contents. 16 | if(DEFINED ENV{CASACORE_DATA}) 17 | foreach(_dir ephemerides geodetic) 18 | if(NOT IS_DIRECTORY $ENV{CASACORE_DATA}/${_dir}) 19 | message( 20 | SEND_ERROR 21 | "Directory $ENV{CASACORE_DATA}/${_dir} does not exist. " 22 | "Does environment variable CASACORE_DATA point to a valid data directory?" 23 | ) 24 | endif() 25 | endforeach() 26 | install( 27 | DIRECTORY $ENV{CASACORE_DATA} 28 | DESTINATION casacore 29 | COMPONENT data) 30 | else() 31 | message( 32 | WARNING 33 | "Environment variable CASACORE_DATA is not defined. " 34 | "Casacore data files will not be included in the python-casacore package." 35 | ) 36 | endif() 37 | 38 | add_subdirectory(src) 39 | if(BUILD_TESTING) 40 | add_subdirectory(tests) 41 | endif() 42 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | python-casacore 2 | =============== 3 | 4 | Python-casacore is a set of Python bindings for `casacore `_, 5 | a c++ library used in radio astronomy. Python-casacore replaces the old 6 | `pyrap `_. 7 | 8 | 9 | The python-casacore documentation can be found on `casacore.github.io/python-casacore `_. 10 | 11 | Build status 12 | ------------ 13 | 14 | .. image:: https://github.com/casacore/python-casacore/actions/workflows/linux.yml/badge.svg 15 | :target: https://github.com/casacore/python-casacore/actions/workflows/linux.yml 16 | .. image:: https://github.com/casacore/python-casacore/actions/workflows/osx.yml/badge.svg 17 | :target: https://github.com/casacore/python-casacore/actions/workflows/osx.yml 18 | 19 | 20 | Installation 21 | ============ 22 | 23 | Binary wheels 24 | ------------- 25 | 26 | We distribute binary manylinux2014 for Linux, which requires pip >= 19.3. To 27 | install python-casacore from a binary wheel run:: 28 | 29 | $ pip install python-casacore 30 | 31 | 32 | Debian & Ubuntu 33 | --------------- 34 | 35 | python-casacore is now part of Debian and Ubuntu and can be installed using apt:: 36 | 37 | $ sudo apt-get install python3-casacore 38 | 39 | 40 | from source 41 | ----------- 42 | 43 | install these requirements: 44 | 45 | * `Casacore `__ 46 | * `Boost-python `_ 47 | * `numpy `_ 48 | * `cfitsio `_ 49 | * `wcslib `_ 50 | * `pip `_ 51 | 52 | On ubuntu you can install these with:: 53 | 54 | $ apt-get install casacore-dev libboost-python-dev python3-numpy \ 55 | libcfitsio3-dev wcslib-dev python3-pip 56 | 57 | * compile and install:: 58 | 59 | $ pip install --no-binary python-casacore python-casacore 60 | 61 | * or if you are installing from the source repository:: 62 | 63 | $ pip install . 64 | 65 | * If the compilation fails you might need to help the compiler find the paths to the 66 | boost and casacore libraries and headers. You can control this with the `CFLAGS` environment 67 | variable. For example on OS X when using homebrew and clang you need to do something like 68 | this:: 69 | 70 | CFLAGS="-std=c++11 \ 71 | -I/usr/local/Cellar/boost/1.68.0/include/ \ 72 | -I/usr/local/include/ \ 73 | -L/usr/local/Cellar/boost/1.68.0/lib \ 74 | -L/usr/local/lib/" \ 75 | pip install python-casacore 76 | 77 | Support 78 | ======= 79 | 80 | if you have any problems, suggestions or questions please open an issue on the 81 | python-casacore github issue tracker. 82 | 83 | Credits 84 | ======= 85 | 86 | * `Ger van Diepen `_ 87 | * `Malte Marquarding `_ 88 | * `Gijs Molenaar `_ 89 | * `Tammo Jan Dijkema `_ 90 | -------------------------------------------------------------------------------- /casacore/.aipsrc: -------------------------------------------------------------------------------- 1 | measures.directory: ${CASACORE_DATADIR} 2 | -------------------------------------------------------------------------------- /casacore/__init__.py: -------------------------------------------------------------------------------- 1 | import os 2 | from ._version import __version__ 3 | 4 | __mincasacoreversion__ = "3.1.1" 5 | 6 | # If environment variable `AIPSPATH` is not set, then set it to the directory 7 | # containing the `.aipsrc` file that is distributed with this package. 8 | # This `.aipsrc` file uses the environment `CASACORE_DATADIR`, which should 9 | # point to the directory containing the casacore data files. 10 | if "AIPSPATH" not in os.environ: 11 | root = os.path.dirname(__file__) 12 | os.environ["AIPSPATH"] = root 13 | os.environ["CASACORE_DATADIR"] = os.path.join(root, "data") 14 | -------------------------------------------------------------------------------- /casacore/functionals/__init__.py: -------------------------------------------------------------------------------- 1 | # __init__.py: Top level .py file for python functionals interface 2 | # Copyright (C) 2006,2007 3 | # Associated Universities, Inc. Washington DC, USA. 4 | # 5 | # This library is free software; you can redistribute it and/or modify it 6 | # under the terms of the GNU Lesser General Public License as published by 7 | # the Free Software Foundation; either version 3 of the License, or (at your 8 | # option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, but WITHOUT 11 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | # License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public License 16 | # along with this library; if not, write to the Free Software Foundation, 17 | # Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 18 | # 19 | # Correspondence concerning AIPS++ should be addressed as follows: 20 | # Internet email: aips2-request@nrao.edu. 21 | # Postal address: AIPS++ Project Office 22 | # National Radio Astronomy Observatory 23 | # 520 Edgemont Road 24 | # Charlottesville, VA 22903-2475 USA 25 | # 26 | # $Id: __init__.py,v 1.1 2006/09/29 06:42:55 mmarquar Exp $ 27 | """ 28 | Introduction 29 | ============ 30 | 31 | A functional is a function with parameters, defined as *f(p;x)*, where *p* are 32 | the parameters, and *x* the arguments. Methods are available to calculate the 33 | value of a function for a series of argument values for the given set of 34 | parameters, and for the automatic calculation of the derivatives with respect 35 | to the parameters. 36 | 37 | The created functionals can be used for fitiing as provided by 38 | :mod:`casacore.fitting`. 39 | 40 | A functional has a mask associated with it, to indicate if certain parameters 41 | have to be solved for. See masks for details. 42 | 43 | To access the functionals module ``import casacore.functionals``. 44 | 45 | Functionals are created in a variety of ways, in general by specifying the 46 | name of the functional, together with some necessary information like e.g. 47 | the order of a polynomial, or the code needed to compile your privately 48 | defined function. Parameters can be set at creation time or later:: 49 | 50 | >>> from casacore.functionals import functional, gaussian1d 51 | >>> a = gaussian1d() # creates a 1D Gaussian, default arguments 52 | >>> b = functional('gaussian1d') # creates the same one 53 | >>> print a.f(1) # the value at x=1 54 | [0.062500000000000028] 55 | >>> print a(1) 56 | [0.062500000000000028] 57 | >>> print a.fdf([0,0.5]); # value and derivatives 58 | >>> print a([0, 0.5], derivatives=True) 59 | 60 | In some cases an order can be specified as well (e.g. for polynomials):: 61 | 62 | >>> from casacore.functionals import functional, poly 63 | >>> a = poly(3) # creates a 3rd order polynomial 64 | >>> print a 65 | {'ndim': 1, 'masks': array([ True, True, True, True], dtype=bool), 66 | 'params': array([ 1., 1., 1., 1.]), 'npar': 4, 'type': 5, 'order': 3} 67 | 68 | An extremely valuable aspect of the Functionals module is the ability to 69 | create a functional from a compiled string specifying an arbitrary function. 70 | For example, let us make our own polynomial ``1 + 2*x + 3*x2`` and evaluate it 71 | at a few abcissa locations:: 72 | 73 | >>> from casacore.functionals import compiled 74 | >>> a = compiled('p0 + p1*x + p2*x*x', [1,2,3]) # Define 75 | >>> a([0,10,20]) # Evaluate at x=[0,10,20] 76 | [1.0, 321.0, 1241.0] 77 | 78 | The functions created can also be used to specify the function to be fitted 79 | in a least squares fit. 80 | 81 | """ 82 | from .functional import * 83 | -------------------------------------------------------------------------------- /casacore/images/__init__.py: -------------------------------------------------------------------------------- 1 | # __init__.py: Python image functions 2 | # Copyright (C) 2008 3 | # Associated Universities, Inc. Washington DC, USA. 4 | # 5 | # This library is free software; you can redistribute it and/or modify it 6 | # under the terms of the GNU Lesser General Public License as published by 7 | # the Free Software Foundation; either version 3 of the License, or (at your 8 | # option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, but WITHOUT 11 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | # License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public License 16 | # along with this library; if not, write to the Free Software Foundation, 17 | # Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 18 | # 19 | # Correspondence concerning AIPS++ should be addressed as follows: 20 | # Internet email: aips2-request@nrao.edu. 21 | # Postal address: AIPS++ Project Office 22 | # National Radio Astronomy Observatory 23 | # 520 Edgemont Road 24 | # Charlottesville, VA 22903-2475 USA 25 | # 26 | # $Id$ 27 | 28 | """Python interface to the Casacore images module. 29 | 30 | A `casacore image <../../casacore/doc/html/group__Images__module.html>`_ 31 | represents an astronomical image of arbitrary dimensionality. 32 | Several image formats are recognized: 33 | 34 | `casacore paged image <../../casacore/doc/html/classcasa_1_1PagedImage.html>`_ 35 | is the native casacore image format stored in a casacore table. 36 | `HDF5 `_ 37 | is the HDF5 format often used in the earth science community. 38 | `FITS `_ 39 | is the well-known astronomical FITS format 40 | `miriad `_ 41 | is the format used by the radio-astronomical MIRIAD package. 42 | 43 | The following functionality exists: 44 | 45 | - get and put data (slices) 46 | - get or put a mask 47 | - get meta data like coordinates and history 48 | - get, put, or search optional image attributes (as used for LOFAR) 49 | - get statistics 50 | - form a subimage 51 | - form an image expression which is treated as an ordinary image 52 | - regrid the image 53 | - write the image to a FITS file 54 | 55 | """ 56 | 57 | # Make image interface available. 58 | from .image import image 59 | -------------------------------------------------------------------------------- /casacore/quanta/__init__.py: -------------------------------------------------------------------------------- 1 | from ._quanta import * 2 | 3 | from .quantity import quantity, is_quantity 4 | 5 | constants = constants() 6 | units = units() 7 | prefixes = prefixes() 8 | del Quantity, QuantVec, from_string, from_dict_v 9 | -------------------------------------------------------------------------------- /casacore/quanta/quantity.py: -------------------------------------------------------------------------------- 1 | from ._quanta import QuantVec 2 | from ._quanta import Quantity 3 | from ._quanta import from_string, from_dict, from_dict_v 4 | 5 | 6 | def is_quantity(q): 7 | """Indicate whether the object is a valid quantity""" 8 | return isinstance(q, QuantVec) or isinstance(q, Quantity) 9 | 10 | 11 | # Quantity returns new Quantities, so we need to insert these 12 | # functions into Quantity 13 | def new_get_value(quant, *args): 14 | val = QuantVec._get_value(quant, *args) 15 | if len(val) == 1: 16 | return val[0] 17 | else: 18 | return val 19 | 20 | 21 | QuantVec.get_value = new_get_value 22 | 23 | 24 | def to_string(quant, fmt="%0.5g"): 25 | val = quant.get_value() 26 | if hasattr(val, "__len__"): 27 | fmt = "[" + ", ".join([fmt % i for i in val]) + "] %s" 28 | return fmt % quant.get_unit() 29 | fmt += " %s" 30 | return fmt % (val, quant.get_unit()) 31 | 32 | 33 | QuantVec.to_string = to_string 34 | Quantity.to_string = to_string 35 | QuantVec.__str__ = to_string 36 | Quantity.__str__ = to_string 37 | 38 | 39 | # QuantVec.__repr__ = to_string 40 | # Quantity.__repr__ = to_string 41 | 42 | 43 | def quantity(*args): 44 | """Create a quantity. This can be from a scalar or vector. 45 | 46 | Example:: 47 | 48 | q1 = quantity(1.0, "km/s") 49 | q2 = quantity("1km/s") 50 | q1 = quantity([1.0,2.0], "km/s") 51 | 52 | """ 53 | if len(args) == 1: 54 | if isinstance(args[0], str): 55 | # use copy constructor to create quantity from string 56 | return Quantity(from_string(args[0])) 57 | elif isinstance(args[0], dict): 58 | if hasattr(args[0]["value"], "__len__"): 59 | return QuantVec(from_dict_v(args[0])) 60 | else: 61 | return Quantity(from_dict(args[0])) 62 | elif isinstance(args[0], Quantity) or isinstance(args[0], QuantVec): 63 | return args[0] 64 | else: 65 | raise TypeError("Invalid argument type for") 66 | else: 67 | if hasattr(args[0], "__len__"): 68 | return QuantVec(*args) 69 | else: 70 | return Quantity(*args) 71 | -------------------------------------------------------------------------------- /casacore/tables/__init__.py: -------------------------------------------------------------------------------- 1 | # __init__.py: Top level .py file for python table interface 2 | # Copyright (C) 2006 3 | # Associated Universities, Inc. Washington DC, USA. 4 | # 5 | # This library is free software; you can redistribute it and/or modify it 6 | # under the terms of the GNU Lesser General Public License as published by 7 | # the Free Software Foundation; either version 3 of the License, or (at your 8 | # option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, but WITHOUT 11 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | # License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public License 16 | # along with this library; if not, write to the Free Software Foundation, 17 | # Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 18 | # 19 | # Correspondence concerning AIPS++ should be addressed as follows: 20 | # Internet email: aips2-request@nrao.edu. 21 | # Postal address: AIPS++ Project Office 22 | # National Radio Astronomy Observatory 23 | # 520 Edgemont Road 24 | # Charlottesville, VA 22903-2475 USA 25 | # 26 | # $Id: __init__.py,v 1.6 2006/11/06 01:54:21 gvandiep Exp $ 27 | 28 | """Python interface to the Casacore tables module. 29 | 30 | A `casacore table <../../casacore/doc/html/group__Tables__module.html>`_ 31 | is similar to a relational data base table with the extension 32 | that table cells can contain n-dimensional arrays. 33 | It has a rich SQL-like query language 34 | (`TaQL <../../doc/199.html>`_). 35 | 36 | A table consists of numbered rows and named columns. A column can hold 37 | scalar values or arrays of any dimensionality and shape. Furthermore the 38 | table and each column can hold a set of keywords (e.g. to define the units). 39 | It is nestable, thus the value of a keyword can be a keyword set in itself. 40 | 41 | The `tables` module consists of a few classes: 42 | 43 | :class:`table` 44 | main module to open, create, access, and query tables 45 | :class:`tablecolumn` 46 | access the contents of a column in an easier way 47 | :class:`tablerow` 48 | access the contents of table rows or parts of it 49 | :class:`tableiter` 50 | iterate through a table based on the contents of one or more columns 51 | :class:`tableindex` 52 | build and use an index on one or more table columns 53 | submodule `tableutil <#table-utility-functions>`_ 54 | table utility functions (e.g. to create a table description) 55 | submodule `msutil <#measurementset-utility-functions>`_ 56 | MeasuementSet utility functions (e.g. to concat MSs) 57 | 58 | """ 59 | 60 | from .msutil import * 61 | from .table import table 62 | from .table import default_ms 63 | from .table import default_ms_subtable 64 | from .table import tablecommand 65 | from .table import taql 66 | from .tablecolumn import tablecolumn 67 | from .tableindex import tableindex 68 | from .tableiter import tableiter 69 | from .tablerow import tablerow 70 | from .tableutil import * 71 | -------------------------------------------------------------------------------- /casacore/tables/tablehelper.py: -------------------------------------------------------------------------------- 1 | # tablehelper.py: Helper table functions 2 | # Copyright (C) 2006 3 | # Associated Universities, Inc. Washington DC, USA. 4 | # 5 | # This library is free software; you can redistribute it and/or modify it 6 | # under the terms of the GNU Lesser General Public License as published by 7 | # the Free Software Foundation; either version 3 of the License, or (at your 8 | # option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, but WITHOUT 11 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | # License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public License 16 | # along with this library; if not, write to the Free Software Foundation, 17 | # Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 18 | # 19 | # Correspondence concerning AIPS++ should be addressed as follows: 20 | # Internet email: aips2-request@nrao.edu. 21 | # Postal address: AIPS++ Project Office 22 | # National Radio Astronomy Observatory 23 | # 520 Edgemont Road 24 | # Charlottesville, VA 22903-2475 USA 25 | # 26 | # $Id: tableutil.py,v 1.6 2006/11/08 00:12:55 gvandiep Exp $ 27 | 28 | import numpy 29 | import re 30 | from ..quanta import quantity 31 | 32 | 33 | # A keywordset in a table can hold tables, but it is not possible to 34 | # pass them around because a ValueHolder cannot deal with it. 35 | # Therefore it is passed around as a string with a special prefix. 36 | def _add_prefix(name): 37 | """Add the prefix 'Table: ' to a table name to get a specific keyword value.""" 38 | return 'Table: ' + name 39 | 40 | 41 | def _do_remove_prefix(name): 42 | """Strip the possible prefix 'Table: ' from a table name.""" 43 | res = name 44 | if isinstance(res, str): 45 | if res.find('Table: ') == 0: 46 | res = res.replace('Table: ', '', 1) 47 | return res 48 | 49 | 50 | def _remove_prefix(name): 51 | """Strip the possible prefix 'Table: ' from one or more table names.""" 52 | if isinstance(name, str): 53 | return _do_remove_prefix(name) 54 | return [_do_remove_prefix(nm) for nm in name] 55 | 56 | 57 | def _check_index(key, name): 58 | # The __index__ method converts e.g. np.int16 to a proper integer. 59 | # An exception is thrown if the type does not have __index__ which 60 | # means that the given key cannot be used as an index. 61 | try: 62 | return key.__index__() 63 | except: 64 | raise TypeError(name + " indices must be integer (or None in a slice)") 65 | 66 | 67 | # Check a key or slice given to index a tablerow or tablecolumn object. 68 | # A TypeError exception is raised if values or not integer or None. 69 | # An IndexError is raised if incorrect values are given. 70 | # It returns a list of length 1 if a single index is given. 71 | # Otherwise it returns [startrow, nrow, step]. 72 | def _check_key_slice(key, nrows, name): 73 | if not isinstance(key, slice): 74 | inx = _check_index(key, name) 75 | # A single index (possibly negative, thus from the end). 76 | if inx < 0: 77 | inx += nrows 78 | if inx < 0 or inx >= nrows: 79 | raise IndexError(name + " index out of range") 80 | return [inx] 81 | # Given as start:stop:step where each part is optional and can 82 | # be negative. 83 | incr = 1 84 | if key.step is not None: 85 | incr = _check_index(key.step, name) 86 | if incr == 0: 87 | raise RuntimeError(name + " slice step cannot be zero") 88 | strow = 0 89 | endrow = nrows 90 | if incr < 0: 91 | strow = nrows - 1 92 | endrow = -1 93 | if key.start is not None: 94 | strow = _check_index(key.start, name) 95 | if strow < 0: 96 | strow += nrows 97 | strow = min(max(strow, 0), nrows - 1) 98 | if key.stop is not None: 99 | endrow = _check_index(key.stop, name) 100 | if endrow < 0: 101 | endrow += nrows 102 | endrow = min(max(endrow, -1), nrows) 103 | if incr > 0: 104 | nrow = int((endrow - strow + incr - 1) / incr) 105 | else: 106 | nrow = int((strow - endrow - incr - 1) / -incr) 107 | nrow = max(0, nrow) 108 | return [strow, nrow, incr] 109 | 110 | 111 | # Convert Python value type to a glish-like type string 112 | # as expected by the table code. 113 | def _value_type_name(value): 114 | if isinstance(value, bool): 115 | return 'boolean' 116 | if isinstance(value, int): 117 | return 'integer' 118 | if isinstance(value, float): 119 | return 'double' 120 | if isinstance(value, complex): 121 | return 'dcomplex' 122 | if isinstance(value, str): 123 | return 'string' 124 | if isinstance(value, dict): 125 | return 'record' 126 | return 'unknown' 127 | 128 | 129 | def _format_date(val, unit): 130 | """ 131 | Format dates. 132 | :param val: Value (just the value, not a quantity) 133 | :param unit: Unit. Should be 'rad' or 's' 134 | :return: A string representation of this date. 135 | 136 | >>> _format_date(4914741782.503475, 's') 137 | "14-Aug-2014/14:03:03" 138 | """ 139 | if val == numpy.floor(val) and unit == 'd': 140 | # Do not show time part if 0 141 | return quantity(val, unit).formatted('YMD_ONLY') 142 | else: 143 | return quantity(val, unit).formatted('DMY') 144 | 145 | 146 | def _format_quantum(val, unit): 147 | """ 148 | Format a quantity with reasonable units. 149 | :param val: The value (just the value, not a quantity) 150 | :param unit: Unit (something that can be fed to quanta). 151 | :return: A string representation of this quantity. 152 | 153 | >>> _format_quantum(3, 'm') 154 | "3 m" 155 | >>> _format_quantum(4914741782.503475, 's') 156 | "4.91474e+09 s" 157 | """ 158 | q = quantity(val, unit) 159 | if q.canonical().get_unit() in ['rad', 's']: 160 | return quantity(val, 'm').formatted()[:-1] + unit 161 | else: 162 | return q.formatted() 163 | 164 | 165 | def _format_cell(val, colkeywords): 166 | """ 167 | Format a cell of the table. Colkeywords can add units. 168 | :param val: A plain value (not a quantum) 169 | :param colkeywords: 170 | :return: A HTML representation of this cell. 171 | """ 172 | out = "" 173 | 174 | # String arrays are returned as dict, undo that for printing 175 | if isinstance(val, dict): 176 | tmpdict = numpy.array(val['array']) 177 | tmpdict.reshape(val['shape']) 178 | # Leave out quotes around strings 179 | numpy.set_printoptions(formatter={'all': lambda x: str(x)}) 180 | out += numpy.array2string(tmpdict, separator=', ') 181 | # Revert previous numpy print options 182 | numpy.set_printoptions(formatter=None) 183 | else: 184 | valtype = 'other' 185 | 186 | # Check if the column unit is like 'm' or ['m','m','m'] 187 | singleUnit = ('QuantumUnits' in colkeywords and 188 | (numpy.array(colkeywords['QuantumUnits']) == numpy.array(colkeywords['QuantumUnits'])[0]).all()) 189 | if colkeywords.get('MEASINFO', {}).get('type') == 'epoch' and singleUnit: 190 | # Format a date/time. Use quanta for scalars, use numpy for array logic around it 191 | # (quanta does not support higher dimensional arrays) 192 | valtype = 'epoch' 193 | if isinstance(val, numpy.ndarray): 194 | numpy.set_printoptions(formatter={'all': lambda x: _format_date(x, colkeywords['QuantumUnits'][0])}) 195 | out += numpy.array2string(val, separator=', ') 196 | numpy.set_printoptions(formatter=None) 197 | else: 198 | out += _format_date(val, colkeywords['QuantumUnits'][0]) 199 | elif colkeywords.get('MEASINFO', {}).get('type') == 'direction' and singleUnit and val.shape == (1, 2): 200 | # Format one direction. TODO: extend to array of directions 201 | valtype = 'direction' 202 | out += "[" 203 | part = quantity(val[0, 0], 'rad').formatted("TIME", precision=9) 204 | part = re.sub(r'(\d+):(\d+):(.*)', r'\1h\2m\3', part) 205 | out += part + ", " 206 | part = quantity(val[0, 1], 'rad').formatted("ANGLE", precision=9) 207 | part = re.sub(r'(\d+)\.(\d+)\.(.*)', r'\1d\2m\3', part) 208 | out += part + "]" 209 | elif isinstance(val, numpy.ndarray) and singleUnit: 210 | # Format any array with units 211 | valtype = 'quanta' 212 | numpy.set_printoptions(formatter={'all': lambda x: _format_quantum(x, colkeywords['QuantumUnits'][0])}) 213 | out += numpy.array2string(val, separator=', ') 214 | numpy.set_printoptions(formatter=None) 215 | elif isinstance(val, numpy.ndarray): 216 | valtype = 'other' 217 | # Undo quotes around strings 218 | numpy.set_printoptions(formatter={'all': lambda x: str(x)}) 219 | out += numpy.array2string(val, separator=', ') 220 | numpy.set_printoptions(formatter=None) 221 | elif singleUnit: 222 | valtype = 'onequantum' 223 | out += _format_quantum(val, colkeywords['QuantumUnits'][0]) 224 | else: 225 | valtype = 'other' 226 | out += str(val) 227 | 228 | if 'QuantumUnits' in colkeywords and valtype == 'other': 229 | # Print units if they haven't been taken care of 230 | if not (numpy.array(colkeywords['QuantumUnits']) == numpy.array(colkeywords['QuantumUnits'])[0]).all(): 231 | # Multiple different units for element in an array. 232 | # For now, just print the units and let the user figure out what it means 233 | out += " " + str(colkeywords['QuantumUnits']) 234 | else: 235 | out += " " + colkeywords['QuantumUnits'][0] 236 | 237 | # Numpy sometimes adds double newlines, don't do that 238 | out = out.replace('\n\n', '\n') 239 | return out 240 | 241 | 242 | def _format_row(row, colnames, tab): 243 | """ 244 | Helper function for _repr_html. Formats one row. 245 | :param row: row of this table 246 | :param colnames: vector of column names 247 | :param tab: table, used to get the column keywords 248 | :return: html-formatted row 249 | """ 250 | out = "" 251 | 252 | out += "\n" 253 | for colname in colnames: 254 | out += "" 255 | out += _format_cell(row[colname], tab.getcolkeywords(colname)) 256 | out += "\n" 257 | out += "\n" 258 | return out 259 | -------------------------------------------------------------------------------- /casacore/tables/tableindex.py: -------------------------------------------------------------------------------- 1 | # tableindex.py: Python tableindex functions 2 | # Copyright (C) 2006 3 | # Associated Universities, Inc. Washington DC, USA. 4 | # 5 | # This library is free software; you can redistribute it and/or modify it 6 | # under the terms of the GNU Lesser General Public License as published by 7 | # the Free Software Foundation; either version 3 of the License, or (at your 8 | # option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, but WITHOUT 11 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | # License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public License 16 | # along with this library; if not, write to the Free Software Foundation, 17 | # Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 18 | # 19 | # Correspondence concerning AIPS++ should be addressed as follows: 20 | # Internet email: aips2-request@nrao.edu. 21 | # Postal address: AIPS++ Project Office 22 | # National Radio Astronomy Observatory 23 | # 520 Edgemont Road 24 | # Charlottesville, VA 22903-2475 USA 25 | # 26 | # $Id: tableindex.py,v 1.6 2006/11/08 00:12:55 gvandiep Exp $ 27 | 28 | # Make interface to class TableIndexProxy available. 29 | from ._tables import TableIndex 30 | 31 | 32 | class tableindex(TableIndex): 33 | """The Python interface to Casacore table index. 34 | 35 | A tableindex makes it possible to find rows in a :class:`table` based on 36 | the contents of one or more columns. When constructing the `tableindex` it 37 | has to be specified for which column or columns an index has to be built. 38 | Those columns will be loaded in memory and thereafter row numbers can be 39 | found in a fast way using a binary search. 40 | 41 | Using a table index is only useful if many searches will be done in the 42 | table. For a single or few searches it is better to query the table using 43 | method :func:`table.query`. 44 | 45 | Normally an index will be build on one or more scalar columns (e.g. 46 | on ANTENNA1 and ANTENNA2 in a measurementset table). However, it is also 47 | possible to buo.d an index for a column containing arrays (e.g. for a 48 | column where each cell can contain multiple names. In that case only a 49 | single column can be indexed. 50 | 51 | The index can be unique, but does not need to be. 52 | A unique index can be asked for the row number containing a given key. 53 | A non-unique index can only be asked for the row numbers containing a key. 54 | The returned sequence can thereafter be used in :func:`table.selectrows` 55 | to form that subset of the table. 56 | 57 | `tableindex` supports Python's index operator [] as explained in the 58 | methods :func:`rownr` and :func:`rownrs`. 59 | 60 | """ 61 | 62 | def __init__(self, table, columnnames, sort=True): 63 | TableIndex.__init__(self, table, columnnames, not sort) 64 | 65 | """Create the index on one or more columns. 66 | 67 | By default the columns get sorted when forming in the index. By giving 68 | `sort=False` this can be omitted in case the table is already in the 69 | correct order. 70 | 71 | Method :func:`table.index` is a somewhat easier way to create a 72 | `tableindex` object. 73 | 74 | """ 75 | 76 | # Turn a key into a dict if needed. 77 | def _makekey(self, key): 78 | d = key 79 | if not isinstance(d, dict): 80 | cols = self.colnames() 81 | if len(cols) != 1: 82 | raise RuntimeError("key has to be given as a dict for a multi-column index") 83 | d = {cols[0]: key} 84 | return d 85 | 86 | def rownr(self, key): 87 | """Get the unique row number containing the key. 88 | 89 | If the index is made from a single column, the keycan be given as a 90 | single value. 91 | Otherwise the key has to be given as a dict where the name of each 92 | field in the dict should correspond with the column name in the index. 93 | 94 | For example:: 95 | 96 | t = table('3c343.MS/ANTENNA') 97 | tinx = t.index ('NAME') # build index for antenna name 98 | rownr = tinx.rownr('RTE') # find an antenna by name 99 | rownr = tinx['RTE'] # same as above 100 | t.getcell ('POSITION', rownr) # get position of that antenna 101 | 102 | As shown in the example above the python index operator can also 103 | be used to find a row number if the index if made of a single column. 104 | 105 | An exception will be raised if the index is not unique. In that case 106 | method :func:`rownrs` should be used instead. 107 | 108 | """ 109 | return self._rownr(self._makekey(key)) 110 | 111 | def rownrs(self, key, upperkey={}, lowerincl=True, upperincl=True): 112 | """Get a sequence of row numbers containing the key(s). 113 | 114 | A single key can be given, but by giving argument `upperkey` as well 115 | a key range can be given (where upper key must be > lower). 116 | One can specify if the lower and upper key should be part of the range 117 | (`incl=True`) or not. By default both keys are part of the range. 118 | 119 | The key and optional upper key have to be given in the same way as 120 | for method :func:`rownr`. 121 | 122 | Similar to method :func:`rownr`. python's index operator [] can be used 123 | if the index consists of a single column. However, in this case only 124 | key ranges can be used (because the index operator with a single key 125 | returns a single row number, thus can only be used for unique indices). 126 | The lower key is inclusive, but the upper key is exclusive conform 127 | the standard python index semantics. 128 | 129 | For example:: 130 | 131 | t = table('3c343.MS') 132 | tinx = t.index ('ANTENNA1') # build index for antenna name 133 | rownr = tinx.rownr(0) # find antenna1 = 0 134 | rownr = tinx[0:1] # same as above 135 | 136 | """ 137 | lkey = self._makekey(key) 138 | ukey = self._makekey(upperkey) 139 | if len(ukey) == 0: 140 | return self._rownrs(lkey) 141 | return self._rownrsrange(lkey, ukey, lowerincl, upperincl) 142 | 143 | def isunique(self): 144 | """Tell if all keys in the index are unique.""" 145 | return self._isunique() 146 | 147 | def colnames(self): 148 | """Return the column names the index is made of.""" 149 | return self._colnames() 150 | 151 | def setchanged(self, columnnames=[]): 152 | """Tell the index that data has changed. 153 | 154 | The index is smart enough to detect that the number of rows in the 155 | indexed table has changed. However, it cannot detect if a value in 156 | a column contained in this inex has changed. So it has to be told 157 | explicitly. 158 | 159 | `columnnames` 160 | The names of the columns in which data have changed. 161 | Giving no names means that all columns in the index have changed. 162 | """ 163 | return self._setchanged(columnnames) 164 | 165 | def __getitem__(self, key): 166 | if not isinstance(key, slice): 167 | rnr = self.rownr(key) 168 | if rnr < 0: 169 | raise KeyError("key not found in tableindex") 170 | return rnr 171 | if key.step is not None: 172 | raise RuntimeError("tableindex slicing cannot have a step") 173 | lowerkey = 0 174 | if key.start is not None: 175 | lowerkey = key.start 176 | upperkey = 2147483647; # highest int 177 | if key.stop is not None: 178 | upperkey = key.stop 179 | if (lowerkey >= upperkey): 180 | raise RuntimeError("tableindex slice stop must be > start") 181 | rnrs = self.rownrs(lowerkey, upperkey, True, False) 182 | if len(rnrs) == 0: 183 | raise KeyError("keys not found in tableindex") 184 | return rnrs 185 | -------------------------------------------------------------------------------- /casacore/tables/tableiter.py: -------------------------------------------------------------------------------- 1 | # tableiter.py: Python tableiter functions 2 | # Copyright (C) 2006 3 | # Associated Universities, Inc. Washington DC, USA. 4 | # 5 | # This library is free software; you can redistribute it and/or modify it 6 | # under the terms of the GNU Lesser General Public License as published by 7 | # the Free Software Foundation; either version 3 of the License, or (at your 8 | # option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, but WITHOUT 11 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | # License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public License 16 | # along with this library; if not, write to the Free Software Foundation, 17 | # Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 18 | # 19 | # Correspondence concerning AIPS++ should be addressed as follows: 20 | # Internet email: aips2-request@nrao.edu. 21 | # Postal address: AIPS++ Project Office 22 | # National Radio Astronomy Observatory 23 | # 520 Edgemont Road 24 | # Charlottesville, VA 22903-2475 USA 25 | # 26 | # $Id: tableiter.py,v 1.6 2006/12/11 02:46:08 gvandiep Exp $ 27 | 28 | # Make interface to class TableIterProxy available. 29 | from ._tables import TableIter 30 | 31 | from .table import table 32 | 33 | 34 | class tableiter(TableIter): 35 | """The Python interface to Casacore table iterators 36 | 37 | A `tableiter` allows iteration through a table based on the contents 38 | of one or more columns. Each step in the iteration process forms 39 | a subset of the table for which the specified columns have the same value. 40 | 41 | It can easily be constructed using the :func:`table.iter` method as done 42 | in the example below:: 43 | 44 | t = table('3c343.MS') 45 | for ts in t.iter('ANTENNA1'): 46 | print ts.nrows() 47 | 48 | In this example `ts` will be a so-called reference table which can be 49 | operated on like any other table object. 50 | 51 | Multiple column names should be given in a sequence (tuple or list). 52 | 53 | """ 54 | 55 | def __init__(self, table, columnnames, order='', sort=True): 56 | st = sort 57 | if isinstance(sort, bool): 58 | st = 'heapsort' 59 | if not sort: 60 | st = 'nosort' 61 | TableIter.__init__(self, table, columnnames, order, st) 62 | 63 | def __iter__(self): 64 | # __iter__ is needed 65 | return self 66 | 67 | def next(self): 68 | # next returns a Table object, so turn that into table. 69 | return table(self._next(), _oper=3) 70 | 71 | def reset(self): 72 | """Reset the iterator to the beginning.""" 73 | self._reset() 74 | 75 | __next__ = next 76 | -------------------------------------------------------------------------------- /casacore/tables/tablerow.py: -------------------------------------------------------------------------------- 1 | # tablerow.py: Python tablerow functions 2 | # Copyright (C) 2006 3 | # Associated Universities, Inc. Washington DC, USA. 4 | # 5 | # This library is free software; you can redistribute it and/or modify it 6 | # under the terms of the GNU Lesser General Public License as published by 7 | # the Free Software Foundation; either version 3 of the License, or (at your 8 | # option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, but WITHOUT 11 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | # License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public License 16 | # along with this library; if not, write to the Free Software Foundation, 17 | # Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 18 | # 19 | # Correspondence concerning AIPS++ should be addressed as follows: 20 | # Internet email: aips2-request@nrao.edu. 21 | # Postal address: AIPS++ Project Office 22 | # National Radio Astronomy Observatory 23 | # 520 Edgemont Road 24 | # Charlottesville, VA 22903-2475 USA 25 | # 26 | # $Id: tablerow.py,v 1.6 2007/08/28 07:22:18 gvandiep Exp $ 27 | 28 | # Make interface to class TableRowProxy available. 29 | from ._tables import TableRow 30 | 31 | from .tablehelper import _check_key_slice 32 | 33 | 34 | # A normal tablerow object keeps a reference to a table object to be able 35 | # to know the actual number of rows. 36 | # However, a mutual dependency is created when doing that for the tablerow 37 | # object inside the table object. 38 | # Therefore an intermediate _tablerow exists to be used in class table. 39 | 40 | class _tablerow(TableRow): 41 | def __init__(self, table, columnnames, exclude=False): 42 | TableRow.__init__(self, table, columnnames, exclude) 43 | 44 | def iswritable(self): 45 | """Tell if all columns in the row object are writable.""" 46 | return self._iswritable() 47 | 48 | def get(self, rownr): 49 | """Get the contents of the given row.""" 50 | return self._get(rownr) 51 | 52 | def put(self, rownr, value, matchingfields=True): 53 | """Put the values into the given row. 54 | 55 | The value should be a dict (as returned by method :func:`get`. 56 | The names of the fields in the dict should match the names of the 57 | columns used in the `tablerow` object. 58 | 59 | `matchingfields=True` means that the value may contain more fields 60 | and only fields matching a column name will be used. 61 | 62 | """ 63 | self._put(rownr, value, matchingfields) 64 | 65 | def _getitem(self, key, nrows): 66 | sei = _check_key_slice(key, nrows, 'tablerow') 67 | rownr = sei[0] 68 | if len(sei) == 1: 69 | return self.get(rownr) 70 | result = [] 71 | inx = 0 72 | while inx < sei[1]: 73 | result.append(self.get(rownr)) 74 | rownr += sei[2] 75 | inx += 1 76 | return result 77 | 78 | def _setitem(self, key, value, nrows): 79 | sei = _check_key_slice(key, nrows, 'tablerow') 80 | rownr = sei[0] 81 | if len(sei) == 1: 82 | return self.put(rownr, value) 83 | if isinstance(value, dict): 84 | # The same value is put in all rows. 85 | inx = 0 86 | while inx < sei[1]: 87 | self.put(rownr, value, True) 88 | rownr += sei[2] 89 | inx += 1 90 | else: 91 | # Each row has its own value. 92 | if len(value) != sei[1]: 93 | raise RuntimeError("tablerow slice length differs from value length") 94 | for val in value: 95 | self.put(rownr, val, True) 96 | rownr += sei[2] 97 | 98 | 99 | class tablerow(_tablerow): 100 | """The Python interface to Casacore table rows. 101 | 102 | A table row is a record (dict) containing the values of a single row for 103 | one or more columns in a table. In constructing the `tablerow` object, one 104 | can specify which columns are to be included or excluded. 105 | By default all columns will be used, but if the table is writable, 106 | only writable columns will be used. 107 | 108 | A `tablerow` object can easily be constructed using :func:`table.row`. 109 | 110 | One or more rows can be read or written using the standard python indexing 111 | syntax where (negative) strides are possible. 112 | For example: 113 | 114 | t = table ('3c343.MS') 115 | tr = t.row (['ANTENNA1', 'ANTENNA2', 'ARRAY_ID']) 116 | tr[0] # get row 0 117 | tr[:5] # get row 0,1,2,3,4 118 | tr[-5,-1,] # get last 4 rows 119 | tr[-1,-5,-1] # get last 4 rows in reversed order 120 | tr[1] = tr[0] # put values of row 0 into row 1 121 | 122 | Note that the last line will fail because the table is opened readonly. 123 | The argument `readonly=False` is needed in the table constructor to make 124 | it work. 125 | 126 | The `tablerow` class supports the context manager idiom (__enter__ and __exit__). 127 | When used in a `with` statement, the table changes will be flushed 128 | automatically, which is handy when writing to table rows. 129 | For example:: 130 | 131 | with t.row() as tr: 132 | tr.put (1, tr.get(0)) # copy row 0 to row 1 133 | 134 | """ 135 | 136 | def __init__(self, table, columnnames=[], exclude=False): 137 | _tablerow.__init__(self, table, columnnames, exclude) 138 | self._table = table 139 | 140 | def __enter__(self): 141 | """Function to enter a with block.""" 142 | return self 143 | 144 | def __exit__(self, type, value, traceback): 145 | """Function to exit a with block which flushes the table object.""" 146 | self._table.flush() 147 | 148 | def __len__(self): 149 | return self._table.nrows() 150 | 151 | def __getitem__(self, key): 152 | return self._getitem(key, self._table.nrows()) 153 | 154 | def __setitem__(self, key, value): 155 | return self._setitem(key, value, self._table.nrows()) 156 | -------------------------------------------------------------------------------- /casacore/tables/wxtablebrowser.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from wxPython.grid import * 4 | from wxPython.wx import * 5 | 6 | 7 | class wxCasaTable(wxPyGridTableBase): 8 | """ 9 | This is all it takes to make a custom data table to plug into a 10 | wxGrid. There are many more methods that can be overridden, but 11 | the ones shown below are the required ones. This table simply 12 | provides strings containing the row and column values. 13 | """ 14 | 15 | def __init__(self, log, ctable): 16 | wxPyGridTableBase.__init__(self) 17 | self.log = log 18 | self.casatab = ctable 19 | self.odd = wxGridCellAttr() 20 | self.odd.SetBackgroundColour("gray90") 21 | self.even = wxGridCellAttr() 22 | self.even.SetBackgroundColour("white") 23 | 24 | def GetAttr(self, row, col, kind): 25 | attr = [self.even, self.odd][row % 2] 26 | attr.IncRef() 27 | return attr 28 | 29 | def GetColLabelValue(self, col): 30 | colnames = self.casatab.colnames() 31 | return colnames[col] 32 | 33 | def GetNumberRows(self): 34 | return self.casatab.nrows() 35 | 36 | def GetNumberCols(self): 37 | return self.casatab.ncols() 38 | 39 | def IsEmptyCell(self, row, col): 40 | return False 41 | 42 | def GetValue(self, row, col): 43 | coln = self.casatab.colnames() 44 | cell = 'array' 45 | ## if self.casatab.isscalarcol(coln[col]): 46 | ## cellval = self.casatab.getcell(coln[col],row) 47 | ## if isinstance(cellval,float): 48 | ## if coln[col] == "TIME": 49 | ## cell = str(cellval) 50 | ## else: 51 | ## cell = "%3.5f" % cellval 52 | ## else: 53 | ## cell = str(cellval) 54 | ## else: 55 | ## cell += self.casatab.getcolshapestring(coln[col],row,1)[0] 56 | ## return cell 57 | return str(self.casatab.getcell(coln[col], row)) 58 | 59 | def SetValue(self, row, col, value): 60 | self.log.write('SetValue(%d, %d, "%s") ignored.\n' % (row, col, value)) 61 | 62 | 63 | # --------------------------------------------------------------------------- 64 | 65 | class wxCasaTableGrid(wxGrid): 66 | def __init__(self, parent, log, ctable): 67 | wxGrid.__init__(self, parent, -1) 68 | table = wxCasaTable(log, ctable) 69 | # The second parameter means that the grid is to take ownership of the 70 | # table and will destroy it when done. Otherwise you would need to keep 71 | # a reference to it and call it's Destroy method later. 72 | self.SetTable(table, True) 73 | EVT_GRID_CELL_RIGHT_CLICK(self, self.OnRightDown) # added 74 | 75 | def OnRightDown(self, event): # added 76 | print(self.GetSelectedRows()) # added 77 | 78 | 79 | # --------------------------------------------------------------------------- 80 | 81 | class CasaTestFrame(wxFrame): 82 | def __init__(self, parent, log, ctable): 83 | wxFrame.__init__(self, parent, -1, "Casa Table Browser", 84 | size=(640, 480)) 85 | grid = wxCasaTableGrid(self, log, ctable) 86 | grid.EnableEditing(False) 87 | # grid.AutoSizeColumns() 88 | 89 | 90 | # --------------------------------------------------------------------------- 91 | 92 | if __name__ == '__main__': 93 | import sys 94 | 95 | app = wxPySimpleApp() 96 | from casacore.tables import table as casatable 97 | 98 | casatab = casatable('/nfs/aips++/data/atnf/scripts/C972.ms') 99 | frame = CasaTestFrame(None, sys.stdout, casatab) 100 | frame.Show(True) 101 | app.MainLoop() 102 | 103 | 104 | # --------------------------------------------------------------------------- 105 | -------------------------------------------------------------------------------- /casacore/util/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Utilities for casacore modules. 3 | """ 4 | from .substitute import substitute, getlocals, getvariable 5 | -------------------------------------------------------------------------------- /cmake/FindCFITSIO.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find CFITSIO. 2 | # Variables used by this module: 3 | # CFITSIO_ROOT_DIR - CFITSIO root directory 4 | # Variables defined by this module: 5 | # CFITSIO_FOUND - system has CFITSIO 6 | # CFITSIO_INCLUDE_DIR - the CFITSIO include directory (cached) 7 | # CFITSIO_INCLUDE_DIRS - the CFITSIO include directories 8 | # (identical to CFITSIO_INCLUDE_DIR) 9 | # CFITSIO_LIBRARY - the CFITSIO library (cached) 10 | # CFITSIO_LIBRARIES - the CFITSIO libraries 11 | # (identical to CFITSIO_LIBRARY) 12 | # CFITSIO_VERSION_STRING the found version of CFITSIO, padded to 3 digits 13 | 14 | # Copyright (C) 2009 15 | # ASTRON (Netherlands Institute for Radio Astronomy) 16 | # P.O.Box 2, 7990 AA Dwingeloo, The Netherlands 17 | # 18 | # This file is part of the LOFAR software suite. 19 | # The LOFAR software suite is free software: you can redistribute it and/or 20 | # modify it under the terms of the GNU General Public License as published 21 | # by the Free Software Foundation, either version 3 of the License, or 22 | # (at your option) any later version. 23 | # 24 | # The LOFAR software suite is distributed in the hope that it will be useful, 25 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 27 | # GNU General Public License for more details. 28 | # 29 | # You should have received a copy of the GNU General Public License along 30 | # with the LOFAR software suite. If not, see . 31 | # 32 | # $Id$ 33 | 34 | if(NOT CFITSIO_FOUND) 35 | 36 | find_path(CFITSIO_INCLUDE_DIR fitsio.h 37 | HINTS ${CFITSIO_ROOT_DIR} PATH_SUFFIXES include include/cfitsio 38 | include/libcfitsio0) 39 | 40 | if(CFITSIO_INCLUDE_DIR) 41 | FILE(READ "${CFITSIO_INCLUDE_DIR}/fitsio.h" CFITSIO_H) 42 | set(CFITSIO_VERSION_REGEX ".*#define CFITSIO_VERSION[^0-9]*([0-9]+)\\.([0-9]+).*") 43 | if ("${CFITSIO_H}" MATCHES ${CFITSIO_VERSION_REGEX}) 44 | # Pad CFITSIO minor version to three digit because 3.181 is older than 3.35 45 | STRING(REGEX REPLACE ${CFITSIO_VERSION_REGEX} 46 | "\\1.\\200" CFITSIO_VERSION_STRING "${CFITSIO_H}") 47 | STRING(SUBSTRING ${CFITSIO_VERSION_STRING} 0 5 CFITSIO_VERSION_STRING) 48 | STRING(REGEX REPLACE "^([0-9]+)[.]([0-9]+)" "\\1" CFITSIO_VERSION_MAJOR ${CFITSIO_VERSION_STRING}) 49 | # CFITSIO_VERSION_MINOR will contain 80 for 3.08, 181 for 3.181 and 200 for 3.2 50 | STRING(REGEX REPLACE "^([0-9]+)[.]0*([0-9]+)" "\\2" CFITSIO_VERSION_MINOR ${CFITSIO_VERSION_STRING}) 51 | else () 52 | set(CFITSIO_VERSION_STRING "Unknown") 53 | endif() 54 | endif(CFITSIO_INCLUDE_DIR) 55 | 56 | find_library(CFITSIO_LIBRARY cfitsio 57 | HINTS ${CFITSIO_ROOT_DIR} PATH_SUFFIXES lib) 58 | find_library(M_LIBRARY m) 59 | mark_as_advanced(CFITSIO_INCLUDE_DIR CFITSIO_LIBRARY M_LIBRARY) 60 | 61 | if(CMAKE_VERSION VERSION_LESS "2.8.3") 62 | find_package_handle_standard_args(CFITSIO DEFAULT_MSG 63 | CFITSIO_LIBRARY M_LIBRARY CFITSIO_INCLUDE_DIR) 64 | else () 65 | include(FindPackageHandleStandardArgs) 66 | find_package_handle_standard_args(CFITSIO 67 | REQUIRED_VARS CFITSIO_LIBRARY M_LIBRARY CFITSIO_INCLUDE_DIR 68 | VERSION_VAR CFITSIO_VERSION_STRING) 69 | endif () 70 | 71 | set(CFITSIO_INCLUDE_DIRS ${CFITSIO_INCLUDE_DIR}) 72 | set(CFITSIO_LIBRARIES ${CFITSIO_LIBRARY} ${M_LIBRARY}) 73 | 74 | endif(NOT CFITSIO_FOUND) 75 | -------------------------------------------------------------------------------- /cmake/FindWCSLIB.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find WCSLIB: the FITS "World Coordinate System" library 2 | # Variables used by this module: 3 | # WCSLIB_ROOT_DIR - WCSLIB root directory 4 | # Variables defined by this module: 5 | # WCSLIB_FOUND - system has WCSLIB 6 | # WCSLIB_INCLUDE_DIR - the WCSLIB include directory (cached) 7 | # WCSLIB_INCLUDE_DIRS - the WCSLIB include directories 8 | # (identical to WCSLIB_INCLUDE_DIR) 9 | # WCSLIB_LIBRARY - the WCSLIB library (cached) 10 | # WCSLIB_LIBRARIES - the WCSLIB libraries 11 | # (identical to WCSLIB_LIBRARY) 12 | # WCSLIB_VERSION_STRING the found version of WCSLIB 13 | 14 | # Copyright (C) 2009 15 | # ASTRON (Netherlands Institute for Radio Astronomy) 16 | # P.O.Box 2, 7990 AA Dwingeloo, The Netherlands 17 | # 18 | # This file is part of the LOFAR software suite. 19 | # The LOFAR software suite is free software: you can redistribute it and/or 20 | # modify it under the terms of the GNU General Public License as published 21 | # by the Free Software Foundation, either version 3 of the License, or 22 | # (at your option) any later version. 23 | # 24 | # The LOFAR software suite is distributed in the hope that it will be useful, 25 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 27 | # GNU General Public License for more details. 28 | # 29 | # You should have received a copy of the GNU General Public License along 30 | # with the LOFAR software suite. If not, see . 31 | # 32 | # $Id$ 33 | 34 | if(NOT WCSLIB_FOUND) 35 | 36 | find_path(WCSLIB_INCLUDE_DIR wcslib/wcsconfig.h 37 | HINTS ${WCSLIB_ROOT_DIR} PATH_SUFFIXES include) 38 | 39 | if(WCSLIB_INCLUDE_DIR) 40 | FILE(READ "${WCSLIB_INCLUDE_DIR}/wcslib/wcsconfig.h" WCSLIB_H) 41 | set(WCSLIB_VERSION_REGEX ".*#define WCSLIB_VERSION[^0-9]*([0-9]+)\\.([0-9]+).*") 42 | if ("${WCSLIB_H}" MATCHES ${WCSLIB_VERSION_REGEX}) 43 | STRING(REGEX REPLACE ${WCSLIB_VERSION_REGEX} 44 | "\\1.\\2" WCSLIB_VERSION_STRING "${WCSLIB_H}") 45 | STRING(REGEX REPLACE "^([0-9]+)[.]([0-9]+)" "\\1" WCSLIB_VERSION_MAJOR ${WCSLIB_VERSION_STRING}) 46 | STRING(REGEX REPLACE "^([0-9]+)[.]([0-9]+)" "\\2" WCSLIB_VERSION_MINOR ${WCSLIB_VERSION_STRING}) 47 | else () 48 | set(WCSLIB_VERSION_STRING "Unknown") 49 | endif () 50 | endif(WCSLIB_INCLUDE_DIR) 51 | 52 | find_library(WCSLIB_LIBRARY wcs 53 | HINTS ${WCSLIB_ROOT_DIR} PATH_SUFFIXES lib) 54 | find_library(M_LIBRARY m) 55 | mark_as_advanced(WCSLIB_INCLUDE_DIR WCSLIB_LIBRARY M_LIBRARY) 56 | 57 | if(CMAKE_VERSION VERSION_LESS "2.8.3") 58 | find_package_handle_standard_args(WCSLIB DEFAULT_MSG 59 | WCSLIB_LIBRARY M_LIBRARY WCSLIB_INCLUDE_DIR) 60 | else () 61 | include(FindPackageHandleStandardArgs) 62 | find_package_handle_standard_args(WCSLIB 63 | REQUIRED_VARS WCSLIB_LIBRARY M_LIBRARY WCSLIB_INCLUDE_DIR 64 | VERSION_VAR WCSLIB_VERSION_STRING) 65 | endif () 66 | 67 | set(WCSLIB_INCLUDE_DIRS ${WCSLIB_INCLUDE_DIR}) 68 | set(WCSLIB_LIBRARIES ${WCSLIB_LIBRARY} ${M_LIBRARY}) 69 | 70 | endif(NOT WCSLIB_FOUND) 71 | -------------------------------------------------------------------------------- /doc/259.css: -------------------------------------------------------------------------------- 1 | 2 | /* start css.sty */ 3 | .cmr-10{font-size:90%;} 4 | .cmr-10x-x-109{} 5 | .cmr-17{font-size:154%;} 6 | .cmr-12{font-size:109%;} 7 | .cmbx-10{font-size:90%; font-weight: bold;} 8 | .cmtt-10x-x-109{font-family: monospace;} 9 | p.noindent { text-indent: 0em } 10 | td p.noindent { text-indent: 0em; margin-top:0em; } 11 | p.nopar { text-indent: 0em; } 12 | p.indent{ text-indent: 1.5em } 13 | @media print {div.crosslinks {visibility:hidden;}} 14 | a img { border-top: 0; border-left: 0; border-right: 0; } 15 | center { margin-top:1em; margin-bottom:1em; } 16 | td center { margin-top:0em; margin-bottom:0em; } 17 | .Canvas { position:relative; } 18 | img.math{vertical-align:middle;} 19 | li p.indent { text-indent: 0em } 20 | .enumerate1 {list-style-type:decimal;} 21 | .enumerate2 {list-style-type:lower-alpha;} 22 | .enumerate3 {list-style-type:lower-roman;} 23 | .enumerate4 {list-style-type:upper-alpha;} 24 | div.newtheorem { margin-bottom: 2em; margin-top: 2em;} 25 | .obeylines-h,.obeylines-v {white-space: nowrap; } 26 | div.obeylines-v p { margin-top:0; margin-bottom:0; } 27 | .overline{ text-decoration:overline; } 28 | .overline img{ border-top: 1px solid black; } 29 | td.displaylines {text-align:center; white-space:nowrap;} 30 | .centerline {text-align:center;} 31 | .rightline {text-align:right;} 32 | div.verbatim {font-family: monospace; white-space: nowrap; } 33 | table.verbatim {width:100%;} 34 | .fbox {padding-left:3.0pt; padding-right:3.0pt; text-indent:0pt; border:solid black 0.4pt; } 35 | div.center div.fbox {text-align:center; clear:both; padding-left:3.0pt; padding-right:3.0pt; text-indent:0pt; border:solid black 0.4pt; } 36 | table.minipage{width:100%;} 37 | div.center, div.center div.center {text-align: center; margin-left:1em; margin-right:1em;} 38 | div.center div {text-align: left;} 39 | div.flushright, div.flushright div.flushright {text-align: right;} 40 | div.flushright div {text-align: left;} 41 | div.flushleft {text-align: left;} 42 | .underline{ text-decoration:underline; } 43 | .underline img{ border-bottom: 1px solid black; margin-bottom:1pt; } 44 | .framebox-c, .framebox-l, .framebox-r { padding-left:3.0pt; padding-right:3.0pt; text-indent:0pt; border:solid black 0.4pt; } 45 | .framebox-c {text-align:center;} 46 | .framebox-l {text-align:left;} 47 | .framebox-r {text-align:right;} 48 | span.thank-mark{ vertical-align: super } 49 | span.footnote-mark sup.textsuperscript, span.footnote-mark a sup.textsuperscript{ font-size:80%; } 50 | div.tabular, div.center div.tabular {text-align: center; margin-top:0.5em; margin-bottom:0.5em; } 51 | table.tabular td p{margin-top:0em;} 52 | table.tabular {margin-left: auto; margin-right: auto;} 53 | div.td00{ margin-left:0pt; margin-right:0pt; } 54 | div.td01{ margin-left:0pt; margin-right:5pt; } 55 | div.td10{ margin-left:5pt; margin-right:0pt; } 56 | div.td11{ margin-left:5pt; margin-right:5pt; } 57 | table[rules] {border-left:solid black 0.4pt; border-right:solid black 0.4pt; } 58 | td.td00{ padding-left:0pt; padding-right:0pt; } 59 | td.td01{ padding-left:0pt; padding-right:5pt; } 60 | td.td10{ padding-left:5pt; padding-right:0pt; } 61 | td.td11{ padding-left:5pt; padding-right:5pt; } 62 | table[rules] {border-left:solid black 0.4pt; border-right:solid black 0.4pt; } 63 | .hline hr, .cline hr{ height : 1px; margin:0px; } 64 | .tabbing-right {text-align:right;} 65 | span.TEX {letter-spacing: -0.125em; } 66 | span.TEX span.E{ position:relative;top:0.5ex;left:-0.0417em;} 67 | a span.TEX span.E {text-decoration: none; } 68 | span.LATEX span.A{ position:relative; top:-0.5ex; left:-0.4em; font-size:85%;} 69 | span.LATEX span.TEX{ position:relative; left: -0.4em; } 70 | div.float img, div.float .caption {text-align:center;} 71 | div.figure img, div.figure .caption {text-align:center;} 72 | .marginpar {width:20%; float:right; text-align:left; margin-left:auto; margin-top:0.5em; font-size:85%; text-decoration:underline;} 73 | .marginpar p{margin-top:0.4em; margin-bottom:0.4em;} 74 | table.equation {width:100%;} 75 | .equation td{text-align:center; } 76 | td.equation { margin-top:1em; margin-bottom:1em; } 77 | td.equation-label { width:5%; text-align:center; } 78 | td.eqnarray4 { width:5%; white-space: normal; } 79 | td.eqnarray2 { width:5%; } 80 | table.eqnarray-star, table.eqnarray {width:100%;} 81 | div.eqnarray{text-align:center;} 82 | div.array {text-align:center;} 83 | div.pmatrix {text-align:center;} 84 | table.pmatrix {width:100%;} 85 | span.pmatrix img{vertical-align:middle;} 86 | div.pmatrix {text-align:center;} 87 | table.pmatrix {width:100%;} 88 | img.cdots{vertical-align:middle;} 89 | .partToc a, .partToc, .likepartToc a, .likepartToc {line-height: 200%; font-weight:bold; font-size:110%;} 90 | .caption td.id{font-weight: bold; white-space: nowrap; } 91 | table.caption {text-align:center;} 92 | h1.partHead{text-align: center} 93 | p.bibitem { text-indent: -2em; margin-left: 2em; margin-top:0.6em; margin-bottom:0.6em; } 94 | p.bibitem-p { text-indent: 0em; margin-left: 2em; margin-top:0.6em; margin-bottom:0.6em; } 95 | .paragraphHead, .likeparagraphHead { margin-top:2em; font-weight: bold;} 96 | .subparagraphHead, .likesubparagraphHead { font-weight: bold;} 97 | .quote {margin-bottom:0.25em; margin-top:0.25em; margin-left:1em; margin-right:1em; text-align:justify;} 98 | .verse{white-space:nowrap; margin-left:2em} 99 | div.maketitle {text-align:center;} 100 | h2.titleHead{text-align:center;} 101 | div.maketitle{ margin-bottom: 2em; } 102 | div.author, div.date {text-align:center;} 103 | div.thanks{text-align:left; margin-left:10%; font-size:85%; font-style:italic; } 104 | div.author{white-space: nowrap;} 105 | .quotation {margin-bottom:0.25em; margin-top:0.25em; margin-left:1em; } 106 | .abstract p {margin-left:5%; margin-right:5%;} 107 | table.abstract {width:100%;} 108 | .figure img.graphics {margin-left:10%;} 109 | /* end css.sty */ 110 | 111 | -------------------------------------------------------------------------------- /doc/259.latex: -------------------------------------------------------------------------------- 1 | \documentclass[11pt]{article} 2 | \usepackage{hyperref} 3 | \usepackage[dvips]{graphicx, color} 4 | %%----------------------------------------------------------------------------- 5 | 6 | \begin{document} 7 | 8 | \title{NOTE 259: pyrap binding to casacore} 9 | \author{Ger van Diepen, ASTRON Dwingeloo} 10 | \date{November 10, 2006} 11 | \maketitle 12 | \begin{abstract} 13 | pyrap is a Python binding to casacore classes using Boost.Python. 14 | It consists of a set of standard converters and bindings to the classes. 15 | As much as possible the bindings are the same as in glish. 16 | \end{abstract} 17 | %%--------------------------------------------------------------------------- 18 | 19 | \tableofcontents 20 | \newpage 21 | \input{pyrap.tex} 22 | \end{document} 23 | -------------------------------------------------------------------------------- /doc/259.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/casacore/python-casacore/8fcf796b24cdb6799a93c3f955885ecf6d1c5cd2/doc/259.pdf -------------------------------------------------------------------------------- /doc/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | 9 | # Internal variables. 10 | PAPEROPT_a4 = -D latex_paper_size=a4 11 | PAPEROPT_letter = -D latex_paper_size=letter 12 | ALLSPHINXOPTS = -d .build/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 13 | 14 | .PHONY: help clean html web pickle htmlhelp latex changes linkcheck 15 | 16 | help: 17 | @echo "Please use \`make ' where is one of" 18 | @echo " html to make standalone HTML files" 19 | @echo " pickle to make pickle files" 20 | @echo " json to make JSON files" 21 | @echo " htmlhelp to make HTML files and a HTML help project" 22 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 23 | @echo " changes to make an overview over all changed/added/deprecated items" 24 | @echo " linkcheck to check all external links for integrity" 25 | 26 | clean: 27 | -rm -rf .build/* 28 | 29 | html: 30 | mkdir -p .build/html .build/doctrees 31 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) .build/html 32 | @echo 33 | @echo "Build finished. The HTML pages are in .build/html." 34 | 35 | pickle: 36 | mkdir -p .build/pickle .build/doctrees 37 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) .build/pickle 38 | @echo 39 | @echo "Build finished; now you can process the pickle files." 40 | 41 | web: pickle 42 | 43 | json: 44 | mkdir -p .build/json .build/doctrees 45 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) .build/json 46 | @echo 47 | @echo "Build finished; now you can process the JSON files." 48 | 49 | htmlhelp: 50 | mkdir -p .build/htmlhelp .build/doctrees 51 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) .build/htmlhelp 52 | @echo 53 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 54 | ".hhp project file in .build/htmlhelp." 55 | 56 | latex: 57 | mkdir -p .build/latex .build/doctrees 58 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) .build/latex 59 | @echo 60 | @echo "Build finished; the LaTeX files are in .build/latex." 61 | @echo "Run \`make all-pdf' or \`make all-ps' in that directory to" \ 62 | "run these through (pdf)latex." 63 | 64 | changes: 65 | mkdir -p .build/changes .build/doctrees 66 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) .build/changes 67 | @echo 68 | @echo "The overview file is in .build/changes." 69 | 70 | linkcheck: 71 | mkdir -p .build/linkcheck .build/doctrees 72 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) .build/linkcheck 73 | @echo 74 | @echo "Link check complete; look for any errors in the above output " \ 75 | "or in .build/linkcheck/output.txt." 76 | -------------------------------------------------------------------------------- /doc/casacore_fitting.rst: -------------------------------------------------------------------------------- 1 | =========================== 2 | Module :mod:`fitting` 3 | =========================== 4 | 5 | .. automodule:: casacore.fitting 6 | 7 | API 8 | --- 9 | 10 | .. autoclass:: casacore.fitting.fitserver 11 | :members: 12 | :undoc-members: 13 | :inherited-members: 14 | -------------------------------------------------------------------------------- /doc/casacore_functionals.rst: -------------------------------------------------------------------------------- 1 | ========================= 2 | Module :mod:`functionals` 3 | ========================= 4 | 5 | .. automodule:: casacore.functionals 6 | 7 | Class :class:`functionals.functional` 8 | ------------------------------------- 9 | .. autoclass:: casacore.functionals.functional 10 | :members: 11 | 12 | 13 | Class :class:`functionals.gaussian1d` 14 | ------------------------------------- 15 | .. autoclass:: casacore.functionals.gaussian1d 16 | :members: 17 | :inherited-members: 18 | 19 | Class :class:`functionals.gaussian2d` 20 | ------------------------------------- 21 | .. autoclass:: casacore.functionals.gaussian2d 22 | :members: 23 | :inherited-members: 24 | 25 | Class :class:`functionals.poly` 26 | ------------------------------------- 27 | .. autoclass:: casacore.functionals.poly 28 | :members: 29 | :inherited-members: 30 | 31 | Class :class:`functionals.oddpoly` 32 | ------------------------------------- 33 | .. autoclass:: casacore.functionals.oddpoly 34 | :members: 35 | :inherited-members: 36 | 37 | Class :class:`functionals.evenpoly` 38 | ------------------------------------- 39 | .. autoclass:: casacore.functionals.evenpoly 40 | :members: 41 | :inherited-members: 42 | 43 | Class :class:`functionals.chebyshev` 44 | ------------------------------------- 45 | .. autoclass:: casacore.functionals.chebyshev 46 | :members: 47 | :inherited-members: 48 | 49 | Class :class:`functionals.compound` 50 | ------------------------------------- 51 | .. autoclass:: casacore.functionals.compound 52 | :members: 53 | :inherited-members: 54 | 55 | Class :class:`functionals.combi` 56 | ------------------------------------- 57 | .. autoclass:: casacore.functionals.combi 58 | :members: 59 | :inherited-members: 60 | 61 | Class :class:`functionals.compiled` 62 | ------------------------------------- 63 | .. autoclass:: casacore.functionals.compiled 64 | :members: 65 | :inherited-members: 66 | -------------------------------------------------------------------------------- /doc/casacore_images.rst: -------------------------------------------------------------------------------- 1 | ==================== 2 | Module :mod:`images` 3 | ==================== 4 | 5 | .. automodule:: casacore.images 6 | 7 | Class :class:`images.image` 8 | --------------------------- 9 | .. autoclass:: casacore.images.image 10 | :members: 11 | :undoc-members: 12 | :inherited-members: 13 | 14 | 15 | 16 | ========================= 17 | Module :mod:`coordinates` 18 | ========================= 19 | 20 | .. automodule:: casacore.images.coordinates 21 | :members: 22 | :undoc-members: 23 | 24 | Class :class:`images.coordinates.coordinatesystem` 25 | -------------------------------------------------- 26 | .. autoclass:: casacore.images.coordinates.coordinatesystem 27 | :members: 28 | :undoc-members: 29 | :inherited-members: 30 | 31 | Class :class:`images.coordinates.coordinate` 32 | -------------------------------------------- 33 | .. autoclass:: casacore.images.coordinates.coordinate 34 | :members: 35 | :undoc-members: 36 | :inherited-members: 37 | 38 | Class :class:`images.coordinates.directioncoordinate` 39 | ----------------------------------------------------- 40 | .. autoclass:: casacore.images.coordinates.directioncoordinate 41 | :members: 42 | :undoc-members: 43 | 44 | Class :class:`images.coordinates.spectralcoordinate` 45 | ---------------------------------------------------- 46 | .. autoclass:: casacore.images.coordinates.spectralcoordinate 47 | :members: 48 | :undoc-members: 49 | 50 | Class :class:`images.coordinates.linearcoordinate` 51 | -------------------------------------------------- 52 | .. autoclass:: casacore.images.coordinates.linearcoordinate 53 | :members: 54 | :undoc-members: 55 | 56 | Class :class:`images.coordinates.stokescoordinate` 57 | -------------------------------------------------- 58 | .. autoclass:: casacore.images.coordinates.stokescoordinate 59 | :members: 60 | :undoc-members: 61 | 62 | Class :class:`images.coordinates.tabularcoordinate` 63 | --------------------------------------------------- 64 | .. autoclass:: casacore.images.coordinates.tabularcoordinate 65 | :members: 66 | :undoc-members: 67 | -------------------------------------------------------------------------------- /doc/casacore_measures.rst: -------------------------------------------------------------------------------- 1 | =============================== 2 | Module :mod:`casacore.measures` 3 | =============================== 4 | 5 | .. module:: casacore.measures 6 | 7 | Introduction 8 | ============ 9 | 10 | This is a python binding to 11 | `casacore measures <../../casacore/doc/html/group__Measures__module.html>`_ 12 | 13 | A measure is a quantity with a specified reference frame (e.g. *UTC*, *J2000*, 14 | *mars*). The measures module provides an interface to the handling of 15 | measures. The basic functionality provided is: 16 | 17 | * Conversion of measures, especially between different frames 18 | (e.g. *UTC* to *LAST*) 19 | * Calculation of e.g. a rest frequency from a velocity and a 20 | frequency. 21 | 22 | To access the measures do the following. We will use `dm` as the measures 23 | instance through all examples:: 24 | 25 | >>> from casacore.measures import measures 26 | >>> dm = measures() 27 | 28 | Measures 29 | -------- 30 | 31 | Measures are e.g. an epoch or coordinates which have in addition to values - 32 | :class:`casacore.quanta.Quantity` - also a reference specification and possibly 33 | an offset. They are represented as records with fields describing the various 34 | entities embodied in the measure. These entities can be obtained by the access 35 | methods: 36 | 37 | * :meth:`~casacore.measures.measures.get_type` 38 | * :meth:`~casacore.measures.measures.get_ref` 39 | * :meth:`~casacore.measures.measures.get_offset` 40 | * :meth:`~casacore.measures.measures.get_value`. 41 | 42 | Each measure has its own list of reference codes (see the individual methods 43 | for creating them, like :meth:`~casacore.measures.measures.direction`). If an 44 | empty or no code reference code is given, the default code for that type of 45 | measure will be used (e.g. it is *J2000* for a 46 | :meth:`~casacore.measures.measures.direction`). If an unknown code is given, 47 | this default is also returned, but with a warning message. 48 | 49 | The values of a measure (like the right-ascension for a 50 | :meth:`~casacore.measures.measures.direction`) are given as 51 | :func:`casacore.quanta.quantity`. Each of them can be either a scalar quantity 52 | with a scalar or vector for its actual value (see the following example):: 53 | 54 | >>> from casacore.quanta import quantity 55 | >>> dm.epoch('utc','today') # note that your value will be different 56 | {'m0': {'unit': 'd', 'value': 55147.912709756973}, 57 | 'refer': 'UTC', 58 | 'type': 'epoch'} 59 | >>> dm.direction('j2000','5h20m','-30.2deg') 60 | {'m0': {'unit': 'rad', 'value': 1.3962634015954634}, 61 | 'm1': {'unit': 'rad', 'value': -0.52708943410228748}, 62 | 'refer': 'J2000', 63 | 'type': 'direction'} 64 | >>> a = dm.direction('j2000','5h20m','-30.2deg') 65 | >>> print a['type'] 66 | direction 67 | >>> dm.get_offset(a) 68 | None 69 | >>> dm.getref(a) 70 | J2000 71 | >>> dm.get_value(a) 72 | [1.3962634016 rad, -0.527089434102 rad] 73 | >>> dm.get_value(a)[0] 74 | 1.3962634016 rad 75 | >>> dm.get_value(a)[1] 76 | -0.527089434102 rad 77 | >>> # try as a scalar quantity with multiple values 78 | >>> a = dm.direction('j2000', quantity([10,20],'deg'), 79 | quantity([30,40], 'deg')) 80 | >>> dm.get_value(a)[0] 81 | [0.17453292519943295, 0.3490658503988659] rad 82 | >>> dm.get_value(a)[0].get_value()[1] 83 | 0.3490658503988659 84 | >>> print a 85 | {'m0': {'unit': 'rad', 'value': array([ 0.17453293, 0.34906585])}, 86 | 'm1': {'unit': 'rad', 'value': array([ 0.52359878, 0.6981317 ])}, 87 | 'refer': 'J2000', 88 | 'type': 'direction'} 89 | 90 | Known measures are: 91 | 92 | * :meth:`~casacore.measures.measures.epoch`: an instance in time (internally 93 | expressed as MJD or MGSD) 94 | * :meth:`~casacore.measures.measures.direction`: a direction towards an 95 | astronomical object (including planets, sun, moon) 96 | * :meth:`~casacore.measures.measures.position`: a position on Earth 97 | * :meth:`~casacore.measures.measures.frequency`: electromagnetic wave energy 98 | * :meth:`~casacore.measures.measures.radialvelocity`: radial velocity of 99 | astronomical object 100 | * :meth:`~casacore.measures.measures.doppler`: doppler shift (i.e. radial 101 | velocity in non-velocity units like *Optical*, *Radio*. 102 | * :meth:`~casacore.measures.measures.baseline`: interferometer baseline 103 | * :meth:`~casacore.measures.measures.uvw`: UVW coordinates 104 | * :meth:`~casacore.measures.measures.earthmagnetic`: Earth' magnetic field 105 | 106 | In addition to the reference code (like *J2000*), a measure needs sometimes 107 | more information to be convertable to another reference code (e.g. a time 108 | and position to convert it to an azimuth/elevation). This additional 109 | information is called the reference frame, and can specify one or more of 110 | 'where am i', 'when is it', 'what direction", 'how fast'. 111 | 112 | The frame values can be set using the method :meth:`measures.do_frame`. 113 | 114 | Since you would normally work from a fixed position, the position frame 115 | element ('where you are'), can be specified in your .aipsrc if its name is in 116 | the Observatory list (obslist) tool function. You can set your preferred 117 | position by adding to your *.casarc* file:: 118 | 119 | measures.default.observatory: atca 120 | 121 | API 122 | --- 123 | 124 | .. autofunction:: casacore.measures.is_measure 125 | 126 | .. autoclass:: casacore.measures.measures 127 | :members: 128 | :exclude-members: asbaseline, doframe, framenow, getvalue, todop, todoppler, 129 | torestfrequency, torest, touvw, tofrequency, 130 | toradialvelocity 131 | -------------------------------------------------------------------------------- /doc/casacore_quanta.rst: -------------------------------------------------------------------------------- 1 | ============================= 2 | Module :mod:`casacore.quanta` 3 | ============================= 4 | 5 | .. module:: casacore.quanta 6 | 7 | Python bindings for 8 | `casacore Quantum objects <../../casacore/doc/html/classcasa_1_1Quantum.html>`_ 9 | It transparently handles Quantity and Quantum >. 10 | 11 | Introduction 12 | ============ 13 | 14 | A quantity is a value with a unit. For example, '5km/s', or '20Jy/pc2'. This 15 | module enables you to create and manipulate such quantities. The types of 16 | functionality provided are: 17 | 18 | * Conversion of quantities to different units 19 | * Calculations with quantities 20 | 21 | Constants, time and angle formatting 22 | ------------------------------------ 23 | 24 | If you would like to see all the possible constants known to quanta you can 25 | execute the function :func:`casacore.quanta.constants.keys()`. You can get the 26 | value of any constant in that dictionary with a command such as:: 27 | 28 | >>> from casacore import quanta 29 | >>> boltzmann = quanta.constants['k'] 30 | >>> print 'Boltzmann constant is ', boltzmann 31 | Boltzmann constant is 1.3806578e-23 J/K 32 | 33 | There are some extra handy ways you can manipulate strings when you are 34 | dealing with times or angles. The following list shows special strings and 35 | string formats which you can input to the quantity function. Something in 36 | square brackets is optional. There are examples after the list. 37 | 38 | * time: [+-]hh:mm:ss.t... - This is the preferred time format (trailing 39 | fields can be omitted) 40 | * time: [+-]hhHmmMss.t..[S] - This is an alternative time format (HMS case 41 | insensitive, trailing second fields can be 42 | omitted) 43 | * angle: [+-]dd.mm.ss.t.. - This is the preferred angle format (trailing 44 | fields after second priod can be omitted; dd.. 45 | is valid) 46 | * angle: [+-]ddDmmMss.t...[S] - This is an alternative angle format (DMS 47 | case insensitive, trailing fields can be 48 | omitted after M) 49 | * today - The special string "today" gives the UTC time at the instant 50 | the command was issued. 51 | * today/time - The special string "today" plus the specified time 52 | string gives the UTC time at the specified instant 53 | * yyyy/mm/dd[/time] - gives the UTC time at the specified instant 54 | * yyyy-mm-dd[Ttime[+-hh[:mm]]] - gives the UTC time from ISO 8601 format 55 | with timezone offset 56 | * dd[-]mmm[-][cc]yy[/time] - gives the UTC time at the specified instant 57 | in calendar style notation (23-jun-1999) 58 | 59 | All possible units are visible in the dict `casacore.quanta.constants.units`, 60 | and all possible prefixes (all SI prefixes) are in the dict 61 | `casacore.quanta.constants.prefixes`. 62 | 63 | Note that the standard unit for degrees is 'deg', and for days 'd'. Formatting 64 | is done in such a way that it interprets a 'd' as degrees if preceded by a 65 | value without a period and if any value following it is terminated with an 'm'. 66 | In other cases 'days' are assumed. Here are some examples:: 67 | 68 | >>> from casacore.quanta import quantity 69 | >>> print quantity('today') 70 | 50611.2108 d 71 | >>> print quantity('5jul1998') 72 | 50999 unit=d 73 | print quantity('5jul1998/12:') 74 | 50999.5 d 75 | >>> print quantity('-30.12.2') 76 | 30.2005556 deg 77 | >>> print quantity('2:2:10') 78 | 30.5416667 deg 79 | >>> print quantity('23h3m2.2s') 80 | 345.759167 deg 81 | 82 | Python :mod:`datetime` to quantity:: 83 | 84 | >>> import datetime 85 | >>> utcnow = datetime.datetime.utcnow() 86 | >>> q = quantity(utcnow.isoformat()) 87 | 88 | The (string) output of quantities can be controlled in different ways: 89 | 90 | Standard output: 91 | 92 | >>> q = quantity('23h3m2.2s') 93 | >>> print q 94 | 345.75917 deg 95 | 96 | Angle/time quantity formatting: 97 | 98 | >>> print q.formatted("ANGLE") 99 | +345.45.33 100 | 101 | Precision formatting: 102 | 103 | >>> print q.to_string("%0.2f") 104 | 345.76 deg 105 | 106 | API 107 | === 108 | 109 | .. function:: is_quantity(q) 110 | 111 | :param q: the object to check. 112 | 113 | .. function:: quantity(*args) 114 | 115 | A Factory function to create a :class:`casacore.quanta.Quantity` instance. 116 | This can be from a scalar or vector and a unit. 117 | 118 | :param args: 119 | * A string will be parsed into a :class:`casacore.quanta.Quantity` 120 | * A `dict` with the keys `value` and `unit` 121 | * two arguments representing `value` and `unit` 122 | 123 | Examples:: 124 | 125 | q1 = quantity(1.0, "km/s") 126 | q2 = quantity("1km/s") 127 | q3 = quantity([1.0,2.0], "km/s") 128 | 129 | 130 | .. class:: Quantity 131 | 132 | A unit-value based physical quantity. 133 | 134 | .. method:: set_value(val) 135 | 136 | Set the value of the quantity 137 | 138 | :param val: The new value to change to (in current units) 139 | 140 | .. method:: get(unit=None) 141 | 142 | Return the quantity as another (conformant) one. 143 | 144 | :param unit: an optional conformant unit to convert the quantity to. 145 | If the unit isn't specified the canonical unit is used. 146 | :rtype: :class:`casacore.quanta.Quantity` 147 | 148 | Example:: 149 | 150 | >>> q = quantity('1km/s') 151 | >>> print q.get('m/s') 152 | 1000.0 m/s 153 | 154 | .. method:: get_value(unit) 155 | 156 | Get the value of the quantity suing the optiona unit 157 | 158 | :param unit: a conformant unit to convert the quantity to. 159 | :rtype: `float` ot `list` of `float` 160 | 161 | Example:: 162 | 163 | >>> q = quantity('1km/s') 164 | >>> print q.get_value() 165 | 1.0 166 | 167 | .. method:: get_unit() 168 | 169 | Retrieve the unit 170 | 171 | :rtype: string 172 | 173 | .. method:: conforms(other) 174 | 175 | Check if another :class:`casacore.quanta.Quantity` conforms to self. 176 | 177 | :param other: an :class:`casacore.quanta.Quantity` object to compare to 178 | 179 | .. method:: convert(other=None) 180 | 181 | Convert the quantity using the given :class:`Quantity` or unit string. 182 | 183 | :param other: an optional conformant :class:`Quantity` to convert to. 184 | If other isn't specified the canonical unit is used. 185 | 186 | Example:: 187 | 188 | >>> q = quantity('1km/s') 189 | >>> q.convert() 190 | >>> print q 191 | 1000.0 m/s 192 | 193 | .. method:: to_dict() 194 | 195 | Return self as a python :class:`dict` with `value` and `unit` keys. 196 | 197 | :rtype: :class:`dict` 198 | 199 | .. method:: to_angle() 200 | 201 | Convert to an angle Quantity. 202 | This will only work if it conforms to angle 203 | 204 | :rtype: :class:`casacore.quanta.Quantity` 205 | 206 | .. method:: to_time() 207 | 208 | Convert to a time Quantity (e.g. hour angle). 209 | This will only work if it conforms to time 210 | 211 | :rtype: :class:`casacore.quanta.Quantity` 212 | 213 | .. method:: to_unix_time() 214 | 215 | Convert to a unix time value (in seconds). 216 | This can be used to create python :class:`datetime.datetime` objects 217 | 218 | :rtype: float 219 | 220 | .. method:: to_string(fmt="%0.5f") 221 | 222 | Return a string with the Quantity values' precision formatted with `fmt`. 223 | 224 | :param fmt: the printf type formatting string. 225 | :rtype: string 226 | 227 | .. method:: formatted(fmt) 228 | 229 | Return a formatted string representation of the Quantity. 230 | 231 | :param fmt: the format code for angle or time formatting as per 232 | `casacore angle format <../../casacore/doc/html/classcasa_1_1MVAngle.html#ef9ddd9c3fe111aef61b066b2745ced4>`_ and `casacore time format <../../casacore/doc/html/classcasa_1_1MVTime.html#906c0740cdae7a50ef933d6c3e2ac5ab>`_ 233 | :rtype: string 234 | 235 | On top of the listed method, it also supports all mathematical operators and 236 | functions like: 237 | 238 | * \*, \*=, +, +=, -, -=, /, /= 239 | * <, <=, >, >=, ==, != 240 | * abs, pow, root, srqt, cels, floor, sin, cos, asin, acos, atan, atan2 241 | log, log10, exp 242 | * near and nearabs 243 | 244 | Examples:: 245 | 246 | >>> q = quantity("1km/s") 247 | >>> print q*2 248 | 2.0 km/s 249 | >>> print 2*q 250 | 2.0 km/s 251 | >>> q /= 2 252 | >>> print q 253 | 0.5 km/s 254 | >>> q2 = quantity("0rad") 255 | >>> print dq.cos(q) 256 | 1.0 257 | -------------------------------------------------------------------------------- /doc/casacore_tables.rst: -------------------------------------------------------------------------------- 1 | ==================== 2 | Module :mod:`tables` 3 | ==================== 4 | 5 | .. automodule:: casacore.tables 6 | 7 | Table utility functions 8 | ----------------------- 9 | :func:`default_ms` 10 | Create a default MS. 11 | :func:`default_ms_subtable` 12 | Create a default MS subtable. 13 | :func:`taql` or `tablecommand()` 14 | Execute TaQL query command 15 | :func:`tablefromascii` 16 | Create table from ASCII file 17 | :func:`maketabdesc` or `tablecreatedesc` 18 | Create table description 19 | :func:`makescacoldesc` or `tablecreatescalarcoldesc` 20 | Create description of column holding scalars 21 | :func:`makearrcoldesc` or `tablecreatearraycoldesc` 22 | Create description of column holding arrays 23 | :func:`makecoldesc` 24 | Create description of any column 25 | :func:`tabledefinehypercolumn` 26 | Advanced definition of hypercolumn for tiled storage managers 27 | :func:`tableexists` 28 | Test if a table exists 29 | :func:`tableiswritable` 30 | Test if a table is writable 31 | :func:`tablecopy` 32 | Copy a table 33 | :func:`tabledelete` 34 | Delete a table 35 | :func:`tablerename` 36 | Rename a table 37 | :func:`tableinfo` 38 | Get the type info of a table 39 | :func:`tablesummary` 40 | Get a summary of the table 41 | 42 | MeasurementSet utility functions 43 | -------------------------------- 44 | :func:`addImagingColumns` 45 | Add MeasurementSet columns needed for the CASA imager 46 | :func:`removeImagingColumns` 47 | Remove CASA imager columns CORRECTED_DATA, MODEL_DATA, and 48 | IMAGING_WEIGHT 49 | :func:`addDerivedMSCal` 50 | Add the DerivedMSCal virtual columns like PA1, HA1 to a MeasurementSet 51 | :func:`removeDerivedMSCal` 52 | Remove the DerivedMSCal virtual columns like PA1, HA1 from a MeasurementSet 53 | :func:`msconcat` 54 | Concatenate spectral windows in different MSs to a single MS (in a virtual way) 55 | :func:`required_ms_desc` 56 | Obtained the table descriptor describing a basic MS or an MS subtable. 57 | :func:`complete_ms_desc` 58 | Obtain the table descriptor describing a complete MS or MS subtable. 59 | 60 | Utility functions details 61 | ------------------------- 62 | .. autofunction:: casacore.tables.taql 63 | .. autofunction:: casacore.tables.tablefromascii 64 | .. autofunction:: casacore.tables.maketabdesc 65 | .. autofunction:: casacore.tables.makedminfo 66 | .. autofunction:: casacore.tables.makescacoldesc 67 | .. autofunction:: casacore.tables.makearrcoldesc 68 | .. autofunction:: casacore.tables.makecoldesc 69 | .. autofunction:: casacore.tables.tabledefinehypercolumn 70 | .. autofunction:: casacore.tables.tableexists 71 | .. autofunction:: casacore.tables.tableiswritable 72 | .. autofunction:: casacore.tables.tablecopy 73 | .. autofunction:: casacore.tables.tabledelete 74 | .. autofunction:: casacore.tables.tablerename 75 | .. autofunction:: casacore.tables.tableinfo 76 | .. autofunction:: casacore.tables.tablesummary 77 | .. autofunction:: casacore.tables.addImagingColumns 78 | .. autofunction:: casacore.tables.removeImagingColumns 79 | .. autofunction:: casacore.tables.addDerivedMSCal 80 | .. autofunction:: casacore.tables.removeDerivedMSCal 81 | .. autofunction:: casacore.tables.msconcat 82 | 83 | Class :class:`tables.table` 84 | --------------------------- 85 | .. autoclass:: casacore.tables.table 86 | :members: 87 | :undoc-members: 88 | :inherited-members: 89 | 90 | Class :class:`tables.tablecolumn` 91 | --------------------------------- 92 | .. autoclass:: casacore.tables.tablecolumn 93 | :members: 94 | :undoc-members: 95 | :inherited-members: 96 | 97 | Class :class:`tables.tablerow` 98 | ------------------------------ 99 | .. autoclass:: casacore.tables.tablerow 100 | :members: 101 | :undoc-members: 102 | :inherited-members: 103 | 104 | Class :class:`tables.tableiter` 105 | ------------------------------- 106 | .. autoclass:: casacore.tables.tableiter 107 | :members: 108 | :undoc-members: 109 | :inherited-members: 110 | 111 | Class :class:`tables.tableindex` 112 | -------------------------------- 113 | .. autoclass:: casacore.tables.tableindex 114 | :members: 115 | :undoc-members: 116 | :inherited-members: 117 | 118 | .. automodule:: casacore.tables.tableutil 119 | .. automodule:: casacore.tables.msutil 120 | -------------------------------------------------------------------------------- /doc/casacore_util.rst: -------------------------------------------------------------------------------- 1 | =========================== 2 | Module :mod:`casacore.util` 3 | =========================== 4 | 5 | General utility functions for casacore modules 6 | ---------------------------------------------- 7 | .. automodule:: casacore.util 8 | 9 | :func:`~casacore.util.getlocals` 10 | Get local python variables 11 | :func:`~casacore.util.substitute` 12 | Substitute global python variables in a command string 13 | 14 | Description 15 | ----------- 16 | .. autofunction:: casacore.util.getlocals 17 | .. autofunction:: casacore.util.substitute 18 | 19 | 20 | -------------------------------------------------------------------------------- /doc/conf.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # pyrap documentation build configuration file, created by 4 | # sphinx-quickstart on Tue Jan 13 10:29:11 2009. 5 | # 6 | # This file is execfile()d with the current directory set to its containing dir. 7 | # 8 | # The contents of this file are pickled, so don't put values in the namespace 9 | # that aren't pickleable (module imports are okay, they're removed automatically). 10 | # 11 | # All configuration values have a default; values that are commented out 12 | # serve to show the default. 13 | # If your extensions are in another directory, add it here. If the directory 14 | # is relative to the documentation root, use os.path.abspath to make it 15 | # absolute, like shown here. 16 | #sys.path.append(os.path.abspath('.')) 17 | 18 | try: 19 | import importlib.metadata as metadata 20 | except ImportError: # for python<3.8 21 | import importlib_metadata as metadata 22 | 23 | # General configuration 24 | # --------------------- 25 | 26 | # Add any Sphinx extension module names here, as strings. They can be extensions 27 | # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. 28 | extensions = ['sphinx.ext.autodoc'] 29 | 30 | # Add any paths that contain templates here, relative to this directory. 31 | templates_path = ['.templates'] 32 | 33 | # The suffix of source filenames. 34 | source_suffix = '.rst' 35 | 36 | # The encoding of source files. 37 | #source_encoding = 'utf-8' 38 | 39 | # The master toctree document. 40 | master_doc = 'index' 41 | 42 | # General information about the project. 43 | project = u'python-casacore' 44 | copyright = u'2009, Malte Marquarding, Ger van Diepen' 45 | 46 | # The version info for the project you're documenting, acts as replacement for 47 | # |version| and |release|, also used in various other places throughout the 48 | # built documents. 49 | 50 | # The full version, including alpha/beta/rc tags. 51 | release = metadata.version('python-casacore') 52 | # The short X.Y version. 53 | version = '.'.join(release.split('.')[:2]) 54 | 55 | # The language for content autogenerated by Sphinx. Refer to documentation 56 | # for a list of supported languages. 57 | #language = None 58 | 59 | # There are two options for replacing |today|: either, you set today to some 60 | # non-false value, then it is used: 61 | #today = '' 62 | # Else, today_fmt is used as the format for a strftime call. 63 | #today_fmt = '%B %d, %Y' 64 | 65 | # List of documents that shouldn't be included in the build. 66 | #unused_docs = [] 67 | 68 | # List of directories, relative to source directory, that shouldn't be searched 69 | # for source files. 70 | exclude_trees = ['.build'] 71 | 72 | # The reST default role (used for this markup: `text`) to use for all documents. 73 | #default_role = None 74 | 75 | # If true, '()' will be appended to :func: etc. cross-reference text. 76 | #add_function_parentheses = True 77 | 78 | # If true, the current module name will be prepended to all description 79 | # unit titles (such as .. function::). 80 | #add_module_names = True 81 | 82 | # If true, sectionauthor and moduleauthor directives will be shown in the 83 | # output. They are ignored by default. 84 | #show_authors = False 85 | 86 | # The name of the Pygments (syntax highlighting) style to use. 87 | pygments_style = 'sphinx' 88 | 89 | 90 | # Options for HTML output 91 | # ----------------------- 92 | 93 | # The style sheet to use for HTML and HTML Help pages. A file of that name 94 | # must exist either in Sphinx' static/ path, or in one of the custom paths 95 | # given in html_static_path. 96 | html_style = 'default.css' 97 | 98 | # The name for this set of Sphinx documents. If None, it defaults to 99 | # " v documentation". 100 | #html_title = None 101 | 102 | # A shorter title for the navigation bar. Default is the same as html_title. 103 | #html_short_title = None 104 | 105 | # The name of an image file (relative to this directory) to place at the top 106 | # of the sidebar. 107 | #html_logo = None 108 | 109 | # The name of an image file (within the static path) to use as favicon of the 110 | # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 111 | # pixels large. 112 | #html_favicon = None 113 | 114 | # Add any paths that contain custom static files (such as style sheets) here, 115 | # relative to this directory. They are copied after the builtin static files, 116 | # so a file named "default.css" will overwrite the builtin "default.css". 117 | html_static_path = ['.static'] 118 | 119 | # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, 120 | # using the given strftime format. 121 | #html_last_updated_fmt = '%b %d, %Y' 122 | 123 | # If true, SmartyPants will be used to convert quotes and dashes to 124 | # typographically correct entities. 125 | #html_use_smartypants = True 126 | 127 | # Custom sidebar templates, maps document names to template names. 128 | #html_sidebars = {} 129 | 130 | # Additional templates that should be rendered to pages, maps page names to 131 | # template names. 132 | #html_additional_pages = {} 133 | 134 | # If false, no module index is generated. 135 | #html_use_modindex = True 136 | 137 | # If false, no index is generated. 138 | #html_use_index = True 139 | 140 | # If true, the index is split into individual pages for each letter. 141 | #html_split_index = False 142 | 143 | # If true, the reST sources are included in the HTML build as _sources/. 144 | #html_copy_source = True 145 | 146 | # If true, an OpenSearch description file will be output, and all pages will 147 | # contain a tag referring to it. The value of this option must be the 148 | # base URL from which the finished HTML is served. 149 | #html_use_opensearch = '' 150 | 151 | # If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml"). 152 | #html_file_suffix = '' 153 | 154 | # Output file base name for HTML help builder. 155 | htmlhelp_basename = 'pyrapdoc' 156 | 157 | 158 | # Options for LaTeX output 159 | # ------------------------ 160 | 161 | # The paper size ('letter' or 'a4'). 162 | latex_paper_size = 'a4' 163 | 164 | # The font size ('10pt', '11pt' or '12pt'). 165 | #latex_font_size = '10pt' 166 | 167 | # Grouping the document tree into LaTeX files. List of tuples 168 | # (source start file, target name, title, author, document class [howto/manual]). 169 | latex_documents = [ 170 | ('index', 'casacore.tex', 'python-casacore Documentation', 171 | 'Malte Marquarding, Ger van Diepen', 'manual'), 172 | ] 173 | 174 | # The name of an image file (relative to this directory) to place at the top of 175 | # the title page. 176 | #latex_logo = None 177 | 178 | # For "manual" documents, if this is true, then toplevel headings are parts, 179 | # not chapters. 180 | #latex_use_parts = False 181 | 182 | # Additional stuff for the LaTeX preamble. 183 | #latex_preamble = '' 184 | 185 | # Documents to append as an appendix to all manuals. 186 | #latex_appendices = [] 187 | 188 | # If false, no module index is generated. 189 | #latex_use_modindex = True 190 | -------------------------------------------------------------------------------- /doc/index.rst: -------------------------------------------------------------------------------- 1 | .. pyrap documentation master file, created by sphinx-quickstart on Thu Dec 11 14:52:50 2008. 2 | You can adapt this file completely to your liking, but it should at least 3 | contain the root `toctree` directive. 4 | 5 | Welcome to python-casacore's documentation! 6 | =========================================== 7 | 8 | `python-casacore `_ is a python 9 | binding to the `casacore `_ library. 10 | It consists of the following modules: 11 | 12 | :mod:`casacore.util` 13 | Common utility functions 14 | :mod:`casacore.tables` 15 | Relational data base like table system supporting multi-dimensional arrays. 16 | :mod:`casacore.images` and :mod:`casacore.images.coordinates` 17 | Access, arithmetic, and analysis on multi-dimensional images. 18 | :mod:`casacore.functionals` 19 | Functions with one or more dimensions 20 | :mod:`casacore.fitting` 21 | Fitting data to functionals. 22 | :mod:`casacore.quanta` 23 | Handling of values and units. 24 | :mod:`casacore.measures` 25 | Handling of astronomical coordinates 26 | 27 | 28 | Contents: 29 | 30 | .. toctree:: 31 | :maxdepth: 3 32 | 33 | casacore_util.rst 34 | casacore_tables.rst 35 | casacore_images.rst 36 | casacore_functionals.rst 37 | casacore_fitting.rst 38 | casacore_quanta.rst 39 | casacore_measures.rst 40 | 41 | 42 | Indices and tables 43 | ================== 44 | 45 | * :ref:`genindex` 46 | * :ref:`modindex` 47 | * :ref:`search` 48 | 49 | -------------------------------------------------------------------------------- /doc/requirements.txt: -------------------------------------------------------------------------------- 1 | importlib-metadata; python_version<'3.8' 2 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | ######################### 2 | # build-system settings # 3 | ######################### 4 | 5 | [build-system] 6 | requires = [ 7 | "scikit-build-core>=0.8", 8 | ] 9 | build-backend = "scikit_build_core.build" 10 | 11 | 12 | #################### 13 | # project settings # 14 | #################### 15 | 16 | [project] 17 | name = "python-casacore" 18 | description = "A wrapper around CASACORE, the radio astronomy library" 19 | dynamic = ["version"] 20 | keywords = ["pyrap", "casacore", "utilities", "astronomy"] 21 | license = {file = "LICENSE"} 22 | readme = {file = "README.rst", content-type = "text/x-rst"} 23 | requires-python = ">=3.8" 24 | authors = [ 25 | {name = "Malte Marquarding", email = "Malte.Marquarding@gmail.com"}, 26 | {name = "Ger van Diepen", email = "gervandiepen@gmail.com"}, 27 | {name = "Gijs Molenaar", email = "gijs@pythonic.nl"}, 28 | {name = "Tammo Jan Dijkema", email = "dijkema@astron.nl"}, 29 | {name = "Marcel Loose", email = "loose@astron.nl"}, 30 | ] 31 | classifiers=[ 32 | "Development Status :: 5 - Production/Stable", 33 | "Intended Audience :: Science/Research", 34 | "License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)", 35 | "Natural Language :: English", 36 | "Operating System :: POSIX :: Linux", 37 | "Programming Language :: C++", 38 | "Programming Language :: Python :: 3", 39 | "Topic :: Scientific/Engineering :: Astronomy", 40 | ] 41 | dependencies = [ 42 | "numpy", 43 | ] 44 | 45 | [project.urls] 46 | Homepage = "https://github.com/casacore/python-casacore" 47 | 48 | 49 | ######################### 50 | # cibuildwheel settings # 51 | ######################### 52 | 53 | [tool.cibuildwheel] 54 | build = "cp3{8,9,10,11,12,13}-*_x86_64" 55 | build-verbosity = 1 56 | environment = """ \ 57 | CXXFLAGS="-I/usr/include/cfitsio" \ 58 | """ 59 | test-command = "cd {package}/tests && pytest" 60 | test-requires = "pytest" 61 | 62 | [tool.cibuildwheel.macos] 63 | repair-wheel-command = """\ 64 | DYLD_LIBRARY_PATH=${BOOST_INSTALL_DIR}/lib delocate-wheel \ 65 | --require-archs {delocate_archs} -w {dest_dir} -v {wheel}\ 66 | """ 67 | 68 | [tool.cibuildwheel.linux] 69 | skip = ["*-musllinux_*"] 70 | 71 | [[tool.cibuildwheel.overrides]] 72 | select="cp38-*" 73 | manylinux-x86_64-image = "quay.io/casacore/casacore:py38_master" 74 | 75 | [[tool.cibuildwheel.overrides]] 76 | select="cp39-*" 77 | manylinux-x86_64-image = "quay.io/casacore/casacore:py39_master" 78 | 79 | [[tool.cibuildwheel.overrides]] 80 | select="cp310-*" 81 | manylinux-x86_64-image = "quay.io/casacore/casacore:py310_master" 82 | 83 | [[tool.cibuildwheel.overrides]] 84 | select="cp311-*" 85 | manylinux-x86_64-image = "quay.io/casacore/casacore:py311_master" 86 | 87 | [[tool.cibuildwheel.overrides]] 88 | select="cp312-*" 89 | manylinux-x86_64-image = "quay.io/casacore/casacore:py312_master" 90 | 91 | [[tool.cibuildwheel.overrides]] 92 | select="cp313-*" 93 | manylinux-x86_64-image = "quay.io/casacore/casacore:py313_master" 94 | 95 | 96 | ######################### 97 | # scikit-build settings # 98 | ######################### 99 | 100 | [tool.scikit-build] 101 | cmake.version = ">=3.15" 102 | ninja.version = ">=1.5" 103 | logging.level = "INFO" 104 | install.components = ["data", "libraries"] 105 | metadata.version.provider = "scikit_build_core.metadata.setuptools_scm" 106 | sdist.exclude = [".github", ".gitignore"] 107 | sdist.include = ["casacore/_version.py"] 108 | wheel.packages = ["casacore", "pyrap"] 109 | 110 | [tool.scikit-build.cmake.define] 111 | BUILD_TESTING = "ON" 112 | 113 | 114 | ########################### 115 | # setuptools_scm settings # 116 | ########################### 117 | 118 | [tool.setuptools_scm] 119 | write_to = "casacore/_version.py" 120 | -------------------------------------------------------------------------------- /pyrap/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | backwards compatibility module 3 | """ -------------------------------------------------------------------------------- /pyrap/fitting.py: -------------------------------------------------------------------------------- 1 | from casacore.fitting import * -------------------------------------------------------------------------------- /pyrap/functionals.py: -------------------------------------------------------------------------------- 1 | from casacore.functionals import * -------------------------------------------------------------------------------- /pyrap/images.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/casacore/python-casacore/8fcf796b24cdb6799a93c3f955885ecf6d1c5cd2/pyrap/images.py -------------------------------------------------------------------------------- /pyrap/images/__init__.py: -------------------------------------------------------------------------------- 1 | from casacore.images import * -------------------------------------------------------------------------------- /pyrap/images/coordinates.py: -------------------------------------------------------------------------------- 1 | from casacore.images.coordinates import * -------------------------------------------------------------------------------- /pyrap/images/image.py: -------------------------------------------------------------------------------- 1 | from casacore.images.image import * -------------------------------------------------------------------------------- /pyrap/measures.py: -------------------------------------------------------------------------------- 1 | from casacore.measures import * -------------------------------------------------------------------------------- /pyrap/quanta.py: -------------------------------------------------------------------------------- 1 | from casacore.quanta import * -------------------------------------------------------------------------------- /pyrap/tables.py: -------------------------------------------------------------------------------- 1 | from casacore.tables import * -------------------------------------------------------------------------------- /pyrap/util.py: -------------------------------------------------------------------------------- 1 | from casacore.util import * -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | python_add_library(_fitting MODULE WITH_SOABI fit.cc fitting.cc) 2 | 3 | python_add_library(_functionals MODULE WITH_SOABI functional.cc functionals.cc) 4 | 5 | python_add_library(_images MODULE WITH_SOABI images.cc pyimages.cc) 6 | 7 | python_add_library(_measures MODULE WITH_SOABI pymeas.cc pymeasures.cc) 8 | 9 | python_add_library( 10 | _quanta 11 | MODULE 12 | WITH_SOABI 13 | quanta.cc 14 | quantamath.cc 15 | quantity.cc 16 | quantvec.cc) 17 | 18 | python_add_library( 19 | _tables 20 | MODULE 21 | WITH_SOABI 22 | pytable.cc 23 | pytableindex.cc 24 | pytableiter.cc 25 | pytablerow.cc 26 | tables.cc 27 | pyms.cc) 28 | 29 | get_directory_property(_targets BUILDSYSTEM_TARGETS) 30 | foreach(_target ${_targets}) 31 | string(REGEX REPLACE "^_" "casacore/" _destination "${_target}") 32 | target_include_directories(${_target} PRIVATE ${Boost_INCLUDE_DIRS} 33 | ${CASACORE_INCLUDE_DIRS}) 34 | target_link_directories(${_target} PRIVATE ${CASACORE_LIBRARY_DIRS}) 35 | target_link_libraries(${_target} PRIVATE ${CASACORE_LIBRARIES}) 36 | if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin") 37 | target_link_options(${_target} PRIVATE "LINKER:--as-needed") 38 | endif() 39 | install(TARGETS ${_target} LIBRARY DESTINATION ${_destination} 40 | COMPONENT libraries) 41 | endforeach() 42 | -------------------------------------------------------------------------------- /src/fit.cc: -------------------------------------------------------------------------------- 1 | //# fit.cc: python module for fitting proxy object. 2 | //# Copyright (C) 2006 3 | //# Associated Universities, Inc. Washington DC, USA. 4 | //# 5 | //# This library is free software; you can redistribute it and/or modify it 6 | //# under the terms of the GNU Lesser General Public License as published by 7 | //# the Free Software Foundation; either version 3 of the License, or (at your 8 | //# option) any later version. 9 | //# 10 | //# This library is distributed in the hope that it will be useful, but WITHOUT 11 | //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | //# License for more details. 14 | //# 15 | //# You should have received a copy of the GNU Lesser General Public License 16 | //# along with this library; if not, write to the Free Software Foundation, 17 | //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 18 | //# 19 | //# Correspondence concerning AIPS++ should be addressed as follows: 20 | //# Internet email: aips2-request@nrao.edu. 21 | //# Postal address: AIPS++ Project Office 22 | //# National Radio Astronomy Observatory 23 | //# 520 Edgemont Road 24 | //# Charlottesville, VA 22903-2475 USA 25 | //# 26 | //# $Id: pyfit.cc,v 1.2 2007/03/08 22:51:10 mmarquar Exp $ 27 | 28 | #include 29 | #include 30 | 31 | #include 32 | #include 33 | 34 | #include 35 | 36 | using namespace boost::python; 37 | 38 | namespace casacore { namespace python { 39 | void fit() 40 | { 41 | class_ ("fitting") 42 | .def (init<>()) 43 | .def ("getid", &FittingProxy::getid) 44 | .def ("getstate", &FittingProxy::getstate) 45 | .def ("init", &FittingProxy::init) 46 | .def ("done", &FittingProxy::done) 47 | .def ("reset", &FittingProxy::reset) 48 | .def ("set", &FittingProxy::set) 49 | .def ("functional", &FittingProxy::functional, 50 | (boost::python::arg("id"), 51 | boost::python::arg("fnct"), 52 | boost::python::arg("x"), 53 | boost::python::arg("y"), 54 | boost::python::arg("wt"), 55 | boost::python::arg("mxit"), 56 | boost::python::arg("constraint"))) 57 | .def ("linear", &FittingProxy::linear, 58 | (boost::python::arg("id"), 59 | boost::python::arg("fnct"), 60 | boost::python::arg("x"), 61 | boost::python::arg("y"), 62 | boost::python::arg("wt"), 63 | boost::python::arg("constraint"))) 64 | .def ("cxfunctional", &FittingProxy::cxfunctional, 65 | (boost::python::arg("id"), 66 | boost::python::arg("fnct"), 67 | boost::python::arg("x"), 68 | boost::python::arg("y"), 69 | boost::python::arg("wt"), 70 | boost::python::arg("mxit"), 71 | boost::python::arg("constraint"))) 72 | .def ("cxlinear", &FittingProxy::cxlinear, 73 | (boost::python::arg("id"), 74 | boost::python::arg("fnct"), 75 | boost::python::arg("x"), 76 | boost::python::arg("y"), 77 | boost::python::arg("wt"), 78 | boost::python::arg("constraint"))) 79 | ; 80 | } 81 | }} 82 | -------------------------------------------------------------------------------- /src/fitting.cc: -------------------------------------------------------------------------------- 1 | //# fitting.cc: python module for casacore fitting 2 | //# Copyright (C) 2006,2007 3 | //# Associated Universities, Inc. Washington DC, USA. 4 | //# 5 | //# This library is free software; you can redistribute it and/or modify it 6 | //# under the terms of the GNU Lesser General Public License as published by 7 | //# the Free Software Foundation; either version 3 of the License, or (at your 8 | //# option) any later version. 9 | //# 10 | //# This library is distributed in the hope that it will be useful, but WITHOUT 11 | //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | //# License for more details. 14 | //# 15 | //# You should have received a copy of the GNU Lesser General Public License 16 | //# along with this library; if not, write to the Free Software Foundation, 17 | //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 18 | //# 19 | //# Correspondence concerning AIPS++ should be addressed as follows: 20 | //# Internet email: aips2-request@nrao.edu. 21 | //# Postal address: AIPS++ Project Office 22 | //# National Radio Astronomy Observatory 23 | //# 520 Edgemont Road 24 | //# Charlottesville, VA 22903-2475 USA 25 | //# 26 | //# $Id: fitting.cc,v 1.1 2006/10/20 06:30:03 mmarquar Exp $ 27 | 28 | 29 | #include 30 | 31 | #include "fitting.h" 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | BOOST_PYTHON_MODULE(_fitting) 39 | { 40 | casacore::python::register_convert_excp(); 41 | casacore::python::register_convert_basicdata(); 42 | casacore::python::register_convert_casa_record(); 43 | casacore::python::fit(); 44 | } 45 | -------------------------------------------------------------------------------- /src/fitting.h: -------------------------------------------------------------------------------- 1 | //# fitting.cc: python module for casacore fitting 2 | //# Copyright (C) 2006,2007 3 | //# Associated Universities, Inc. Washington DC, USA. 4 | //# 5 | //# This library is free software; you can redistribute it and/or modify it 6 | //# under the terms of the GNU Lesser General Public License as published by 7 | //# the Free Software Foundation; either version 3 of the License, or (at your 8 | //# option) any later version. 9 | //# 10 | //# This library is distributed in the hope that it will be useful, but WITHOUT 11 | //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | //# License for more details. 14 | //# 15 | //# You should have received a copy of the GNU Lesser General Public License 16 | //# along with this library; if not, write to the Free Software Foundation, 17 | //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 18 | //# 19 | //# Correspondence concerning AIPS++ should be addressed as follows: 20 | //# Internet email: aips2-request@nrao.edu. 21 | //# Postal address: AIPS++ Project Office 22 | //# National Radio Astronomy Observatory 23 | //# 520 Edgemont Road 24 | //# Charlottesville, VA 22903-2475 USA 25 | //# 26 | //# $Id: fitting.h,v 1.1 2006/10/20 06:30:03 mmarquar Exp $ 27 | 28 | #ifndef PYRAP_FITTING_H 29 | #define PYRAP_FITTING_H 30 | 31 | #include 32 | 33 | namespace casacore { 34 | namespace python { 35 | void fit(); 36 | } // python 37 | } //casa 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /src/functional.cc: -------------------------------------------------------------------------------- 1 | //# functionals.cc: python module for casacore functionals. 2 | //# Copyright (C) 2006,2007 3 | //# Associated Universities, Inc. Washington DC, USA. 4 | //# 5 | //# This library is free software; you can redistribute it and/or modify it 6 | //# under the terms of the GNU Lesser General Public License as published by 7 | //# the Free Software Foundation; either version 3 of the License, or (at your 8 | //# option) any later version. 9 | //# 10 | //# This library is distributed in the hope that it will be useful, but WITHOUT 11 | //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | //# License for more details. 14 | //# 15 | //# You should have received a copy of the GNU Lesser General Public License 16 | //# along with this library; if not, write to the Free Software Foundation, 17 | //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 18 | //# 19 | //# Correspondence concerning AIPS++ should be addressed as follows: 20 | //# Internet email: aips2-request@nrao.edu. 21 | //# Postal address: AIPS++ Project Office 22 | //# National Radio Astronomy Observatory 23 | //# 520 Edgemont Road 24 | //# Charlottesville, VA 22903-2475 USA 25 | //# 26 | //# $Id: pyfunctional.cc,v 1.1 2006/09/29 06:42:55 mmarquar Exp $ 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | using namespace boost::python; 35 | 36 | namespace casacore { namespace python { 37 | 38 | 39 | void functional() 40 | { 41 | class_ ("_functional") 42 | .def ( init< const Record&, int>()) 43 | .def ("_f", &FunctionalProxy::f) 44 | .def ("_fc", &FunctionalProxy::fc) 45 | .def ("_fdf", &FunctionalProxy::fdf) 46 | .def ("_fdfc", &FunctionalProxy::fdfc) 47 | .def ("_add", &FunctionalProxy::add) 48 | .def ("_addc", &FunctionalProxy::addc) 49 | .def ("todict", &FunctionalProxy::asrecord) 50 | .def ("npar", &FunctionalProxy::npar) 51 | .def ("ndim", &FunctionalProxy::ndim) 52 | .def ("_setparameters", &FunctionalProxy::setparameters) 53 | .def ("_setparametersc", &FunctionalProxy::setparametersc) 54 | .def ("_setpar", &FunctionalProxy::setpar) 55 | .def ("_setparc", &FunctionalProxy::setparc) 56 | .def ("_parameters", &FunctionalProxy::parameters) 57 | .def ("_parametersc", &FunctionalProxy::parametersc) 58 | .def ("_setmasks", &FunctionalProxy::setmasks) 59 | .def ("_masks", &FunctionalProxy::masks) 60 | .def ("_setmask", &FunctionalProxy::setmask) 61 | ; 62 | } 63 | } } 64 | -------------------------------------------------------------------------------- /src/functionals.cc: -------------------------------------------------------------------------------- 1 | //# functionals.cc: python module for casacore functionals 2 | //# Copyright (C) 2006,2007 3 | //# Associated Universities, Inc. Washington DC, USA. 4 | //# 5 | //# This library is free software; you can redistribute it and/or modify it 6 | //# under the terms of the GNU Lesser General Public License as published by 7 | //# the Free Software Foundation; either version 3 of the License, or (at your 8 | //# option) any later version. 9 | //# 10 | //# This library is distributed in the hope that it will be useful, but WITHOUT 11 | //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | //# License for more details. 14 | //# 15 | //# You should have received a copy of the GNU Lesser General Public License 16 | //# along with this library; if not, write to the Free Software Foundation, 17 | //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 18 | //# 19 | //# Correspondence concerning AIPS++ should be addressed as follows: 20 | //# Internet email: aips2-request@nrao.edu. 21 | //# Postal address: AIPS++ Project Office 22 | //# National Radio Astronomy Observatory 23 | //# 520 Edgemont Road 24 | //# Charlottesville, VA 22903-2475 USA 25 | //# 26 | //# $Id: pyfunctionals.cc,v 1.2 2006/10/17 03:37:27 gvandiep Exp $ 27 | 28 | #include "functionals.h" 29 | 30 | #include 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | BOOST_PYTHON_MODULE(_functionals) 38 | { 39 | casacore::python::register_convert_excp(); 40 | casacore::python::register_convert_basicdata(); 41 | casacore::python::register_convert_casa_record(); 42 | 43 | casacore::python::functional(); 44 | } 45 | -------------------------------------------------------------------------------- /src/functionals.h: -------------------------------------------------------------------------------- 1 | //# functional.cc: python module for casacore functionals 2 | //# Copyright (C) 2006,2007 3 | //# Associated Universities, Inc. Washington DC, USA. 4 | //# 5 | //# This library is free software; you can redistribute it and/or modify it 6 | //# under the terms of the GNU Lesser General Public License as published by 7 | //# the Free Software Foundation; either version 3 of the License, or (at your 8 | //# option) any later version. 9 | //# 10 | //# This library is distributed in the hope that it will be useful, but WITHOUT 11 | //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | //# License for more details. 14 | //# 15 | //# You should have received a copy of the GNU Lesser General Public License 16 | //# along with this library; if not, write to the Free Software Foundation, 17 | //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 18 | //# 19 | //# Correspondence concerning AIPS++ should be addressed as follows: 20 | //# Internet email: aips2-request@nrao.edu. 21 | //# Postal address: AIPS++ Project Office 22 | //# National Radio Astronomy Observatory 23 | //# 520 Edgemont Road 24 | //# Charlottesville, VA 22903-2475 USA 25 | //# 26 | //# $Id: pyfunctionals.h,v 1.1 2006/09/29 06:42:55 mmarquar Exp $ 27 | 28 | #ifndef PYRAP_FUNCTIONALS_H 29 | #define PYRAP_FUNCTIONALS_H 30 | 31 | #include 32 | 33 | namespace casacore { 34 | namespace python { 35 | void functional(); 36 | } // python 37 | } //casa 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /src/images.cc: -------------------------------------------------------------------------------- 1 | //# pymeas.cc: python module for ImageProxy object. 2 | //# Copyright (C) 2008 3 | //# Associated Universities, Inc. Washington DC, USA. 4 | //# 5 | //# This library is free software; you can redistribute it and/or modify it 6 | //# under the terms of the GNU Lesser General Public License as published by 7 | //# the Free Software Foundation; either version 3 of the License, or (at your 8 | //# option) any later version. 9 | //# 10 | //# This library is distributed in the hope that it will be useful, but WITHOUT 11 | //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | //# License for more details. 14 | //# 15 | //# You should have received a copy of the GNU Lesser General Public License 16 | //# along with this library; if not, write to the Free Software Foundation, 17 | //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 18 | //# 19 | //# Correspondence concerning AIPS++ should be addressed as follows: 20 | //# Internet email: aips2-request@nrao.edu. 21 | //# Postal address: AIPS++ Project Office 22 | //# National Radio Astronomy Observatory 23 | //# 520 Edgemont Road 24 | //# Charlottesville, VA 22903-2475 USA 25 | //# 26 | //# $Id: pyimages.cc,v 1.1 2006/09/28 05:55:00 mmarquar Exp $ 27 | 28 | #include "pyimages.h" 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | #include 40 | 41 | BOOST_PYTHON_MODULE(_images) 42 | { 43 | // Register the required pyrap converters. 44 | casacore::python::register_convert_excp(); 45 | casacore::python::register_convert_basicdata(); 46 | casacore::python::register_convert_casa_valueholder(); 47 | casacore::python::register_convert_casa_record(); 48 | casacore::python::register_convert_std_vector(); 49 | 50 | // Register the FITS and Miriad image types. 51 | casacore::FITSImage::registerOpenFunction(); 52 | casacore::MIRIADImage::registerOpenFunction(); 53 | 54 | // Make python interface to images. 55 | casacore::python::pyimages(); 56 | } 57 | -------------------------------------------------------------------------------- /src/pyimages.cc: -------------------------------------------------------------------------------- 1 | //# pyimages.cc: python module for aips++ images system 2 | //# Copyright (C) 2008 3 | //# Associated Universities, Inc. Washington DC, USA. 4 | //# 5 | //# This library is free software; you can redistribute it and/or modify it 6 | //# under the terms of the GNU Lesser General Public License as published by 7 | //# the Free Software Foundation; either version 3 of the License, or (at your 8 | //# option) any later version. 9 | //# 10 | //# This library is distributed in the hope that it will be useful, but WITHOUT 11 | //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | //# License for more details. 14 | //# 15 | //# You should have received a copy of the GNU Lesser General Public License 16 | //# along with this library; if not, write to the Free Software Foundation, 17 | //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 18 | //# 19 | //# Correspondence concerning AIPS++ should be addressed as follows: 20 | //# Internet email: aips2-request@nrao.edu. 21 | //# Postal address: AIPS++ Project Office 22 | //# National Radio Astronomy Observatory 23 | //# 520 Edgemont Road 24 | //# Charlottesville, VA 22903-2475 USA 25 | //# 26 | //# $Id$ 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | using namespace boost::python; 36 | 37 | namespace casacore { namespace python { 38 | 39 | void pyimages() 40 | { 41 | // Note that all constructors must have a different number of arguments. 42 | class_ ("Image") 43 | // 1 arg: copy constructor 44 | .def (init()) 45 | // 2 arg: concat from image names 46 | .def (init, Int>()) 47 | // 3 arg: open image or image expression 48 | .def (init >()) 49 | // 4 arg: concat from images objects 50 | .def (init, Int, Int, Int>()) 51 | // 8 arg: create image from array 52 | .def (init()) 54 | // 9 arg: create image from shape 55 | .def (init()) 57 | 58 | // Member functions. 59 | // Functions starting with un underscore are wrapped in image.py. 60 | .def ("_ispersistent", &ImageProxy::isPersistent) 61 | .def ("_name", &ImageProxy::name, 62 | (boost::python::arg("strippath"))) 63 | .def ("_shape", &ImageProxy::shape) 64 | .def ("_ndim", &ImageProxy::ndim) 65 | .def ("_size", &ImageProxy::size) 66 | .def ("_datatype", &ImageProxy::dataType) 67 | .def ("_imagetype", &ImageProxy::imageType) 68 | .def ("_getdata", &ImageProxy::getData) 69 | .def ("_getmask", &ImageProxy::getMask) 70 | .def ("_putdata", &ImageProxy::putData) 71 | .def ("_putmask", &ImageProxy::putMask) 72 | .def ("_haslock", &ImageProxy::hasLock, 73 | (boost::python::arg("write"))) 74 | .def ("_lock", &ImageProxy::lock, 75 | (boost::python::arg("write"), 76 | boost::python::arg("nattempts"))) 77 | .def ("_unlock", &ImageProxy::unlock) 78 | .def ("_attrgroupnames", &ImageProxy::attrGroupNames) 79 | .def ("_attrcreategroup", &ImageProxy::createAttrGroup, 80 | (boost::python::arg("groupname"))) 81 | .def ("_attrnames", &ImageProxy::attrNames, 82 | (boost::python::arg("groupname"))) 83 | .def ("_attrnrows", &ImageProxy::attrNrows, 84 | (boost::python::arg("groupname"))) 85 | .def ("_attrget", &ImageProxy::getAttr, 86 | (boost::python::arg("groupname"), 87 | boost::python::arg("attrname"), 88 | boost::python::arg("rownr"))) 89 | .def ("_attrgetrow", &ImageProxy::getAttrRow, 90 | (boost::python::arg("groupname"), 91 | boost::python::arg("rownr"))) 92 | .def ("_attrgetunit", &ImageProxy::getAttrUnit, 93 | (boost::python::arg("groupname"), 94 | boost::python::arg("attrname"))) 95 | .def ("_attrgetmeas", &ImageProxy::getAttrMeas, 96 | (boost::python::arg("groupname"), 97 | boost::python::arg("attrname"))) 98 | .def ("_attrput", &ImageProxy::putAttr, 99 | (boost::python::arg("groupname"), 100 | boost::python::arg("attrname"), 101 | boost::python::arg("rownr"), 102 | boost::python::arg("value"), 103 | boost::python::arg("unit"), 104 | boost::python::arg("meas"))) 105 | .def ("_subimage", &ImageProxy::subImage, 106 | (boost::python::arg("blc"), 107 | boost::python::arg("trc"), 108 | boost::python::arg("inc"), 109 | boost::python::arg("dropdegenerate"))) 110 | .def ("_coordinates", &ImageProxy::coordSys) 111 | .def ("_toworld", &ImageProxy::toWorld, 112 | (boost::python::arg("pixel"), 113 | boost::python::arg("reverseAxes"))) 114 | .def ("_topixel", &ImageProxy::toPixel, 115 | (boost::python::arg("world"), 116 | boost::python::arg("reverseAxes"))) 117 | .def ("_imageinfo", &ImageProxy::imageInfo) 118 | .def ("_miscinfo", &ImageProxy::miscInfo) 119 | .def ("_unit", &ImageProxy::unit) 120 | .def ("_history", &ImageProxy::history) 121 | .def ("_tofits", &ImageProxy::toFits, 122 | (boost::python::arg("filename"), 123 | boost::python::arg("overwrite"), 124 | boost::python::arg("velocity"), 125 | boost::python::arg("optical"), 126 | boost::python::arg("bitpix"), 127 | boost::python::arg("minpix"), 128 | boost::python::arg("maxpix"))) 129 | .def ("_saveas", &ImageProxy::saveAs, 130 | (boost::python::arg("filename"), 131 | boost::python::arg("overwrite"), 132 | boost::python::arg("hdf5"), 133 | boost::python::arg("copymask"), 134 | boost::python::arg("newmaskname"), 135 | boost::python::arg("newtileshape"))) 136 | .def ("_statistics", &ImageProxy::statistics, 137 | (boost::python::arg("axes"), 138 | boost::python::arg("mask"), 139 | boost::python::arg("minMaxValues"), 140 | boost::python::arg("exclude"), 141 | boost::python::arg("robust"))) 142 | .def ("_regrid", &ImageProxy::regrid, 143 | (boost::python::arg("axes"), 144 | boost::python::arg("outname"), 145 | boost::python::arg("overwrite"), 146 | boost::python::arg("outshape"), 147 | boost::python::arg("coordsys"), 148 | boost::python::arg("interpolation"), 149 | boost::python::arg("decimate"), 150 | boost::python::arg("replicate"), 151 | boost::python::arg("refchange"), 152 | boost::python::arg("forceregrid"))) 153 | ; 154 | } 155 | 156 | }} 157 | -------------------------------------------------------------------------------- /src/pyimages.h: -------------------------------------------------------------------------------- 1 | //# pyimages.cc: python module for casacore images package 2 | //# Copyright (C) 2008 3 | //# Associated Universities, Inc. Washington DC, USA. 4 | //# 5 | //# This library is free software; you can redistribute it and/or modify it 6 | //# under the terms of the GNU Lesser General Public License as published by 7 | //# the Free Software Foundation; either version 3 of the License, or (at your 8 | //# option) any later version. 9 | //# 10 | //# This library is distributed in the hope that it will be useful, but WITHOUT 11 | //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | //# License for more details. 14 | //# 15 | //# You should have received a copy of the GNU Lesser General Public License 16 | //# along with this library; if not, write to the Free Software Foundation, 17 | //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 18 | //# 19 | //# Correspondence concerning AIPS++ should be addressed as follows: 20 | //# Internet email: aips2-request@nrao.edu. 21 | //# Postal address: AIPS++ Project Office 22 | //# National Radio Astronomy Observatory 23 | //# 520 Edgemont Road 24 | //# Charlottesville, VA 22903-2475 USA 25 | //# 26 | //# $Id: $ 27 | 28 | #ifndef PYRAP_IMAGES_H 29 | #define PYRAP_IMAGES_H 30 | 31 | #include 32 | 33 | namespace casacore { 34 | namespace python { 35 | void pyimages(); 36 | } // python 37 | } //casa 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /src/pymeas.cc: -------------------------------------------------------------------------------- 1 | //# pymeas.cc: python module for MeasuresProxy object. 2 | //# Copyright (C) 2006 3 | //# Associated Universities, Inc. Washington DC, USA. 4 | //# 5 | //# This library is free software; you can redistribute it and/or modify it 6 | //# under the terms of the GNU Lesser General Public License as published by 7 | //# the Free Software Foundation; either version 3 of the License, or (at your 8 | //# option) any later version. 9 | //# 10 | //# This library is distributed in the hope that it will be useful, but WITHOUT 11 | //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | //# License for more details. 14 | //# 15 | //# You should have received a copy of the GNU Lesser General Public License 16 | //# along with this library; if not, write to the Free Software Foundation, 17 | //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 18 | //# 19 | //# Correspondence concerning AIPS++ should be addressed as follows: 20 | //# Internet email: aips2-request@nrao.edu. 21 | //# Postal address: AIPS++ Project Office 22 | //# National Radio Astronomy Observatory 23 | //# 520 Edgemont Road 24 | //# Charlottesville, VA 22903-2475 USA 25 | //# 26 | //# $Id: pymeas.cc,v 1.1 2006/09/28 05:55:00 mmarquar Exp $ 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | using namespace boost::python; 35 | 36 | namespace casacore { namespace python { 37 | void pymeas() 38 | { 39 | class_ ("measures") 40 | .def (init<>()) 41 | .def ("measure", &MeasuresProxy::measure) 42 | .def ("dirshow", &MeasuresProxy::dirshow) 43 | .def ("doframe", &MeasuresProxy::doframe) 44 | .def ("linelist", &MeasuresProxy::linelist) 45 | .def ("obslist", &MeasuresProxy::obslist) 46 | .def ("source", &MeasuresProxy::source) 47 | .def ("line", &MeasuresProxy::line) 48 | .def ("observatory", &MeasuresProxy::observatory) 49 | .def ("srclist", &MeasuresProxy::srclist) 50 | .def ("doptofreq", &MeasuresProxy::doptofreq) 51 | .def ("doptorv", &MeasuresProxy::doptorv) 52 | .def ("todop", &MeasuresProxy::todop) 53 | .def ("torest", &MeasuresProxy::torest) 54 | .def ("separation", &MeasuresProxy::separation) 55 | .def ("posangle", &MeasuresProxy::posangle) 56 | .def ("uvw", &MeasuresProxy::uvw) 57 | .def ("expand", &MeasuresProxy::expand) 58 | .def ("alltyp", &MeasuresProxy::alltyp) 59 | ; 60 | } 61 | }} 62 | -------------------------------------------------------------------------------- /src/pymeasures.cc: -------------------------------------------------------------------------------- 1 | //# pyemasures.cc: python module for aips++ measures system 2 | //# Copyright (C) 2006 3 | //# Associated Universities, Inc. Washington DC, USA. 4 | //# 5 | //# This library is free software; you can redistribute it and/or modify it 6 | //# under the terms of the GNU Lesser General Public License as published by 7 | //# the Free Software Foundation; either version 3 of the License, or (at your 8 | //# option) any later version. 9 | //# 10 | //# This library is distributed in the hope that it will be useful, but WITHOUT 11 | //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | //# License for more details. 14 | //# 15 | //# You should have received a copy of the GNU Lesser General Public License 16 | //# along with this library; if not, write to the Free Software Foundation, 17 | //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 18 | //# 19 | //# Correspondence concerning AIPS++ should be addressed as follows: 20 | //# Internet email: aips2-request@nrao.edu. 21 | //# Postal address: AIPS++ Project Office 22 | //# National Radio Astronomy Observatory 23 | //# 520 Edgemont Road 24 | //# Charlottesville, VA 22903-2475 USA 25 | //# 26 | //# $Id: pymeasures.cc,v 1.2 2006/10/17 03:37:27 gvandiep Exp $ 27 | 28 | #include 29 | #include 30 | #include 31 | //#include 32 | #include 33 | #include "pymeasures.h" 34 | 35 | BOOST_PYTHON_MODULE(_measures) 36 | { 37 | casacore::python::register_convert_excp(); 38 | casacore::python::register_convert_basicdata(); 39 | casacore::python::register_convert_casa_record(); 40 | 41 | casacore::python::pymeas(); 42 | } 43 | -------------------------------------------------------------------------------- /src/pymeasures.h: -------------------------------------------------------------------------------- 1 | //# pymeasures.cc: python module for AIPS++ measures system 2 | //# Copyright (C) 2006, 2007 3 | //# Associated Universities, Inc. Washington DC, USA. 4 | //# 5 | //# This library is free software; you can redistribute it and/or modify it 6 | //# under the terms of the GNU Lesser General Public License as published by 7 | //# the Free Software Foundation; either version 3 of the License, or (at your 8 | //# option) any later version. 9 | //# 10 | //# This library is distributed in the hope that it will be useful, but WITHOUT 11 | //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | //# License for more details. 14 | //# 15 | //# You should have received a copy of the GNU Lesser General Public License 16 | //# along with this library; if not, write to the Free Software Foundation, 17 | //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 18 | //# 19 | //# Correspondence concerning AIPS++ should be addressed as follows: 20 | //# Internet email: aips2-request@nrao.edu. 21 | //# Postal address: AIPS++ Project Office 22 | //# National Radio Astronomy Observatory 23 | //# 520 Edgemont Road 24 | //# Charlottesville, VA 22903-2475 USA 25 | //# 26 | //# $Id: pymeasures.h,v 1.1 2006/09/28 05:55:00 mmarquar Exp $ 27 | 28 | #ifndef PYRAP_MEASURES_H 29 | #define PYRAP_MEASURES_H 30 | 31 | #include 32 | 33 | namespace casacore { 34 | namespace python { 35 | void pymeas(); 36 | } // python 37 | } //casa 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /src/pytableindex.cc: -------------------------------------------------------------------------------- 1 | //# pytableindex.cc: python module for TableIndexProxy object. 2 | //# Copyright (C) 2006 3 | //# Associated Universities, Inc. Washington DC, USA. 4 | //# 5 | //# This library is free software; you can redistribute it and/or modify it 6 | //# under the terms of the GNU Lesser General Public License as published by 7 | //# the Free Software Foundation; either version 3 of the License, or (at your 8 | //# option) any later version. 9 | //# 10 | //# This library is distributed in the hope that it will be useful, but WITHOUT 11 | //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | //# License for more details. 14 | //# 15 | //# You should have received a copy of the GNU Lesser General Public License 16 | //# along with this library; if not, write to the Free Software Foundation, 17 | //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 18 | //# 19 | //# Correspondence concerning AIPS++ should be addressed as follows: 20 | //# Internet email: aips2-request@nrao.edu. 21 | //# Postal address: AIPS++ Project Office 22 | //# National Radio Astronomy Observatory 23 | //# 520 Edgemont Road 24 | //# Charlottesville, VA 22903-2475 USA 25 | //# 26 | //# $Id: pytableindex.cc,v 1.1 2006/09/19 06:44:14 gvandiep Exp $ 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | using namespace boost::python; 36 | 37 | namespace casacore { namespace python { 38 | 39 | void pytableindex() 40 | { 41 | class_ ("TableIndex", 42 | init, Bool>()) 43 | 44 | .def ("_isunique", &TableIndexProxy::isUnique) 45 | .def ("_colnames", &TableIndexProxy::columnNames) 46 | .def ("_setchanged", &TableIndexProxy::setChanged) 47 | .def ("_rownr", &TableIndexProxy::getRowNumber) 48 | .def ("_rownrs", &TableIndexProxy::getRowNumbers) 49 | .def ("_rownrsrange", &TableIndexProxy::getRowNumbersRange) 50 | ; 51 | } 52 | 53 | }} 54 | -------------------------------------------------------------------------------- /src/pytableiter.cc: -------------------------------------------------------------------------------- 1 | //# pytableiter.cc: python module for TableIterProxy object. 2 | //# Copyright (C) 2006 3 | //# Associated Universities, Inc. Washington DC, USA. 4 | //# 5 | //# This library is free software; you can redistribute it and/or modify it 6 | //# under the terms of the GNU Lesser General Public License as published by 7 | //# the Free Software Foundation; either version 3 of the License, or (at your 8 | //# option) any later version. 9 | //# 10 | //# This library is distributed in the hope that it will be useful, but WITHOUT 11 | //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | //# License for more details. 14 | //# 15 | //# You should have received a copy of the GNU Lesser General Public License 16 | //# along with this library; if not, write to the Free Software Foundation, 17 | //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 18 | //# 19 | //# Correspondence concerning AIPS++ should be addressed as follows: 20 | //# Internet email: aips2-request@nrao.edu. 21 | //# Postal address: AIPS++ Project Office 22 | //# National Radio Astronomy Observatory 23 | //# 520 Edgemont Road 24 | //# Charlottesville, VA 22903-2475 USA 25 | //# 26 | //# $Id: pytableiter.cc,v 1.1 2006/09/19 06:44:14 gvandiep Exp $ 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | using namespace boost::python; 36 | 37 | namespace casacore { namespace python { 38 | 39 | void pytableiter() 40 | { 41 | class_ ("TableIter", 42 | init, String, String>()) 43 | 44 | .def ("_reset", &TableIterProxy::reset) 45 | .def ("_next", &TableIterProxy::next) 46 | ; 47 | } 48 | 49 | }} 50 | -------------------------------------------------------------------------------- /src/pytablerow.cc: -------------------------------------------------------------------------------- 1 | //# pytablerow.cc: python module for TableRowProxy object. 2 | //# Copyright (C) 2006 3 | //# Associated Universities, Inc. Washington DC, USA. 4 | //# 5 | //# This library is free software; you can redistribute it and/or modify it 6 | //# under the terms of the GNU Lesser General Public License as published by 7 | //# the Free Software Foundation; either version 3 of the License, or (at your 8 | //# option) any later version. 9 | //# 10 | //# This library is distributed in the hope that it will be useful, but WITHOUT 11 | //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | //# License for more details. 14 | //# 15 | //# You should have received a copy of the GNU Lesser General Public License 16 | //# along with this library; if not, write to the Free Software Foundation, 17 | //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 18 | //# 19 | //# Correspondence concerning AIPS++ should be addressed as follows: 20 | //# Internet email: aips2-request@nrao.edu. 21 | //# Postal address: AIPS++ Project Office 22 | //# National Radio Astronomy Observatory 23 | //# 520 Edgemont Road 24 | //# Charlottesville, VA 22903-2475 USA 25 | //# 26 | //# $Id: pytablerow.cc,v 1.2 2006/10/25 22:14:54 gvandiep Exp $ 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | using namespace boost::python; 36 | 37 | namespace casacore { namespace python { 38 | 39 | void pytablerow() 40 | { 41 | class_ ("TableRow", 42 | init, Bool>()) 43 | 44 | .def ("_iswritable", &TableRowProxy::isWritable) 45 | .def ("_get", &TableRowProxy::get, 46 | (boost::python::arg("rownr"))) 47 | .def ("_put", &TableRowProxy::put, 48 | (boost::python::arg("rownr"), 49 | boost::python::arg("value"), 50 | boost::python::arg("matchingfields"))) 51 | ; 52 | } 53 | 54 | }} 55 | -------------------------------------------------------------------------------- /src/quanta.cc: -------------------------------------------------------------------------------- 1 | //# quanta.cc: python module for casacore Quanta 2 | //# Copyright (C) 2007 3 | //# Australia Telescope National Facility, AUSTRALIA 4 | //# 5 | //# This library is free software; you can redistribute it and/or modify it 6 | //# under the terms of the GNU Lesser General Public License as published by 7 | //# the Free Software Foundation; either version 3 of the License, or (at your 8 | //# option) any later version. 9 | //# 10 | //# This library is distributed in the hope that it will be useful, but WITHOUT 11 | //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | //# License for more details. 14 | //# 15 | //# You should have received a copy of the GNU Lesser General Public License 16 | //# along with this library; if not, write to the Free Software Foundation, 17 | //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 18 | //# 19 | //# Correspondence concerning pyrap should be addressed as follows: 20 | //# Internet email: pyrap-devel@googlegroups.com 21 | //# Postal address: Australia Telescope National Facility 22 | //# PO Box 76 23 | //# Epping NSW 1710 24 | //# AUSTRALIA 25 | //# 26 | //# $Id:$ 27 | 28 | #include "quanta.h" 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | #include 35 | 36 | BOOST_PYTHON_MODULE(_quanta) 37 | { 38 | casacore::python::register_convert_excp(); 39 | casacore::python::register_convert_basicdata(); 40 | casacore::python::register_convert_casa_record(); 41 | 42 | casacore::python::quantity(); 43 | casacore::python::quantvec(); 44 | casacore::python::quantamath(); 45 | } 46 | -------------------------------------------------------------------------------- /src/quanta.h: -------------------------------------------------------------------------------- 1 | //# quanta.h: python module for casacore Quanta 2 | //# Copyright (C) 2007 3 | //# Australia Telescope National Facility, AUSTRALIA 4 | //# 5 | //# This library is free software; you can redistribute it and/or modify it 6 | //# under the terms of the GNU Lesser General Public License as published by 7 | //# the Free Software Foundation; either version 3 of the License, or (at your 8 | //# option) any later version. 9 | //# 10 | //# This library is distributed in the hope that it will be useful, but WITHOUT 11 | //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | //# License for more details. 14 | //# 15 | //# You should have received a copy of the GNU Lesser General Public License 16 | //# along with this library; if not, write to the Free Software Foundation, 17 | //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 18 | //# 19 | //# Correspondence concerning pyrap should be addressed as follows: 20 | //# Internet email: pyrap-devel@googlegroups.com 21 | //# Postal address: Australia Telescope National Facility 22 | //# PO Box 76 23 | //# Epping NSW 1710 24 | //# AUSTRALIA 25 | //# 26 | //# $Id:$ 27 | 28 | #ifndef PYRAP_QUANTA_H 29 | #define PYRAP_QUANTA_H 30 | 31 | #include 32 | 33 | namespace casacore { 34 | namespace python { 35 | void quantity(); 36 | void quantvec(); 37 | void quantamath(); 38 | } // python 39 | } //casa 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /src/quantamath.cc: -------------------------------------------------------------------------------- 1 | //# quantamath.cc: python module for Quantum > global math. 2 | //# Copyright (C) 2007 3 | //# Australia Telescope National Facility, AUSTRALIA 4 | //# 5 | //# This library is free software; you can redistribute it and/or modify it 6 | //# under the terms of the GNU Lesser General Public License as published by 7 | //# the Free Software Foundation; either version 3 of the License, or (at your 8 | //# option) any later version. 9 | //# 10 | //# This library is distributed in the hope that it will be useful, but WITHOUT 11 | //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | //# License for more details. 14 | //# 15 | //# You should have received a copy of the GNU Lesser General Public License 16 | //# along with this library; if not, write to the Free Software Foundation, 17 | //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 18 | //# 19 | //# Correspondence concerning pyrap should be addressed as follows: 20 | //# Internet email: pyrap-devel@googlegroups.com 21 | //# Postal address: Australia Telescope National Facility 22 | //# PO Box 76 23 | //# Epping NSW 1710 24 | //# AUSTRALIA 25 | //# $Id:$ 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #include 34 | 35 | using namespace boost::python; 36 | 37 | namespace casacore { 38 | namespace python { 39 | 40 | dict constants() { 41 | dict d; 42 | const uInt N = 20; 43 | static String types[N] = { 44 | "pi", "ee", "c", "G", "h", "HI", "R", "NA", "e", "mp", 45 | "mp_me", "mu0", "epsilon0", "k", "F", "me", "re", "a0", 46 | "R0", "k2" 47 | }; 48 | static Quantity res[N] = { 49 | Quantity(C::pi,""), Quantity(C::e,""), 50 | #if CASACORE_MAJOR_VERSION>2 || (CASACORE_MAJOR_VERSION==2 && \ 51 | (CASACORE_MINOR_VERSION>4 || (CASACORE_MINOR_VERSION==4 \ 52 | && CASACORE_PATCH_VERSION>0))) 53 | QC::c(), QC::G(), QC::h(), QC::HI(), QC::R(), QC::NA(), QC::e(), 54 | QC::mp(), QC::mp_me(), QC::mu0(), QC::epsilon0(), QC::k(), QC::F(), 55 | QC::me(), QC::re(), QC::a0(), QC::R0(), QC::k2() 56 | #else 57 | QC::c, QC::G, QC::h, QC::HI, QC::R, QC::NA, QC::e, 58 | QC::mp, QC::mp_me, QC::mu0, QC::epsilon0, QC::k, QC::F, 59 | QC::me, QC::re, QC::a0, QC::R0, QC::k2 60 | #endif 61 | }; 62 | for (int i=0; i<20;++i) { 63 | d[types[i]] = res[i]; 64 | } 65 | return d; 66 | } 67 | 68 | dict unitMap(map mymap) { 69 | dict d; 70 | 71 | for (map::iterator i=mymap.begin(); 72 | i != mymap.end(); ++i) { 73 | list unitdesc; 74 | ostringstream oss; 75 | // Test for casacore > 2.0.3 76 | #if CASACORE_MAJOR_VERSION>2 || (CASACORE_MAJOR_VERSION==2 && \ 77 | (CASACORE_MINOR_VERSION>0 || (CASACORE_MINOR_VERSION==0 \ 78 | && CASACORE_PATCH_VERSION>3))) 79 | // Use the getter introduced in casacore 2.0.4 80 | unitdesc.append((i->second).getFullName()); 81 | #else 82 | // Do the same thing with some string parsing (yuk) 83 | oss << i->second; 84 | string namestring=oss.str(); 85 | unitdesc.append(namestring.substr(11, namestring.rfind(")")-11)); 86 | oss.str(""); 87 | #endif 88 | oss<<(i->second).getVal().getDim(); 89 | Quantity q((i->second).getVal().getFac(),oss.str()); 90 | unitdesc.append(q); 91 | d[(i->second).getName() ] = unitdesc; 92 | } 93 | return d; 94 | } 95 | 96 | dict units() { 97 | map mapSI = UnitMap::giveSI(); 98 | map mapDef = UnitMap::giveDef(); 99 | map mapCust = UnitMap::giveCust(); 100 | mapSI.insert(mapDef.begin(), mapDef.end()); 101 | mapSI.insert(mapCust.begin(), mapCust.end()); 102 | return unitMap(mapSI); 103 | } 104 | 105 | dict prefixes() { 106 | map mapPref = UnitMap::givePref(); 107 | return unitMap(mapPref); 108 | } 109 | 110 | 111 | typedef Quantum > QProxy; 112 | typedef Vector VD; 113 | void quantamath() 114 | { 115 | // misc 116 | def ("constants", &constants); 117 | def ("units", &units); 118 | def ("prefixes", &prefixes); 119 | 120 | // Quantum > functions 121 | 122 | def ("nearabs", (Bool ( * )( const QProxy&, const QProxy&, 123 | Double ) )(&nearAbs)); 124 | def ("nearabs", (Bool ( * )( const VD&, const QProxy&, 125 | Double ) )(&nearAbs)); 126 | def ("nearabs", (Bool ( * )( const QProxy&, const VD&, 127 | Double ) )(&nearAbs)); 128 | 129 | def ("near", (Bool ( * )( const QProxy&, const QProxy&, 130 | Double ) )(&near)); 131 | def ("near", (Bool ( * )( const VD&, const QProxy&, 132 | Double ) )(&near)); 133 | def ("near", (Bool ( * )( const QProxy&, const VD&, 134 | Double ) )(&near)); 135 | 136 | def ("abs", (QProxy ( * )( const QProxy&) )(&abs)); 137 | def ("pow", (QProxy ( * )( const QProxy&, Int) )(&pow)); 138 | def ("root", (QProxy ( * )( const QProxy&, Int) )(&root)); 139 | def ("sqrt", (QProxy ( * )( const QProxy&) )(&sqrt)); 140 | def ("ceil", (QProxy ( * )( const QProxy&) )(&ceil)); 141 | def ("floor", (QProxy ( * )( const QProxy&) )(&floor)); 142 | 143 | def ("sin", (QProxy ( * )( const QProxy&) )(&sin)); 144 | def ("cos", (QProxy ( * )( const QProxy&) )(&cos)); 145 | def ("tan", (QProxy ( * )( const QProxy&) )(&tan)); 146 | def ("asin", (QProxy ( * )( const QProxy&) )(&asin)); 147 | def ("acos", (QProxy ( * )( const QProxy&) )(&acos)); 148 | def ("atan", (QProxy ( * )( const QProxy&) )(&atan)); 149 | def ("atan2", (QProxy ( * )( const QProxy&, const QProxy&) )(&atan2)); 150 | def ("atan2", (QProxy ( * )( const QProxy&, const VD&) )(&atan2)); 151 | def ("atan2", (QProxy ( * )( const VD&, const QProxy&) )(&atan2)); 152 | 153 | def ("log", (QProxy ( * )( const QProxy&) )(&log)); 154 | def ("log10", (QProxy ( * )( const QProxy&) )(&log10)); 155 | def ("exp", (QProxy ( * )( const QProxy&) )(&exp)); 156 | 157 | 158 | // Quantity functions 159 | 160 | def ("nearabs", (Bool ( * )( const Quantity&, 161 | const Quantity&) )(&nearAbs)); 162 | def ("nearabs", (Bool ( * )( const Quantity&, const Quantity&, 163 | Double ) )(&nearAbs)); 164 | def ("nearabs", (Bool ( * )( const Double&, const Quantity&, 165 | Double ) )(&nearAbs)); 166 | def ("nearabs", (Bool ( * )( const Quantity&, const Double&, 167 | Double ) )(&nearAbs)); 168 | def ("near", (Bool ( * )( const Quantity&, const Quantity&) )(&near)); 169 | 170 | def ("near", (Bool ( * )( const Quantity&, const Quantity&, 171 | Double ) )(&near)); 172 | def ("near", (Bool ( * )( const Double&, const Quantity&, 173 | Double ) )(&near)); 174 | def ("near", (Bool ( * )( const Quantity&, const Double&, 175 | Double ) )(&near)); 176 | def ("abs", (Quantity ( * )( const Quantity&) )(&abs)); 177 | def ("pow", (Quantity ( * )( const Quantity&, Int) )(&pow)); 178 | def ("root", (Quantity ( * )( const Quantity&, Int) )(&root)); 179 | def ("sqrt", (Quantity ( * )( const Quantity&) )(&sqrt)); 180 | def ("ceil", (Quantity ( * )( const Quantity&) )(&ceil)); 181 | def ("floor", (Quantity ( * )( const Quantity&) )(&floor)); 182 | 183 | def ("sin", (Quantity ( * )( const Quantity&) )(&sin)); 184 | def ("cos", (Quantity ( * )( const Quantity&) )(&cos)); 185 | def ("tan", (Quantity ( * )( const Quantity&) )(&tan)); 186 | def ("asin", (Quantity ( * )( const Quantity&) )(&asin)); 187 | def ("acos", (Quantity ( * )( const Quantity&) )(&acos)); 188 | def ("atan", (Quantity ( * )( const Quantity&) )(&atan)); 189 | def ("atan2", (Quantity ( * )( const Quantity&, 190 | const Quantity&) )(&atan2)); 191 | def ("atan2", (Quantity ( * )( const Quantity&, 192 | const Double&) )(&atan2)); 193 | def ("atan2", (Quantity ( * )( const Double&, 194 | const Quantity&) )(&atan2)); 195 | 196 | def ("log", (Quantity ( * )( const Quantity&) )(&log)); 197 | def ("log10", (Quantity ( * )( const Quantity&) )(&log10)); 198 | def ("exp", (Quantity ( * )( const Quantity&) )(&exp)); 199 | } 200 | } 201 | } 202 | -------------------------------------------------------------------------------- /src/quantity.cc: -------------------------------------------------------------------------------- 1 | //# quantity.cc: python module for Quantum > objects. 2 | //# Copyright (C) 2007 3 | //# Australia Telescope National Facility, AUSTRALIA 4 | //# 5 | //# This library is free software; you can redistribute it and/or modify it 6 | //# under the terms of the GNU Lesser General Public License as published by 7 | //# the Free Software Foundation; either version 3 of the License, or (at your 8 | //# option) any later version. 9 | //# 10 | //# This library is distributed in the hope that it will be useful, but WITHOUT 11 | //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | //# License for more details. 14 | //# 15 | //# You should have received a copy of the GNU Lesser General Public License 16 | //# along with this library; if not, write to the Free Software Foundation, 17 | //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 18 | //# 19 | //# Correspondence concerning pyrap should be addressed as follows: 20 | //# Internet email: pyrap-devel@googlegroups.com 21 | //# Postal address: Australia Telescope National Facility 22 | //# PO Box 76 23 | //# Epping NSW 1710 24 | //# AUSTRALIA 25 | //# 26 | //# $Id:$ 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | #include 40 | #include 41 | #include 42 | 43 | using namespace boost::python; 44 | 45 | 46 | namespace casacore { 47 | namespace python { 48 | 49 | Quantity fromString(const String& str) { 50 | QuantumHolder qh; 51 | String err; 52 | if ( !qh.fromString(err, str) ) { 53 | throw(AipsError(err)); 54 | } 55 | return qh.asQuantity(); 56 | } 57 | 58 | 59 | String printTime(const Quantity& q, const String& fmt, uInt prec) { 60 | MVTime mvt(q); 61 | if (fmt.empty()) { 62 | return mvt.string(prec); 63 | } 64 | return mvt.string(MVTime::giveMe(fmt), prec); 65 | } 66 | 67 | String printAngle(const Quantity& q, const String& fmt, uInt prec) { 68 | MVAngle mva(q); 69 | if (fmt.empty()) { 70 | return mva.string(prec); 71 | } 72 | return mva.string(MVAngle::giveMe(fmt), prec); 73 | } 74 | 75 | String printQuantum(const Quantity& q, const String& fmt="", uInt prec=0) { 76 | if (q.get().getFullUnit() == Unit("s")) { 77 | return printTime(q, fmt, prec); 78 | } else if (q.get().getFullUnit() == Unit("rad")) { 79 | return printAngle(q, fmt, prec); 80 | } 81 | ostringstream oss; 82 | q.print(oss); 83 | return String(oss); 84 | } 85 | // Introduce the overloaded PrintQuantum function 86 | BOOST_PYTHON_FUNCTION_OVERLOADS(printQuantumOVL, printQuantum, 1, 3) 87 | 88 | // these functions take Unit as argument, enable outside access through 89 | // strings 90 | Quantity getWithUnit(const Quantity& q, const String& u) { 91 | Unit unit(u); 92 | return q.get(unit); 93 | } 94 | Double getValueWithUnit(const Quantity& q, const String& u) { 95 | Unit unit(u); 96 | return q.getValue(unit); 97 | } 98 | 99 | Quantity fromRecord(const Record& rec) { 100 | QuantumHolder qh; 101 | String err; 102 | if ( !qh.fromRecord(err, rec) ) { 103 | throw(AipsError(err)); 104 | } 105 | return qh.asQuantity(); 106 | } 107 | 108 | bool conforms(const Quantity& left, const Quantity& right) { 109 | return (left.getFullUnit().getValue() == right.getFullUnit().getValue()); 110 | } 111 | 112 | Record toRecord(const Quantity& q) { 113 | QuantumHolder qh(q); 114 | String err; 115 | Record rec; 116 | if ( !qh.toRecord(err, rec) ) { 117 | throw(AipsError(err)); 118 | } 119 | return rec; 120 | } 121 | 122 | Quantity toTime(const Quantity& q) { 123 | if (q.check(UnitVal::TIME)) { 124 | return q; 125 | } else { 126 | Quantity q0 = MVTime(q).get(); 127 | return q0; 128 | } 129 | } 130 | 131 | Quantity toAngle(const Quantity& q) { 132 | if (q.check(UnitVal::ANGLE)) { 133 | return q; 134 | } else { 135 | Quantity q0 = MVAngle(q).get(); 136 | return q0; 137 | } 138 | } 139 | 140 | Double toUnixTime(const Quantity& q) { 141 | // MJD = JD - 2400000.5 142 | // unix = (JD - 2440587.5) * 86400.0 143 | const Double mjdsecToUnixsec = (2400000.5 - 2440587.5) * 86400.0; 144 | Quantity qt = toTime(q); 145 | return qt.get().getValue() + mjdsecToUnixsec; 146 | } 147 | 148 | Quantity norm(const Quantity& self, Double a) { 149 | return Quantity(MVAngle(self)(a).degree(), "deg"); 150 | } 151 | 152 | }} 153 | 154 | namespace casacore { namespace python { 155 | void quantity() 156 | { 157 | class_ ("Quantity") 158 | .def (init< >()) 159 | .def (init< const Quantity& > ()) 160 | .def (init< Double, const String& >()) 161 | .def ("__repr__", &printQuantum, (boost::python::arg("self"), 162 | boost::python::arg("fmt")="", 163 | boost::python::arg("precision")=0)) 164 | .def ("get_value", (const Double& ( Quantity::* )( ) const)(&Quantity::getValue), 165 | return_value_policy < copy_const_reference> () 166 | ) 167 | .def ("get_value", &getValueWithUnit) 168 | .def ("get_unit", &Quantity::getUnit, 169 | return_value_policy < copy_const_reference> ()) 170 | .def ("convert", (void ( Quantity::* )( const Quantity& ) )(&Quantity::convert)) 171 | .def ("convert", (void ( Quantity::* )( ) )(&Quantity::convert)) 172 | .def ("set_value", &Quantity::setValue) 173 | .def ("get", (Quantity ( Quantity::* )( ) const)(&Quantity::get)) 174 | .def ("canonical", (Quantity ( Quantity::* )( ) const)(&Quantity::get)) 175 | .def ("get", (Quantity ( Quantity::* )( const Quantity& ) const)(&Quantity::get)) 176 | .def ("get", &getWithUnit) 177 | .def ("conforms", &conforms) 178 | .def ("totime", &toTime) 179 | .def ("to_time", &toTime) 180 | .def ("toangle", &toAngle) 181 | .def ("to_angle", &toAngle) 182 | .def ("to_unix_time", &toUnixTime) 183 | .def ("to_dict", &toRecord) 184 | .def ("norm", &norm, (boost::python::arg("self"), boost::python::arg("a")=-0.5)) 185 | .def (-self) 186 | .def (self - self) 187 | .def (self -= self) 188 | .def (self -= Double()) 189 | .def (self - Double() ) 190 | .def (Double() - self) 191 | .def (+self) 192 | .def (self + self) 193 | .def (self += self) 194 | .def (self += Double()) 195 | .def (self + Double() ) 196 | .def (Double() + self) 197 | .def (self * self) 198 | .def (self *= self) 199 | .def (self *= Double()) 200 | .def (self * Double() ) 201 | .def (Double() * self) 202 | .def (self / self) 203 | .def (self /= self) 204 | .def (self /= Double()) 205 | .def (self / Double() ) 206 | .def (Double() / self) 207 | .def (self == self) 208 | .def (self == Double()) 209 | .def (Double() == self) 210 | .def (self != self) 211 | .def (self != Double()) 212 | .def (Double() != self) 213 | 214 | .def (self < self) 215 | .def (self < Double()) 216 | .def (Double() < self) 217 | .def (self <= self) 218 | .def (self <= Double()) 219 | .def (Double() <= self) 220 | 221 | .def (self > self) 222 | .def (self > Double()) 223 | .def (Double() > self) 224 | .def (self >= self) 225 | .def (self >= Double()) 226 | .def (Double() >= self) 227 | .def ("formatted", &printQuantum, printQuantumOVL((boost::python::arg("q"), 228 | boost::python::arg("fmt")="", 229 | boost::python::arg("precision")=0))) 230 | ; 231 | def ("from_string", &fromString); 232 | def ("from_dict", &fromRecord); 233 | 234 | } 235 | }} 236 | -------------------------------------------------------------------------------- /src/quantvec.cc: -------------------------------------------------------------------------------- 1 | //# quantity.cc: python module for Quantum > objects. 2 | //# Copyright (C) 2007 3 | //# Australia Telescope National Facility, AUSTRALIA 4 | //# 5 | //# This library is free software; you can redistribute it and/or modify it 6 | //# under the terms of the GNU Lesser General Public License as published by 7 | //# the Free Software Foundation; either version 3 of the License, or (at your 8 | //# option) any later version. 9 | //# 10 | //# This library is distributed in the hope that it will be useful, but WITHOUT 11 | //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | //# License for more details. 14 | //# 15 | //# You should have received a copy of the GNU Lesser General Public License 16 | //# along with this library; if not, write to the Free Software Foundation, 17 | //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 18 | //# 19 | //# Correspondence concerning pyrap should be addressed as follows: 20 | //# Internet email: pyrap-devel@googlegroups.com 21 | //# Postal address: Australia Telescope National Facility 22 | //# PO Box 76 23 | //# Epping NSW 1710 24 | //# AUSTRALIA 25 | //# 26 | //# $Id:$ 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | #include 40 | #include 41 | 42 | using namespace boost::python; 43 | 44 | namespace casacore { 45 | namespace python { 46 | 47 | typedef Quantum > QProxy; 48 | typedef Vector VD; 49 | 50 | /* 51 | String qpprintQuantum(const QProxy& q) { 52 | ostringstream oss; 53 | q.print(oss); 54 | return String(oss); 55 | } 56 | */ 57 | // these functions take Unit as argument, enable outside access through 58 | // strings 59 | QProxy qpgetWithUnit(const QProxy& q, const String& u) { 60 | Unit unit(u); 61 | return q.get(unit); 62 | } 63 | VD qpgetValueWithUnit(const QProxy& q, const String& u) { 64 | Unit unit(u); 65 | return q.getValue(unit); 66 | } 67 | 68 | QProxy qpfromRecord(const Record& rec) { 69 | QuantumHolder qh; 70 | String err; 71 | if ( !qh.fromRecord(err, rec) ) { 72 | throw(AipsError(err)); 73 | } 74 | return qh.asQuantumVectorDouble(); 75 | } 76 | 77 | bool qpconforms(const QProxy& left, const QProxy& right) { 78 | return (left.getFullUnit().getValue() == right.getFullUnit().getValue()); 79 | } 80 | 81 | Record qptoRecord(const QProxy& q) { 82 | QuantumHolder qh(q); 83 | String err; 84 | Record rec; 85 | if ( !qh.toRecord(err, rec) ) { 86 | throw(AipsError(err)); 87 | } 88 | return rec; 89 | } 90 | 91 | QProxy qptoTime(const QProxy& q) { 92 | if (q.check(UnitVal::TIME)) { 93 | return q; 94 | } else { 95 | VD values = q.getValue(); 96 | Unit u = q.getUnit(); 97 | Unit outu; 98 | VD outvals(values.nelements()); 99 | for (uInt i=0; i < values.nelements(); ++i) { 100 | Quantity q0 = MVTime(Quantity(values[i], u)).get(); 101 | outu = q0.getUnit(); 102 | cout << q0 << endl; 103 | outvals[i] = q0.getValue(); 104 | } 105 | return QProxy(outvals, outu); 106 | } 107 | } 108 | 109 | QProxy qptoAngle(const QProxy& q) { 110 | if (q.check(UnitVal::ANGLE)) { 111 | return q; 112 | } else { 113 | VD values = q.getValue(); 114 | Unit u = q.getUnit(); 115 | Unit outu; 116 | VD outvals(values.nelements()); 117 | for (uInt i=0; i < values.nelements(); ++i) { 118 | Quantity q0 = MVAngle(Quantity(values[i], u)).get(); 119 | outu = q0.getUnit(); 120 | cout << q0 << endl; 121 | outvals[i] = q0.getValue(); 122 | } 123 | return QProxy(outvals, outu); 124 | } 125 | 126 | } 127 | 128 | 129 | QProxy norm(const QProxy& self, Double a) { 130 | VD val = self.get().getValue(); 131 | VD outval(val.nelements()); 132 | for (uInt i=0; i< val.nelements(); ++i) { 133 | outval(i) = MVAngle(val[i])(a).degree(); 134 | } 135 | return QProxy(outval, "deg"); 136 | } 137 | 138 | String printTime(const QProxy& q, const String& fmt) { 139 | ostringstream oss; 140 | VD val = q.get().getValue(); 141 | size_t n = val.nelements(); 142 | Unit u = q.get().getUnit(); 143 | oss << "["; 144 | for (size_t i=0; i < n; ++i) { 145 | MVTime mvt(Quantity(val[i], u)); 146 | if (fmt =="") { 147 | oss << mvt.string(); 148 | } else { 149 | oss << mvt.string(MVTime::giveMe(fmt)); 150 | } 151 | if ( i < n-1 ) { 152 | oss << ", "; 153 | } 154 | } 155 | oss << "]"; 156 | return String(oss); 157 | } 158 | 159 | String printAngle(const QProxy& q, const String& fmt) { 160 | ostringstream oss; 161 | VD val = q.get().getValue(); 162 | size_t n = val.nelements(); 163 | Unit u = q.get().getUnit(); 164 | oss << "["; 165 | for (size_t i=0; i < n; ++i) { 166 | MVAngle mva(Quantity(val[i], u)); 167 | if (fmt =="") { 168 | oss << mva.string(); 169 | } else { 170 | oss << mva.string(MVAngle::giveMe(fmt)); 171 | } 172 | if ( i < n-1 ) { 173 | oss << ", "; 174 | } 175 | } 176 | oss << "]"; 177 | return String(oss); 178 | } 179 | 180 | String qpprintQuantum(const QProxy& q, const String& fmt) { 181 | if (q.get().getFullUnit() == Unit("s")) { 182 | return printTime(q, fmt); 183 | } else if (q.get().getFullUnit() == Unit("rad")) { 184 | return printAngle(q, fmt); 185 | } 186 | ostringstream oss; 187 | q.print(oss); 188 | return String(oss); 189 | } 190 | 191 | }} 192 | 193 | namespace casacore { namespace python { 194 | 195 | void quantvec() 196 | { 197 | class_ ("QuantVec") 198 | .def (init< >()) 199 | .def (init< const QProxy& > ()) 200 | .def (init< const VD&, const String& >()) 201 | .def ("__repr__", &qpprintQuantum, (boost::python::arg("self"), 202 | boost::python::arg("fmt")="")) 203 | .def ("_get_value", (const VD& ( QProxy::* )( ) const)(&QProxy::getValue), 204 | return_value_policy < copy_const_reference> () 205 | ) 206 | .def ("_get_value", &qpgetValueWithUnit) 207 | .def ("get_unit", &QProxy::getUnit, 208 | return_value_policy < copy_const_reference> ()) 209 | .def ("convert", (void ( QProxy::* )( const QProxy& ) )(&QProxy::convert)) 210 | .def ("convert", (void ( QProxy::* )( ) )(&QProxy::convert)) 211 | .def ("set_value", &QProxy::setValue) 212 | .def ("get", (QProxy ( QProxy::* )( ) const)(&QProxy::get)) 213 | .def ("canonical", (QProxy ( QProxy::* )( ) const)(&QProxy::get)) 214 | .def ("get", 215 | (QProxy ( QProxy::* )( const QProxy& ) const)(&QProxy::get)) 216 | .def ("get", &qpgetWithUnit) 217 | .def ("conforms", &qpconforms) 218 | .def ("norm", &norm, (boost::python::arg("self"), boost::python::arg("a")=-0.5)) 219 | .def ("totime", &qptoTime) 220 | .def ("to_time", &qptoTime) 221 | .def ("toangle", &qptoAngle) 222 | .def ("to_angle", &qptoAngle) 223 | .def ("to_dict", &qptoRecord) 224 | .def (-self) 225 | .def (self - self) 226 | .def (self -= self) 227 | .def (self -= VD()) 228 | .def (self - VD() ) 229 | .def (VD() - self) 230 | .def (+self) 231 | .def (self + self) 232 | .def (self += self) 233 | .def (self += VD()) 234 | .def (self + VD() ) 235 | .def (VD() + self) 236 | .def (self * self) 237 | .def (self *= self) 238 | .def (self *= VD()) 239 | .def (self * VD() ) 240 | .def (VD() * self) 241 | .def (self / self) 242 | .def (self /= self) 243 | .def (self /= VD()) 244 | .def (self / VD() ) 245 | .def (VD() / self) 246 | .def (self == self) 247 | .def (self == VD()) 248 | .def (VD() == self) 249 | .def (self != self) 250 | .def (self != VD()) 251 | .def (VD() != self) 252 | 253 | 254 | .def (self < self) 255 | .def (self < VD()) 256 | .def (VD() < self) 257 | .def (self <= self) 258 | .def (self <= VD()) 259 | .def (VD() <= self) 260 | 261 | .def (self > self) 262 | .def (self > VD()) 263 | .def (VD() > self) 264 | .def (self >= self) 265 | .def (self >= VD()) 266 | .def (VD() >= self) 267 | .def ("formatted", &qpprintQuantum) 268 | ; 269 | def ("from_dict_v", &qpfromRecord); 270 | 271 | } 272 | }} 273 | -------------------------------------------------------------------------------- /src/tables.cc: -------------------------------------------------------------------------------- 1 | //# tables.cc: python module for AIPS++ table system 2 | //# Copyright (C) 2006 3 | //# Associated Universities, Inc. Washington DC, USA. 4 | //# 5 | //# This library is free software; you can redistribute it and/or modify it 6 | //# under the terms of the GNU Lesser General Public License as published by 7 | //# the Free Software Foundation; either version 3 of the License, or (at your 8 | //# option) any later version. 9 | //# 10 | //# This library is distributed in the hope that it will be useful, but WITHOUT 11 | //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | //# License for more details. 14 | //# 15 | //# You should have received a copy of the GNU Lesser General Public License 16 | //# along with this library; if not, write to the Free Software Foundation, 17 | //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 18 | //# 19 | //# Correspondence concerning AIPS++ should be addressed as follows: 20 | //# Internet email: aips2-request@nrao.edu. 21 | //# Postal address: AIPS++ Project Office 22 | //# National Radio Astronomy Observatory 23 | //# 520 Edgemont Road 24 | //# Charlottesville, VA 22903-2475 USA 25 | //# 26 | //# $Id: tables.cc,v 1.5 2006/10/17 03:37:27 gvandiep Exp $ 27 | 28 | #include "tables.h" 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include 38 | #include 39 | 40 | #include 41 | 42 | BOOST_PYTHON_MODULE(_tables) 43 | { 44 | casacore::python::register_convert_excp(); 45 | casacore::python::register_convert_basicdata(); 46 | casacore::python::register_convert_casa_valueholder(); 47 | casacore::python::register_convert_casa_record(); 48 | casacore::python::register_convert_std_vector(); 49 | 50 | casacore::python::pytable(); 51 | casacore::python::pytablerow(); 52 | casacore::python::pytableiter(); 53 | casacore::python::pytableindex(); 54 | 55 | casacore::python::pyms(); 56 | 57 | // Register the TaQL meas and mscal functions. 58 | // Normally they are loaded as a shared library, but that cannot 59 | // be done if the program is built statically. 60 | register_meas(); 61 | register_derivedmscal(); 62 | } 63 | 64 | -------------------------------------------------------------------------------- /src/tables.h: -------------------------------------------------------------------------------- 1 | //# tables.cc: python module for AIPS++ table system 2 | //# Copyright (C) 2006 3 | //# Associated Universities, Inc. Washington DC, USA. 4 | //# 5 | //# This library is free software; you can redistribute it and/or modify it 6 | //# under the terms of the GNU Lesser General Public License as published by 7 | //# the Free Software Foundation; either version 3 of the License, or (at your 8 | //# option) any later version. 9 | //# 10 | //# This library is distributed in the hope that it will be useful, but WITHOUT 11 | //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | //# License for more details. 14 | //# 15 | //# You should have received a copy of the GNU Lesser General Public License 16 | //# along with this library; if not, write to the Free Software Foundation, 17 | //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 18 | //# 19 | //# Correspondence concerning AIPS++ should be addressed as follows: 20 | //# Internet email: aips2-request@nrao.edu. 21 | //# Postal address: AIPS++ Project Office 22 | //# National Radio Astronomy Observatory 23 | //# 520 Edgemont Road 24 | //# Charlottesville, VA 22903-2475 USA 25 | //# 26 | //# $Id: tables.h,v 1.3 2006/09/20 02:38:41 gvandiep Exp $ 27 | 28 | #ifndef APPSPYTHON_PYCASATABLE_H 29 | #define APPSPYTHON_PYCASATABLE_H 30 | 31 | #include 32 | 33 | namespace casacore { 34 | namespace python { 35 | 36 | void pytable(); 37 | void pytablerow(); 38 | void pytableiter(); 39 | void pytableindex(); 40 | 41 | void pyms(); 42 | 43 | } // python 44 | } //casa 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | python_add_library(_tConvert MODULE WITH_SOABI tConvert.cc) 2 | target_include_directories(_tConvert PRIVATE ${Boost_INCLUDE_DIRS} 3 | ${CASACORE_INCLUDE_DIRS}) 4 | target_link_directories(_tConvert PRIVATE ${CASACORE_LIBRARY_DIRS}) 5 | target_link_libraries(_tConvert PRIVATE ${CASACORE_LIBRARIES}) 6 | if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin") 7 | target_link_options(_tConvert PRIVATE "LINKER:--as-needed") 8 | endif() 9 | install(TARGETS _tConvert LIBRARY DESTINATION casacore COMPONENT libraries) 10 | -------------------------------------------------------------------------------- /tests/requirements.txt: -------------------------------------------------------------------------------- 1 | pytest-cov 2 | -------------------------------------------------------------------------------- /tests/tConvert.cc: -------------------------------------------------------------------------------- 1 | 2 | //# tConvert.cc: Test program for libcasacore_python's C++/Python converters 3 | //# Copyright (C) 2006 4 | //# Associated Universities, Inc. Washington DC, USA. 5 | //# 6 | //# This library is free software; you can redistribute it and/or modify it 7 | //# under the terms of the GNU Lesser General Public License as published by 8 | //# the Free Software Foundation; either version 3 of the License, or (at your 9 | //# option) any later version. 10 | //# 11 | //# This library is distributed in the hope that it will be useful, but WITHOUT 12 | //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 14 | //# License for more details. 15 | //# 16 | //# You should have received a copy of the GNU Lesser General Public License 17 | //# along with this library; if not, write to the Free Software Foundation, 18 | //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 19 | //# 20 | //# Correspondence concerning AIPS++ should be addressed as follows: 21 | //# Internet email: aips2-request@nrao.edu. 22 | //# Postal address: AIPS++ Project Office 23 | //# National Radio Astronomy Observatory 24 | //# 520 Edgemont Road 25 | //# Charlottesville, VA 22903-2475 USA 26 | //# 27 | //# $Id: tConvert.cc,v 1.4 2006/11/06 00:14:44 gvandiep Exp $ 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #if CASACORE_MAJOR_VERSION < 3 || \ 36 | (CASACORE_MAJOR_VERSION == 3 && CASACORE_MINOR_VERSION < 4) 37 | // This include disappeared in the arrays refactor for casacore 3.4.0 38 | #include 39 | #endif 40 | #include 41 | #include 42 | 43 | #include 44 | 45 | using namespace boost::python; 46 | 47 | namespace casacore { namespace python { 48 | 49 | struct TConvert 50 | { 51 | TConvert() {} 52 | Bool testbool (Bool in) 53 | {cout << "bool " << in << endl; return in;} 54 | Int testint (Int in) 55 | {cout << "Int " << in << endl; return in;} 56 | Int64 testint64 (Int64 in) 57 | {cout << "Int64 " << in << endl; return in;} 58 | Int testssize (::ssize_t in) 59 | {cout << "ssize " << in << endl; return in;} 60 | Float testfloat (Float in) 61 | {cout << "Float " << in << endl; return in;} 62 | Double testdouble (Double in) 63 | {cout << "Double " << in << endl; return in;} 64 | Complex testcomplex (const Complex& in) 65 | {cout << "Complex " << in << endl; return in;} 66 | DComplex testdcomplex (const DComplex& in) 67 | {cout << "DComplex " << in << endl; return in;} 68 | String teststring (const String& in) 69 | {cout << "String " << in << endl; String out=in; return out;} 70 | String testunicode (const String& in) 71 | {cout << "Unicode " << in << endl; String out=in; return out;} 72 | Record testrecord (const Record& in) 73 | {cout << "Record "; in.print(cout); cout << endl; return in;} 74 | ValueHolder testvh (const ValueHolder& in) 75 | {cout << "VH " << in.dataType() << endl; return in;} 76 | Vector testvecbool (const Vector& in) 77 | {cout << "VecBool " << in << endl; return in;} 78 | Vector testvecint (const Vector& in) 79 | {cout << "VecInt " << in << endl; return in;} 80 | Vector testveccomplex (const Vector& in) 81 | {cout << "VecComplex " << in << endl; return in;} 82 | Vector testvecstr (const Vector& in) 83 | {cout << "VecStr " << in << endl; return in;} 84 | std::vector teststdvecbool (const std::vector& in) 85 | {cout << "vecbool " << in << endl; return in;} 86 | std::vector teststdvecuint (const std::vector& in) 87 | {cout << "vecuInt " << in << endl; return in;} 88 | std::vector > teststdvecvecuint 89 | (const std::vector >& in) 90 | {cout << "vecvecuInt " << in << endl; return in;} 91 | std::vector teststdvecvh (const std::vector& in) 92 | {cout << "vecvh " << in.size() << endl; return in;} 93 | IPosition testipos (const IPosition& in) 94 | {cout << "IPos " << in << endl; return in;} 95 | void testIterError() 96 | {throw IterError();} 97 | }; 98 | 99 | 100 | void testConvert() 101 | { 102 | class_ ("tConvert", init<>()) 103 | .def ("testbool", &TConvert::testbool) 104 | .def ("testint", &TConvert::testint) 105 | .def ("testint64", &TConvert::testint64) 106 | .def ("testssize", &TConvert::testssize) 107 | .def ("testfloat", &TConvert::testfloat) 108 | .def ("testdouble", &TConvert::testdouble) 109 | .def ("testcomplex", &TConvert::testcomplex) 110 | .def ("testdcomplex", &TConvert::testdcomplex) 111 | .def ("teststring", &TConvert::teststring) 112 | .def ("testunicode", &TConvert::testunicode) 113 | .def ("testrecord", &TConvert::testrecord) 114 | .def ("testvh", &TConvert::testvh) 115 | .def ("testvecbool", &TConvert::testvecbool) 116 | .def ("testvecint", &TConvert::testvecint) 117 | .def ("testveccomplex", &TConvert::testveccomplex) 118 | .def ("testvecstr", &TConvert::testvecstr) 119 | .def ("teststdvecbool", &TConvert::teststdvecbool) 120 | .def ("teststdvecuint", &TConvert::teststdvecuint) 121 | .def ("teststdvecvecuint", &TConvert::teststdvecvecuint) 122 | .def ("teststdvecvh" , &TConvert::teststdvecvh) 123 | .def ("testipos", &TConvert::testipos) 124 | .def ("testitererror", &TConvert::testIterError) 125 | ; 126 | } 127 | 128 | }} 129 | 130 | 131 | BOOST_PYTHON_MODULE(_tConvert) 132 | { 133 | // Register the required converters. 134 | casacore::python::register_convert_excp(); 135 | casacore::python::register_convert_basicdata(); 136 | casacore::python::register_convert_casa_valueholder(); 137 | casacore::python::register_convert_casa_record(); 138 | casacore::python::register_convert_std_vector(); 139 | casacore::python::register_convert_std_vector(); 140 | casacore::python::register_convert_std_vector >(); 141 | casacore::python::register_convert_std_vector(); 142 | 143 | // Execute the test. 144 | casacore::python::testConvert(); 145 | } 146 | -------------------------------------------------------------------------------- /tests/test_convert.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from unittest import TestCase 3 | 4 | import numpy as np 5 | from casacore._tConvert import tConvert 6 | 7 | 8 | class TestConvert(TestCase): 9 | @classmethod 10 | def setUpClass(cls): 11 | cls.t = tConvert() 12 | 13 | def arrvh(self, arr): 14 | print(' testarrvh') 15 | print(self.t.testvh(arr)) 16 | print(self.t.testvh(arr[0])) 17 | print(self.t.testvh([arr[0]])) 18 | print(self.t.testvh([arr[0], arr[1]])) 19 | 20 | def arrb(self, arr): 21 | self.arrvh(arr) 22 | print(self.t.testbool(arr[0])) 23 | 24 | def arri(self, arr): 25 | self.arrvh(arr) 26 | print(self.t.testint(arr[0])) 27 | print(self.t.testint64(arr[0])) 28 | print(self.t.testssize(arr[0])) 29 | print(self.t.testfloat(arr[0])) 30 | print(self.t.testcomplex(arr[0])) 31 | 32 | def arrf(self, arr): 33 | self.arrvh(arr) 34 | print(self.t.testfloat(arr[0])) 35 | print(self.t.testcomplex(arr[0])) 36 | 37 | def arrc(self, arr): 38 | self.arrvh(arr) 39 | print(self.t.testcomplex(arr[0])) 40 | 41 | def test_na(self): 42 | # Test byte and sbyte. 43 | b = np.array([-1, -2], np.int8) 44 | print(self.t.testvh(b)) 45 | # UInt8 is Bool, therefore use Int16. 46 | b = np.array([211, 212], np.int16) 47 | print(self.t.testvh(b)) 48 | print('>>>') 49 | res = self.t.testvh(np.array((0,))) 50 | print('<<<') 51 | print(res.shape) 52 | print(self.t.testvh({'shape': [2, 2], 'array': ['abcd', 'c', '12', 'x12']})) 53 | 54 | def test_np(self): 55 | # Test byte and sbyte. 56 | b = np.int8([-1, -2]) 57 | print(self.t.testvh(b)) 58 | b = np.uint8([211, 212]) 59 | print(self.t.testvh(b)) 60 | print('>>>') 61 | res = self.t.testvh(np.array([])) 62 | print('<<<') 63 | print(res.shape) 64 | print(self.t.testvh(np.array([["abcd", "c"], ["12", "x12"]]))) 65 | 66 | def test_nps(self): 67 | self.arrb(np.array([True, False])) 68 | self.arri(np.array([-6, -7], dtype=np.int8)) 69 | self.arri(np.array([5, 6], dtype=np.uint8)) 70 | self.arri(np.array([-16, -17], dtype=np.int16)) 71 | self.arri(np.array([15, 16], dtype=np.uint16)) 72 | self.arri(np.array([-26, -27], dtype=np.int32)) 73 | self.arri(np.array([25, 26], dtype=np.uint32)) 74 | self.arri(np.array([-36, -37], dtype=np.int64)) 75 | self.arri(np.array([35, 36], dtype=np.uint64)) 76 | self.arrf(np.array([-46, -47], dtype=np.float32)) 77 | self.arrf(np.array([45, 46], dtype=np.float64)) 78 | self.arrc(np.array([-56 - 66j, -57 - 67j], dtype=np.complex64)) 79 | self.arrc(np.array([-76 - 86j, -77 - 87j], dtype=np.complex128)) 80 | 81 | def test_main(self): 82 | print('') 83 | print('begin dotest') 84 | print(self.t.testbool(True)) 85 | print(self.t.testbool(False)) 86 | print(self.t.testint(-1)) 87 | print(self.t.testint(10)) 88 | print(self.t.testint64(-123456789013)) 89 | print(self.t.testint64(123456789014)) 90 | print(self.t.testssize(-2)) 91 | print(self.t.testssize(11)) 92 | print(self.t.testfloat(3.14)) 93 | print(self.t.testfloat(12)) 94 | print(self.t.testdouble(3.14)) 95 | print(self.t.testdouble(12)) 96 | print(self.t.teststring("this is a string")) 97 | print(self.t.testunicode(u"this is a unicode")) 98 | 99 | arr = np.array([2, 3], np.int32) 100 | print(self.t.testint(arr[0])) 101 | print(self.t.testint64(arr[0])) 102 | print(self.t.testfloat(arr[0])) 103 | print(self.t.testdouble(arr[0])) 104 | arr = np.array([2.2, 3.2], np.float32) 105 | print(self.t.testint(arr[0])) 106 | print(self.t.testfloat(arr[0])) 107 | print(self.t.testdouble(arr[0])) 108 | arr = np.array([2.4, 3.4], np.float64) 109 | print(self.t.testint(arr[0])) 110 | print(self.t.testfloat(arr[0])) 111 | print(self.t.testdouble(arr[0])) 112 | 113 | print(self.t.testipos([2, 3, 4])) 114 | print(self.t.testipos(1)) 115 | print(self.t.testipos(np.array([2]))) 116 | print(self.t.testipos(np.array(3))) 117 | 118 | print(self.t.testvecint([1, 2, 3, 4])) 119 | print(self.t.testvecint([])) 120 | print(self.t.testvecint((-1, -2, -3, -4))) 121 | print(self.t.testvecint(-10)) 122 | print(self.t.testvecint(np.array((10, 11, 12)))) 123 | print(self.t.testvecint(np.array(1))) 124 | print(self.t.testveccomplex([1 + 2j, -1 - 3j, -1.5 + 2.5j])) 125 | print(self.t.testvecstr(["a1", "a2", "b1", "b2"])) 126 | print(self.t.testvecstr(())) 127 | print(self.t.testvecstr("sc1")) 128 | print(self.t.teststdvecuint([1, 2, 4])) 129 | print(self.t.teststdvecuint(())) 130 | print(self.t.teststdvecuint(10)) 131 | print(self.t.teststdvecvecuint([[1, 2, 4]])) 132 | print(self.t.teststdvecvecuint((()))) 133 | print(self.t.teststdvecvecuint(())) 134 | print(self.t.teststdvecvecuint([1, 2, 4])) 135 | print(self.t.teststdvecvecuint(20)) 136 | 137 | print(self.t.testvh(True)) 138 | print(self.t.testvh(2)) 139 | print(self.t.testvh(1234567890123)) 140 | print(self.t.testvh(1.3)) 141 | print(self.t.testvh(10 - 11j)) 142 | print(self.t.testvh("str")) 143 | print(self.t.testvh([True]) + 0) # add 0 to convert nppy to integer) 144 | print(self.t.testvh([2, 4, 6, 8, 10])) 145 | print(self.t.testvh([1.3, 4, 5, 6])) 146 | print(self.t.testvh([10 - 11j, 1 + 2j])) 147 | # print(self.t.testvh ([])) 148 | print(self.t.testvh(["str1", "str2"])) 149 | print(self.t.testvh({"shape": [2, 2], "array": ["str1", "str2", "str3", "str4"]})) 150 | a = self.t.testvh({"shape": [2, 2], "array": ["str1", "str2", "str3", "str4"]}) 151 | print(a) 152 | print(self.t.testvh(a)) 153 | 154 | print(self.t.testvh([u"str1", u"str2"])) 155 | print(self.t.testvh({"shape": [2, 2], "array": [u"str1", u"str2", u"str3", u"str4"]})) 156 | a1 = self.t.testvh({"shape": [2, 2], "array": [u"str1", u"str2", u"str3", u"str4"]}) 157 | print(a1) 158 | print(self.t.testvh(a1)) 159 | 160 | a = self.t.testvh([10 - 11j, 1 + 2j]) 161 | print(a.shape) 162 | print(self.t.testvh(a)) 163 | 164 | b = np.int32([[2, 3], [4, 5]]) 165 | print(b) 166 | print(self.t.testvh(b)) 167 | 168 | b = np.int32([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) 169 | print(b[2:9:2]) 170 | print(self.t.testvh(b[2:9:2])) 171 | 172 | b = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10.]) 173 | print(b[2:9:2]) 174 | print(self.t.testvh(b[2:9:2])) 175 | a = b[2:9:2] 176 | print(self.t.testvh(a)) 177 | 178 | print(self.t.testvh(np.array([20. + 10j]))) 179 | print(self.t.testvh(np.array(21.))) 180 | 181 | print('>>>') 182 | res = self.t.testvh(np.array([])) 183 | print('<<<') 184 | print(res.shape) 185 | print('>>>') 186 | res = self.t.testvh(np.array([[]])) 187 | print('<<<') 188 | print(res.shape) 189 | 190 | # On 64-bit machines the output also contains 'dtype=int32' 191 | # So leave it out. 192 | a = self.t.testrecord({"int": 1, "int64": 123456789012, "str": "bc", 'vecint': [1, 2, 3]}) 193 | print('>>>') 194 | print(a) 195 | print('<<<') 196 | print('end dotest') 197 | print('') 198 | -------------------------------------------------------------------------------- /tests/test_fitting.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from casacore import fitting, functionals 3 | import numpy as np 4 | 5 | 6 | class TestFitting(unittest.TestCase): 7 | """Test class for Fitting module.""" 8 | 9 | def setUp(self): 10 | """Set up fitserver for all the tests.""" 11 | self.fitserver = fitting.fitserver() 12 | 13 | def test_fitter(self): 14 | """Testing fitter.""" 15 | self.fitserver.fitter() 16 | 17 | def test_fitserver(self): 18 | """Testing fitserver.""" 19 | self.assertEqual(self.fitserver.getstate(), 20 | {'colfac': 1e-08, 21 | 'lmfac': 0.001, 22 | 'n': 0, 23 | 'typ': 'real'}) 24 | self.fitserver.set(n=1, colfac=1.0e-09, lmfac=1.0e-2, ftype=1) 25 | self.assertEqual(self.fitserver.getstate(), 26 | {'colfac': 1e-09, 27 | 'lmfac': 0.01, 28 | 'n': 1, 29 | 'typ': 'complex'}) 30 | 31 | def test_poly(self): 32 | """Test poly.""" 33 | x = -1 + 0.1 * np.arange(21) 34 | y = functionals.poly(2, [3.03, 2.06, 0.03])(x) 35 | self.fitserver.linear(functionals.compiled('p'), [], y) 36 | np.testing.assert_equal(self.fitserver.solution(), sum(y)/len(y)) 37 | np.testing.assert_equal(self.fitserver.sd(), self.fitserver.stddev()) 38 | np.testing.assert_allclose(self.fitserver.error(), 39 | np.array([0.27893394])) 40 | self.assertAlmostEqual(self.fitserver.chi2(), 32.6777389399999) 41 | self.assertEqual(self.fitserver.rank(), 1) 42 | np.testing.assert_allclose(self.fitserver.covariance()[0], 43 | np.array([0.04761905])) 44 | 45 | def test_functional(self): 46 | """Test functional method.""" 47 | f = functionals.compiled('p6+p0*exp(-((x-p1)/p2)^2)' + 48 | ' + p3*exp(-((x-p4)/p5)^2)', 49 | [20, 10, 4, 10, 33, 4, 10]) 50 | xg = 0.5 * np.arange(1, 101) - 0.5 51 | yg = np.array(f(xg)) + np.random.normal(0, 0.3, 100) 52 | f.set_parameters([22, 11, 5, 10, 30, 5, 9]) 53 | self.fitserver.clearconstraints() 54 | self.fitserver.functional(f, xg, yg) 55 | print(self.fitserver.solution()) 56 | 57 | def test_complex_fitting(self): 58 | """Testing complex fitting.""" 59 | x = -1 + np.arange(0, 21)*0.1 60 | y = functionals.poly(2, [3.03, 2.06, 0.03])(x) 61 | self.fitserver.linear(functionals.poly(1), x, y) 62 | print('linear', self.fitserver.solution()) 63 | id1 = self.fitserver.fitter() 64 | self.fitserver.set(ftype='complex', fid=id1) 65 | self.fitserver.linear(functionals.poly(1, dtype='complex'), x, y, 66 | fid=id1) 67 | np.testing.assert_allclose(self.fitserver.solution(fid=id1), 68 | np.array([3.041+0.j, 2.060+0.j])) 69 | 70 | def test_constraint(self): 71 | """Test constraint.""" 72 | from casacore import functionals as dfs 73 | yz = np.array([np.zeros(10) + 50 + np.random.normal(0, 1, 10), 74 | np.zeros(10) + 60 + np.random.normal(0, 1, 10), 75 | np.zeros(10) + 70 + np.random.normal(0, 1, 10)] 76 | ).flatten() 77 | xz = np.array([1, 0, 0]*10 + [0, 1, 0]*10 + [0, 0, 1]*10) 78 | f = dfs.compiled('p*x+p1*x1+p2*x2') 79 | self.fitserver.linear(f, xz, yz) 80 | self.fitserver.addconstraint(x=[1, 1, 1], y=180) 81 | self.fitserver.linear(f, xz, yz) 82 | self.assertAlmostEqual(sum(self.fitserver.solution()), 180.0) 83 | self.fitserver.clearconstraints() 84 | 85 | def test_fitspoly(self): 86 | """Test fitspoly.""" 87 | x = np.arange(1, 11) 88 | y = 2. + 0.5*x - 0.1*x**2 89 | self.fitserver.fitspoly(3, x, y) 90 | np.testing.assert_allclose(self.fitserver.solution(), 91 | np.array([2.00000000e+00, 92 | 5.00000000e-01, 93 | -1.00000000e-01, 94 | -4.70734562e-14])) 95 | 96 | def test_fitavg(self): 97 | """Test fitavg.""" 98 | x = np.arange(1, 11) 99 | y = 2. + 0.5*x - 0.1*x**2 100 | self.fitserver.fitavg(y) 101 | np.testing.assert_allclose(self.fitserver.solution(), 102 | np.array([0.9])) 103 | 104 | def test_done(self): 105 | """Test done method.""" 106 | fit = fitting.fitserver() 107 | x = np.arange(1, 11) 108 | y = 1. + 2*x - x**2 109 | fit.fitpoly(3, x, y) 110 | np.testing.assert_allclose(fit.solution()[0], 1) 111 | fit.done() 112 | with self.assertRaises(ValueError): 113 | fit.solution() 114 | -------------------------------------------------------------------------------- /tests/test_measures.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from casacore import measures 3 | 4 | class TestMeasures(unittest.TestCase): 5 | def test_epoch(self): 6 | dm = measures.measures() 7 | epoch = dm.epoch(rf='utc', v0='2009-09-09T09:09') 8 | epoch_d = dm.get_value(epoch) 9 | -------------------------------------------------------------------------------- /tests/test_quanta.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from casacore.quanta import * 3 | 4 | 5 | class TestQuanta(unittest.TestCase): 6 | def test_quanta(self): 7 | q0 = quantity('1deg') 8 | self.assertTrue(is_quantity(q0)) 9 | q1 = quantity(1.0, 'deg') 10 | self.assertTrue(is_quantity(q1)) 11 | self.assertEqual(q1, q0) 12 | 13 | q2 = quantity([180.0, 0.0], 'deg') 14 | self.assertTrue(is_quantity(q2)) 15 | self.assertNotEqual(q1, q2) 16 | self.assertEqual(str(q0+q1), '2 deg') 17 | self.assertEqual(str(q0-q1), '0 deg') 18 | self.assertEqual(str(q0*q1), '1 deg.deg') 19 | self.assertEqual(str(q0/q1), '1 deg/(deg)') 20 | self.assertEqual(str(q0+1), '2 deg') 21 | self.assertEqual(str(q2+[1, 1]), '[181, 1] deg') 22 | print(sin(q0)) 23 | print(sin(q2)) 24 | self.assertEqual(str(q0.get()), '0.017453 rad') 25 | self.assertEqual(str(q0.get('h')), '0.066667 h') 26 | self.assertEqual(str(q0.canonical()), '0.017453 rad') 27 | self.assertEqual(str(q0.get_value()), '1.0') 28 | self.assertEqual(str(q0.get_value('arcsec')), '3600.0') 29 | self.assertEqual(q0.get_unit(), 'deg') 30 | 31 | q3 = quantity('12h10m5s') 32 | print(q3.to_time()) 33 | self.assertEqual(str(q3.to_unix_time()), '-3506672995.0') 34 | print(q3.to_angle()) 35 | self.assertEqual(q3.formatted("ANGLE"), '+182.31.15') 36 | self.assertEqual(q3.to_string("%0.3f"), '182.521 deg') 37 | q4 = quantity({'unit': 'deg', 'value': 182.52083333333334}) 38 | self.assertEqual(q3, q4) 39 | q5 = quantity(q4) 40 | self.assertEqual(q5, q4) 41 | 42 | self.assertIn('Jy', units) 43 | self.assertEqual(units['Jy'], ['jansky', quantity(1e-26, 'kg.s-2')]) 44 | self.assertIn('a', prefixes) 45 | self.assertEqual(prefixes['a'], ['atto', 1e-18]) 46 | 47 | boltzmann = constants['k'] 48 | self.assertEqual(str(boltzmann), '1.3807e-23 J/K') 49 | -------------------------------------------------------------------------------- /tests/test_unicode.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | import numpy as np 3 | import unittest 4 | from casacore.tables import table, maketabdesc, makescacoldesc 5 | from tempfile import mkdtemp 6 | from shutil import rmtree 7 | from os.path import join 8 | 9 | unicode_string = u'«ταБЬℓσ»' 10 | 11 | 12 | class TestUnicode(unittest.TestCase): 13 | @classmethod 14 | def setUpClass(cls): 15 | cls.workdir = mkdtemp() 16 | 17 | @classmethod 18 | def tearDownClass(cls): 19 | rmtree(cls.workdir) 20 | 21 | def test_table_unicode(self): 22 | t = table(join(self.workdir, unicode_string), maketabdesc(), ack=False) 23 | 24 | def test_getcol(self): 25 | c1 = makescacoldesc(unicode_string, 0) 26 | t = table(join(self.workdir, 'ascii'), maketabdesc([c1]), ack=False) 27 | t.getcol(unicode_string) 28 | 29 | def test_numpy_unicode(self): 30 | table_path = join(self.workdir, 'blah.ms') 31 | col1 = makescacoldesc('mycol1', 'test', valuetype='string') 32 | col2 = makescacoldesc('mycol2', 'test', valuetype='string') 33 | t = table(table_path, maketabdesc([col1, col2]), ack=False) 34 | t.addrows(2) 35 | t.putcol('mycol1', np.array([unicode_string, unicode_string])) 36 | t.putcol('mycol2', [unicode_string, unicode_string]) 37 | t.close() 38 | 39 | t = table(table_path) 40 | self.assertEqual(t.getcol('mycol1'), t.getcol('mycol2')) 41 | -------------------------------------------------------------------------------- /tests/test_util.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from pyrap.util import substitute 3 | 4 | 5 | def f1(arg): 6 | a = 3 7 | s = substitute('subs as $a $arg', locals=locals()) 8 | print(a, arg, s) 9 | 10 | 11 | class TestUtil(unittest.TestCase): 12 | def test_util(self): 13 | a = 1 14 | b = 2 15 | p = "$((a+b)*(a+b))" 16 | s = substitute(p, locals=locals()) 17 | print("a=%d, b=%d, %s => %s" % (a, b, p, s)) 18 | f1(23) 19 | f1('xyz') 20 | 21 | def test_substitute(self): 22 | a = 2 23 | b = 3 24 | c = "xyz" 25 | d1 = True 26 | s1 = (1, 2, 3) 27 | s2 = ['ab', 'cde', 'f', 'ghij'] 28 | 29 | self.assertTrue(substitute('$a $b $c $d1') == '2 3 "xyz" T') 30 | self.assertTrue(substitute('$(a) $(b) $(c) $(d1)') == '2 3 "xyz" T') 31 | self.assertTrue(substitute('$b $0 $a "$a" $b') == '3 $0 2 "$a" 3') 32 | self.assertTrue(substitute('$(a+b)') == '5') 33 | self.assertTrue(substitute('$((a+b)*(a+b))') == '25') 34 | self.assertTrue(substitute('$((a+b)*(a+c))') == '$((a+b)*(a+c))') 35 | self.assertTrue(substitute('"$(a+b)"') == '"$(a+b)"') 36 | self.assertTrue(substitute('\\$(a+b) \\\\$a \\$a') == 37 | '\\$(a+b) \\\\2 \\$a') 38 | 39 | self.assertTrue(substitute('$(a+b)+$a') == '5+2') 40 | self.assertTrue(substitute('$((a+b)+a)') == '7') 41 | self.assertTrue(substitute('$((a+b)*(a+b))') == '25') 42 | self.assertTrue(substitute('$(len("ab cd( de"))') == '9') 43 | self.assertTrue(substitute( 44 | ' $s1 $s2 ') == ' [1,2,3] ["ab","cde","f","ghij"] ') 45 | -------------------------------------------------------------------------------- /tests/timage.py.out: -------------------------------------------------------------------------------- 1 | 2 [4, 3] 12 12 False float Temporary_Image 2 | [[ 1. 2. 3.] 3 | [ 4. 5. 6.] 4 | [ 7. 8. 9.] 5 | [ 10. 11. 12.]] 6 | [[ 1. 2.] 7 | [ 4. 5.] 8 | [ 7. 8.]] 9 | [[ 1. 2. 3.] 10 | [ 7. 8. 9.]] 11 | [[ 2. 4. 6.] 12 | [ 8. 10. 12.] 13 | [ 14. 16. 18.] 14 | [ 20. 22. 24.]] 15 | [[ 1. 2. 3.] 16 | [ 7. 8. 9.]] 17 | [[ 2. 3. 4.] 18 | [ 4. 5. 6.] 19 | [ 8. 9. 10.] 20 | [ 10. 11. 12.]] 21 | [[False False False] 22 | [False False False] 23 | [False False False] 24 | [False False False]] 25 | [4, 6] 26 | [[ 2. 3. 4. 4. 6. 8.] 27 | [ 4. 5. 6. 8. 10. 12.] 28 | [ 8. 9. 10. 16. 18. 20.] 29 | [ 10. 11. 12. 20. 22. 24.]] 30 | [[ 2. 3. 4. 4. 6. 8.] 31 | [ 4. 5. 6. 8. 10. 12.] 32 | [ 8. 9. 10. 16. 18. 20.] 33 | [ 10. 11. 12. 20. 22. 24.]] 34 | [[ 2. 3. 4. 4. 6. 8.] 35 | [ 4. 5. 6. 8. 10. 12.] 36 | [ 8. 9. 10. 16. 18. 20.] 37 | [ 10. 11. 12. 20. 22. 24.]] 38 | [[ True True False False False False] 39 | [False False False False False False] 40 | [False False False False False False] 41 | [False False False False False False]] 42 | [[ True True False False False False] 43 | [False False False False False False] 44 | [False False False False False False] 45 | [False False False False False False]] 46 | [[ 12. 13. 14. 14. 16. 18.] 47 | [ 14. 15. 16. 18. 20. 22.] 48 | [ 18. 19. 20. 26. 28. 30.] 49 | [ 20. 21. 22. 30. 32. 34.]] 50 | {'rms': array([ 22.0608654]), 'medabsdevmed': array([ 4.]), 'minpos': array([2, 0], dtype=int32), 'min': array([ 14.]), 'max': array([ 34.]), 'sum': array([ 467.]), 'quartile': array([ 6.]), 'sumsq': array([ 10707.]), 'median': array([ 20.]), 'npts': array([ 22.]), 'maxpos': array([5, 3], dtype=int32), 'sigma': array([ 6.14841689]), 'mean': array([ 21.22727273])} 51 | [[ NaN NaN 14. 14. 16. 18.] 52 | [ 14. 15. 16. 18. 20. 22.] 53 | [ 18. 19. 20. 26. 28. 30.] 54 | [ 20. 21. 22. 30. 32. 34.]] 55 | -------------------------------------------------------------------------------- /tests/tquanta.py.out: -------------------------------------------------------------------------------- 1 | True 2 | True 3 | True 4 | True 5 | True 6 | 2.00000 deg 7 | 0.00000 deg 8 | 1.00000 deg.deg 9 | 1.00000 deg/(deg) 10 | 2.00000 deg 11 | [181.00000, 1.00000] deg 12 | 0.01745 13 | [0.00000, 0.00000] 14 | 0.01745 rad 15 | 0.06667 h 16 | 0.01745 rad 17 | 1.0 18 | 3600.0 19 | deg 20 | 0.50700 d 21 | -3506672995.0 22 | 182.52083 deg 23 | +182.31.15 24 | 182.521 deg 25 | -------------------------------------------------------------------------------- /tests/ttable.py.out: -------------------------------------------------------------------------------- 1 | 0 2 | ['cols', 'colc', 'coli', 'cold', 'colb', 'colarr'] 3 | {} 4 | {'readme': '', 'subType': '', 'type': ''} 5 | {'readme': 'test table run\n', 'subType': '', 'type': 'test'} 6 | 2 7 | 0 8 | ['coli', 'cold'] 9 | [ 5. 4.] 10 | ['cols', 'colc', 'coli', 'cold', 'colb', 'colarr', 'coli2'] 11 | {'*1': {'SEQNR': 0, 'TYPE': 'StandardStMan', 'NAME': 'StandardStMan', 'COLUMNS': ['colarr', 'colarrssm', 'colb', 'colc', 'cold', 'coli', 'cols'], 'SPEC': {'ActualCacheSize': 2, 'PERSCACHESIZE': 2, 'IndexLength': 0, 'BUCKETSIZE': 1540}}, '*2': {'SEQNR': 1, 'TYPE': 'IncrementalStMan', 'NAME': 'ism1', 'COLUMNS': ['coli2'], 'SPEC': {'ActualCacheSize': 1, 'PERSCACHESIZE': 1, 'BUCKETSIZE': 32768}}, '*3': {'SEQNR': 2, 'TYPE': 'TiledShapeStMan', 'NAME': 'tsm1', 'COLUMNS': ['colarrtsm'], 'SPEC': {'DEFAULTTILESHAPE': array([], dtype=int32), 'HYPERCUBES': {}, 'MAXIMUMCACHESIZE': 0, 'SEQNR': 2, 'ActualMaxCacheSize': 0, 'IndexSize': 0}}} 12 | {'comment': '', 'dataManagerType': 'TiledShapeStMan', '_c_order': True, 'option': 0, 'valueType': 'dcomplex', 'maxlen': 0, 'dataManagerGroup': 'tsm1', 'ndim': 2} 13 | {'TYPE': 'TiledShapeStMan', 'SEQNR': 3, 'NAME': 'tsm2', 'SPEC': {'DEFAULTTILESHAPE': array([], dtype=int32), 'HYPERCUBES': {}, 'MAXIMUMCACHESIZE': 0, 'SEQNR': 3, 'ActualMaxCacheSize': 0, 'IndexSize': 0}} 14 | [[[ 1.+0.j 2.+0.j 3.+0.j] 15 | [ 4.+0.j 5.+0.j 6.+0.j]] 16 | 17 | [[ 11.+0.j 12.+0.j 13.+0.j] 18 | [ 14.+0.j 15.+0.j 16.+0.j]]] 19 | [[ 5.+0.j 6.+0.j]] 20 | {'key1': 'keyval', 'keyrec': {'skey1': 1, 'skey2': 3.0}} 21 | keyval 22 | ['key1', 'keyrec'] 23 | ['key1', 'keyrec'] 24 | ['skey1', 'skey2'] 25 | {} 26 | ['coli', 'cold', 'colarrtsm'] 27 | {'colarrtsm': array([[ 1.+0.j, 2.+0.j, 3.+0.j], 28 | [ 4.+0.j, 5.+0.j, 6.+0.j]]), 'cold': 4.0, 'coli': 1} 29 | {'cold': 14.0, 'colarr': array([[ 1.+0.j, 2.+0.j, 3.+0.j], 30 | [ 4.+0.j, 5.+0.j, 6.+0.j]]), 'coli': 10} 31 | [100000.] 32 | [11 3] 33 | [1 1] [2, 3] 34 | [2 2 2] [1, 4, 5] 35 | [3 3] [6, 7] 36 | [4 4] [8, 9] 37 | [5 5] [10, 11] 38 | [6 6] [12, 13] 39 | [7 7] [14, 15] 40 | [8 8] [16, 17] 41 | [9 9] [18, 19] 42 | [10 10 10] [0, 20, 21] 43 | [9, 8, 7, 6, 5, 4, 23] 44 | [10, 2, 1, 1, 2, 2, 23, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10] 45 | False ['coli'] 46 | [6] 47 | [] 48 | [1, 4, 5] 49 | [1, 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15] 50 | [7, 8, 9, 10, 11, 12, 13] 51 | [1, 4, 5, 7, 8, 9, 10, 11, 12, 13] 52 | -------------------------------------------------------------------------------- /tests/tutil.py.out: -------------------------------------------------------------------------------- 1 | a=1, b=2, $((a+b)*(a+b)) => 9 2 | 3 23 subs as 3 23 3 | 3 xyz subs as 3 "xyz" 4 | --------------------------------------------------------------------------------