Skip to content

Commit

Permalink
enforce freqs fed as float in pspecbeam.Jy_to_mK
Browse files Browse the repository at this point in the history
  • Loading branch information
nkern committed Apr 8, 2018
1 parent 7dd8764 commit 1abccaa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion hera_pspec/pspecbeam.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,12 @@ def Jy_to_mK(self, freqs, stokes='pseudo_I'):
-------
M : float ndarray, contains Jy -> mK factor at each frequency
"""
if isinstance(freqs, (int, np.float, float)):
if isinstance(freqs, (np.float, float)):
freqs = np.array([freqs])
elif not isinstance(freqs, np.ndarray):
raise TypeError("freqs must be fed as a float ndarray")
elif isinstance(freqs, np.ndarray) and freqs.dtype not in (float, np.float, np.float64):
raise TypeError("freqs must be fed as a float ndarray")
if np.min(freqs) < self.beam_freqs.min(): print "Warning: min freq {} < self.beam_freqs.min(), extrapolating...".format(np.min(freqs))
if np.max(freqs) > self.beam_freqs.max(): print "Warning: max freq {} > self.beam_freqs.max(), extrapolating...".format(np.max(freqs))

Expand Down
6 changes: 5 additions & 1 deletion hera_pspec/tests/test_pspecbeam.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ def test_UVbeam(self):
nt.assert_equal(len(M), 11)
nt.assert_almost_equal(M[0], 41.360105524572283)
M = self.bm.Jy_to_mK(99e6)
M = self.bm.Jy_to_mK(201)
M = self.bm.Jy_to_mK(201e6)
# test exception
nt.assert_raises(TypeError, self.bm.Jy_to_mK, [1])
nt.assert_raises(TypeError, self.bm.Jy_to_mK, np.array([1]))


def test_Gaussbeam(self):
Om_p = self.gauss.power_beam_int()
Expand Down

0 comments on commit 1abccaa

Please sign in to comment.