diff --git a/docs/changes/17.optimization.rst b/docs/changes/17.optimization.rst new file mode 100644 index 0000000..3d7ae08 --- /dev/null +++ b/docs/changes/17.optimization.rst @@ -0,0 +1,2 @@ +- Add test for source visibility altitude restrictions in `tests/test_source_visibility.py` +- Fix typo in `utils.py` diff --git a/radiotools/plotting/utils.py b/radiotools/plotting/utils.py index 6366c83..7de6020 100644 --- a/radiotools/plotting/utils.py +++ b/radiotools/plotting/utils.py @@ -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'``, diff --git a/tests/test_source_visibility.py b/tests/test_source_visibility.py index ebe84c4..8f643eb 100644 --- a/tests/test_source_visibility.py +++ b/tests/test_source_visibility.py @@ -1,6 +1,7 @@ from contextlib import contextmanager import matplotlib.pyplot as plt +import numpy as np import pandas as pd @@ -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:]))