Skip to content

Commit

Permalink
Merge 2ea9ce9 into 87c6d0a
Browse files Browse the repository at this point in the history
  • Loading branch information
steven-murray committed Aug 27, 2019
2 parents 87c6d0a + 2ea9ce9 commit 435498a
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 81 deletions.
23 changes: 4 additions & 19 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,15 @@ install:
- conda info -a

# create environment and install dependencies
- conda create -q -n test-environment python=$TRAVIS_PYTHON_VERSION numpy>=1.15.0 scipy nose pip matplotlib coverage
- conda create -q -n test-environment python=$TRAVIS_PYTHON_VERSION coveralls
- source activate test-environment
- conda install -c conda-forge healpy aipy
- pip install coveralls
- pip install h5py
- if [[ "$TRAVIS_PYTHON_VERSION" == "2.7" ]]; then
pip install scikit-learn==0.20.3;
else
pip install scikit-learn;
fi
- pip install git+https://github.com/HERA-Team/pyuvdata.git$PYUVDATA_VERSION
- pip install git+https://github.com/HERA-Team/omnical.git
- pip install git+https://github.com/HERA-Team/linsolve.git
- pip install git+https://github.com/HERA-Team/hera_qm.git
- pip install git+https://github.com/HERA-Team/uvtools.git
- pip install git+https://github.com/HERA-Team/hera_cal.git
- pip install pyyaml
- pip install multiprocess
- python setup.py install
- conda env update -n test-environment -f environment.yml
- pip install .

before_script:
- "export MPLBACKEND=agg"

script: nosetests hera_pspec --with-coverage --cover-package=hera_pspec --verbose
script: nosetests -P hera_pspec --with-coverage --cover-package=hera_pspec --verbose

after_success:
- coveralls
54 changes: 34 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,41 @@ The ``hera_pspec`` library provides all of the tools and data structures needed
For usage examples and documentation, see http://hera-pspec.readthedocs.io/en/latest/.

## Installation
Preferred method of installation for users is simply `pip install .`
(or `pip install git+https://github.com/HERA-Team/hera_pspec`). This will install
required dependencies. See below for manual dependency management.

### Dependencies
If you are using `conda`, you may wish to install the following dependencies manually
to avoid them being installed automatically by `pip`::

$ conda install -c conda-forge "numpy>=1.15" "astropy>=2.0" "aipy>=3.0rc2" h5py pyuvdata scipy matplotlib pyyaml h5py scikit-learn

### Developing
If you are developing `hera_pspec`, it is preferred that you do so in a fresh `conda`
environment. The following commands will install all relevant development packages::

$ git clone https://github.com/HERA-Team/hera_pspec.git
$ cd hera_pspec
$ conda create -n hera_pspec python=3
$ conda activate hera_pspec
$ conda env update -n hera_pspec -f environment.yml
$ pip install -e .

This will install extra dependencies required for testing/development as well as the
standard ones.

### Running Tests
Uses the `nose` package to execute test suite.
From the source `hera_pspec` directory run: `nosetests`.

### Code Dependencies

* numpy >= 1.15
* pyuvdata (`pip install pyuvdata` or use https://github.com/HERA-Team/pyuvdata.git)
* aipy (```conda install -c conda-forge aipy```)
* scipy >= 0.19
* matplotlib >= 2.2
* astropy >= 2.0
* hera_cal (https://github.com/HERA-Team/hera_cal.git)
* pyyaml
* hdf5

For anaconda users, we suggest using conda to install astropy, numpy and scipy.

### Installing hera_pspec
Clone the repo using
`git clone https://github.com/HERA-Team/hera_pspec.git`

Navigate into the directory and run `python setup.py install`.

## Running `hera_pspec`

See the documentation for an [overview and examples](http://hera-pspec.readthedocs.io/en/latest/pspec.html) of how to run `hera_pspec`. There are also some example Jupyter notebooks, including [`examples/PS_estimation_examples.ipynb`](examples/PS_estimation_example.ipynb) (a brief tutorial on how to create delay spectra), and [`examples/PSpecBeam_tutorial.ipynb`](examples/PSpecBeam_tutorial.ipynb) (a brief tutorial on handling beam objects).
See the documentation for an
[overview and examples](http://hera-pspec.readthedocs.io/en/latest/pspec.html)
of how to run `hera_pspec`. There are also some example Jupyter notebooks,
including [`examples/PS_estimation_examples.ipynb`](examples/PS_estimation_example.ipynb)
(a brief tutorial on how to create delay spectra), and
[`examples/PSpecBeam_tutorial.ipynb`](examples/PSpecBeam_tutorial.ipynb) (a brief
tutorial on handling beam objects).
24 changes: 24 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: hera_pspec
channels:
- conda-forge
- defaults
dependencies:
- aipy>=3.0.0rc2
- astropy>=2.0
- h5py
- matplotlib>=2.0
- nose
- numpy>=1.15
- pip
- pyyaml
- scikit-learn
- scipy
- six
- pyuvdata>=1.4.1
- pip:
- git+https://github.com/HERA-Team/linsolve
- git+https://github.com/HERA-Team/uvtools
- git+https://github.com/HERA-Team/hera_cal
- pyephem
- multiprocess

55 changes: 45 additions & 10 deletions hera_pspec/tests/test_version.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,74 @@
"""Tests for version.py."""
import nose.tools as nt
import sys
import os
import sys

import nose.tools as nt

try:
# Python 2
from cStringIO import StringIO
except:
# Python 3
from io import StringIO
import subprocess
import hera_pspec
from hera_pspec import version
import json


def test_main():
version_info = hera_pspec.version.construct_version_info()
version_info = version.construct_version_info()

saved_stdout = sys.stdout
try:
out = StringIO()
sys.stdout = out
hera_pspec.version.main()
output = out.getvalue()
nt.assert_equal(output, 'Version = {v}\ngit origin = {o}\n'
'git branch = {b}\ngit description = {d}\n'
'git branch = {b}\ngit description = {d}\n'
.format(v=version_info['version'],
o=version_info['git_origin'],
b=version_info['git_branch'],
d=version_info['git_description']))

git_info = hera_pspec.version._get_gitinfo_file()



finally:
sys.stdout = saved_stdout

# Test history string function
history = hera_pspec.version.history_string()


def test_get_gitinfo_file():
dir = version.hera_pspec_dir

git_file = os.path.join(dir, 'GIT_INFO')
if not os.path.exists(git_file):
# write a file to read in
temp_git_file = os.path.join(dir, 'GIT_INFO')
version_info = version.construct_version_info()
data = [version_info['git_origin'], version_info['git_origin'],
version_info['git_origin'], version_info['git_origin']]
with open(temp_git_file, 'w') as outfile:
json.dump(data, outfile)
git_file = temp_git_file

with open(git_file) as data_file:
data = [version._unicode_to_str(x) for x in json.loads(data_file.read().strip())]
git_origin = data[0]
git_hash = data[1]
git_description = data[2]
git_branch = data[3]

test_file_info = {
'git_origin': git_origin, 'git_hash': git_hash,
'git_description': git_description, 'git_branch': git_branch
}

if 'temp_git_file' in locals():
file_info = version._get_gitinfo_file(git_file=temp_git_file)
os.remove(temp_git_file)
else:
file_info = version._get_gitinfo_file()

assert file_info == test_file_info
1 change: 0 additions & 1 deletion hera_pspec/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import aipy, uvtools
from hera_cal import redcal
from collections import OrderedDict as odict
from pyuvdata import utils as uvutils
from pyuvdata import UVData
from datetime import datetime

Expand Down
1 change: 0 additions & 1 deletion hera_pspec/uvpspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import os, copy, shutil, operator, ast, fnmatch
from pyuvdata import uvutils as uvutils
import h5py
import operator
import warnings
import json

Expand Down
37 changes: 21 additions & 16 deletions hera_pspec/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@

from __future__ import print_function, division, absolute_import

import inspect
import json
import os
import six
import subprocess
import json
import inspect
import sys

hera_pspec_dir = os.path.dirname(os.path.realpath(__file__))

PY2 = sys.version_info < (3, 0)


def _get_git_output(args, capture_stderr=False):
"""
Expand All @@ -27,7 +29,7 @@ def _get_git_output(args, capture_stderr=False):

data = data.strip()

if six.PY2:
if PY2:
return data
return data.decode('utf8')

Expand All @@ -51,7 +53,7 @@ def _get_gitinfo_file(git_file=None):


def _unicode_to_str(u):
if six.PY2:
if PY2:
return u.encode('utf8')
return u

Expand All @@ -71,16 +73,16 @@ def construct_version_info():

try:
version_info['git_origin'] = _get_git_output(
['config', '--get', 'remote.origin.url'],
capture_stderr=True)
['config', '--get', 'remote.origin.url'],
capture_stderr=True)
version_info['git_hash'] = _get_git_output(
['rev-parse', 'HEAD'],
capture_stderr=True)
['rev-parse', 'HEAD'],
capture_stderr=True)
version_info['git_description'] = _get_git_output(
['describe', '--dirty', '--tag', '--always'])
['describe', '--dirty', '--tag', '--always'])
version_info['git_branch'] = _get_git_output(
['rev-parse', '--abbrev-ref', 'HEAD'],
capture_stderr=True)
['rev-parse', '--abbrev-ref', 'HEAD'],
capture_stderr=True)
except subprocess.CalledProcessError: # pragma: no cover
try:
# Check if a GIT_INFO file was created when installing package
Expand All @@ -97,22 +99,23 @@ def history_string(notes=''):
disk can use. Optionally add notes.
"""
history = '\n------------\nThis file was produced by the function ' \
+ str(inspect.stack()[1][3]) + '()'
+ str(inspect.stack()[1][3]) + '()'
# inspect.stack()[1][3] is the name of the function that called this fn

history += ' in ' + os.path.basename(inspect.stack()[1][1]) + ' using: '
# inspect.stack()[1][1] is path to the file that contains the function
# that called this function
version_info = construct_version_info()

for v in sorted(version_info.keys()):
history += '\n ' + v + ': ' + version_info[v]

if (notes is not None) and (notes != ''):
history += '\n\nNotes:\n'
history += notes
return history + '\n------------\n'


def print_version_info():
"""
Print git/version info.
Expand All @@ -122,6 +125,7 @@ def print_version_info():
print('git branch = {0}'.format(git_branch))
print('git description = {0}'.format(git_description))


version_info = construct_version_info()
version = version_info['version']
git_origin = version_info['git_origin']
Expand All @@ -133,5 +137,6 @@ def print_version_info():
def main():
print_version_info()


if __name__ == '__main__':
main()
45 changes: 31 additions & 14 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
from setuptools import setup
import sys
import os
from hera_pspec import version
import json
import os
import sys

from setuptools import setup

sys.path.append("hera_pspec")
import version

data = [version.git_origin, version.git_hash, version.git_description, version.git_branch]
with open(os.path.join('hera_pspec', 'GIT_INFO'), 'w') as outfile:
json.dump(data, outfile, default=str)


def package_files(package_dir, subdirectory):
# walk the input package_dir/subdirectory
# return a package_data list
Expand All @@ -18,23 +22,36 @@ def package_files(package_dir, subdirectory):
path = path.replace(package_dir + '/', '')
paths.append(os.path.join(path, filename))
return paths


data_files = package_files('hera_pspec', 'data') + package_files('hera_pspec', '../pipelines')

setup_args = {
'name': 'hera_pspec',
'author': 'HERA Team',
'url': 'https://github.com/HERA-Team/hera_pspec',
'license': 'BSD',
'version': version.version,
'description': 'HERA Power Spectrum Estimator Code.',
'packages': ['hera_pspec'],
'package_dir': {'hera_pspec': 'hera_pspec'},
'name': 'hera_pspec',
'author': 'HERA Team',
'url': 'https://github.com/HERA-Team/hera_pspec',
'license': 'BSD',
'version': version.version,
'description': 'HERA Power Spectrum Estimator Code.',
'packages': ['hera_pspec'],
'package_dir': {'hera_pspec': 'hera_pspec'},
'package_data': {'hera_pspec': data_files},
'install_requires': ['numpy>=1.15', 'scipy','matplotlib>=2.2'],
'install_requires': [
'numpy>=1.15',
'scipy',
'matplotlib>=2.2'
'pyuvdata',
'astropy>=2.0',
'aipy>=3.0rc2',
'pyyaml',
'h5py',
'uvtools @ git+git://github.com/HERA-Team/uvtools',
'hera_cal @ git+git://github.com/HERA-Team/hera_cal'
],
'include_package_data': True,
'scripts': ['scripts/pspec_run.py', 'scripts/pspec_red.py',
'scripts/bootstrap_run.py'],
'zip_safe': False,
'zip_safe': False,
}

if __name__ == '__main__':
Expand Down

0 comments on commit 435498a

Please sign in to comment.