Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 8 additions & 12 deletions sacc/sacc.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from astropy.table import Table

from .tracers import BaseTracer
from .windows import BaseWindow, BandpowerWindow
from .windows import BaseWindow, BandpowerWindow, TopHatWindow
from .covariance import BaseCovariance, concatenate_covariances
from .utils import unique_list
from .data_types import standard_types, DataPoint
Expand Down Expand Up @@ -970,13 +970,8 @@ def get_bandpower_windows(self, indices):
"tracers and data type) or get windows "
"later.")
ws = ws[0]
if not isinstance(ws, BandpowerWindow):
warnings.warn("No bandpower windows associated to these data")
return None
else:
w_inds = np.array(self._get_tags_by_index(['window_ind'],
indices)[0])
return ws.get_section(w_inds)
w_inds = np.array(self._get_tags_by_index(['window_ind'], indices)[0])
return ws.get_section(w_inds)

def get_ell_cl(self, data_type, tracer1, tracer2,
return_cov=False, return_ind=False):
Expand Down Expand Up @@ -1200,12 +1195,13 @@ def add_ell_cl(self, data_type, tracer1, tracer2, ell, x,
None

"""
if isinstance(window, BandpowerWindow):
if len(ell) != window.nv:
if isinstance(window, (BandpowerWindow, TopHatWindow)):
nv = window.nv if isinstance(window, BandpowerWindow) else len(window.min)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will crash if window.min is an integer?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, we must ensure window.min is an array. This will fail here but also here.

The min/max class attributes must be arrays. We can use np.asarray within the __init__ of TopHatWindow but I think this is related to the redesign/rethink of the window classes you mention.

if len(ell) != nv:
raise ValueError("Input bandpowers are misshapen")
tag_extra = range(window.nv)
tag_extra = range(nv)
tag_extra_name = "window_ind"
window_use = [window for i in range(window.nv)]
window_use = [window for i in range(nv)]
else:
tag_extra = None
tag_extra_name = None
Expand Down
34 changes: 21 additions & 13 deletions sacc/windows.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import warnings

import numpy as np
from astropy.table import Table

Expand Down Expand Up @@ -78,6 +80,23 @@ def from_tables(cls, table_list):
windows.update(subclass.from_table(table))
return windows

def get_section(self, indices):
"""Get part of this window function corresponding to the input
indices.

Parameters
----------
indices: int or array_like
Indices to return.

Returns
-------
window: `Window`
A `Window object.
"""
warnings.warn("No bandpower windows associated to these data")
return None


class TopHatWindow(BaseWindow, window_type='TopHat'):
"""A window function that is constant between two values.
Expand Down Expand Up @@ -158,6 +177,8 @@ def from_table(cls, table):
"""
return {row['id']: cls(row['min'], row['max']) for row in table}

def get_section(self, indices):
return self.__class__(self.min[indices], self.max[indices])

class LogTopHatWindow(TopHatWindow, window_type='LogTopHat'):
"""A window function that is log-constant between two values.
Expand Down Expand Up @@ -317,17 +338,4 @@ def from_table(cls, table):
return {table.meta['SACCNAME']: cls(table['values'], table['weight'])}

def get_section(self, indices):
"""Get part of this window function corresponding to the input
indices.

Parameters
----------
indices: int or array_like
Indices to return.

Returns
-------
window: `Window`
A `Window object.
"""
return self.__class__(self.values, self.weight[:, indices])