astropy / astroplan

Observation planning package for astronomers – maintainer @bmorris3
https://astroplan.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
199 stars 109 forks source link

Add `origin_mismatch` option to constraints on angular separations #598

Open monodera opened 9 hours ago

monodera commented 9 hours ago

As noted in the astropy document, a warning is emitted if the coordinate transformation can cause the angular separation value to be order-dependent.

https://docs.astropy.org/en/stable/coordinates/common_errors.html#object-separation

This warning can be very long when supplying a time or a target array with many elements. I'd like to have the origin_mismatch option with warn as the default for these constraints class related to object separations.

Apparently, only sun and moon constraints needs to be updated, so changes will be small. However, I'm not sure which place is the best location to do this. For example, one can set at the initialization of the class object or at compute_constraint() for each actrual calculation.

monodera commented 9 hours ago

Here is a code to reproduce the issue.

import astropy.units as u
from astroplan import (
    FixedTarget,
    MoonSeparationConstraint,
    Observer,
    time_grid_from_range,
)
from astropy.time import Time

# Define the observer location
observer = Observer.at_site("subaru")

# Define the time of observation
# time = Time("2024-11-01 06:00:00")
time = time_grid_from_range(
    Time(["2024-11-01 06:00:00", "2024-11-2 12:00:00"]), time_resolution=1 * u.hour
)

# Define Altair's position
altair = FixedTarget.from_name("Altair")

is_moon_sep = MoonSeparationConstraint(min=30 * u.deg).compute_constraint(
    time, observer, altair
)

print(is_moon_sep)

The output looks like the following:

WARNING: NonRotationTransformationWarning: transforming other coordinates from <ICRS Frame> to <GCRS Frame (obstime=[2460615.75       2460615.79166667 2460615.83333333 2460615.875
 2460615.91666667 2460615.95833333 2460616.         2460616.04166667
 2460616.08333333 2460616.125      2460616.16666667 2460616.20833333
 2460616.25       2460616.29166666 2460616.33333333 2460616.375
 2460616.41666666 2460616.45833333 2460616.5        2460616.54166666
 2460616.58333333 2460616.625      2460616.66666666 2460616.70833333
 2460616.75       2460616.79166666 2460616.83333333 2460616.875
 2460616.91666666 2460616.95833333], obsgeoloc=[( 5458755.11003467, -2516673.60527893, 2137903.93412022),
 ( 5925040.40529078, -1015180.69622756, 2136724.35471743),
 ( 5985697.51507074,   555877.85742337, 2136518.58968424),
 ( 5636570.22364069,  2088853.33558418, 2137300.74504035),
 ( 4901580.6866605 ,  3478706.46530145, 2139017.23199948),
 ( 3831090.28833509,  4630204.69744148, 2141550.43853266),
 ( 2498448.88622571,  5464447.52799117, 2144726.78798785),
 (  994968.88899754,  5924272.74985137, 2148328.63260246),
 ( -576331.45738994,  5978173.19948575, 2152109.16696554),
 (-2107786.86586661,  5622455.62347709, 2155809.33954631),
 (-3494462.21906323,  4881493.73974981, 2159175.60348554),
 (-4641342.70926342,  3806058.15373756, 2161977.29032919),
 (-5469844.24009132,  2469837.56341173, 2164022.41621114),
 (-5923197.9980933 ,   964389.61973115, 2165170.83739422),
 (-5970340.24410597,  -607132.5911369 , 2165343.853699  ),
 (-5608040.79643232, -2137048.58323382, 2164529.601741  ),
 (-4861124.3624515 , -3520528.72304739, 2162783.86838417),
 (-3780769.55304816, -4662777.14172733, 2160226.26863325),
 (-2441002.13116331, -5485527.13511121, 2157032.04982652),
 ( -933622.77377211, -5932403.98807659, 2153420.08370663),
 (  638083.08975828, -5972787.75956537, 2149637.86906414),
 ( 2166422.38885398, -5603911.3610131 , 2145944.57275684),
 ( 3546673.52406901, -4851050.1550868 , 2142593.27098361),
 ( 4684261.87684442, -3765790.09127087, 2139813.6077687 ),
 ( 5501240.04951876, -2422493.04361828, 2137796.05892514),
 ( 5941628.81041949,  -913201.54524705, 2136678.8797841 ),
 ( 5975252.783208  ,   658667.95352019, 2136538.63108875),
 ( 5599808.05956396,  2185411.1662779 , 2137384.93227458),
 ( 4841020.06266928,  3562415.85360496, 2139159.80169356),
 ( 3750880.84470717,  4695329.83949315, 2141741.62903419)] m, obsgeovel=[( 183.52413261,  397.68227993, -0.45689588),
 (  74.03385279,  431.68444788, -0.1946207 ),
 ( -40.52921654,  436.10765624,  0.08099212),
 (-152.31522947,  410.64882737,  0.35105693),
 (-253.66462362,  357.05239675,  0.59706811),
 (-337.63295229,  278.99078453,  0.80216812),
 (-398.46671705,  181.81276173,  0.95230266),
 (-431.99759661,   72.17695324,  1.03718372),
 (-435.92805967,  -42.40441025,  1.05099452),
 (-409.98879145, -154.08022933,  0.99278821),
 (-355.95714706, -255.19849208,  0.8665527 ),
 (-277.53536743, -338.83058889,  0.68093749),
 (-180.09690222, -399.24605989,  0.44866102),
 ( -70.31822179, -432.30524523,  0.18563917),
 (  44.27865362, -435.74293402, -0.0901053 ),
 ( 155.84156171, -409.3235763 , -0.35967768),
 ( 256.7262272 , -354.85742286, -0.60460605),
 ( 340.02004657, -276.07648712, -0.80810702),
 ( 400.01573864, -178.37882807, -0.95623575),
 ( 432.6024068 ,  -68.45867579, -1.03884158),
 ( 435.54721685,   46.15225564, -1.05026354),
 ( 408.64839079,  157.6008408 , -0.98971835),
 ( 353.74903255,  258.25063776, -0.86135412),
 ( 274.61083868,  341.20513612, -0.67396612),
 ( 176.65634747,  400.78030493, -0.4403942 ),
 (  66.59738735,  432.89406172, -0.17664295),
 ( -48.0248167 ,  435.34597622,  0.09921488),
 (-159.35636683,  407.96804361,  0.36827683),
 (-259.76884036,  352.63619608,  0.61210591),
 (-342.38198825,  273.14176433,  0.813994  )] m / s)>. Angular separation can depend on the direction of the transformation. [astropy.coordinates.baseframe]
[ True  True  True  True  True  True  True  True  True  True  True  True
  True  True  True  True  True  True  True  True  True  True  True  True
  True  True  True  True  True  True]