Skip to content

Commit

Permalink
Add parameter for minimal and maximal altitudes
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross03 committed Dec 20, 2024
1 parent b65e290 commit 7bba756
Showing 1 changed file with 37 additions and 5 deletions.
42 changes: 37 additions & 5 deletions radiotools/visibility/visibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ def __init__(
location: str | EarthLocation = None,
obs_length: float = 4.0,
frame: str | BaseCoordinateFrame = "icrs",
min_alt: float = 15.0,
max_alt: float = 85.0,
print_optimal_date: bool = False,
) -> None:
"""Initializes the class with source and observation information.
Expand All @@ -83,8 +85,18 @@ def __init__(
frame : str or :class:`astropy.coordinates.BaseCoordinateFrame`, optional
Type of coordinate frame the source sky coordinates
should represent. Defaults: 'icrs'
min_alt : float, optional
The minimum altitude of the source (in degrees) above the horizon to
be determined as visible. Default: 15.0
max_alt : float, optional
The maximum altitude of the source (in degrees) above the horizon to
be determined as visible. Default: 85.0
print_optimal_date: bool, optional
If `True` prints the optimal date for the observation. Default: ``False``
"""
if isinstance(target, tuple):
if isinstance(target, tuple) or (
isinstance(target, np.ndarray) and target.size == 2
):
self.ra = u.Quantity(target[0], unit=u.deg)
self.dec = u.Quantity(target[1], unit=u.deg)
self.source = SkyCoord(self.ra, self.dec, frame=frame)
Expand Down Expand Up @@ -123,6 +135,19 @@ def __init__(
self.date = date
self.obs_length = obs_length

if min_alt > max_alt:
raise ValueError(
"The provided minimum altitude must be smaller then the maximum altitude!"
)

if min_alt < 0 or min_alt > 90 or max_alt < 0 or max_alt > 90:
raise ValueError(
"The minimum and maximum altitude must be in the range of 0 to 90 degrees!"
)

self.min_alt = min_alt
self.max_alt = max_alt

self._get_dates()
self._get_pos()

Expand Down Expand Up @@ -206,8 +231,8 @@ def _plot_config(self, ax) -> None:

text = "Solid lines indicate that the source\n"
text += "is visible. The visibility window is\n"
text += "limited to a range between 15 deg\n"
text += "and 85 deg. For array layouts with\n"
text += f"limited to a range between {self.min_alt} deg\n"
text += f"and {self.max_alt} deg. For array layouts with\n"
text += "more than 10 stations, only the first\n"
text += "station (ID 0) is shown."

Expand Down Expand Up @@ -277,7 +302,8 @@ def plot(self, figsize: tuple[int, int] = (10, 5), colors: list = None) -> tuple
color = next(colors)

mask = np.logical_and(
source_pos.alt > 15 * u.deg, 85 * u.deg > source_pos.alt
source_pos.alt > self.min_alt * u.deg,
self.max_alt * u.deg > source_pos.alt,
)
visible = source_pos.alt.copy()
visible.value[~mask] = np.nan
Expand Down Expand Up @@ -330,7 +356,7 @@ def get_optimal_date(self, print_result: bool = False) -> list:

for key, val in self.source_pos.items():
maximum = np.max(val.alt)
if maximum > 85 * u.deg or maximum < 15 * u.deg:
if maximum > self.max_alt * u.deg or maximum < self.min_alt * u.deg:
continue
idx_max = np.argmax(val.alt)
delta = datetime.timedelta(hours=self.obs_length / 2)
Expand All @@ -354,6 +380,12 @@ def get_optimal_date(self, print_result: bool = False) -> list:

dt[i, j] = self._time_delta(r1, r2)

if dt.sum(axis=0).size == 0:
raise ValueError(
"The source is not visible with the chosen parameters, "
"so no optimal date could be determined!"
)

result = times[np.argmax(dt.sum(axis=0))]

if print_result:
Expand Down

0 comments on commit 7bba756

Please sign in to comment.