diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..869c286 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,28 @@ +# .coveragerc to control coverage.py +[run] +branch = True +source = RIMEz +# omit = bad_file.py + +[paths] +source = + src/ + */site-packages/ + +[report] +# Regexes for lines to exclude from consideration +exclude_lines = + # Have to re-enable the standard pragma + pragma: no cover + + # Don't complain about missing debug-only code: + def __repr__ + if self\.debug + + # Don't complain if tests don't hit defensive assertion code: + raise AssertionError + raise NotImplementedError + + # Don't complain if non-runnable code isn't run: + if 0: + if __name__ == .__main__.: diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..2a8129f --- /dev/null +++ b/.flake8 @@ -0,0 +1,5 @@ +[flake8] +ignore = E203, E266, E501, W503, F403, F401 +max-line-length = 88 +max-complexity = 18 +select = B,C,E,F,W,T4,B9 diff --git a/.gitignore b/.gitignore index b4b502d..0740992 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,51 @@ -*.pyc +# Temporary and binary files +*~ +*.py[cod] +*.so +*.cfg +!.isort.cfg +!setup.cfg +*.orig +*.log +*.pot +__pycache__/* +.cache/* +.*.swp +*/.ipynb_checkpoints/* +.DS_Store + +# Project files +.ropeproject +.project +.pydevproject +.settings +.idea +tags + +# Package files +*.egg +*.eggs/ +.installed.cfg *.egg-info -pip-wheel-metadata -.eggs/ \ No newline at end of file +pip-wheel-metadata/ + +# Unittest and coverage +htmlcov/* +.coverage +.tox +junit.xml +coverage.xml +.pytest_cache/ + +# Build and docs folder/files +build/* +dist/* +sdist/* +docs/api/* +docs/_rst/* +docs/_build/* +cover/* +MANIFEST + +# Per-project virtualenvs +.venv*/ diff --git a/.isort.cfg b/.isort.cfg new file mode 100644 index 0000000..cd42a6b --- /dev/null +++ b/.isort.cfg @@ -0,0 +1,10 @@ +[settings] +line_length=88 +indent=' ' +skip=.tox,.venv,build,dist +known_standard_library=setuptools,pkg_resources +known_test=pytest +known_first_party=RIMEz +sections=FUTURE,STDLIB,COMPAT,TEST,THIRDPARTY,FIRSTPARTY,LOCALFOLDER +default_section=THIRDPARTY +multi_line_output=3 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 087d0de..98689fa 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,42 @@ +exclude: '^docs/conf.py' + repos: -- repo: https://github.com/ambv/black - rev: stable - hooks: - - id: black +- repo: git://github.com/pre-commit/pre-commit-hooks + rev: v2.2.3 + hooks: + - id: trailing-whitespace + - id: check-added-large-files + - id: check-ast + - id: check-json + - id: check-merge-conflict + - id: check-xml + - id: check-yaml + - id: debug-statements + - id: end-of-file-fixer + - id: requirements-txt-fixer + - id: mixed-line-ending + args: ['--fix=no'] + - id: flake8 + additional_dependencies: + - flake8-quotes + - flake8-comprehensions + - flake8-black + - flake8-builtins + - flake8-eradicate + - pep8-naming + - flake8-isort + - flake8-pytest + - flake8-docstrings + - flake8-rst-docstrings + - flake8-rst + - darglint + - flake8-copyright + - flake8-ownership +- repo: https://github.com/pre-commit/mirrors-isort + rev: v4.3.4 + hooks: + - id: isort +- repo: https://github.com/ambv/black + rev: stable + hooks: + - id: black diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..597b5b7 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,39 @@ +# Travis configuration file using the build matrix feature +# Read more under http://docs.travis-ci.com/user/build-configuration/ +# THIS SCRIPT IS SUPPOSED TO BE AN EXAMPLE. MODIFY IT ACCORDING TO YOUR NEEDS! + +sudo: false +language: python +virtualenv: + system_site_packages: false +matrix: + fast_finish: true + include: + - python: 3.6 + env: DISTRIB="ubuntu" TOX_PYTHON_VERSION="py36" COVERAGE="true" + - env: DISTRIB="conda" PYTHON_VERSION="3.6" COVERAGE="false" +install: + - source tests/travis_install.sh + - pip install -r requirements.txt + # ^ DEPRECATION WARNING: + # The automatic creation of a `requirements.txt` file is deprecated. + # See `Dependency Management` in the docs for other options. +before_script: + - git config --global user.email "you@example.com" + - git config --global user.name "Your Name" +script: + - python setup.py develop + - tox + - | + if [[ "$COVERAGE" == "true" ]]; then + pre-commit install + pre-commit run --all-files + fi +after_success: + - if [[ "$COVERAGE" == "true" ]]; then coveralls || echo "failed"; fi +after_script: + - travis-cleanup +cache: + pip: true + directories: + - $HOME/miniconda diff --git a/AUTHORS.rst b/AUTHORS.rst new file mode 100644 index 0000000..a3264d2 --- /dev/null +++ b/AUTHORS.rst @@ -0,0 +1,7 @@ +============ +Contributors +============ + +* Zachary Martinot +* Paul La Plante +* Steven Murray diff --git a/CHANGELOG.rst b/CHANGELOG.rst new file mode 100644 index 0000000..8efe5aa --- /dev/null +++ b/CHANGELOG.rst @@ -0,0 +1,15 @@ +========= +Changelog +========= + +Unreleased +========== + +Added +~~~~~ +* Multiple package tooling updates. + + +Version 0.1.1 +============= +Easily installable version. diff --git a/README.rst b/README.rst index 55ffdf1..79be7c4 100644 --- a/README.rst +++ b/README.rst @@ -48,7 +48,6 @@ using the environment variable ``FFTW_PATH``, which should be the path to the $ FFTW_PATH=/usr/lib pip install . - User Install ------------ If you just want to install ``RIMEz`` for general use, install with:: @@ -60,4 +59,42 @@ Developer Install If you are developing ``RIMEz``, clone the repo, install the dependencies as above, and then do (in the repo):: - $ pip install -e .[dev] + $ pip install -e ".[all,dev]" + + +Optional Extras +--------------- +There are a number of optional extras that can be installed along with ``RIMEz``, +including ``gsm`` (which permits using the GSM as a sky model). To use all (user-focused) +optional extras, install with ``pip install ".[all]"``, otherwise you can pick and +choose by using a comma-separated list in the square brackets. + +There are also a number of development-related groups of optional extras. If you are +developing, we recommend using *all* of them by installing the ``dev`` extra +(as specified above). + +Development +=========== +To install ``RIMEz`` for development, see above. +We *strongly* recommend installing the provided pre-commit hooks the first time you +clone the repo:: + + $ pre-commit install + +This will allow linting checks (and auto-fixes!) to be performed automatically +whenever you commit. + +Testing +------- +To run tests locally, use ``tox``. This is preferred over using ``pytest`` directly +because it also tests the package installation and setup. You can run a single +tox environment by using ``tox -e ENVNAME``. In particular, to run the linting +checks, use ``tox -e lint`` (however, these exact checks will be run when you commit, +if you have installed the pre-commit hooks, as above). + +Versioning +---------- +We use ``setuptools_scm`` for versioning the code. To create a new version, we recommend +creating a new dedicated branch to bump the version. On this branch, update the +``CHANGELOG.rst``, and make a commit with an associated git tag with the format +``vMAJOR.MINOR.PATCH``. Once merged into master, the new version will be active. diff --git a/RIMEz/__init__.py b/RIMEz/__init__.py deleted file mode 100644 index 09fffc9..0000000 --- a/RIMEz/__init__.py +++ /dev/null @@ -1,17 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright (c) 2019 UPennEoR -# Licensed under the MIT License - -from . import management -from . import rime_funcs -from . import sky_models -from . import beam_models -from . import utils - -from pkg_resources import get_distribution, DistributionNotFound - -try: - __version__ = get_distribution(__name__).version -except DistributionNotFound: - # package is not installed - pass diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000..63c77be --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,193 @@ +# Makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +PAPER = +BUILDDIR = ../build/sphinx/ +AUTODOCDIR = api +AUTODOCBUILD = sphinx-apidoc +PROJECT = RIMEz +MODULEDIR = ../src/RIMEz + +# User-friendly check for sphinx-build +ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $?), 1) +$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) +endif + +# Internal variables. +PAPEROPT_a4 = -D latex_paper_size=a4 +PAPEROPT_letter = -D latex_paper_size=letter +ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . +# the i18n builder cannot share the environment and doctrees with the others +I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . + +.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext doc-requirements + +help: + @echo "Please use \`make ' where is one of" + @echo " html to make standalone HTML files" + @echo " dirhtml to make HTML files named index.html in directories" + @echo " singlehtml to make a single large HTML file" + @echo " pickle to make pickle files" + @echo " json to make JSON files" + @echo " htmlhelp to make HTML files and a HTML help project" + @echo " qthelp to make HTML files and a qthelp project" + @echo " devhelp to make HTML files and a Devhelp project" + @echo " epub to make an epub" + @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" + @echo " latexpdf to make LaTeX files and run them through pdflatex" + @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" + @echo " text to make text files" + @echo " man to make manual pages" + @echo " texinfo to make Texinfo files" + @echo " info to make Texinfo files and run them through makeinfo" + @echo " gettext to make PO message catalogs" + @echo " changes to make an overview of all changed/added/deprecated items" + @echo " xml to make Docutils-native XML files" + @echo " pseudoxml to make pseudoxml-XML files for display purposes" + @echo " linkcheck to check all external links for integrity" + @echo " doctest to run all doctests embedded in the documentation (if enabled)" + +clean: + rm -rf $(BUILDDIR)/* $(AUTODOCDIR) + +$(AUTODOCDIR): $(MODULEDIR) + mkdir -p $@ + $(AUTODOCBUILD) -f -o $@ $^ + +doc-requirements: $(AUTODOCDIR) + +html: doc-requirements + $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." + +dirhtml: doc-requirements + $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." + +singlehtml: doc-requirements + $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml + @echo + @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." + +pickle: doc-requirements + $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle + @echo + @echo "Build finished; now you can process the pickle files." + +json: doc-requirements + $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json + @echo + @echo "Build finished; now you can process the JSON files." + +htmlhelp: doc-requirements + $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp + @echo + @echo "Build finished; now you can run HTML Help Workshop with the" \ + ".hhp project file in $(BUILDDIR)/htmlhelp." + +qthelp: doc-requirements + $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp + @echo + @echo "Build finished; now you can run "qcollectiongenerator" with the" \ + ".qhcp project file in $(BUILDDIR)/qthelp, like this:" + @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/$(PROJECT).qhcp" + @echo "To view the help file:" + @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/$(PROJECT).qhc" + +devhelp: doc-requirements + $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp + @echo + @echo "Build finished." + @echo "To view the help file:" + @echo "# mkdir -p $HOME/.local/share/devhelp/$(PROJECT)" + @echo "# ln -s $(BUILDDIR)/devhelp $HOME/.local/share/devhelp/$(PROJEC)" + @echo "# devhelp" + +epub: doc-requirements + $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub + @echo + @echo "Build finished. The epub file is in $(BUILDDIR)/epub." + +patch-latex: + find _build/latex -iname "*.tex" | xargs -- \ + sed -i'' 's~includegraphics{~includegraphics\[keepaspectratio,max size={\\textwidth}{\\textheight}\]{~g' + +latex: doc-requirements + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + $(MAKE) patch-latex + @echo + @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." + @echo "Run \`make' in that directory to run these through (pdf)latex" \ + "(use \`make latexpdf' here to do that automatically)." + +latexpdf: doc-requirements + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + $(MAKE) patch-latex + @echo "Running LaTeX files through pdflatex..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +latexpdfja: doc-requirements + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through platex and dvipdfmx..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +text: doc-requirements + $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text + @echo + @echo "Build finished. The text files are in $(BUILDDIR)/text." + +man: doc-requirements + $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man + @echo + @echo "Build finished. The manual pages are in $(BUILDDIR)/man." + +texinfo: doc-requirements + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo + @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." + @echo "Run \`make' in that directory to run these through makeinfo" \ + "(use \`make info' here to do that automatically)." + +info: doc-requirements + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo "Running Texinfo files through makeinfo..." + make -C $(BUILDDIR)/texinfo info + @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." + +gettext: doc-requirements + $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale + @echo + @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." + +changes: doc-requirements + $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes + @echo + @echo "The overview file is in $(BUILDDIR)/changes." + +linkcheck: doc-requirements + $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck + @echo + @echo "Link check complete; look for any errors in the above output " \ + "or in $(BUILDDIR)/linkcheck/output.txt." + +doctest: doc-requirements + $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest + @echo "Testing of doctests in the sources finished, look at the " \ + "results in $(BUILDDIR)/doctest/output.txt." + +xml: doc-requirements + $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml + @echo + @echo "Build finished. The XML files are in $(BUILDDIR)/xml." + +pseudoxml: doc-requirements + $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml + @echo + @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." diff --git a/docs/_static/.gitignore b/docs/_static/.gitignore new file mode 100644 index 0000000..3c96363 --- /dev/null +++ b/docs/_static/.gitignore @@ -0,0 +1 @@ +# Empty directory diff --git a/docs/authors.rst b/docs/authors.rst new file mode 100644 index 0000000..cd8e091 --- /dev/null +++ b/docs/authors.rst @@ -0,0 +1,2 @@ +.. _authors: +.. include:: ../AUTHORS.rst diff --git a/docs/changelog.rst b/docs/changelog.rst new file mode 100644 index 0000000..871950d --- /dev/null +++ b/docs/changelog.rst @@ -0,0 +1,2 @@ +.. _changes: +.. include:: ../CHANGELOG.rst diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 0000000..d7a8bbb --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,275 @@ +# -*- coding: utf-8 -*- +# +# This file is execfile()d with the current directory set to its containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +import os +import sys +import inspect +import shutil + +__location__ = os.path.join( + os.getcwd(), os.path.dirname(inspect.getfile(inspect.currentframe())) +) + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +sys.path.insert(0, os.path.join(__location__, "../src")) + +# -- Run sphinx-apidoc ------------------------------------------------------ +# This hack is necessary since RTD does not issue `sphinx-apidoc` before running +# `sphinx-build -b html . _build/html`. See Issue: +# https://github.com/rtfd/readthedocs.org/issues/1139 +# DON'T FORGET: Check the box "Install your project inside a virtualenv using +# setup.py install" in the RTD Advanced Settings. +# Additionally it helps us to avoid running apidoc manually + +try: # for Sphinx >= 1.7 + from sphinx.ext import apidoc +except ImportError: + from sphinx import apidoc + +output_dir = os.path.join(__location__, "api") +module_dir = os.path.join(__location__, "../src/RIMEz") +try: + shutil.rmtree(output_dir) +except FileNotFoundError: + pass + +try: + import sphinx + from pkg_resources import parse_version + + cmd_line_template = "sphinx-apidoc -f -o {outputdir} {moduledir}" + cmd_line = cmd_line_template.format(outputdir=output_dir, moduledir=module_dir) + + args = cmd_line.split(" ") + if parse_version(sphinx.__version__) >= parse_version("1.7"): + args = args[1:] + + apidoc.main(args) +except Exception as e: + print("Running `sphinx-apidoc` failed!\n{}".format(e)) + +# -- General configuration ----------------------------------------------------- + +# If your documentation needs a minimal Sphinx version, state it here. +# needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be extensions +# coming with Sphinx (named 'sphinx.ext.*') or your custom ones. +extensions = [ + "sphinx.ext.autodoc", + "sphinx.ext.intersphinx", + "sphinx.ext.todo", + "sphinx.ext.autosummary", + "sphinx.ext.viewcode", + "sphinx.ext.coverage", + "sphinx.ext.doctest", + "sphinx.ext.ifconfig", + "sphinx.ext.mathjax", + "sphinx.ext.napoleon", +] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ["_templates"] + +# The suffix of source filenames. +source_suffix = ".rst" + +# The encoding of source files. +# source_encoding = 'utf-8-sig' + +# The master toctree document. +master_doc = "index" + +# General information about the project. +project = u"RIMEz" +copyright = u"2019, Steven Murray" + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The short X.Y version. +version = "" # Is set by calling `setup.py docs` +# The full version, including alpha/beta/rc tags. +release = "" # Is set by calling `setup.py docs` + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +# language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +# today = '' +# Else, today_fmt is used as the format for a strftime call. +# today_fmt = '%B %d, %Y' + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +exclude_patterns = ["_build"] + +# The reST default role (used for this markup: `text`) to use for all documents. +# default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +# add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +# add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +# show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = "sphinx" + +# A list of ignored prefixes for module index sorting. +# modindex_common_prefix = [] + +# If true, keep warnings as "system message" paragraphs in the built documents. +# keep_warnings = False + + +# -- Options for HTML output --------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +html_theme = "alabaster" + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +html_theme_options = {"sidebar_width": "300px", "page_width": "1200px"} + +# Add any paths that contain custom themes here, relative to this directory. +# html_theme_path = [] + +# The name for this set of Sphinx documents. If None, it defaults to +# " v documentation". +try: + from RIMEz import __version__ as version +except ImportError: + pass +else: + release = version + +# A shorter title for the navigation bar. Default is the same as html_title. +# html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +# html_logo = "" + +# The name of an image file (within the static path) to use as favicon of the +# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +# html_favicon = None + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ["_static"] + +# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, +# using the given strftime format. +# html_last_updated_fmt = '%b %d, %Y' + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +# html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +# html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +# html_additional_pages = {} + +# If false, no module index is generated. +# html_domain_indices = True + +# If false, no index is generated. +# html_use_index = True + +# If true, the index is split into individual pages for each letter. +# html_split_index = False + +# If true, links to the reST sources are added to the pages. +# html_show_sourcelink = True + +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. +# html_show_sphinx = True + +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. +# html_show_copyright = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +# html_use_opensearch = '' + +# This is the file name suffix for HTML files (e.g. ".xhtml"). +# html_file_suffix = None + +# Output file base name for HTML help builder. +htmlhelp_basename = "RIMEz-doc" + + +# -- Options for LaTeX output -------------------------------------------------- + +latex_elements = { + # The paper size ('letterpaper' or 'a4paper'). + # 'papersize': 'letterpaper', + # The font size ('10pt', '11pt' or '12pt'). + # 'pointsize': '10pt', + # Additional stuff for the LaTeX preamble. + # 'preamble': '', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, author, documentclass [howto/manual]). +latex_documents = [ + ("index", "user_guide.tex", u"RIMEz Documentation", u"Steven Murray", "manual") +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +# latex_logo = "" + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +# latex_use_parts = False + +# If true, show page references after internal links. +# latex_show_pagerefs = False + +# If true, show URL addresses after external links. +# latex_show_urls = False + +# Documents to append as an appendix to all manuals. +# latex_appendices = [] + +# If false, no module index is generated. +# latex_domain_indices = True + +# -- External mapping ------------------------------------------------------------ +python_version = ".".join(map(str, sys.version_info[0:2])) +intersphinx_mapping = { + "sphinx": ("http://www.sphinx-doc.org/en/stable", None), + "python": ("https://docs.python.org/" + python_version, None), + "matplotlib": ("https://matplotlib.org", None), + "numpy": ("https://docs.scipy.org/doc/numpy", None), + "sklearn": ("http://scikit-learn.org/stable", None), + "pandas": ("http://pandas.pydata.org/pandas-docs/stable", None), + "scipy": ("https://docs.scipy.org/doc/scipy/reference", None), +} diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 0000000..fd6b5e3 --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,59 @@ +===== +RIMEz +===== + +This is the documentation of **RIMEz**. + +.. note:: + + This is the main page of your project's `Sphinx`_ documentation. + It is formatted in `reStructuredText`_. Add additional pages + by creating rst-files in ``docs`` and adding them to the `toctree`_ below. + Use then `references`_ in order to link them from this page, e.g. + :ref:`authors` and :ref:`changes`. + + It is also possible to refer to the documentation of other Python packages + with the `Python domain syntax`_. By default you can reference the + documentation of `Sphinx`_, `Python`_, `NumPy`_, `SciPy`_, `matplotlib`_, + `Pandas`_, `Scikit-Learn`_. You can add more by extending the + ``intersphinx_mapping`` in your Sphinx's ``conf.py``. + + The pretty useful extension `autodoc`_ is activated by default and lets + you include documentation from docstrings. Docstrings can be written in + `Google style`_ (recommended!), `NumPy style`_ and `classical style`_. + + +Contents +======== + +.. toctree:: + :maxdepth: 2 + + License + Authors + Changelog + Module Reference + + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` + +.. _toctree: http://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html +.. _reStructuredText: http://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html +.. _references: http://www.sphinx-doc.org/en/stable/markup/inline.html +.. _Python domain syntax: http://sphinx-doc.org/domains.html#the-python-domain +.. _Sphinx: http://www.sphinx-doc.org/ +.. _Python: http://docs.python.org/ +.. _Numpy: http://docs.scipy.org/doc/numpy +.. _SciPy: http://docs.scipy.org/doc/scipy/reference/ +.. _matplotlib: https://matplotlib.org/contents.html# +.. _Pandas: http://pandas.pydata.org/pandas-docs/stable +.. _Scikit-Learn: http://scikit-learn.org/stable +.. _autodoc: http://www.sphinx-doc.org/en/stable/ext/autodoc.html +.. _Google style: https://github.com/google/styleguide/blob/gh-pages/pyguide.md#38-comments-and-docstrings +.. _NumPy style: https://numpydoc.readthedocs.io/en/latest/format.html +.. _classical style: http://www.sphinx-doc.org/en/stable/domains.html#info-field-lists diff --git a/docs/license.rst b/docs/license.rst new file mode 100644 index 0000000..3989c51 --- /dev/null +++ b/docs/license.rst @@ -0,0 +1,7 @@ +.. _license: + +======= +License +======= + +.. include:: ../LICENSE.txt diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..eb57ef1 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,140 @@ +# This file is used to configure your project. +# Read more about the various options under: +# http://setuptools.readthedocs.io/en/latest/setuptools.html#configuring-setup-using-setup-cfg-files + +[metadata] +name = RIMEz +description = Methods and input models for computing radio-interferometric visibilities +author = Zachary Martinot +author-email = zmarti@sas.upenn.edu +license = mit +long-description = file: README.rst +long-description-content-type = text/x-rst; charset=UTF-8 +url = https://github.com/UPennEoR/RIMEz +project-urls = + Documentation = https://rimez.readthedocs.org +# Change if running only on Windows, Mac or Linux (comma-separated) +platforms = any +# Add here all kinds of additional classifiers as defined under +# https://pypi.python.org/pypi?%3Aaction=list_classifiers +classifiers = + Development Status :: 4 - Beta + Programming Language :: Python + +[options] +zip_safe = False +packages = find: +include_package_data = True +package_dir = + =src +# DON'T CHANGE THE FOLLOWING LINE! IT WILL BE UPDATED BY PYSCAFFOLD! +setup_requires = pyscaffold>=3.2a0,<3.3a0 +# Add here dependencies of your project (semicolon/line-separated), e.g. +install_requires = + numpy + numba + cffi + astropy + h5py + scipy + healpy + pyuvdata + ssht_numba @ git+git://github.com/UPennEoR/ssht_numba + spin1_beam_model @ git+git://github.com/UPennEoR/spin1_beam_model + +# Require a specific Python version, e.g. Python 2.7 or >= 3.4 +python_requires = >=3.5 + +[options.packages.find] +where = src +exclude = + tests + +[options.extras_require] +# Add here bundles of optional dependencies +gsm = + pygsm @ git+git://github.com/telegraphic/PyGSM +# 'all' should be all optional dependencies that are not development-focused +# It seems there's no way to just use other groups, so each dep has to be copied. +all = + pygsm @ git+git://github.com/telegraphic/PyGSM +# Now we focus on dev-focused requirements. We separate it into testing, docs and then +# a catch-all 'dev' +testing = + pytest + pytest-cov + tox +docs = + sphinx +dev = + pytest + pytest-cov + tox + sphinx + +[options.entry_points] +# Add here console scripts like: +# console_scripts = +# script_name = RIMEz.module:function +# For example: +# console_scripts = +# fibonacci = RIMEz.skeleton:run +# And any other entry points, for example: +# pyscaffold.cli = +# awesome = pyscaffoldext.awesome.extension:AwesomeExtension + +[test] +# py.test options when running `python setup.py test` +# addopts = --verbose +extras = True + +[tool:pytest] +# Options for py.test: +# Specify command line options as you would do when invoking py.test directly. +# e.g. --cov-report html (or xml) for html/xml output or --junitxml junit.xml +# in order to write a coverage file that can be read by Jenkins. +addopts = + --cov RIMEz --cov-report term-missing + --verbose +norecursedirs = + dist + build + .tox +testpaths = tests + +[aliases] +dists = bdist_wheel + +[bdist_wheel] +# Use this option if your package is pure-python +universal = 1 + +[build_sphinx] +source_dir = docs +build_dir = build/sphinx + +[devpi:upload] +# Options for the devpi: PyPI server and packaging tool +# VCS export must be deactivated since we are using setuptools-scm +no-vcs = 1 +formats = bdist_wheel + +[flake8] +# Some sane defaults for the code style checker flake8 +exclude = + .tox + build + dist + .eggs + docs/conf.py + +[pyscaffold] +# PyScaffold's parameters when the project was created. +# This will be used when updating. Do not change! +version = 3.2.3 +package = RIMEz +extensions = + no_skeleton + pre_commit + tox + travis diff --git a/setup.py b/setup.py index d36ba32..e831c35 100644 --- a/setup.py +++ b/setup.py @@ -1,33 +1,25 @@ # -*- coding: utf-8 -*- -# Copyright (c) 2019 UPennEoR -# Licensed under the MIT License - +""" + Setup file for RIMEz. + Use setup.cfg to configure your project. + + This file was generated with PyScaffold 3.2.3. + PyScaffold helps you to put up the scaffold of your new Python project. + Learn more under: https://pyscaffold.org/ +""" +import distutils.command.build as _build import os import sys - -from setuptools import setup from distutils import spawn -import distutils.command.build as _build - - -req = [ - "numpy", - "numba", - "cffi", - "astropy", - "h5py", - "scipy", - "healpy", - "pyuvdata", - "ssht_numba @ git+git://github.com/UPennEoR/ssht_numba", - "spin1_beam_model @ git+git://github.com/UPennEoR/spin1_beam_model", -] - -req_gsm = ["pygsm @ git+git://github.com/telegraphic/PyGSM"] +from pkg_resources import VersionConflict, require +from setuptools import setup -req_all = req_gsm +try: + require("setuptools>=38.3") +except VersionConflict: + print("Error: version of setuptools is too old (<38.3)!") + sys.exit(1) -req_dev = ["pytest", "sphinx", "bump2version"] # make sure the fortran library is built before installing class CustomBuild(_build.build): @@ -37,7 +29,7 @@ def run(self): sys.stderr.write("make is required to build this package.\n") sys.exit(-1) _source_dir = os.path.join( - os.path.split(__file__)[0], "RIMEz", "dfitpack_wrappers" + os.path.split(__file__)[0], "src", "RIMEz", "dfitpack_wrappers" ) try: os.chdir(_source_dir) @@ -50,24 +42,9 @@ def run(self): _build.build.run(self) -setup( - name="RIMEz", - description="Methods and input models for computing visibilities.", - url="https://github.com/UPennEOR/RIMEz", - author="Zachary Martinot", - author_email="zmarti@sas.upenn.edu", - packages=["RIMEz"], - package_data={"RIMEz": ["dfitpack_wrappers/dfitpack_wrappers.so"]}, - zip_safe=False, - install_requires=req, - # fmt: off - extras_require={ - "dev": req_dev + req_all, - "gsm": req_gsm, - "all": req_all - }, - # fmt: on - cmdclass={"build": CustomBuild}, - use_scm_version=True, - setup_requires=["setuptools_scm"], -) +if __name__ == "__main__": + setup( + cmdclass={"build": CustomBuild}, + package_data={"RIMEz": ["dfitpack_wrappers/dfitpack_wrappers.so"]}, + use_pyscaffold=True, + ) diff --git a/src/RIMEz/__init__.py b/src/RIMEz/__init__.py new file mode 100644 index 0000000..6702d55 --- /dev/null +++ b/src/RIMEz/__init__.py @@ -0,0 +1,11 @@ +# -*- coding: utf-8 -*- +from pkg_resources import get_distribution, DistributionNotFound + +try: + # Change here if project is renamed and does not equal the package name + dist_name = __name__ + __version__ = get_distribution(dist_name).version +except DistributionNotFound: + __version__ = "unknown" +finally: + del get_distribution, DistributionNotFound diff --git a/RIMEz/beam_models.py b/src/RIMEz/beam_models.py similarity index 98% rename from RIMEz/beam_models.py rename to src/RIMEz/beam_models.py index 59f734d..088e3d4 100644 --- a/RIMEz/beam_models.py +++ b/src/RIMEz/beam_models.py @@ -2,10 +2,10 @@ # Copyright (c) 2019 UPennEoR # Licensed under the MIT License -import numpy as np -import numba as nb import ctypes +import numba as nb +import numpy as np from spin1_beam_model.jones_matrix_field import AntennaFarFieldResponse from .dfitpack_numba import bispeu_nb @@ -115,7 +115,6 @@ def spline_beam_func(nu, alt, az): J_aa = np.zeros(theta.shape + (2, 2), dtype=nb.complex128) u = [-1.0, -1j] # negative for components in alt/az basis - # u = [1., 1j] for kk in range(2): for aa in range(2): @@ -177,7 +176,6 @@ def airy_dipole(nu, alt, az, a): zero_inds = np.where(arg == 0.0)[0] arg[zero_inds] = 1e-20 G = 2.0 * njit_J1(arg) / arg - # G = np.ones_like(arg) # '00' <-> 'East,Alt', '01' <-> 'East,Az', # '10' <-> 'North,Alt', '11' <-> 'North,Az' @@ -221,7 +219,6 @@ def heraish_beam_func(i, nu, alt, az): Umat[:, 0, 0], Umat[:, 0, 1] = cosX, sinX Umat[:, 1, 0], Umat[:, 1, 1] = sinX, -cosX - # J_eq = np.einsum('...ab,...cb->...ac', J_aa, Umat) result = apply_basis_transform(J_aa, Umat) tukeyW = tukey_window(alt, np.radians(2.0)) for n in range(result.shape[0]): diff --git a/RIMEz/dfitpack_numba.py b/src/RIMEz/dfitpack_numba.py similarity index 100% rename from RIMEz/dfitpack_numba.py rename to src/RIMEz/dfitpack_numba.py index 1369933..bfdcbe5 100644 --- a/RIMEz/dfitpack_numba.py +++ b/src/RIMEz/dfitpack_numba.py @@ -4,9 +4,9 @@ import os -import numpy as np -import numba as nb import cffi +import numba as nb +import numpy as np ffi = cffi.FFI() diff --git a/RIMEz/dfitpack_wrappers/.gitignore b/src/RIMEz/dfitpack_wrappers/.gitignore similarity index 100% rename from RIMEz/dfitpack_wrappers/.gitignore rename to src/RIMEz/dfitpack_wrappers/.gitignore diff --git a/RIMEz/dfitpack_wrappers/Makefile b/src/RIMEz/dfitpack_wrappers/Makefile similarity index 100% rename from RIMEz/dfitpack_wrappers/Makefile rename to src/RIMEz/dfitpack_wrappers/Makefile diff --git a/RIMEz/dfitpack_wrappers/bispeu.f b/src/RIMEz/dfitpack_wrappers/bispeu.f similarity index 100% rename from RIMEz/dfitpack_wrappers/bispeu.f rename to src/RIMEz/dfitpack_wrappers/bispeu.f diff --git a/RIMEz/dfitpack_wrappers/dfitpack_wrappers.f90 b/src/RIMEz/dfitpack_wrappers/dfitpack_wrappers.f90 similarity index 90% rename from RIMEz/dfitpack_wrappers/dfitpack_wrappers.f90 rename to src/RIMEz/dfitpack_wrappers/dfitpack_wrappers.f90 index a405867..6a4a467 100644 --- a/RIMEz/dfitpack_wrappers/dfitpack_wrappers.f90 +++ b/src/RIMEz/dfitpack_wrappers/dfitpack_wrappers.f90 @@ -10,7 +10,7 @@ module dfitpack_wrappers subroutine bispeu_wrap(tx,nx,ty,ny,c,kx,ky,x,y,z,m,wrk,lwrk,ier) bind(c) - integer(4), intent(in) :: nx,ny,kx,ky,m,lwrk + integer(4), intent(in) :: nx,ny,kx,ky,m,lwrk real(8), intent(in) :: tx(nx),ty(ny),c((nx-kx-1)*(ny-ky-1)),& x(m),y(m),wrk(lwrk) integer(4), intent(out) :: ier diff --git a/RIMEz/dfitpack_wrappers/fpbisp.f b/src/RIMEz/dfitpack_wrappers/fpbisp.f similarity index 99% rename from RIMEz/dfitpack_wrappers/fpbisp.f rename to src/RIMEz/dfitpack_wrappers/fpbisp.f index 269a318..53b83fd 100644 --- a/RIMEz/dfitpack_wrappers/fpbisp.f +++ b/src/RIMEz/dfitpack_wrappers/fpbisp.f @@ -76,4 +76,3 @@ subroutine fpbisp(tx,nx,ty,ny,c,kx,ky,x,mx,y,my,z,wx,wy,lx,ly) 130 continue return end - diff --git a/RIMEz/dfitpack_wrappers/fpbspl.f b/src/RIMEz/dfitpack_wrappers/fpbspl.f similarity index 94% rename from RIMEz/dfitpack_wrappers/fpbspl.f rename to src/RIMEz/dfitpack_wrappers/fpbspl.f index 6d155f2..7197682 100644 --- a/RIMEz/dfitpack_wrappers/fpbspl.f +++ b/src/RIMEz/dfitpack_wrappers/fpbspl.f @@ -32,9 +32,9 @@ subroutine fpbspl(t,n,k,x,l,h) li = l+i lj = li-j if (t(li).ne.t(lj)) goto 15 - h(i+1) = 0.0d0 + h(i+1) = 0.0d0 goto 20 - 15 f = hh(i)/(t(li)-t(lj)) + 15 f = hh(i)/(t(li)-t(lj)) h(i) = h(i)+f*(t(li)-x) h(i+1) = f*(x-t(lj)) 20 continue diff --git a/RIMEz/management.py b/src/RIMEz/management.py similarity index 91% rename from RIMEz/management.py rename to src/RIMEz/management.py index 789340f..c2e1291 100644 --- a/RIMEz/management.py +++ b/src/RIMEz/management.py @@ -6,15 +6,11 @@ import warnings import h5py - import numpy as np - -from . import utils -from . import rime_funcs -from . import sky_models - -import ssht_numba as sshtn import spin1_beam_model as s1b +import ssht_numba as sshtn + +from . import rime_funcs, sky_models, utils def _get_versions(): @@ -228,35 +224,6 @@ def write_uvdata_time_series( uvd.write_uvh5(uvdata_file_path, clobber=clobber) - # def write_uvdata_time_series(self, - # uvdata_file_path, - # clobber=False, - # instrument='RIMEz calculation', - # telescope_name='probably HERA, but who knows?', - # history='', - # object_name=''): - # - # if getattr(self, 'V', None) is None: - # raise ValueError("No visibility data available for writing.") - # - # uvd = utils.uvdata_from_sim_data( - # self.array_latitude, - # self.array_longitude, - # self.array_height, - # self.time_sample_jds, - # self.frequency_samples_hz, - # self.antenna_positions_meters, - # self.antenna_pairs_used, - # self.V, - # integration_time=self.integration_time, - # instrument=instrument, - # telescope_name=telescope_name, - # history=history, - # object_name=object_name, - # ) - # - # uvd.write_uvh5(uvdata_file_path, clobber=clobber) - class PointSourceSpectraSet(object): """ @@ -297,7 +264,7 @@ def __init__( ): if file_path is None: - if any([x is None for x in [nu_mhz, Iflux, RA, Dec]]): + if any(x is None for x in [nu_mhz, Iflux, RA, Dec]): raise ValueError( "One of the inputs (nu_mhz, Iflux, RA, Dec) has not been provided." ) diff --git a/RIMEz/rime_funcs.py b/src/RIMEz/rime_funcs.py similarity index 88% rename from RIMEz/rime_funcs.py rename to src/RIMEz/rime_funcs.py index 1f537e1..24ca877 100644 --- a/RIMEz/rime_funcs.py +++ b/src/RIMEz/rime_funcs.py @@ -2,10 +2,10 @@ # Copyright (c) 2019 UPennEoR # Licensed under the MIT License -import numpy as np import numba as nb - +import numpy as np import ssht_numba as sshtn +from scipy import interpolate @nb.njit @@ -36,10 +36,9 @@ def fast_approx_radec2altaz(ra, dec, R): p = np.stack((p1, p2, p3), axis=0) + # q has shape (3, ra.size) q = np.dot(R, p) - # q.shape is (3, ra.size) - # alt = np.arcsin(q[2]) alt = np.arctan(q[2] / np.sqrt(q[0] ** 2.0 + q[1] ** 2.0)) az = np.arctan2(q[1], q[0]) @@ -84,9 +83,9 @@ def vec_psv_constructor(beam_funcs, compile_target="parallel"): ) def vec_psv(R_i, nu_axis, r_axis, ant_pairs, ant_ind2beam_func, S, RA, dec, V_i): c = 299792458.0 # meter/second - # S.shape is (Nfreq, Nsrc, 4) - # RA.shape is (Nsrc,) - # dec.shape is (Nsrc,) + # S has shape (Nfreq, Nsrc, 4) + # RA has shape (Nsrc,) + # dec has shape (Nsrc,) Nbl = ant_pairs.shape[0] beam_func_indices = np.unique(ant_ind2beam_func) @@ -95,7 +94,7 @@ def vec_psv(R_i, nu_axis, r_axis, ant_pairs, ant_ind2beam_func, S, RA, dec, V_i) bsigma = make_bool_sigma_tensor() # s is unit vector toward each source at alpha_i, in ENU basis - # s.shape is (Nsrc,3) + # s has shape (Nsrc,3) s, alt, phi = fast_approx_radec2altaz(RA, dec, R_i.T) s[:, 0] = np.sin(phi) * np.cos(alt) @@ -104,35 +103,22 @@ def vec_psv(R_i, nu_axis, r_axis, ant_pairs, ant_ind2beam_func, S, RA, dec, V_i) v_inds = np.where(alt > 0.0)[0] - # theta = np.pi/2. - alt - # - # s[:,0] = np.sin(phi)*np.sin(theta) - # s[:,1] = np.cos(phi)*np.sin(theta) - # s[:,2] = np.cos(theta) - # - # # find which sources are visible above the horizon - # # v_inds = np.where(theta < np.pi)[0] - # v_inds = np.where(theta < np.pi/2.)[0] - if v_inds.size == 0: V_i = np.zeros((nu_axis.shape[0], Nbl, 2, 2), dtype=nb.complex128) else: s_v = s[v_inds] - # theta_v = theta[v_inds] alt_v = alt[v_inds] phi_v = phi[v_inds] S_v = S[:, v_inds, :] tau_g_v = -2 * np.pi / c * np.dot(r_axis, s_v.T) - # tau_g_v = -2*np.pi/c * r_dot_s_func(r_axis, s_v) for j in range(nu_axis.shape[0]): nu_j = nu_axis[j] S_j_v = S_v[j] - # phases = -2*np.pi*nu_j/c * np.dot(r_axis, s_v.T) phases = nu_j * tau_g_v F_arr = np.cos(phases) + 1j * np.sin(phases) @@ -257,9 +243,9 @@ def vec_mmode_unpol_visibilities( for i_c in range(2): for i_d in range(2): if bsigma[i_b, i_c, 0]: - i_rav = ( - i_ph + ra.shape[1] * i_th - ) # equiv to np.ravel_multi_index((i_th, i_ph), (Lb, 2*Lb-1), order='C') + # equiv to np.ravel_multi_index((i_th, i_ph), (Lb, + # 2*Lb-1), order='C') + i_rav = i_ph + ra.shape[1] * i_th A_p_ab = ( F_arr[p, i_rav] @@ -355,23 +341,10 @@ def mmode_unpol_visibilities( alt_v = alt[v_inds] az_v = az[v_inds] - # theta = np.pi/2. - alt - - # s[:,0] = np.sin(phi)*np.sin(theta) - # s[:,1] = np.cos(phi)*np.sin(theta) - # s[:,2] = np.cos(theta) - - # v_inds = np.where(theta < np.pi/2.) - - # theta_v = theta[v_inds] - # phi_v = phi[v_inds] - for i in range(nu_axis.size): nu_i = nu_axis[i] Slm_i = Slm[i] - # s_dot_r.shape == (r_axis.shape[0],) + ra.shape - # s_dot_r = np.reshape(np.dot(r_axis, s.T), (r_axis.shape[0],) + ra.shape) s_dot_r = np.dot(r_axis, s.T) phases = -2 * np.pi * nu_i / c * s_dot_r @@ -399,9 +372,9 @@ def mmode_unpol_visibilities( for i_c in range(2): for i_d in range(2): if bsigma[i_b, i_c, 0]: - i_rav = ( - i_ph + ra.shape[1] * i_th - ) # equiv to np.ravel_multi_index((i_th, i_ph), (Lb, 2*Lb-1), order='C') + # equiv to np.ravel_multi_index((i_th, i_ph), (Lb, + # 2*Lb-1), order='C') + i_rav = i_ph + ra.shape[1] * i_th A_p_ab = ( F_arr[p, i_rav] @@ -466,14 +439,12 @@ def visiblity_dft_from_mmodes(era_axis, Vm): m_axis = np.arange(-Lm + 1, Lm) for i in range(era_axis.size): - # f_kernel = np.exp(-1j*m_axis*(era_axis[i])) phases = m_axis * era_axis[i] f_kernel = np.cos(phases) - 1j * np.sin(phases) for j in range(Vm.shape[0]): for k in range(Vm.shape[1]): for a in range(2): for b in range(2): - # V_dft[i,j,k,a,b] = np.sum(Vm[j,k,:,a,b] * f_kernel) for n in range(m_axis.shape[0]): V_dft[i, j, k, a, b] += Vm[j, k, n, a, b] * f_kernel[n] @@ -489,9 +460,8 @@ def parallel_visibility_dft_from_mmodes(era_axis, Vm, delta_t): if delta_t == 0.0: delta_t = 1e-20 - omega_e = ( - 7.292115e-5 - ) # radian/second. Mean angular speed of earth, USNO Circular 179 page 16 + # radian/second. Mean angular speed of earth, USNO Circular 179 page 16 + omega_e = 7.292115e-5 delta_era = omega_e * delta_t V_dft = np.zeros( (era_axis.size,) + Vm.shape[:2] + Vm.shape[3:], dtype=np.complex128 @@ -528,25 +498,6 @@ def inner_parallel_visiblity_dft_from_mmodes(era_axis, Vm, V_dft, delta_era): return -# this turns out to be slower than the njited-dft in the case I tested -# (~400 fourier modes -> ~8000 time samples), but I'll leave it here... -# -# import nfft -# -# def visibility_nfft_from_mmodes(era_axis, Vm): -# x_axis = era_axis/(2*np.pi) -# -# V_nfft = np.zeros((era_axis.size,) + Vm.shape[:2] + Vm.shape[3:], dtype=np.complex128) -# -# for jj in range(Vm.shape[0]): -# for kk in range(Vm.shape[1]): -# for aa in range(2): -# for bb in range(2): -# V_nfft[:,jj,kk,aa,bb] = nfft.nfft(x_axis, Vm[jj,kk,:-1,aa,bb], tol=1e-10) -# -# return V_nfft - - def vectorize_vis_mat(vmat_in): V_vec = np.zeros((vmat_in.shape[0] + 1, 8), dtype=np.float64) f = [np.real, np.imag] @@ -590,7 +541,6 @@ def visibility_from_mmodes(Vm, era_axis, up_sampling=10): ind1 = m_axis[-1] + (N_fftup - 1) // 2 ang_shift_up = np.pi - 2 * np.pi * (L_fftup - 1) // (2 * L_fftup - 1) - # phase_shift_up = np.exp(-1j*m_axis*ang_shift_up) phases = m_axis * ang_shift_up phase_shift_up = np.cos(phases) - 1j * np.sin(phases) diff --git a/RIMEz/sky_models.py b/src/RIMEz/sky_models.py similarity index 83% rename from RIMEz/sky_models.py rename to src/RIMEz/sky_models.py index 5485210..a74daf5 100644 --- a/RIMEz/sky_models.py +++ b/src/RIMEz/sky_models.py @@ -2,22 +2,20 @@ # Copyright (c) 2019 UPennEoR # Licensed under the MIT License -import numpy as np +import h5py +import healpy as hp import numba as nb +import numpy as np +import ssht_numba as sshtn from scipy import interpolate -import h5py - -import ssht_numba as sshtn +from . import utils try: import pygsm except ImportError: pygsm = None -import healpy as hp - -from . import utils # simple made-up point source catalog generation, with GLEAM-ish dN/dS and spectral indices @@ -191,28 +189,7 @@ def alt_inner_blocks(I_s, RA_s, dec_s, L, ell_min, delta, Ilm_s): return Ilm -# def point_sources_Ilm(I, RA, dec, L): -# RA = np.array(RA) -# dec = np.array(dec) -# codec = np.pi/2. - dec -# -# delta = sshtn.generate_dl(np.pi/2., L) -# -# Ilm = np.zeros((I.shape[0], L**2), dtype=np.complex128) -# for ell in range(L): -# m = np.arange(-ell, ell+1) -# indices = sshtn.elm2ind(ell, m) -# -# for ii in range(RA.shape[0]): -# Ilm[:, indices] += I[:, ii, None] * np.conj(spin0_spherical_harmonics(ell, codec[ii], RA[ii], delta)) -# -# return Ilm - -# GLEAM - # diffuse sky model generation - - def hp2ssht_index(hp_flm_in, lmax=None): """ Map from healpy indexed harmonic coefficients to ssht index. @@ -261,8 +238,6 @@ def diffuse_sky_model_from_GSM2008(nu_axis, smooth_deg=0.0, ssht_index=True): Jy_per_K = A_Jy * 2 * k_b * (nu_axis * 1e6 / c) ** 2.0 - # R_g2c = hp.rotator.Rotator(coord=['G','C']).mat - R_g2c = utils.get_galactic_to_gcrs_rotation_matrix() gsm8 = pygsm.GlobalSkyModel( @@ -271,23 +246,12 @@ def diffuse_sky_model_from_GSM2008(nu_axis, smooth_deg=0.0, ssht_index=True): I_init = Jy_per_K[:, None] * gsm8.generate(nu_axis) - # rI_init = np.zeros_like(I_init) - # - # for ii in range(I_init.shape[0]): - # rI_init[ii] = linear_interp_rotation(I_init[ii], R_g2c.T) - lmax = 3 * 512 // 2 Ilm_init = hp.map2alm(I_init, lmax=lmax, pol=False, use_pixel_weights=True) for i in range(Ilm_init.shape[0]): hp.rotate_alm(Ilm_init[i, :], matrix=R_g2c, lmax=lmax) - # if smooth_deg != 0.: - # fwhm = np.radians(smooth_deg) - # - # Ilm_init = hp.smoothalm(Ilm_init, fwhm=fwhm, pol=False, verbose=False, inplace=True) - # - if ssht_index: flm = hp2ssht_index(Ilm_init, lmax=lmax) @@ -318,38 +282,6 @@ def diffuse_sky_model_egsm_preview(nu_axis): interpolate.splev(nu_axis, tck_im) ) - # rbf interpolation (sinc or gaussian) - too slow with this many spatial modes! - # delta_nu_in = np.diff(freqs)[0] - # - # def sinc_kernel(self, r): - # tau_c = 1./(2*self.epsilon) - # - # r = np.where(r == 0, 1e-20, r) - # y = 2*np.pi*tau_c*r - # kernel = np.sin(y)/y - # return kernel - # - # def rbf_obj(data): - # rbf = interpolate.Rbf(freqs, data, - # function='gaussian', - # epsilon=delta_nu_in, - # smooth=0.) - # return rbf - # - # Ilm = np.zeros((nu_axis.size, Ilm_init.shape[1]), dtype=np.complex128) - # for ii in range(Ilm.shape[1]): - # - # Ilm_re_intp = rbf_obj(Ilm_init[:,ii].real) - # Ilm_im_intp = rbf_obj(Ilm_init[:,ii].imag) - # - # Ilm[:,ii] = Ilm_re_intp(nu_axis) + 1j*Ilm_im_intp(nu_axis) - - # 3rd order spline - # Ilm_re_intp = interpolate.interp1d(freqs, Ilm_init.real, kind='cubic', axis=0) - # Ilm_im_intp = interpolate.interp1d(freqs, Ilm_init.imag, kind='cubic', axis=0) - # - # Ilm = Ilm_re_intp(nu_axis) + 1j*Ilm_im_intp(nu_axis) - return Ilm @@ -383,7 +315,7 @@ def linear_interp_rotation(hmap, R): return hp.get_interp_val(hmap, t, p) -#### old thing +# old thing def diffuse_sky_model(nu_axis, R_g2c=None, ssht_index=True, smth_deg=0.0): if pygsm is None: raise ImportError( diff --git a/RIMEz/utils.py b/src/RIMEz/utils.py similarity index 97% rename from RIMEz/utils.py rename to src/RIMEz/utils.py index 2456274..c958b39 100644 --- a/RIMEz/utils.py +++ b/src/RIMEz/utils.py @@ -4,19 +4,17 @@ from functools import reduce +import healpy as hp import numpy as np -from scipy import optimize, linalg +import pyuvdata +import ssht_numba as sshtn +from astropy import _erfa from astropy import coordinates as coord from astropy import units -from astropy import _erfa from astropy.time import Time - -import healpy as hp -import pyuvdata from pyuvdata import UVData from pyuvdata.utils import polstr2num - -import ssht_numba as sshtn +from scipy import linalg, optimize from spin1_beam_model.cst_processing import ssht_power_spectrum from .beam_models import az_shiftflip @@ -59,8 +57,7 @@ def b_arc(b, precision=3): if b[0] == 0.0 and b[1] == 0.0: arc = np.nan else: - if b[0] == 0.0: - # i.e. b[1]/b[0] is -np.inf or np.inf + if b[0] == 0.0: # i.e. b[1]/b[0] is -np.inf or np.inf arc = np.pi / 2.0 else: b_grp = np.around(np.linalg.norm(b), precision) @@ -248,8 +245,6 @@ def get_rotations_realistic_from_JDs(jd_axis, array_location): p2 = np.array([0.0, 1.0, 0.0]) p3 = np.array([0.0, 0.0, 1.0]) - # jd_axis = map(lambda era: era2JD(era, JD_INIT), era_axis) - JDs = Time(jd_axis, format="jd", scale="ut1") rotations_axis = np.zeros((JDs.size, 3, 3), dtype=np.float) @@ -351,8 +346,8 @@ def get_galactic_to_gcrs_rotation_matrix(): # as measured by the Frobenius norm. Rt, _ = linalg.orthogonal_procrustes(M, np.eye(3)) + # The 3D rotation matrix that defines the coordinate transformation. R_g2gcrs = np.transpose(Rt) - # R_g2gcrs = np.array(axes_gal.cartesian.xyz).T # The 3D rotation matrix that defines the coordinate transformation. return R_g2gcrs @@ -450,7 +445,6 @@ def beam_func_to_kernel_power_spectrum(nu_hz, b_m, beam_func): # frequency ell_peak_est = np.ceil(2 * np.pi * nu_hz / c_mps * np.linalg.norm(b_m)).astype(int) - # L_use = 3*ell_peak_est/2 L_use = 2 * ell_peak_est # for HERA-sized beam widths this will be sufficient. Significantly narrower @@ -656,11 +650,6 @@ def inflate_uvdata_redundancies(uvd, red_gps): """ red_gps is a list of lists of redundant groups of uvdata baseline numbers """ - # - # antenna_positions, antenna_numbers = uvd.get_ENU_antpos() - # - # red_gps, centers, lengths = pyuvdata.utils.get_antenna_redundancies( - # antenna_numbers, antenna_positions, tol=tol, include_autos=include_autos) # number of baselines in the inflated dataset Nbls_full = reduce(lambda x, y: x + y, map(len, red_gps)) diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..4e881a9 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- +""" + Dummy conftest.py for RIMEz. + + If you don't know what this is for, just leave it empty. + Read more about conftest.py under: + https://pytest.org/latest/plugins.html +""" diff --git a/tests/travis_install.sh b/tests/travis_install.sh new file mode 100644 index 0000000..5695332 --- /dev/null +++ b/tests/travis_install.sh @@ -0,0 +1,61 @@ +#!/bin/bash +# This script is meant to be called by the "install" step defined in +# .travis.yml. See http://docs.travis-ci.com/ for more details. +# The behavior of the script is controlled by environment variabled defined +# in the .travis.yml in the top level folder of the project. +# +# This script is inspired by Scikit-Learn (http://scikit-learn.org/) +# +# THIS SCRIPT IS SUPPOSED TO BE AN EXAMPLE. MODIFY IT ACCORDING TO YOUR NEEDS! + +set -e + +if [[ "$DISTRIB" == "conda" ]]; then + # Deactivate the travis-provided virtual environment and setup a + # conda-based environment instead + deactivate + + if [[ -f "$HOME/miniconda/bin/conda" ]]; then + echo "Skip install conda [cached]" + else + # By default, travis caching mechanism creates an empty dir in the + # beginning of the build, but conda installer aborts if it finds an + # existing folder, so let's just remove it: + rm -rf "$HOME/miniconda" + + # Use the miniconda installer for faster download / install of conda + # itself + wget http://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh \ + -O miniconda.sh + chmod +x miniconda.sh && ./miniconda.sh -b -p $HOME/miniconda + fi + export PATH=$HOME/miniconda/bin:$PATH + # Make sure to use the most updated version + conda update --yes conda + + # Configure the conda environment and put it in the path using the + # provided versions + # (prefer local venv, since the miniconda folder is cached) + conda create -p ./.venv --yes python=${PYTHON_VERSION} pip virtualenv + source activate ./.venv +fi + +# for all +pip install -U pip setuptools +pip install tox + +if [[ "$COVERAGE" == "true" ]]; then + pip install -U pytest-cov pytest-virtualenv coverage coveralls flake8 pre-commit +fi + + +travis-cleanup() { + printf "Cleaning up environments ... " # printf avoids new lines + if [[ "$DISTRIB" == "conda" ]]; then + # Force the env to be recreated next time, for build consistency + source deactivate + conda remove -p ./.venv --all --yes + rm -rf ./.venv + fi + echo "DONE" +} diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..bb74e02 --- /dev/null +++ b/tox.ini @@ -0,0 +1,41 @@ +[tox] +envlist = py35, py36, py37, lint + +[travis] +python = + 3.7: py37 + 3.6: py36 + 3.5: py35 + +[testenv:lint] +basepython=python +deps = + flake8 + flake8-comprehensions + flake8-quotes + flake8-black + flake8-builtins + flake8-eradicate + pep8-naming + flake8-isort + flake8-pytest + flake8-docstrings + flake8-rst-docstrings + flake8-rst + darglint + flake8-copyright + flake8-ownership +skip_install=true +commands= + flake8 . + +[testenv] +passenv = TRAVIS TRAVIS_* +setenv = + PYTHONFAULTHANDLER = 1 + PYTHONPATH = {toxinidir} +extras = + testing +commands = + pip install -U pip + py.test -vv --basetemp={envtmpdir} --cov RIMEz