Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
gnthibault committed Aug 15, 2023
1 parent b575817 commit 314d5bb
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 104 deletions.
1 change: 0 additions & 1 deletion Manager/Manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,6 @@ def _setup_services(self):
setup various services that are supposed to provide infos/data
"""
try:
# TODO TN, I need to properly split observatory related webmanager and services related
self._setup_time_service()
self._setup_weather_service()
self._setup_messaging()
Expand Down
3 changes: 1 addition & 2 deletions ObservationPlanner/Scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,7 @@ def define_target(self, target_name):
frame='icrs',
equinox='J2000.0'))
except:
raise RuntimeError(f"Scheduler: did not managed to "
f"define target {target_name}")
raise RuntimeError(f"Scheduler: did not managed to define target {target_name}")
return target

def initialize_target_list(self):
Expand Down
3 changes: 1 addition & 2 deletions ObservationPlanner/SpectroScheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ def define_target(self, target_name):
target = FixedTarget(name=target_name.replace(" ", ""),
coord=coord)
except:
raise RuntimeError("SpectroScheduler: did not managed to "
"define target {target_name}")
raise RuntimeError(f"SpectroScheduler: did not managed to define target {target_name}")
return target, spinfo

def get_best_reference_target(self, observation):
Expand Down
168 changes: 94 additions & 74 deletions Pointer/InvisibleObjectOffsetPointer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,22 @@
import astropy.units as u

# Local
from Imaging.Image import OffsetError
from Pointer.OffsetPointer import OffsetPointer

class InvisibleObjectOffsetPointer(OffsetPointer):
def __init__(self, config=None):
super().__init__(config=config)
if config is None:
config = dict(
timeout_seconds=300,
sync_mount_upon_solve=False
sync_mount_upon_solve=False,
max_iterations=5,
max_pointing_error_seconds=2
)
super().__init__(config=config)

self.max_iterations = config["max_iterations"]
self.max_pointing_error = OffsetError(*(config["max_pointing_error_seconds"] * u.arcsec,) * 3)

def offset_points(self, mount, camera, guiding_camera, guider, observation, fits_headers):
pointing_event = threading.Event()
Expand Down Expand Up @@ -71,80 +76,95 @@ def offset_points_async(self, mount, camera, guiding_camera, guider, observation
then go to next state.
"""
try:
try:
# Our first action is to stop guiding
if guider is not None:
msg = f"Going to adjust pointing, need to stop guiding"
self.logger.debug(msg)
guider.stop_capture()
try:
exp_time_sec = guiding_camera.is_remaining_exposure_time()
guiding_camera.synchronize_with_image_reception(exp_time_sec=exp_time_sec)
except ImageAcquisitionError as e:
pass

img_num = 0
# Our first action is to stop guiding
if guider is not None:
msg = f"Going to adjust pointing, need to stop guiding"
self.logger.debug(msg)
guider.stop_capture()
try:
exp_time_sec = guiding_camera.is_remaining_exposure_time()
guiding_camera.synchronize_with_image_reception(exp_time_sec=exp_time_sec)
except ImageAcquisitionError as e:
pass

img_num = 0
pointing_error = OffsetError(*(np.inf * u.arcsec,) * 3)
pointing_error_stack = {}

while (img_num < self.max_iterations and pointing_error.magnitude > self.max_pointing_error.magnitude):
pointing_image = self.acquire_pointing(camera, guiding_camera, observation, fits_headers,
img_num)

# Attempt to solve field
pointing_image.solve_field(verbose=True,
gen_hips=False,
remove_extras=False,
skip_solved=False,
use_header_position=True,
sampling_arcsec=camera.sampling_arcsec)

# update mount with the actual position
if self.sync_mount_upon_solve:
mount.sync_to_coord(pointing_image.pointing)

px_identified_target = pointing_image.get_center_coordinates()

except AstrometrySolverError as e:
msg = f"Cannot solve image {pointing_image.fits_file} while in offset_pointing state: {e}"
self.logger.error(msg)
raise RuntimeError(msg)
# TODO TN We can decide to assume that main camera is already pointing to the expected object

# There are some subteleties here: https://astropy-cjhang.readthedocs.io/en/latest/wcs/
radeg, decdeg = pointing_image.wcs.all_pix2world(
camera.adjust_center_x,
camera.adjust_center_y,
0, # 0-based indexing
ra_dec_order=True)
current_sky_coord_of_target_sensor_position = SkyCoord(
ra=float(radeg) * u.degree,
dec=float(decdeg) * u.degree,
frame='icrs',
equinox='J2000.0')
radeg, decdeg = pointing_image.wcs.all_pix2world(
px_identified_target[0],
px_identified_target[1],
0, # 0-based indexing
ra_dec_order=True)
current_sky_coord_of_target_star = SkyCoord(
ra=float(radeg) * u.degree,
dec=float(decdeg) * u.degree,
frame='icrs',
equinox='J2000.0')

pointing_error = pointing_image.pointing_error(
pointing_reference_coord=current_sky_coord_of_target_star
)
offset_delta_ra = current_sky_coord_of_target_sensor_position.ra - current_sky_coord_of_target_star.ra
offset_delta_dec = current_sky_coord_of_target_sensor_position.dec - current_sky_coord_of_target_star.dec
# adjust by slewing to the opposite of the delta
current = mount.get_current_coordinates()
target = SkyCoord(
ra=current.ra + pointing_error.delta_ra - offset_delta_ra,
dec=current.dec + pointing_error.delta_dec - offset_delta_dec,
frame='icrs', equinox='J2000.0')
# Now adjust by slewing to the specified counter-offseted coordinates
mount.slew_to_coord(target)
if guider is not None:
guider.guide(recalibrate=False)
pointing_status[0] = True
try:
# Attempt to solve field
pointing_image.solve_field(verbose=True,
gen_hips=False,
remove_extras=False,
skip_solved=False,
use_header_position=True,
sampling_arcsec=camera.sampling_arcsec)
# update mount with the actual position
if self.sync_mount_upon_solve:
mount.sync_to_coord(pointing_image.pointing)
px_identified_target = pointing_image.get_center_coordinates()
except AstrometrySolverError as e:
msg = f"Cannot solve image {pointing_image.fits_file} while in offset_pointing state: {e}"
self.logger.error(msg)
raise RuntimeError(msg)
# TODO TN We can decide to assume that main camera is already pointing to the expected object

# There are some subteleties here: https://astropy-cjhang.readthedocs.io/en/latest/wcs/
radeg, decdeg = pointing_image.wcs.all_pix2world(
camera.adjust_center_x,
camera.adjust_center_y,
0, # 0-based indexing
ra_dec_order=True)
current_sky_coord_of_target_sensor_position = SkyCoord(
ra=float(radeg) * u.degree,
dec=float(decdeg) * u.degree,
frame='icrs',
equinox='J2000.0')
radeg, decdeg = pointing_image.wcs.all_pix2world(
px_identified_target[0],
px_identified_target[1],
0, # 0-based indexing
ra_dec_order=True)
current_sky_coord_of_target_star = SkyCoord(
ra=float(radeg) * u.degree,
dec=float(decdeg) * u.degree,
frame='icrs',
equinox='J2000.0')

pointing_error = pointing_image.pointing_error(
pointing_reference_coord=current_sky_coord_of_target_star
)
offset_delta_ra = current_sky_coord_of_target_sensor_position.ra - current_sky_coord_of_target_star.ra
offset_delta_dec = current_sky_coord_of_target_sensor_position.dec - current_sky_coord_of_target_star.dec
# adjust by slewing to the opposite of the delta
current = mount.get_current_coordinates()
target = SkyCoord(
ra=current.ra + pointing_error.delta_ra - offset_delta_ra,
dec=current.dec + pointing_error.delta_dec - offset_delta_dec,
frame='icrs', equinox='J2000.0')
# Now adjust by slewing to the specified counter-offseted coordinates
mount.slew_to_coord(target)

# update pointing process tracking information
pointing_error_stack[img_num] = pointing_error
img_num = img_num + 1

if pointing_error.magnitude > self.max_pointing_error.magnitude:
self.logger.error(f"Pointing accuracy was not good enough after "
f"{img_num} iterations, pointing error stack was: "
f"{pointing_error_stack}")
pointing_status[0] = False
else:
self.logger.info(f"Pointing accuracy was estimated good enough after "
f"{img_num} iterations, pointing error stack was: "
f"{pointing_error_stack}")
if guider is not None:
guider.find_star() # Star have changed position, we need to force re-detect stars
guider.guide(recalibrate=False)
pointing_status[0] = True
except Exception as e:
self.logger.error(f"Problem adjusting image: {e}:{traceback.format_exc()}")
finally:
Expand Down
4 changes: 2 additions & 2 deletions StateMachine/States/parked.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ def on_enter(event_data):
# We might have shutdown during previous sleep.
if not model.connected:
break
elif model.is_safe():
elif model.is_safe() and not model.is_simulation():
model.reset_observing_run()
model.next_state = 'ready'
break
elif model.is_dark() is False:
elif model.is_dark() is False or model.is_simulation():
model.logger.debug(f"Looks like it is not dark anymore. Going to clean up.")
model.next_state = 'housekeeping'
break
Expand Down
1 change: 0 additions & 1 deletion StateMachine/States/parking.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ def on_enter(event_data):
model.next_state = 'parked'

msg = f"Taking it on home and then parking."
model.logger.debug(msg)
model.say(msg)

if not model.manager.park():
Expand Down
4 changes: 4 additions & 0 deletions apps/launch_remote_observatory.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ def say(self, msg):
Args:
msg(str): Message to be sent
"""
self.logger.debug(msg)
if not self.has_messaging:
self.logger.info(f"Unit says: {msg}")
else:
Expand Down Expand Up @@ -323,6 +324,9 @@ def is_safe(self, no_warning=False):

return safe

def is_simulation(self):
return self.simulation_mode

def is_dark(self):
"""Is it dark
Expand Down
2 changes: 2 additions & 0 deletions conf_files/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ offset_pointer:
sync_mount_upon_solve: False
use_guider_adjust: False
on_star_identification_failure: trust_astrometry # get_brightest or trust_astrometry
max_iterations: 5
max_pointing_error_seconds: 2
guider:
module : GuiderPHD2
host : localhost
Expand Down
44 changes: 22 additions & 22 deletions conf_files/spectral_targets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,34 @@ constraints :
maxairmass : 17 #for testing, normally use 2
minmoonseparationdeg : 2 # normally put 45
targets :
"Altair" : #HD214680 #HD222404
priority : 0
count : 1
temperature : 10
gain: 150
offset: 30
exp_time_sec : 20
"Arcturus":
priority: 0
count: 1
temperature: 15
gain: 150
offset: 30
exp_time_sec: 20
"10 Lacertae": #HD214680 #HD222404
# "Altair" : #HD214680 #HD222404
# priority : 0
# count : 1
# temperature : 10
# gain: 150
# offset: 30
# exp_time_sec : 20
"Capella":
priority: 0
count: 1
temperature: 15
gain: 150
offset: 30
exp_time_sec: 20
"Gamma Cassiopeiae" :
priority : 0
count : 2
temperature : 10
gain: 150
offset: 30
exp_time_sec : 5
# "10 Lacertae": #HD214680 #HD222404
# priority: 0
# count: 1
# temperature: 15
# gain: 150
# offset: 30
# exp_time_sec: 20
# "Gamma Cassiopeiae" :
# priority : 0
# count : 2
# temperature : 10
# gain: 150
# offset: 30
# exp_time_sec : 5
# "T CrB" :
# priority : 0
# count : 1
Expand Down

0 comments on commit 314d5bb

Please sign in to comment.