PYTHON   71

pwi4 follow altaz csv

Guest on 15th August 2022 12:44:36 PM

  1. from pwi4_client import PWI4
  2. import sys
  3. import time
  4.  
  5. if len(sys.argv) < 2:
  6.     print("Usage: %s [csv_filename] [min_spacing_seconds]" % sys.argv[0])
  7.     print("  csv_filename (required): The file containing jd,coord0,coord1")
  8.     print("  min_spacing_seconds (optional): Resample the CSV with the specified time interval between points")
  9.     sys.exit(1)
  10.  
  11. filename = sys.argv[1]
  12. min_spacing_seconds = 0
  13. if len(sys.argv) > 2:
  14.     min_spacing_seconds = float(sys.argv[2])
  15. min_spacing_days = min_spacing_seconds / 86400.0
  16.  
  17. REPLAY = False  # If true, offset JDs so that first path point occurs "now"
  18. ITERATIONS = 9999 # How many times to repeat this path if REPLAY=True
  19. #COORD_TYPE = "altaz_topocentric" # The type of coordinates contained in the CSV file
  20. COORD_TYPE = "altaz_observed" # The type of coordinates contained in the CSV file
  21.  
  22. pwi4 = PWI4()
  23.  
  24. iterations_to_run = ITERATIONS
  25. if not REPLAY:
  26.     # If we aren't replaying a path, we can't follow
  27.     # that path again once the time has passed, so
  28.     # only run it once
  29.     iterations_to_run = 1  
  30.  
  31. for iteration in range(iterations_to_run):
  32.     print("Iteration %d" % iteration)
  33.  
  34.     jd_now = pwi4.status().mount.julian_date
  35.  
  36.     path_points = []  # Constains tuples of (jd, coord0_degs, coord1_degs)
  37.     first_jd = None
  38.     last_jd = None
  39.     num_points_in_file = 0
  40.     for rawline in open(filename):
  41.         line = rawline.strip()
  42.         if line == "":
  43.             continue
  44.         if line.startswith("#"):
  45.             continue
  46.         fields = line.split(",")
  47.         jd = float(fields[0])
  48.         coord0 = float(fields[1])
  49.         coord1 = float(fields[2])
  50.         num_points_in_file += 1
  51.  
  52.         if first_jd is None:
  53.             first_jd = jd
  54.  
  55.         if REPLAY:
  56.             jd = jd - first_jd + jd_now
  57.        
  58.         if last_jd is None or (jd - last_jd) > min_spacing_days:
  59.             path_points.append((jd, coord0, coord1))
  60.             last_jd = jd
  61.  
  62.     print("%d points in original file" % num_points_in_file)
  63.     if min_spacing_seconds > 0:
  64.         print("Resampled down to %d points with %.2f second mininmum spacing" % (
  65.             len(path_points),
  66.             min_spacing_seconds
  67.             )
  68.         )
  69.  
  70.     # Start a new path of the selected coordinate type
  71.     print("Creating new path")
  72.     pwi4.mount_custom_path_new(COORD_TYPE)
  73.  
  74.     # Upload a list of points
  75.     print("Uploading %d points" % len(path_points))
  76.     pwi4.mount_custom_path_add_point_list(path_points)
  77.  
  78.     # Begin following the path
  79.     print("Following...")
  80.     pwi4.mount_custom_path_apply()
  81.  
  82.     while True:
  83.         jd_now = pwi4.status().mount.julian_date
  84.         delta_seconds = (last_jd - jd_now) * 86400
  85.         if delta_seconds < 0:
  86.             print("Last point in path was at JD=%s (%.1f seconds ago). JD now is %s" % (last_jd, -delta_seconds, jd_now))
  87.             break
  88.         print("%d seconds remain" % delta_seconds)
  89.         time.sleep(10)

Raw Paste


Login or Register to edit or fork this paste. It's free.