Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the new pyuvdata analytic short dipole beam in our polarized source test. #268

Merged
merged 3 commits into from
Dec 2, 2024
Merged
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## [Unreleased]

### Changed
- Use the new pyuvdata analytic short dipole beam for polarized source testing.
- Updated minimum dependency versions: pyuvdata>=3.1.0
- Updated minimum optional dependency versions: lunarsky>=0.2.5

## [1.0.1] - 2024-07-01

### Changed
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ Required:
* h5py>=3.4
* numpy>=1.23
* scipy>=1.8
* pyuvdata>=2.4.3
* pyuvdata>=3.1.0
* setuptools_scm>=8.1

Optional:

* astropy-healpix>=1.0.2 (for working with beams in HEALPix formats)
* astroquery>=0.4.4 (for downloading GLEAM and other VizieR catalogs)
* lunarsky>=0.2.2 (for supporting telescope locations on the moon)
* lunarsky>=0.2.5 (for supporting telescope locations on the moon)

We suggest using conda to install all the dependencies. To install
pyuvdata, astropy-healpix and astroquery, you'll need to add conda-forge as a channel
Expand Down
4 changes: 2 additions & 2 deletions ci/full_deps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ dependencies:
- numpy>=1.23
- pip
- pytest-cov
- pyuvdata>=2.4.3
- pyuvdata>=3.1.0
- scipy>=1.8
- setuptools_scm>=8.1
- pip:
- lunarsky>=0.2.2
- lunarsky>=0.2.5
2 changes: 1 addition & 1 deletion ci/min_deps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dependencies:
- numpy>=1.23
- pytest
- pytest-cov
- pyuvdata>=2.4.3
- pyuvdata>=3.1.0
- scipy>=1.8
- setuptools_scm>=8.1
- pip
4 changes: 2 additions & 2 deletions ci/min_versions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies:
- coverage
- pytest-cov
- setuptools_scm==8.1
- pyuvdata==2.4.3
- pyuvdata==3.1.1 # 3.1.0 is not available on conda
- pip
- pip:
- lunarsky==0.2.2
- lunarsky==0.2.5
2 changes: 1 addition & 1 deletion ci/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ dependencies:
- h5py>=3.4
- numpy>=1.23
- pip
- pyuvdata>=2.4.3
- pyuvdata>=3.1.0
- scipy>=1.8
- setuptools_scm>=8.1
- pip:
Expand Down
2 changes: 1 addition & 1 deletion docs/references/skyh5_memo.tex
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ \section{Introduction}
We assume that the user has a working knowledge of HDF5 and the associated
python bindings in the package \texttt{h5py}\footnote{\url{https://www.h5py.org/}}, as
well as \texttt{SkyModel} objects in \texttt{pyradiosky}. For more information about
HDF5, pleasevisit \url{https://portal.hdfgroup.org/display/HDF5/HDF5}. For more
HDF5, please visit \url{https://portal.hdfgroup.org/display/HDF5/HDF5}. For more
information about the parameters present in a \texttt{SkyModel} object, please visit
\url{https://pyradiosky.readthedocs.io/en/latest/skymodel.html}.
Examples of how to interact with \texttt{SkyModel} objects in \texttt{pyradiosky} are
Expand Down
4 changes: 2 additions & 2 deletions environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ dependencies:
- pre-commit
- pypandoc
- pytest-cov
- pyuvdata>=2.4.3
- pyuvdata>=3.1.0
- scipy>=1.8
- setuptools_scm>=8.1
- sphinx
- pip:
- lunarsky>=0.2.2
- lunarsky>=0.2.5
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dependencies = [
"astropy>=6.0",
"h5py>=3.4",
"numpy>=1.23",
"pyuvdata>=2.4.3",
"pyuvdata>=3.1.0",
"scipy>=1.8",
"setuptools>=64",
"setuptools_scm>=8.1",
Expand All @@ -42,7 +42,7 @@ classifiers = [
[project.optional-dependencies]
healpix = ["astropy-healpix>=1.0.2"]
astroquery = ["astroquery>=0.4.4"]
lunarsky = ["lunarsky>=0.2.2"]
lunarsky = ["lunarsky>=0.2.5"]
all = ["pyradiosky[healpix,astroquery,lunarsky]"]
test = ["coverage", "pre-commit", "pytest", "pytest-cov"]
doc = ["matplotlib", "pypandoc", "sphinx"]
Expand Down
11 changes: 2 additions & 9 deletions src/pyradiosky/skymodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import astropy.units as units
import h5py
import numpy as np
import pyuvdata.utils.history as history_utils
import pyuvdata.utils.tools as uvutils
import scipy.io
from astropy.coordinates import (
AltAz,
Expand All @@ -30,15 +32,6 @@

from . import __version__, spherical_coords_transforms as sct, utils as skyutils

try: # pragma: no cover # This pragma can be removed once pyuvdata v3 is released.
import pyuvdata.utils.history as history_utils
import pyuvdata.utils.tools as uvutils
except ImportError:
# this can be removed once we require pyuvdata >= v3.0
import pyuvdata.utils as history_utils
import pyuvdata.utils as uvutils


__all__ = ["hasmoon", "SkyModel"]

try:
Expand Down
68 changes: 41 additions & 27 deletions tests/test_skymodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,7 @@
import h5py
import numpy as np
import pytest

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

import pyuvdata.utils.history as history_utils
import scipy.io
from astropy import units
from astropy.coordinates import (
Expand All @@ -32,6 +24,8 @@
)
from astropy.time import Time, TimeDelta
from astropy.units import Quantity
from pyuvdata import ShortDipoleBeam
from pyuvdata.testing import check_warnings

from pyradiosky import SkyModel, skymodel, utils as skyutils
from pyradiosky.data import DATA_PATH as SKY_DATA_PATH
Expand Down Expand Up @@ -1355,22 +1349,6 @@ def test_pol_rotator(time_location, spectral_type, unpolarized, below_horizon):
)


def analytic_beam_jones(za, az, sigma=0.3):
"""
Analytic beam with sensible polarization response.

Required for testing polarized sources.
"""
# B = np.exp(-np.tan(za/2.)**2. / 2. / sigma**2.)
B = 1
# J alone gives you the dipole beam.
# B can be used to add another envelope in addition.
J = np.array(
[[np.cos(za) * np.sin(az), np.cos(az)], [np.cos(az) * np.cos(za), -np.sin(az)]]
)
return B * J


def test_polarized_source_visibilities(time_location):
"""Test that visibilities of a polarized source match prior calculations."""
time0, array_location = time_location
Expand Down Expand Up @@ -1428,7 +1406,25 @@ def test_polarized_source_visibilities(time_location):
coherency_matrix_local[:, :, ti] = coherency_tmp

zas = np.pi / 2.0 - alts
Jbeam = analytic_beam_jones(zas, azs)

# use pyuvdata ShortDipoleBeam for a sensible polarized response
dipole_beam = ShortDipoleBeam()
Jbeam = dipole_beam.efield_eval(
az_array=np.asarray(azs),
za_array=np.asarray(zas),
freq_array=np.asarray([150e6]),
)

# swap axes to put feed axis first then basis vector axis to match what is
# done in pyuvsim
Jbeam = np.transpose(Jbeam[:, :, 0].real, axes=[1, 0, 2])

# put ZA response first, then Az response to match what is done in pyuvsim
Jbeam = np.flip(Jbeam, axis=1)

# put north dipole first, then east to match test data
Jbeam = np.flip(Jbeam, axis=0)

coherency_instr_local = np.einsum(
"ab...,bc...,dc...->ad...", Jbeam, coherency_matrix_local, np.conj(Jbeam)
)
Expand Down Expand Up @@ -1538,7 +1534,25 @@ def test_polarized_source_smooth_visibilities(
coherency_matrix_local[:, :, ti] = coherency_tmp

zas = np.pi / 2.0 - alts
Jbeam = analytic_beam_jones(zas, azs)

# use pyuvdata ShortDipoleBeam for a sensible polarized response
dipole_beam = ShortDipoleBeam()
Jbeam = dipole_beam.efield_eval(
az_array=np.asarray(azs),
za_array=np.asarray(zas),
freq_array=np.asarray([150e6]),
)

# swap axes to put feed axis first then basis vector axis to match what is
# done in pyuvsim
Jbeam = np.transpose(Jbeam[:, :, 0].real, axes=[1, 0, 2])

# put ZA response first, then Az response to match what is done in pyuvsim
Jbeam = np.flip(Jbeam, axis=1)

# put north dipole first, then east to match test data
Jbeam = np.flip(Jbeam, axis=0)

coherency_instr_local = np.einsum(
"ab...,bc...,dc...->ad...", Jbeam, coherency_matrix_local, np.conj(Jbeam)
)
Expand Down
Loading