Skip to content

Commit

Permalink
Make imports work with current and future pyuvdata
Browse files Browse the repository at this point in the history
  • Loading branch information
bhazelton committed Jun 20, 2024
1 parent 914e399 commit a9c8476
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
20 changes: 13 additions & 7 deletions src/pyradiosky/skymodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import astropy.units as units
import h5py
import numpy as np
import pyuvdata.utils as uvutils
import scipy.io
from astropy.coordinates import (
AltAz,
Expand All @@ -34,6 +33,13 @@
from . import spherical_coords_transforms as sct
from . import utils as skyutils

try:
import pyuvdata.utils.helpers as uv_helpers
except ImportError:
# this can be removed once we require pyuvdata >= v3.0
import pyuvdata.utils as uv_helpers


__all__ = ["hasmoon", "SkyModel"]

try:
Expand Down Expand Up @@ -321,7 +327,7 @@ def _get_freq_edges_from_centers(freq_array, tols, raise_error=True):
"Cannot calculate frequency edges from frequency center array because "
"there is only one frequency center."
)
if not uvutils._test_array_constant_spacing(freq_array.value, tols=tols_use):
if not uv_helpers._test_array_constant_spacing(freq_array.value, tols=tols_use):
raise ValueError(
"Cannot calculate frequency edges from frequency center array because "
"frequency center spacing is not constant."
Expand Down Expand Up @@ -1049,7 +1055,7 @@ def __init__(
self._filename.form = (len(filename_use),)

self.history = history
if not uvutils._check_history_version(
if not uv_helpers._check_history_version(
self.history, self.pyradiosky_version_str
):
self.history += self.pyradiosky_version_str
Expand Down Expand Up @@ -2890,21 +2896,21 @@ def concat(
this.Ncomponents = this.Ncomponents + other.Ncomponents

# Update filename parameter
this.filename = uvutils._combine_filenames(this.filename, other.filename)
this.filename = uv_helpers._combine_filenames(this.filename, other.filename)
if this.filename is not None:
this._filename.form = (len(this.filename),)

history_update_string = (
" Combined skymodels along the component axis using pyradiosky."
)
histories_match = uvutils._check_histories(this.history, other.history)
histories_match = uv_helpers._check_histories(this.history, other.history)

this.history += history_update_string
if not histories_match:
if verbose_history:
this.history += " Next object history follows. " + other.history
else:
extra_history = uvutils._combine_history_addition(
extra_history = uv_helpers._combine_history_addition(
this.history, other.history
)
if extra_history is not None:
Expand Down Expand Up @@ -4906,7 +4912,7 @@ def write_skyh5(
if self.history is None:
self.history = self.pyradiosky_version_str
else:
if not uvutils._check_history_version(
if not uv_helpers._check_history_version(
self.history, self.pyradiosky_version_str
):
self.history += self.pyradiosky_version_str
Expand Down
13 changes: 7 additions & 6 deletions tests/test_skymodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
import pytest

try:
import pyuvdata.utils.helpers as uv_helpers
from pyuvdata.testing import check_warnings
except ImportError:
# this can be removed once we require pyuvdata >= v3.0
from pyuvdata.tests import check_warnings
import pyuvdata.utils as uv_helpers

import pyuvdata.utils as uvutils
import scipy.io
from astropy import units
from astropy.coordinates import (
Expand Down Expand Up @@ -1628,7 +1629,7 @@ def test_concat(comp_type, spec_type, healpix_disk_new):
+ " Combined skymodels along the component axis using pyradiosky."
+ " Combined skymodels along the component axis using pyradiosky."
)
assert uvutils._check_histories(skyobj_new.history, expected_history)
assert uv_helpers._check_histories(skyobj_new.history, expected_history)

skyobj_new.history = skyobj_full.history
assert skyobj_new == skyobj_full
Expand All @@ -1650,7 +1651,7 @@ def test_concat(comp_type, spec_type, healpix_disk_new):
skyobj_new = skyobj1.concat(skyobj2, inplace=False, run_check=False)
skyobj_new.concat(skyobj3)
assert skyobj_new.history != skyobj_full.history
assert uvutils._check_histories(skyobj_new.history, expected_history)
assert uv_helpers._check_histories(skyobj_new.history, expected_history)

skyobj_new = skyobj1.concat(skyobj2, inplace=False, verbose_history=True)
skyobj_new.concat(skyobj3, verbose_history=True)
Expand All @@ -1665,7 +1666,7 @@ def test_concat(comp_type, spec_type, healpix_disk_new):
+ "Next object history follows. "
+ skyobj3.history
)
assert uvutils._check_histories(skyobj_new.history, expected_history)
assert uv_helpers._check_histories(skyobj_new.history, expected_history)


@pytest.mark.parametrize(
Expand Down Expand Up @@ -2135,12 +2136,12 @@ def test_flux_source_cuts():
expected_history2 = (
skyobj.history + " Downselected to specific components using pyradiosky."
)
assert uvutils._check_histories(skyobj2.history, expected_history2)
assert uv_helpers._check_histories(skyobj2.history, expected_history2)

expected_history3 = (
skyobj.history + " Downselected to specific components using pyradiosky."
)
assert uvutils._check_histories(skyobj3.history, expected_history3)
assert uv_helpers._check_histories(skyobj3.history, expected_history3)

skyobj2.history = skyobj3.history

Expand Down

0 comments on commit a9c8476

Please sign in to comment.