Skip to content

Commit

Permalink
Merge pull request #17 from radionets-project/test_vis_alt_restriction
Browse files Browse the repository at this point in the history
Add test for source vis alt restrictions
  • Loading branch information
aknierim authored Jan 6, 2025
2 parents 5623781 + c1fd23c commit 8607e47
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/changes/17.optimization.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Add test for source visibility altitude restrictions in `tests/test_source_visibility.py`
- Fix typo in `utils.py`
2 changes: 1 addition & 1 deletion radiotools/plotting/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def px2radec(
axis size is used. Default: ``None``
num_ticks : int or tuple, optional
Number of ticks on the axes. If given a tuple,
element 0 correponds to the number of ticks on the
element 0 corresponds to the number of ticks on the
x-axis, while element 1 corresponds to the y-axis.
unit : str, optional
The unit of the ticks. Can be one of ``'microarcsecond'``,
Expand Down
34 changes: 34 additions & 0 deletions tests/test_source_visibility.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from contextlib import contextmanager

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd


Expand Down Expand Up @@ -36,3 +37,36 @@ def test_source_visibility():
]

assert dates == expected_dates


def test_source_visibility_alt_restrictions():
from radiotools.visibility import SourceVisibility

alts = np.array([np.arange(0, 95, 5), np.arange(90, -5, -5)])

opt_dates = [
pd.Timestamp("2022-12-31 16:29:11"),
pd.Timestamp("2022-12-31 22:29:11"),
pd.Timestamp("2023-01-01 04:29:11"),
]

results = []

for i in np.arange(alts.shape[1]):
try:
results.append(
SourceVisibility(
target="crab",
date="2022-12-31",
location="vla",
obs_length=12.0,
min_alt=alts[0][i],
max_alt=alts[1][i],
).get_optimal_date()
== opt_dates
)
except ValueError:
results.append(False)

assert np.all(results[:5])
assert np.all(np.logical_not(results[5:]))

0 comments on commit 8607e47

Please sign in to comment.