Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR for pspec_graduation #4

Merged
merged 29 commits into from
Dec 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
40b79e8
Initial commit for pspec object
Oct 25, 2017
c94c2c2
Added placeholders for some pspec methods
Oct 25, 2017
9d8ee14
Ignore cached Python files
philbull Oct 26, 2017
f30ba72
Add initial unit tests
philbull Oct 26, 2017
84a4d21
Blah
Nov 1, 2017
c560083
Blah 2
Nov 1, 2017
f68550b
Move pspec object spec from notebook to Python script. Add comments f…
philbull Nov 2, 2017
98cf98c
Implemented (but did not test) the writing method for pspec, DeltaSq …
Nov 7, 2017
b088617
Updated oqe.py to be Matt's latest version
Nov 7, 2017
5185084
added hera_pspec directory w/ testing environment and setup.py scripts
nkern Nov 7, 2017
d626061
added test for version.py
nkern Nov 7, 2017
b933880
Merge branch 'setup_testing_env' of https://github.com/HERA-Team/hera…
Nov 7, 2017
20edc16
added BSD LICENSE
nkern Nov 8, 2017
87490a8
updated .travis.yml git fetch command
nkern Nov 8, 2017
0aac1f4
Split DataSet object out from oqe.py and refactor slightly.
philbull Nov 8, 2017
8289400
Merge branch 'pspec_graduation' of github.com:HERA-Team/hera_pspec in…
philbull Nov 8, 2017
46de631
added basic info to README.md
nkern Nov 10, 2017
8c5095e
started conversions.py for helper conversion functions
nkern Nov 11, 2017
e972124
added hera_pspec/data directory for storing data for testing
nkern Nov 12, 2017
cbaa770
modified: hera_pspec/__init__.py
nkern Dec 6, 2017
3b58797
added XY scalar conversiosn to conversions.py
nkern Dec 7, 2017
d09b04c
Merge branch 'pspec_graduation' of https://github.com/HERA-Team/hera_…
nkern Dec 7, 2017
093d280
commented out utils import statement in dataset.py
nkern Dec 7, 2017
7a3514e
erased mysterious hera_qm import in test_conversions.py
nkern Dec 7, 2017
55903fe
Reorganise dataset.py and break some functions out into utils.py
philbull Dec 7, 2017
cc26f66
Merge branch 'pspec_graduation' of github.com:HERA-Team/hera_pspec in…
philbull Dec 7, 2017
04a2345
Fix import error
philbull Dec 7, 2017
db7deb3
Merge branch 'master' into pspec_graduation
philbull Dec 7, 2017
9b172f5
Provide legacy pspec code through the 'legacy' submodule
philbull Dec 7, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# compiled code
*.pyc
*__pycache__/

# build
build/
env/
dist/
eggs/
*.eggs/


43 changes: 43 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
language: python
python:
# We don't actually use the Travis Python, but this keeps it organized.
- "2.7"
install:
# ensure that we have the full tag information available for version.py
- git fetch --tags
- sudo apt-get update
# We do this conditionally because it saves us some downloading if the
# version is the same.
- if [[ "$TRAVIS_PYTHON_VERSION" == "2.7" ]]; then
wget https://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86_64.sh -O miniconda.sh;
else
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh;
fi
- bash miniconda.sh -b -p $HOME/miniconda
- export PATH="$HOME/miniconda/bin:$PATH"
- hash -r
- conda config --set always_yes yes --set changeps1 no
- conda install -q conda=4.3.25
# Useful for debugging any issues with conda
- conda info -a

# create environment and install dependencies
- conda create -q -n test-environment python=$TRAVIS_PYTHON_VERSION numpy scipy nose pip matplotlib coverage
- source activate test-environment
- conda install -c conda-forge aipy
- pip install coveralls
- pip install git+https://github.com/HERA-Team/pyuvdata.git
- pip install git+https://github.com/HERA-Team/omnical.git
- pip install git+https://github.com/HERA-Team/hera_cal.git
- pip install git+https://github.com/HERA-Team/linsolve.git
- python setup.py install

before_script:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
- sleep 3

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

after_success:
- coveralls
29 changes: 29 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
BSD 3-Clause License

Copyright (c) 2017, Hydrogen Epoch of Reionization Array (HERA)
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5 changes: 5 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include *.md
include LICENSE
include hera_pspec/VERSION
include hera_pspec/GIT_INFO

29 changes: 28 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,28 @@
# hera_pspec
# hera_pspec

[![Build Status](https://travis-ci.org/HERA-Team/hera_pspec.svg?branch=master)](https://travis-ci.org/HERA-Team/hera_pspec)

**hera_pspec description**

## Installation

### Code Dependencies

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

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`.

## Package Details and Usage



1 change: 1 addition & 0 deletions hera_pspec/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0.0
10 changes: 9 additions & 1 deletion hera_pspec/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
import pspec
"""
__init__.py file for hera_pspec
"""
import version
import conversions
from dataset import DataSet
import pspec as legacy # XXX: This will eventually be deprecated

__version__ = version.version
256 changes: 256 additions & 0 deletions hera_pspec/conversions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@
"""
conversions.py
--------

Cosmological and instrumental
conversion functions for hera_pspec


"""
import numpy as np
from scipy import integrate
try:
from astropy.cosmology import LambdaCDM
_astropy = True
except:
print("could not import astropy")
_astropy = False


class units:
"""
fundamental constants and conversion constants
in ** SI ** units

c : speed of light m s-1
ckm : speed of light in km s-1
kb : boltzmann constant 2 kg s-2 K-1
hp : planck constant m2 kg s-1
sb : stefan-boltzmann constant W m-2 K-4
f21 : 21cm frequency in Hz
w21 : 21cm wavelength in meters
"""
c = 2.99792458e8 # speed of light in m s-1
ckm = c / 1e3 # speed of light in km s-1
G = 6.67408e-11 # Newton constant m3 kg-1 s-2
kb = 1.38064852e-23 # boltzmann constant m2 kg s-2 K-1
hp = 6.62607004e-34 # planck constant m2 kg s-1
sb = 5.670367e-8 # stefan boltzmann constant W m-2 K-4
f21 = 1.420405751e9 # frequency of 21cm transition in Hz
w21 = 0.211061140542 # 21cm wavelength in meters
H0_to_SI = 3.24078e-20 # km s-1 Mpc-1 to s-1

class Cosmo_Conversions(object):
"""
Cosmo_Conversions class for mathematical conversion functions,
some of which require a cosmological model, others of which
do not require a predefined cosmology.

Default parameter values are Planck 2015 TT,TE,EE+lowP.
(Table 4 of https://doi.org/10.1051/0004-6361/201525830)

Distance measures come from:
Hogg 1999 (astro-ph/9905116)
Furlanetto 2006 (2006PhR...433..181F)

Note that all distance measures are by default in h-1 Mpc,
because the default H0 = 100 km / sec / Mpc. If the user
changes the input H0, distance measures are in Mpc.
"""
# astropy load attribute
_astropy = _astropy

def __init__(self, Om_L=0.68440, Om_b=0.04911, Om_c=0.26442, H0=100.0,
Om_M=None, Om_k=None):
"""


Default parameter values are Planck 2015 TT,TE,EE+lowP.
(Table 4 of https://doi.org/10.1051/0004-6361/201525830)

Parameters:
-----------
Om_L : float, Omega Lambda naught, default=0.68440
cosmological constant energy density fraction at z=0

Om_b : float, Omega baryon naught, default=0.04911
baryon energy density fraction at z=0

Om_c : float, Omega cold dark matter naught, default=0.26442
cdm energy density fraction at z=0

H0 : float, Hubble constant, default=67.31 km s-1 Mpc-1

Om_M : float, Omega matter naught, default=None [optional]
matter energy density faction at z=0

Om_k : float, Omega curvature naught, default=None [optional]
curvature energy density at z=0

Notes:
------
Note that all distance measures are by default in h-1 Mpc,
because the default H0 = 100 km / sec / Mpc. If the user
changes the input H0, the distance measures are in Mpc.
"""
# Setup parameters
if Om_M is not None:
if np.isclose(Om_b + Om_c, Om_M, atol=1e-5) is False:
Om_b = Om_M * 0.156635
Om_c = Om_M * 0.843364
else:
Om_M = Om_b + Om_c

if Om_k is None:
Om_k = 1 - Om_L - Om_M

### TODO add radiation component to class and to distance functions
self.Om_L = Om_L
self.Om_b = Om_b
self.Om_c = Om_c
self.Om_M = Om_M
self.Om_k = Om_k
self.H0 = H0
self.h = self.H0 / 100.0

if _astropy:
self.lcdm = LambdaCDM(H0=self.H0, Om0=self.Om_M, Ode0=self.Om_L)

def f2z(self, freq, ghz=False):
"""
convert frequency to redshift for 21cm line

Parameters:
-----------
freq : frequency in Hz, type=float

ghz : boolean, if True: assume freq is GHz

Output:
-------
z : float
redshift
"""
if ghz:
freq = freq * 1e9

return (units.f21 / freq - 1)

def z2f(self, z, ghz=False):
"""
convert redshift to frequency in Hz for 21cm line

Parameters:
-----------
z : redshift, type=float

ghz: boolean, if True: convert to GHz

Output:
-------
freq : float
frequency in Hz
"""
freq = units.f21 / (z + 1)
if ghz:
freq /= 1e9

return freq

def E(self, z):
"""
ratio of hubble parameters: H(z) / H(z=0)
Hogg99 Eqn. 14

Parameters:
-----------
z : redshift, type=float
"""
return np.sqrt(self.Om_M*(1+z)**3 + self.Om_k*(1+z)**2 + self.Om_L)

def DC(self, z):
"""
line-of-sight comoving distance in Mpc
Hogg99 Eqn. 15

Parameters:
-----------
z : redshift, type=float
"""
return integrate.quad(lambda z: 1/self.E(z), 0, z)[0] * units.ckm / self.H0

def DM(self, z):
"""
transverse comoving distance in Mpc
Hogg99 Eqn. 16

Parameters:
-----------
z : redshift, type=float
"""
DH = units.ckm / self.H0
if self.Om_k > 0:
DM = DH * np.sinh(np.sqrt(self.Om_k) * self.DC(z) / DH) / np.sqrt(self.Om_k)
elif self.Om_k < 0:
DM = DH * np.sin(np.sqrt(np.abs(self.Om_k)) * self.DC(z) / DH) / np.sqrt(np.abs(self.Om_k))
else:
DM = self.DC(z)

return DM

def DA(self, z):
"""
angular diameter (proper) distance in Mpc
Hogg99 Eqn. 18

Parameters:
-----------
z : redshift, type=float
"""
return self.DM(z) / (1 + z)

def dRperp_dtheta(self, z):
"""
conversion factor from angular size (radian) to transverse
comoving distance (Mpc) at a specific redshift: [Mpc / radians]

Parameters:
-----------
z : float, redshift
"""
return self.DM(z)

def dRpara_df(self, z, ghz=False):
"""
conversion from frequency bandwidth to radial
comoving distance at a specific redshift: [Mpc / Hz]

Parameters:
-----------
z : float, redshift
ghz : convert output to [Mpc / GHz]
"""
y = (1 + z)**2.0 / self.E(z) * units.ckm / self.H0 / units.f21
if ghz:
return y * 1e9
else:
return y

def X2Y(self, z):
"""
Conversion from radians^2 Hz -> Mpc^3
at a specific redshift.

Parameters:
-----------
z : float, redshift

Notes:
------
Calls Cosmo_Conversions.dRperp_dtheta() and Cosmo_Conversions.dRpara_df().
"""
return self.dRperp_dtheta(z)**2 * self.dRpara_df(z)




2 changes: 2 additions & 0 deletions hera_pspec/data/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"""init file for hera_pspec/data/"""
DATA_PATH = __path__[0]
Loading