Skip to content

skyweaver.viz.sky

Sky-track plotting utilities.

plot_sky_track

plot_sky_track(track, ax=None, *, cmap=None, color=None, alpha=1.0, lw=1.5)

Plot a satellite sky track in polar alt-az coordinates.

Source code in src/skyweaver/viz/sky.py
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
def plot_sky_track(
    track: SkyTrack,
    ax: PolarAxes | None = None,
    *,
    cmap: str | Colormap | None = None,
    color: str | None = None,
    alpha: float = 1.0,
    lw: float = 1.5,
) -> PolarAxes:
    """Plot a satellite sky track in polar alt-az coordinates."""
    if ax is None:
        _, ax0 = plt.subplots(subplot_kw={"projection": "polar"}, figsize=(7, 7))
        ax = cast(PolarAxes, ax0)

    passes = track.passes()

    if cmap is None:
        pass_colors = [color] * len(passes)
    else:
        cmap_obj = colormaps[cmap] if isinstance(cmap, str) else cmap

        n_passes = len(passes)
        if n_passes == 0:
            pass_colors = []
        elif n_passes == 1:
            pass_colors = [cmap_obj(0.5)]
        else:
            pass_colors = list(cmap_obj(np.linspace(0.0, 1.0, n_passes)))

    for sat_pass, pass_color in zip(passes, pass_colors, strict=True):
        _plot_single_pass(
            sat_pass,
            ax,
            color=pass_color,
            alpha=alpha,
            lw=lw,
        )

    ax.set_title(f"Sky track: {track.orbit.name} at {track.observatory.name}")
    ax.set_theta_zero_location("N")
    ax.set_theta_direction(-1)
    ax.set_ylim(90.0, 0.0)
    ax.set_rgrids([30.0, 60.0, 90.0])
    ax.set_rlabel_position(67.5)
    ax.grid(True)

    return ax

plot_sky_track_healpix

plot_sky_track_healpix(track, *, nside=32, unique_per_pass=True, cmap=None, title=None, unit='counts', half_sky=True, rot=(0, 90, 180), graticule=True, **kwargs)

Plot a HEALPix map of a sky track in local alt-az coordinates.

Parameters:

Name Type Description Default
track SkyTrack

Sky track to bin into HEALPix pixels.

required
nside int

HEALPix nside parameter.

32
unique_per_pass bool

If True, count each pixel at most once per pass.

True
cmap

Optional colormap passed to healpy.

None
title str | None

Plot title. If None, a default title is used.

None
unit str

Colorbar/unit label passed to healpy.

'counts'
half_sky bool

Whether to use a half-sky orthographic projection.

True
rot list[float] | tuple[float, float, float]

Rotation passed to healpy.orthview.

(0, 90, 180)
graticule bool

If True, overlay a graticule and cardinal directions.

True
**kwargs

Additional keyword arguments passed to healpy.orthview.

{}

Returns:

Type Description
ndarray

The HEALPix map that was plotted.

Source code in src/skyweaver/viz/sky.py
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
def plot_sky_track_healpix(
    track: SkyTrack,
    *,
    nside: int = 32,
    unique_per_pass: bool = True,
    cmap=None,
    title: str | None = None,
    unit: str = "counts",
    half_sky: bool = True,
    rot: list[float] | tuple[float, float, float] = (0, 90, 180),
    graticule: bool = True,
    **kwargs,
) -> np.ndarray:
    """Plot a HEALPix map of a sky track in local alt-az coordinates.

    Parameters
    ----------
    track
        Sky track to bin into HEALPix pixels.
    nside
        HEALPix nside parameter.
    unique_per_pass
        If True, count each pixel at most once per pass.
    cmap
        Optional colormap passed to healpy.
    title
        Plot title. If None, a default title is used.
    unit
        Colorbar/unit label passed to healpy.
    half_sky
        Whether to use a half-sky orthographic projection.
    rot
        Rotation passed to ``healpy.orthview``.
    graticule
        If True, overlay a graticule and cardinal directions.
    **kwargs
        Additional keyword arguments passed to ``healpy.orthview``.

    Returns
    -------
    np.ndarray
        The HEALPix map that was plotted.
    """
    healpix_map = track.to_healpix(
        nside=nside,
        unique_per_pass=unique_per_pass,
    )

    if title is None:
        title = f"Sky HEALPix map: {track.orbit.name} at {track.observatory.name}"

    hp.orthview(
        healpix_map,
        rot=rot,
        half_sky=half_sky,
        cmap=cmap,
        unit=unit,
        title=title,
        **kwargs,
    )

    if graticule:
        hp.visufunc.graticule(15, 30, ls=":", color="whitesmoke", alpha=0.5)

        hp.visufunc.projtext(
            0,
            21,
            "N",
            lonlat=True,
            ha="center",
            va="center",
            fontsize=14,
            color="w",
        )
        hp.visufunc.projtext(
            90,
            21,
            "E",
            lonlat=True,
            ha="center",
            va="center",
            fontsize=14,
            color="w",
        )
        hp.visufunc.projtext(
            180,
            21,
            "S",
            lonlat=True,
            ha="center",
            va="center",
            fontsize=14,
            color="w",
        )
        hp.visufunc.projtext(
            270,
            21,
            "W",
            lonlat=True,
            ha="center",
            va="center",
            fontsize=14,
            color="w",
        )

    return healpix_map