Skip to content

Commit

Permalink
merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
r-pascua committed Jan 18, 2024
2 parents 92095b8 + e1f8f61 commit 40b3491
Show file tree
Hide file tree
Showing 24 changed files with 716 additions and 653 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: monthly
12 changes: 6 additions & 6 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: Publish Python distributions to PyPI

# The idea here is that you would make a Release via the web interface on github,
# and this automatically then publishes to pypi

on:
push:
tags:
Expand All @@ -9,18 +12,15 @@ jobs:
build-n-publish:
name: Build and publish to PyPI
runs-on: ubuntu-latest
env:
ENV_NAME: publish
PYTHON: 3.8
steps:
- uses: actions/checkout@main
with:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON }}
python-version: "3.11"

- name: Install build
run: pip install build
Expand All @@ -31,7 +31,7 @@ jobs:
- name: Publish to PyPI
if: startsWith(github.event.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@master
uses: pypa/gh-action-pypi-publish@v1.8.11
with:
user: __token__
password: ${{ secrets.pypi_password }}
4 changes: 2 additions & 2 deletions .github/workflows/test_suite.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- uses: mpi4py/setup-mpi@v1

- name: Setup Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand All @@ -44,7 +44,7 @@ jobs:
python -m pytest --log-cli-level INFO
- name: Upload coverage report
uses: codecov/[email protected].3
uses: codecov/[email protected].4
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.xml
Expand Down
26 changes: 14 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ exclude: 'config.yaml|config_examples/.*.yaml|hera_sim/config/H1C.yaml|hera_sim/

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: check-added-large-files
Expand All @@ -18,7 +18,7 @@ repos:
- id: mixed-line-ending
args: ['--fix=no']
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0 # pick a git hash / tag to point to
rev: 7.0.0 # pick a git hash / tag to point to
hooks:
- id: flake8
additional_dependencies:
Expand All @@ -32,27 +32,29 @@ repos:
- flake8-bugbear
- flake8-comprehensions
- flake8-print
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:

- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.12.1
hooks:
- id: black
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: rst-backticks

- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: rst-backticks

- repo: https://github.com/PyCQA/isort
rev: 5.12.0
rev: 5.13.2
hooks:
- id: isort

- repo: https://github.com/asottile/pyupgrade
rev: v3.7.0
rev: v3.15.0
hooks:
- id: pyupgrade
args: [--py39-plus]

- repo: https://github.com/asottile/setup-cfg-fmt
rev: v2.3.0
rev: v2.5.0
hooks:
- id: setup-cfg-fmt
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
Changelog
=========

dev
===

Fixed
-----
- API calls for pyuvdata v2.4.0.

v4.1.0 [2023.06.26]
===================
This release heavily focuses on performance of the visibility simulators, and in
Expand Down
2 changes: 1 addition & 1 deletion config_examples/simulator.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
simulator: VisCPU
simulator: MatVis
precision: 2
ref_time: mean
correct_source_positions: true
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
]

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = "sphinx"
pygments_style = "trac"

# -- Options for HTML output -------------------------------------------------

Expand Down
38 changes: 30 additions & 8 deletions hera_sim/adjustment.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Module providing tools for adjusting simulation data/metadata to a reference."""

import copy
import logging
import numpy as np
import os
Expand Down Expand Up @@ -274,7 +273,7 @@ def match_antennas(
target = _to_uvdata(target)
if not target.future_array_shapes: # pragma: nocover
target.use_future_array_shapes()
target_copy = copy.deepcopy(target)
target_copy = target.copy()
reference = _to_uvdata(reference)
if not reference.future_array_shapes: # pragma: nocover
reference.use_future_array_shapes()
Expand Down Expand Up @@ -517,6 +516,12 @@ def iswrapped(lsts):

# Ensure reference parameters are a subset of target parameters.
if axis in ("time", "both"):
# Raise an error if the phasing isn't trivial
if not target._check_for_cat_type("unprojected").all():
raise ValueError(
"Time interpolation only supported for unprojected telescopes."
)

# Unwrap the LST axis if we have a phase wrap.
if iswrapped(target_lsts):
target_lsts[target_lsts < target_lsts[0]] += 2 * np.pi
Expand Down Expand Up @@ -546,6 +551,12 @@ def iswrapped(lsts):
new_baseline_array = np.empty(new_Nblts, dtype=int)
new_uvw_array = np.empty((new_Nblts, 3), dtype=float)
new_integration_times = np.empty(new_Nblts, dtype=float)
new_phase_center_id_array = np.zeros(new_Nblts, dtype=int)
new_phase_center_app_ra = np.empty(new_Nblts, dtype=float)
new_phase_center_app_dec = (
np.ones(new_Nblts, dtype=float) * target.phase_center_app_dec[0]
)
new_phase_center_frame_pa = np.zeros(new_Nblts, dtype=float)
if axis == "both":
new_data_shape = (new_Nblts, ref_freqs.size, target.Npols)
else:
Expand All @@ -556,6 +567,7 @@ def iswrapped(lsts):

# Actually update metadata and interpolate the data.
new_data = np.empty(new_data_shape, dtype=complex)
history_update = "" if target.history.endswith("\n") else "\n"
for i, antpair in enumerate(target.get_antpairs()):
if axis == "freq":
for pol_ind, pol in enumerate(target.polarization_array):
Expand All @@ -571,10 +583,10 @@ def iswrapped(lsts):
# Preparation for updating metadata.
ant1, ant2 = antpair
this_slice = slice(i, None, target.Nbls)
old_blt = target._key2inds(antpair)[0][0] # As a reference
this_uvw = target.uvw_array[old_blt]
this_baseline = target.baseline_array[old_blt]
this_integration_time = target.integration_time[old_blt]
old_blts = target._key2inds(antpair)[0] # As a reference
this_uvw = target.uvw_array[old_blts[0]]
this_baseline = target.baseline_array[old_blts[0]]
this_integration_time = target.integration_time[old_blts[0]]

# Now actually update the metadata.
new_ant_1_array[this_slice] = ant1
Expand All @@ -584,6 +596,10 @@ def iswrapped(lsts):
new_time_array[this_slice] = ref_times
new_lst_array[this_slice] = ref_lsts
new_integration_times[this_slice] = this_integration_time
phase_center_interp = interp1d(
target_lsts, target.phase_center_app_ra[old_blts], kind="linear"
)
new_phase_center_app_dec[this_slice] = phase_center_interp(ref_lsts)

# Update the data.
for pol_ind, pol in enumerate(target.polarization_array):
Expand Down Expand Up @@ -617,6 +633,7 @@ def iswrapped(lsts):
if axis in ("freq", "both"):
target.Nfreqs = ref_freqs.size
target.freq_array = ref_freqs
history_update += "Data interpolated in frequency with hera_sim.\n"
if axis in ("time", "both"):
target.Nblts = ref_times.size * target.Nbls
target.Ntimes = ref_times.size
Expand All @@ -627,9 +644,14 @@ def iswrapped(lsts):
target.baseline_array = new_baseline_array
target.uvw_array = new_uvw_array
target.integration_time = new_integration_times
target.phase_center_app_dec = new_phase_center_app_dec
target.phase_center_app_ra = new_phase_center_app_ra
target.phase_center_id_array = new_phase_center_id_array
target.phase_center_frame_pa = new_phase_center_frame_pa
target.blt_order = None
history_update += "Data interpolated in time with hera_sim.\n"

# Now update the data-like attributes
# Now update the data-like attributes; assumes input is unflagged, unavged
target.flag_array = np.zeros(new_data.shape, dtype=bool)
target.nsample_array = np.ones(new_data.shape, dtype=float)
target.data_array = new_data
Expand Down Expand Up @@ -789,7 +811,7 @@ def rephase_to_reference(
vis = data[antpairpol]
bl = bls[antpairpol]
new_data[this_slice, :, pol_ind] = lst_rephase(
vis, bl, data.freqs, dlst, lat=lat, array=True
vis, bl, data.freqs, dlst, lat=lat, inplace=False, array=True
)

# Convert from HERAData object to UVData object
Expand Down
2 changes: 1 addition & 1 deletion hera_sim/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def list_all_components(with_aliases: bool = True) -> str:
for cmp, models in cmps.items():
out += f"{cmp}:\n"

model_to_name = defaultdict(lambda: [])
model_to_name = defaultdict(list)
for name, model in models.items():
model_to_name[model].append(name)

Expand Down
2 changes: 1 addition & 1 deletion hera_sim/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def empty_uvdata(
# This is a bit of a hack, but this seems like the only way?
if pyuvdata.__version__ < "2.2.0":
uvd.set_drift()
else:
elif next(iter(uvd.phase_center_catalog.values()))["cat_type"] != "unprojected":
uvd.fix_phase()

# TODO: the following is a hack patch for pyuvsim which should be fixed there.
Expand Down
6 changes: 3 additions & 3 deletions hera_sim/sigchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -1087,12 +1087,12 @@ def build_coupling_matrix(
else:
power_beam = uvbeam.copy()
power_beam.efield_to_power()
if power_beam.interpolation_function is None:
power_beam.interpolation_function = pixel_interp
if power_beam.freq_interp_kind is None:
power_beam.freq_interp_kind = freq_interp
power_beam = power_beam.interp(
freq_array=freqs * units.GHz.to("Hz"), new_object=True
freq_array=freqs * units.GHz.to("Hz"),
new_object=True,
interpolation_function=pixel_interp,
) # Interpolate to the desired frequencies
power_beam.to_healpix()
power_beam.peak_normalize()
Expand Down
21 changes: 21 additions & 0 deletions hera_sim/tests/test_adjustment.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,27 @@ def test_interpolation_in_frequency_with_simulators(base_config, base_sim):
assert interpolated_sim.data.Nfreqs == base_config["Nfreqs"]


def test_interpolation_phased(base_config, base_sim):
base_config["Nfreqs"] = 200 # Increase frequency resolution.
base_config["start_freq"] = 105e6 # Ensure reference sim freqs contained in target.
base_config["bandwidth"] = 40e6
ref_sim = Simulator(**base_config)

# Simulate foregrounds.
base_sim.add("diffuse_foreground", Tsky_mdl=Tsky_mdl, omega_p=omega_p)
base_sim.data.phase_center_catalog[0]["cat_type"] = "sidereal"

# Interpolate base_sim to ref_sim along the frequency axis.
with pytest.raises(
ValueError, match="Time interpolation only supported for unprojected telescopes"
):
adjustment.interpolate_to_reference(
target=base_sim,
reference=ref_sim,
axis="time",
)


def test_interpolation_in_frequency_with_array(base_config, base_sim):
# Do the same as above, but this time pass a frequency array.
ref_freqs = np.linspace(105e6, 145e6, 200) # Hz
Expand Down
7 changes: 4 additions & 3 deletions hera_sim/tests/test_beams.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
stokes_matrix,
)
from hera_sim.defaults import defaults
from hera_sim.visibilities import ModelData, VisCPU, VisibilitySimulation
from hera_sim.visibilities import MatVis, ModelData, VisibilitySimulation

np.seterr(invalid="ignore")

Expand Down Expand Up @@ -61,7 +61,7 @@ def evaluate_polybeam(polybeam):
za = np.pi / 2 - np.arcsin(n)

freqs = np.arange(1e8, 2.01e8, 0.04e8)
print(len(freqs))

eval_beam = polybeam.interp(az, za, freqs)

# Check that calling the interp() method with wrongly sized
Expand Down Expand Up @@ -118,7 +118,7 @@ def run_sim(
# calculate source fluxes for hera_sim
flux = (freqs[:, np.newaxis] / freqs[0]) ** spectral_index * flux

simulator = VisCPU(
simulator = MatVis(
use_gpu=use_gpu,
mpi_comm=DummyMPIComm() if use_mpi else None,
precision=2,
Expand All @@ -137,6 +137,7 @@ def run_sim(
)
* units.Jy,
name=["derp"] * flux.shape[1],
frame="icrs",
),
)
simulation = VisibilitySimulation(
Expand Down
Loading

0 comments on commit 40b3491

Please sign in to comment.