Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
gnthibault committed Aug 17, 2023
1 parent fc0a05e commit 9d16278
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 42 deletions.
40 changes: 26 additions & 14 deletions Imaging/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ def pointing_error(self, pointing_reference_coord=None):

def get_center_coordinates(self):
"""
Those are 0-based indexing
Those are 0-based indexing, also from documentation:
https://docs.astropy.org/en/stable/api/astropy.wcs.WCS.html#astropy.wcs.WCS.pixel_to_world_values
Note that pixel coordinates are assumed to be 0 at the center of the first pixel in each dimension
:return:
"""
return (self.header["NAXIS1"]/2-0.5,
Expand Down Expand Up @@ -196,8 +198,8 @@ def get_wcs_pointing(self):
"""
if self.wcs is not None:
# This was wrong because crval coord relates to crpix reference pixels
ra = self.wcs.celestial.wcs.crval[0]
dec = self.wcs.celestial.wcs.crval[1]
# ra = self.wcs.celestial.wcs.crval[0]
# dec = self.wcs.celestial.wcs.crval[1]

# TODO TN trying alternative definition
cx, cy = self.get_center_coordinates()
Expand All @@ -207,14 +209,19 @@ def get_wcs_pointing(self):
0, # 0-based indexing
ra_dec_order=True)

fk5_J2015_5 = FK5(equinox=Time(datetime.datetime(year=2015, month=6, day=30)))
pointing = SkyCoord(ra=radeg*u.degree,
dec=decdeg*u.degree,
frame=fk5_J2015_5,
obstime=Time(datetime.datetime(year=2015, month=6, day=30)))
# fk5_J2015_5 = FK5(equinox=Time(datetime.datetime(year=2015, month=6, day=30)))
# pointing = SkyCoord(ra=radeg*u.degree,
# dec=decdeg*u.degree,
# frame=fk5_J2015_5,
# obstime=Time(datetime.datetime(year=2015, month=6, day=30)))
# icrs_j2k = ICRS()
# self.pointing = pointing.transform_to(icrs_j2k)

icrs_j2k = ICRS()
self.pointing = SkyCoord(ra=radeg*u.degree,
dec=decdeg*u.degree,
frame=icrs_j2k)

self.pointing = pointing.transform_to(icrs_j2k)
self.ra = self.pointing.ra.to(u.hourangle)
self.dec = self.pointing.dec.to(u.degree)
# Precess to the current equinox otherwise the RA - LST method
Expand All @@ -228,12 +235,17 @@ def all_pix2world(self, x, y):
y,
0, # 0-based indexing
ra_dec_order=True)
fk5_J2015_5 = FK5(equinox=Time(datetime.datetime(year=2015, month=6, day=30)))
coord = SkyCoord(ra=coord_ra*u.deg,
dec=coord_dec*u.deg,
frame=fk5_J2015_5,
obstime=Time(datetime.datetime(year=2015, month=6, day=30)))
# fk5_J2015_5 = FK5(equinox=Time(datetime.datetime(year=2015, month=6, day=30)))
# coord = SkyCoord(ra=coord_ra*u.deg,
# dec=coord_dec*u.deg,
# frame=fk5_J2015_5,
# obstime=Time(datetime.datetime(year=2015, month=6, day=30)))
# icrs_j2k = ICRS()
icrs_j2k = ICRS()
coord = SkyCoord(ra=coord_ra * u.deg,
dec=coord_dec * u.deg,
frame=icrs_j2k)

return coord.transform_to(icrs_j2k)

def solve_field(self, **kwargs):
Expand Down
3 changes: 2 additions & 1 deletion Mount/IndiMount.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,8 @@ def get_current_coordinates(self):
frame=fk5_now,
obstime=Time.now())
icrs_j2k = ICRS()
self.logger.debug(f"Received coordinates in JNOw/CIRS from mount: {ret}")
# This was too verbose
#self.logger.debug(f"Received coordinates in JNOw/CIRS from mount: {ret}")
ret = ret.transform_to(icrs_j2k)

# ret = SkyCoord(ra=rahour_decdeg['RA'] * u.hourangle,
Expand Down
20 changes: 10 additions & 10 deletions Pointer/InvisibleObjectOffsetPointer.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def offset_points_async(self, mount, camera, guiding_camera, guider, observation
msg = f"Going to adjust pointing, need to stop guiding"
self.logger.debug(msg)
guider.stop_capture()
#guider.set_paused(paused=True, full="full")
try:
exp_time_sec = guiding_camera.is_remaining_exposure_time()
guiding_camera.synchronize_with_image_reception(exp_time_sec=exp_time_sec)
Expand All @@ -104,8 +105,6 @@ def offset_points_async(self, mount, camera, guiding_camera, guider, observation
# update mount with the actual position
if self.sync_mount_upon_solve:
mount.sync_to_coord(pointing_image.pointing)
# We used px_identified_target only if the assumption that target was centered beforehand is ok
current_sky_coord_of_image_center = pointing_image.pointing
# There are some subteleties here: https://astropy-cjhang.readthedocs.io/en/latest/wcs/
current_sky_coord_of_target_sensor_position = pointing_image.all_pix2world(
camera.adjust_center_x,
Expand All @@ -114,22 +113,23 @@ def offset_points_async(self, mount, camera, guiding_camera, guider, observation
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

star_pointing_delta = pointing_image.pointing_error(
pointing_reference_coord=observation.target.coord
)
offset_delta_ra = current_sky_coord_of_target_sensor_position.ra - current_sky_coord_of_image_center.ra
offset_delta_dec = current_sky_coord_of_target_sensor_position.dec - current_sky_coord_of_image_center.dec
star_pointing_delta = pointing_image.pointing_error()
offset_delta_ra = current_sky_coord_of_target_sensor_position.ra - pointing_image.pointing.ra
offset_delta_dec = current_sky_coord_of_target_sensor_position.dec - pointing_image.pointing.dec
# adjust by slewing to the opposite of the delta
current = mount.get_current_coordinates()
target = SkyCoord(
ra=current.ra - star_pointing_delta.delta_ra - offset_delta_ra,
dec=current.dec - star_pointing_delta.delta_dec - offset_delta_dec,
frame='icrs', equinox='J2000.0')

# Virtual target (different from target if we do not do sync on the mount)
virtual_target = SkyCoord(
ra=pointing_image.pointing.ra - star_pointing_delta.delta_ra - offset_delta_ra,
dec=pointing_image.pointing.dec - star_pointing_delta.delta_dec - offset_delta_dec,
frame='icrs', equinox='J2000.0')
pointing_error = pointing_image.pointing_error(
pointing_reference_coord=target
pointing_reference_coord=virtual_target
)
self.logger.debug(f"Offset point, current error is: {pointing_error}")
# update pointing process tracking information
Expand Down
10 changes: 6 additions & 4 deletions Pointer/StarOffsetPointer.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def offset_points_async(self, mount, camera, guiding_camera, guider, observation
msg = f"Going to adjust pointing, need to stop guiding"
self.logger.debug(msg)
guider.stop_capture()
#guider.set_paused(paused=True, full="full")
try:
exp_time_sec = guiding_camera.is_remaining_exposure_time()
guiding_camera.synchronize_with_image_reception(exp_time_sec=exp_time_sec)
Expand Down Expand Up @@ -186,13 +187,13 @@ def offset_points_async(self, mount, camera, guiding_camera, guider, observation
# adjust by slewing to the opposite of the delta
current = mount.get_current_coordinates()
target = SkyCoord(
ra=current.ra - star_pointing_delta.delta_ra + offset_delta_ra,
dec=current.dec - star_pointing_delta.delta_dec + offset_delta_dec,
ra=current.ra - star_pointing_delta.delta_ra - offset_delta_ra,
dec=current.dec - star_pointing_delta.delta_dec - offset_delta_dec,
frame='icrs', equinox='J2000.0')
# Virtual target (different from target if we do not do sync on the mount)
virtual_target = SkyCoord(
ra=pointing_image.pointing.ra - star_pointing_delta.delta_ra + offset_delta_ra,
dec=pointing_image.pointing.dec - star_pointing_delta.delta_dec + offset_delta_dec,
ra=pointing_image.pointing.ra - star_pointing_delta.delta_ra - offset_delta_ra,
dec=pointing_image.pointing.dec - star_pointing_delta.delta_dec - offset_delta_dec,
frame='icrs', equinox='J2000.0')
pointing_error = pointing_image.pointing_error(
pointing_reference_coord=virtual_target
Expand All @@ -218,6 +219,7 @@ def offset_points_async(self, mount, camera, guiding_camera, guider, observation
f"{pointing_error_stack}")

if guider is not None:
# guider.stop_capture()
guider.loop()
half_search_size = camera.adjust_roi_search_size / 2
guider.find_star(x=max(0, int(round(camera.adjust_center_x - half_search_size))),
Expand Down
2 changes: 1 addition & 1 deletion StateMachine/States/observing.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
STATUS_INTERVAL = 10. * u.second
GUIDER_STATUS_INTERVAL = 5. * u.second
WAITING_MSG_INTERVAL = 5. * u.second
MAX_EXTRA_TIME = (60+SLEEP_SECONDS) * u.second
MAX_EXTRA_TIME = (100+SLEEP_SECONDS) * u.second

def on_enter(event_data):
#TODO TN DEBUG
Expand Down
10 changes: 5 additions & 5 deletions conf_files/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ cameras:
SIM_PEMAX: 0
SIM_TIME_FACTOR: 1
SCOPE_INFO: # 200/800 newtonian
FOCAL_LENGTH: 242
APERTURE: 50
FOCAL_LENGTH: 800
APERTURE: 200
subsample_astrometry: 4
do_guiding: false
do_pointing: false
Expand Down Expand Up @@ -236,7 +236,7 @@ offset_pointer:
timeout_seconds: 300
max_identification_error_seconds: 1
sync_mount_upon_solve: False
use_guider_adjust: False
use_guider_adjust: True
on_star_identification_failure: trust_astrometry # get_brightest or trust_astrometry
max_iterations: 5
max_pointing_error_seconds: 2
Expand All @@ -248,9 +248,9 @@ guider:
profile_name : Simulator
exposure_time_sec : 4
settle :
pixels : 1.5
pixels : 3
time : 10
timeout : 60
timeout : 360
dither :
pixels : 0.0
ra_only : False
Expand Down
14 changes: 7 additions & 7 deletions conf_files/spectral_targets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ constraints :
maxairmass : 17 #for testing, normally use 2
minmoonseparationdeg : 2 # normally put 45
targets :
# "Altair":
# priority : 0
# count : 1
# temperature : 10
# gain: 150
# offset: 30
# exp_time_sec : 20
"Altair":
priority : 0
count : 1
temperature : 10
gain: 150
offset: 30
exp_time_sec : 20
"Capella":
priority: 0
count: 1
Expand Down

0 comments on commit 9d16278

Please sign in to comment.