Advertisement
Guest User

Untitled

a guest
Oct 5th, 2023
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. import numpy as np
  2. import warnings
  3. warnings.filterwarnings("ignore")
  4.  
  5. from typing import Callable
  6.  
  7. import pytz
  8. import skyfield.searchlib
  9. from skyfield import api, timelib
  10. from skyfield.jpllib import SpiceKernel, ChebyshevPosition
  11. from skyfield.vectorlib import VectorSum
  12. from skyfield.framelib import ecliptic_frame
  13.  
  14.  
  15. def ecliptic_longitude_exceeds(
  16. longitude: float,
  17. target: str|VectorSum|ChebyshevPosition,
  18. ephemeris: SpiceKernel) -> Callable[[timelib.Time], np.array]:
  19. """
  20. Creates functions that check whether target ecliptic longitude exceeds
  21. value at a specified time
  22. :param longitude: Ecliptic Longitude in decimal degrees
  23. :param target: Object to be checked
  24. :param ephemeris: Ephemeris to be used.
  25. :return: find_discrete-compatible function
  26. """
  27.  
  28. # Change to observe from Earth instead of the Sun
  29. earth = ephemeris['earth']
  30. target = ephemeris[target] if isinstance(target, str) else target
  31.  
  32. def function(time: timelib.Time) -> np.array:
  33. """
  34. :param time: Time of Observation
  35. :return: Array of booleans indicating whether ecliptic longitude > longitude
  36. """
  37. observation = earth.at(time).observe(target).apparent() # Observe from Earth
  38. observed_longitude = observation.frame_latlon(ecliptic_frame)[1]
  39.  
  40. # Use the suggested formula to check longitude exceeds
  41. return ((observed_longitude.degrees - longitude) // 180).astype(int) % 2
  42.  
  43. # Use a step_days of ~1/4 of the expected period
  44. function.step_days = 25 # Adjust this value as needed
  45.  
  46. return function
  47.  
  48.  
  49. def main():
  50.  
  51. ephemeris = api.load('de441.bsp')
  52. ts = api.load.timescale()
  53. utc = pytz.timezone("UTC")
  54. #start, stop = ts.utc(2023), ts.utc(2024)
  55. start = ts.utc(2023, 10, 1) # April 1, 2023
  56. stop = ts.utc(2023, 12, 31) # June 30, 2024
  57.  
  58. moon_exceeds = ecliptic_longitude_exceeds(
  59. longitude=24.5, target="moon", ephemeris=ephemeris
  60. )
  61.  
  62. times, states = skyfield.searchlib.find_discrete(start, stop, moon_exceeds)
  63.  
  64. # Filter longitude_times by in_state == 0
  65. longitude_times = [time for time, in_state in zip(times.astimezone(utc), states) if not in_state]
  66.  
  67. print('\n'.join(str(lt) for lt in longitude_times))
  68.  
  69.  
  70. if __name__ == '__main__':
  71. main()
  72.  
  73. I started with 15 days and increased by 1 day at a time until i got only one date but its not where it should be
  74.  
  75. python skyfieldnode1.py
  76. 2023-11-24 11:02:49.675913+00:00
  77.  
  78.  
  79. ./swetest -pt -b17.11.2023 -ut22:43
  80. ./swetest -pt -b17.11.2023 -ut22:43
  81. date (dmy) 17.11.2023 greg. 22:43:00 UT version 2.10.03
  82. UT: 2460266.446527778 delta t: 69.109781 sec
  83. TT: 2460266.447327659
  84. Epsilon (t/m) 23°26'18.3245 23°26'10.2223
  85. Nutation -0° 0' 7.8330 0° 0' 8.1021
  86. true Node 24°29'59.7465 0° 0' 0.0000 0.002502442 -0° 3'35.2933
  87.  
  88.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement