Skip to content

Commit

Permalink
Merge pull request #210 from HERA-Team/pre-commit-ci-update-config
Browse files Browse the repository at this point in the history
[pre-commit.ci] pre-commit autoupdate
  • Loading branch information
steven-murray authored Jan 31, 2022
2 parents 3ebed9d + ce9010e commit 9576e78
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ repos:
- flake8-comprehensions
- flake8-print
- repo: https://github.com/psf/black
rev: 21.12b0
rev: 22.1.0
hooks:
- id: black
- repo: https://github.com/pre-commit/pygrep-hooks
Expand Down
2 changes: 1 addition & 1 deletion hera_sim/antpos.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def __call__(self, hex_num, **kwargs):
)
y_pos = row * sep * (hex_num - 1) * np.sqrt(3) / 2
theta = np.arctan2(y_pos, x_pos)
if np.sqrt(x_pos ** 2 + y_pos ** 2) > sep * (hex_num + 1):
if np.sqrt(x_pos**2 + y_pos**2) > sep * (hex_num + 1):
if 0 < theta <= 2 * np.pi / 3 + 0.01:
positions.append(
np.asarray([x_pos, y_pos, 0])
Expand Down
6 changes: 3 additions & 3 deletions hera_sim/beams.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ def interp(self, az_array, za_array, freq_array, reuse_spline=None):
Ys = (X * np.sin(a) + Y * np.cos(a)) / self.ystretch

# Updated polar coordinates
theta_s = np.sqrt(Xs ** 2.0 + Ys ** 2.0)
theta_s = np.sqrt(Xs**2.0 + Ys**2.0)
phi_s = np.zeros_like(theta_s)
mask = theta_s == 0.0
phi_s[~mask] = np.arccos(Xs[~mask] / theta_s[~mask])
Expand Down Expand Up @@ -793,8 +793,8 @@ def zernike(coeffs, x, y):
c[: len(coeffs)] += coeffs

# Precompute powers of x and y
x2, x3, x4, x5, x6, x7, x8, x9, x10 = tuple(x ** idx for idx in range(2, 11))
y2, y3, y4, y5, y6, y7, y8, y9, y10 = tuple(y ** idx for idx in range(2, 11))
x2, x3, x4, x5, x6, x7, x8, x9, x10 = tuple(x**idx for idx in range(2, 11))
y2, y3, y4, y5, y6, y7, y8, y9, y10 = tuple(y**idx for idx in range(2, 11))

# Setting the equations for the Zernike polynomials
# r = np.sqrt(powl(x,2) + powl(y,2))
Expand Down
4 changes: 2 additions & 2 deletions hera_sim/foregrounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def __call__(self, lsts, freqs, bl_vec, **kwargs):
# draw flux densities from a power law
alpha = beta + 1
flux_densities = (
Smax ** alpha + Smin ** alpha * (1 - np.random.uniform(size=nsrcs))
Smax**alpha + Smin**alpha * (1 - np.random.uniform(size=nsrcs))
) ** (1 / alpha)

# initialize the visibility array
Expand All @@ -297,7 +297,7 @@ def __call__(self, lsts, freqs, bl_vec, **kwargs):
# convolve vis with beam at each frequency
for j, freq in enumerate(freqs):
# first calculate the beam, using truncated Gaussian model
beam = np.exp(-(has ** 2) / (2 * beam_width[j] ** 2))
beam = np.exp(-(has**2) / (2 * beam_width[j] ** 2))
beam = np.where(np.abs(has) > np.pi / 2, 0, beam)

# who the hell knows what this does
Expand Down
4 changes: 2 additions & 2 deletions hera_sim/simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -1413,10 +1413,10 @@ def _generate_seed(self, model, key):
"""
model = self._get_model_name(model)
# for the sake of randomness
np.random.seed(int(time.time() * 1e6) % 2 ** 32)
np.random.seed(int(time.time() * 1e6) % 2**32)
if model not in self._seeds:
self._seeds[model] = {}
self._seeds[model][key] = np.random.randint(2 ** 32)
self._seeds[model][key] = np.random.randint(2**32)

def _get_seed(self, model, key):
"""Retrieve or generate a random seed given a model and key."""
Expand Down
2 changes: 1 addition & 1 deletion hera_sim/tests/test_beams.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def evaluate_polybeam(polybeam):
L = L.flatten()
m = m.flatten()

lsqr = L ** 2 + m ** 2
lsqr = L**2 + m**2
n = np.where(lsqr < 1, np.sqrt(1 - lsqr), 0)

# Generate azimuth and zenith angle.
Expand Down
2 changes: 1 addition & 1 deletion hera_sim/tests/test_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ def test_bad_initialization_data():


def test_integer_seed(base_sim):
seed = 2 ** 18
seed = 2**18
d1 = base_sim.add("noiselike_eor", add_vis=False, ret_vis=True, seed=seed)
d2 = base_sim.add("noiselike_eor", add_vis=False, ret_vis=True, seed=seed)
assert np.allclose(d1, d2)
Expand Down
2 changes: 1 addition & 1 deletion hera_sim/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def test_delay_filter_norm(freqs):

out /= nreal

assert np.isclose(out, np.sum(tsky ** 2), atol=0, rtol=1e-2)
assert np.isclose(out, np.sum(tsky**2), atol=0, rtol=1e-2)


@pytest.mark.parametrize("bl_len_ns", [50, 150])
Expand Down
30 changes: 15 additions & 15 deletions hera_sim/tests/test_vis.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(self, *args, **kwargs):
np.random.seed(0)
NTIMES = 10
BM_PIX = 31
NPIX = 12 * 16 ** 2
NPIX = 12 * 16**2
NFREQ = 5


Expand Down Expand Up @@ -114,7 +114,7 @@ def test_healvis_beam(uvdata, sky_model):
uvdata=uvdata,
sky_model=sky_model,
),
n_side=2 ** 4,
n_side=2**4,
)

assert len(sim.data_model.beams) == 1
Expand Down Expand Up @@ -271,7 +271,7 @@ def twin_sky_model(uvdata2):

def half_sky_model(uvdata2):
nbase = 4
nside = 2 ** nbase
nside = 2**nbase

sky = create_uniform_sky(
np.unique(uvdata2.freq_array),
Expand All @@ -288,8 +288,8 @@ def half_sky_model(uvdata2):
def create_uniform_sky(freq, nbase=4, scale=1) -> SkyModel:
"""Create a uniform sky with total (integrated) flux density of `scale`"""
nfreq = len(freq)
nside = 2 ** nbase
npix = 12 * nside ** 2
nside = 2**nbase
npix = 12 * nside**2
return SkyModel(
nside=nside,
hpx_inds=np.arange(npix),
Expand All @@ -316,7 +316,7 @@ def test_shapes(uvdata, simulator):
sim = VisibilitySimulation(
data_model=ModelData(uvdata=uvdata, sky_model=sky),
simulator=simulator(),
n_side=2 ** 4,
n_side=2**4,
)

assert sim.simulate().shape == (uvdata.Nblts, 1, NFREQ, uvdata.Npols)
Expand Down Expand Up @@ -373,7 +373,7 @@ def test_single_source_autocorr(uvdata, simulator, sky_model):
sky_model=sky_model,
),
simulator=simulator(),
n_side=2 ** 4,
n_side=2**4,
)
sim.simulate()

Expand All @@ -400,7 +400,7 @@ def test_single_source_autocorr_past_horizon(uvdata, simulator):
sky_model=sky_model,
),
simulator=simulator(),
n_side=2 ** 4,
n_side=2**4,
)
v = sim.simulate()

Expand Down Expand Up @@ -438,7 +438,7 @@ def test_viscpu_coordinate_correction(uvdata2):
assert np.allclose(v, v2)


def align_src_to_healpix(ra, dec, nside=2 ** 4):
def align_src_to_healpix(ra, dec, nside=2**4):
"""Where the point sources will be placed when converted to healpix model
Parameters
Expand Down Expand Up @@ -485,7 +485,7 @@ def test_comparison(uvdata2, sky_model, beam_model):
viscpu = VisibilitySimulation(data_model=model_data, simulator=cpu).simulate()

healvis = VisibilitySimulation(
data_model=model_data, simulator=healvis, n_side=2 ** 4
data_model=model_data, simulator=healvis, n_side=2**4
).simulate()

assert viscpu.shape == healvis.shape
Expand Down Expand Up @@ -515,7 +515,7 @@ def test_vis_cpu_pol_gpu(uvdata_linear):
uvdata=uvdata_linear, sky_model=sky_model, beams=[beam]
),
simulator=simulator,
n_side=2 ** 4,
n_side=2**4,
)

vis_cpu.HAVE_GPU = old
Expand All @@ -541,7 +541,7 @@ def test_ordering(uvdata_linear, simulator, order, conj):
sky_model=sky_model,
),
simulator=simulator(),
n_side=2 ** 4,
n_side=2**4,
)
sim.simulate()

Expand Down Expand Up @@ -605,13 +605,13 @@ def test_vis_cpu_pol(polarization_array, xfail):
VisibilitySimulation(
data_model=ModelData(uvdata=uvdata, sky_model=sky_model, beams=[beam]),
simulator=simulator,
n_side=2 ** 4,
n_side=2**4,
)
else:
VisibilitySimulation(
data_model=ModelData(uvdata=uvdata, sky_model=sky_model, beams=[beam]),
simulator=simulator,
n_side=2 ** 4,
n_side=2**4,
)


Expand Down Expand Up @@ -667,6 +667,6 @@ def test_bad_healvis_skymodel(sky_model):
def test_mK_healvis_skymodel(sky_model):
hv = HealVis()
sky_model.stokes = sky_model.stokes.value * units.mK
sky_model.nside = 2 ** 3
sky_model.nside = 2**3
sky = hv.get_sky_model(sky_model)
assert np.isclose(np.sum(sky.data), np.sum(sky_model.stokes[0].value / 1000))
6 changes: 3 additions & 3 deletions hera_sim/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def get_bl_len_magnitude(bl_len_ns: Union[float, np.ndarray, Sequence]) -> float
The magnitude of the baseline length.
"""
bl_len_ns = _get_bl_len_vec(bl_len_ns)
return np.sqrt(np.sum(bl_len_ns ** 2))
return np.sqrt(np.sum(bl_len_ns**2))


def gen_delay_filter(
Expand Down Expand Up @@ -123,7 +123,7 @@ def gen_delay_filter(

# normalize
if normalize is not None and np.any(delay_filter):
norm = normalize / np.sqrt(np.sum(delay_filter ** 2))
norm = normalize / np.sqrt(np.sum(delay_filter**2))
delay_filter *= norm * np.sqrt(len(delay_filter))

return delay_filter
Expand Down Expand Up @@ -451,7 +451,7 @@ def jansky_to_kelvin(freqs: np.ndarray, omega_p: Union[Beam, np.ndarray]) -> np.

wavelengths = const.c.value / (freqs * 1e9) # meters
# The factor of 1e-26 converts from Jy to W/m^2/Hz.
return 1e-26 * wavelengths ** 2 / (2 * const.k_B.value * omega_p)
return 1e-26 * wavelengths**2 / (2 * const.k_B.value * omega_p)


def Jy2T(freqs, omega_p):
Expand Down
2 changes: 1 addition & 1 deletion hera_sim/visibilities/simulators.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ class VisibilitySimulation:

data_model: ModelData
simulator: VisibilitySimulator
n_side: int = 2 ** 5
n_side: int = 2**5

def __post_init__(self):
"""Perform simple validation on combined attributes."""
Expand Down

0 comments on commit 9576e78

Please sign in to comment.