Skip to content

Commit

Permalink
Merge 5582a15 into 82c0a86
Browse files Browse the repository at this point in the history
  • Loading branch information
philbull authored May 10, 2018
2 parents 82c0a86 + 5582a15 commit 632ead3
Show file tree
Hide file tree
Showing 9 changed files with 305 additions and 165 deletions.
5 changes: 4 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@

# Mock-import modules to allow build to complete without throwing errors
import mock
MOCK_MODULES = ['numpy', 'scipy', 'scipy.interpolate', 'pyuvdata', 'h5py', 'aipy', 'omnical', 'linsolve', 'hera_qm', 'uvtools', 'hera_cal', 'healpy', 'scikit-learn']
MOCK_MODULES = ['numpy', 'scipy', 'scipy.interpolate', 'scipy.integrate',
'pyuvdata', 'h5py', 'aipy', 'omnical', 'linsolve', 'hera_qm',
'uvtools', 'hera_cal', 'healpy', 'scikit-learn', 'astropy',
'astropy.cosmology', 'matplotlib', 'matplotlib.pyplot', 'yaml']
for mod_name in MOCK_MODULES:
sys.modules[mod_name] = mock.Mock()

Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ You can find the code in the ``hera_pspec`` `GitHub repository <https://github.c
pspecdata
uvpspec
container
plot


Indices and tables
Expand Down
30 changes: 30 additions & 0 deletions docs/plot.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Simple plotting functions
=========================

The ``hera_pspec.plot`` module contains functions for making simple plots of delay power spectra.

The following example plots the power spectra from a ``UVPSpec`` object, averaged over baseline-pairs and times.

.. code-block:: python
# Load or generate a UVPSpec object containing delay power spectra
uvp = ...
# Set which baseline-pairs should be included in the plot
blpairs = list(uvp.blpair_array) # This includes all blpairs!
# Plot the delay spectrum, averaged over all blpairs and times
# (for the spectral window with index=0, and polarization 'xx')
ax = hp.plot.delay_spectrum(uvp, [blpairs,], spw=0, pol='xx',
average_blpairs=True, average_times=True,
delay=False)
# Setting delay=False plots the power spectrum in cosmological units
For a more extensive worked example, see `this example Jupyter notebook <https://github.com/HERA-Team/hera_pspec/blob/master/examples/Plotting_examples.ipynb>`_.

The only plotting function currently available in the `hera_pspec.plot` module is `delay_spectrum()`.

.. autofunction:: hera_pspec.plot.delay_spectrum


4 changes: 3 additions & 1 deletion docs/pspec.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ The most frequently-used methods from ``PSpecData`` are listed below. See :any:`

.. autoclass:: hera_pspec.PSpecData
:members: __init__, add, pspec, rephase_to_dset, scalar, delays, units
:noindex:


``UVPSpec``: Container for power spectra
Expand Down Expand Up @@ -167,6 +168,7 @@ The ``UVPSpec`` class
The most relevant methods from ``UVPSpec`` are listed below. See :any:`uvpspec` for a full listing of all methods provided by ``UVPSpec``.

.. autoclass:: hera_pspec.UVPSpec
:members: __init__, get_data, get_wgts, get_integrations, get_nsamples, get_dlys, get_kvecs, get_blpair_seps, select, read_hdf5, write_hdf5, generate_noise_spectra, average_spectra, fold_spectra, get_blpair_groups_from_bl_groups
:members: __init__, get_data, get_wgts, get_integrations, get_nsamples, get_dlys, get_kperps, get_kparas, get_blpair_seps, select, read_hdf5, write_hdf5, generate_noise_spectra, average_spectra, fold_spectra, get_blpair_groups_from_bl_groups
:noindex:


5 changes: 2 additions & 3 deletions hera_pspec/conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
Cosmological and instrumental
conversion functions for hera_pspec
"""
import numpy as np
from scipy import integrate
import scipy.integrate as integrate

try:
from astropy.cosmology import LambdaCDM
_astropy = True
Expand Down
3 changes: 2 additions & 1 deletion hera_pspec/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def delay_spectrum(uvp, blpairs, spw, pol, average_blpairs=False,
If True, average spectra over the time axis. Default: False.
fold : bool, optional
Whether to fold the power spectrum in |k_parallel|. Default: False.
Whether to fold the power spectrum in :math:`|k_\parallel|`.
Default: False.
plot_noise : bool, optional
Whether to plot noise power spectrum curves or not. Default: False.
Expand Down
30 changes: 15 additions & 15 deletions hera_pspec/pspecbeam.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import numpy as np
import os
import aipy
import pyuvdata
from hera_pspec import conversions
from scipy import __version__ as scipy_version
from scipy import integrate
import hera_pspec.conversions as conversions
import scipy.integrate as integrate
from scipy.interpolate import interp1d
from pyuvdata import UVBeam, utils as uvutils
import aipy
from pyuvdata import utils as uvutils


def _compute_pspec_scalar(cosmo, beam_freqs, omega_ratio, pspec_freqs,
num_steps=5000, taper='none', little_h=True,
Expand Down Expand Up @@ -241,17 +237,20 @@ def Jy_to_mK(self, freqs, pol='I'):

def get_Omegas(self, pols):
"""
Get OmegaP and OmegaPP across beam_freqs for requested polarizatiosn
Get OmegaP and OmegaPP across beam_freqs for requested polarizations.
Parameters
----------
pols : list of polarization strings or integers
pols : list
List of polarization strings or integers.
Returns (OmegaP, OmegaPP)
Returns
-------
OmegaP : ndarray containing power_beam_int, shape=(Nbeam_freqs, Npols)
OmegaP : array_like
Array containing power_beam_int, shape: (Nbeam_freqs, Npols).
OmegaPP : ndarray containing power_sq_beam_int, shape=(Nbeam_freqs, Npols)
OmegaPP : array_like
Array containing power_sq_beam_int, shape: (Nbeam_freqs, Npols).
"""
# type check
if isinstance(pols, (int, np.int, np.int32)):
Expand Down Expand Up @@ -373,7 +372,7 @@ def __init__(self, beam_fname, cosmo=None):
Cosmology object. Uses the default cosmology object if not
specified. Default: None.
"""
self.primary_beam = pyuvdata.UVBeam()
self.primary_beam = UVBeam()
self.primary_beam.read_beamfits(beam_fname)

self.beam_freqs = self.primary_beam.freq_array[0]
Expand Down Expand Up @@ -608,7 +607,8 @@ def power_beam_sq_int(self, pol='I'):
Returns
-------
primary_beam_area: float, array-like
primary_beam_area: array_like
Array of floats containing the primary beam-squared area.
"""
if pol in self.OmegaPP.keys():
return self.OmegaPP[pol]
Expand All @@ -620,7 +620,7 @@ def power_beam_sq_int(self, pol='I'):

def __str__(self):
"""
Print string with useful information.
Return a string with useful information about this object.
"""
s = "PSpecBeamFromArray object\n"
s += "\tFrequency range: Min. %4.4e Hz, Max. %4.4e Hz\n" \
Expand Down
47 changes: 28 additions & 19 deletions hera_pspec/pspecdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -1048,8 +1048,8 @@ def pspec(self, bls1, bls2, dsets, input_data_weight='identity', norm='I',
taper='none', little_h=True, spw_ranges=None, verbose=True,
history=''):
"""
Estimate the delay power spectrum from a pair of datasets contained in this
object, using the optimal quadratic estimator from arXiv:1502.06016.
Estimate the delay power spectrum from a pair of datasets contained in
this object, using the optimal quadratic estimator of arXiv:1502.06016.
In this formulation, the power spectrum is proportional to the
visibility data via
Expand All @@ -1071,9 +1071,8 @@ def pspec(self, bls1, bls2, dsets, input_data_weight='identity', norm='I',
Parameters
----------
bls1 : list of baseline groups, each being a list of ant-pair tuples
bls2 : list of baseline groups, each being a list of ant-pair tuples
bls1, bls2 : list
List of baseline groups, each group being a list of ant-pair tuples.
dsets : length-2 tuple or list
Contains indices of self.dsets to use in forming power spectra,
Expand Down Expand Up @@ -1101,11 +1100,10 @@ def pspec(self, bls1, bls2, dsets, input_data_weight='identity', norm='I',
A list of spectral window channel ranges to select within the total
bandwidth of the datasets, each of which forms an independent power
spectrum estimate. Example: [(220, 320), (650, 775)].
Each tuple should contain a start and stop channel used to index
the `freq_array` of each dataset. The default (None) is to use the
entire band provided in each dataset.
verbose : bool, optional
If True, print progress, warnings and debugging info to stdout.
Expand All @@ -1119,30 +1117,41 @@ def pspec(self, bls1, bls2, dsets, input_data_weight='identity', norm='I',
Examples
--------
Example 1 : no grouping, i.e. each baseline is its own group, no
brackets needed for each bl.
if
*Example 1:* No grouping; i.e. each baseline is its own group, no
brackets needed for each bl. If::
A = (1, 2); B = (2, 3); C = (3, 4); D = (4, 5); E = (5, 6); F = (6, 7)
and
and::
bls1 = [ A, B, C ]
bls2 = [ D, E, F ]
then
then::
blpairs = [ (A, D), (B, E), (C, F) ]
Example 2: grouping, blpairs come in lists of blgroups, which are considered
"grouped" in OQE
if
*Example 2:* Grouping; blpairs come in lists of blgroups, which are
considered "grouped" in OQE.
If::
bls1 = [ [A, B], [C, D] ]
bls2 = [ [C, D], [E, F] ]
then
then::
blpairs = [ [(A, C), (B, D)], [(C, E), (D, F)] ]
Example 3: mixed grouping, i.e. some blpairs are grouped, others are not
if
*Example 3:* Mixed grouping; i.e. some blpairs are grouped, others are
not. If::
bls1 = [ [A, B], C ]
bls2 = [ [D, E], F ]
then
then::
blpairs = [ [(A, D), (B, E)], (C, F)]
"""
# Validate the input data to make sure it's sensible
self.validate_datasets(verbose=verbose)
Expand Down
Loading

0 comments on commit 632ead3

Please sign in to comment.