Skip to content

Commit

Permalink
Rounding and keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Feb 6, 2024
1 parent dd2b37b commit 13ba7cc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
14 changes: 7 additions & 7 deletions src/lvmguider/actor/commands/focus.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ async def focus(

focuser = Focuser(command.actor.telescope)

if guess is None:
guess = await focuser.get_from_temperature(command)

try:
await focuser.focus(
command,
Expand All @@ -99,7 +96,7 @@ async def focus(


@lvmguider_parser.command("adjust-focus")
@click.argument("FOCUS_VALUE", type=float)
@click.argument("FOCUS_VALUE", type=float, required=False)
@click.option(
"--relative",
is_flag=True,
Expand All @@ -112,7 +109,7 @@ async def focus(
)
async def adjust_focus(
command: GuiderCommand,
focus_value: float,
focus_value: float | None = None,
relative: bool = False,
reference: bool = False,
):
Expand All @@ -137,7 +134,10 @@ async def adjust_focus(
relative = False
else:
delta_t = c_temp - command.actor._reference_focus.temperature
focus_value = delta_t * command.actor.config["focus.model.a"]
command.debug(f"Setting focus based on delta temperare: {delta_t:.2f}")

focus_model_a: float = command.actor.config["focus.model.a"]
focus_value = delta_t * focus_model_a
relative = True # Always relative to the reference focus.

if relative:
Expand All @@ -152,4 +152,4 @@ async def adjust_focus(
time(),
)

return command.finish(f"Focus adjusted to {focus:.2f}.")
return command.finish(f"Focus adjusted to {focus_value:.2f}.")
2 changes: 1 addition & 1 deletion src/lvmguider/cameras.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ async def expose(
"filenames": [str(fn) for fn in filenames],
"flavour": flavour,
"n_sources": len(valid),
"focus_position": round(focus_position, 1),
"focus_position": round(focus_position, 2),
"fwhm": numpy.round(float(fwhm), 3) if fwhm else -999.0,
}
)
Expand Down
19 changes: 11 additions & 8 deletions src/lvmguider/focus.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ async def focus(
steps += 1

if initial_guess is None:
initial_guess = await self.get_focus_position(command)
command.debug(f"Using focuser position: {initial_guess} DT")
initial_guess = await self.get_from_temperature(command)
command.debug(f"Using initial focus position: {initial_guess:.2f} DT")

assert initial_guess is not None

Expand Down Expand Up @@ -205,19 +205,22 @@ async def focus(

await self.goto_focus_position(command, numpy.round(fit_data["xmin"], 2))

bench_temperature = await self.get_bench_temperature(command)
command.info(
best_focus=dict(
focus=numpy.round(fit_data["xmin"], 2),
fwhm=numpy.round(fit_data["ymin"], 2),
r2=numpy.round(fit_data["R2"], 3),
initial_guess=numpy.round(initial_guess, 2),
bench_temperature=numpy.round(bench_temperature, 2),
fit_method=fit_method,
)
)

current_temperature = await self.get_bench_temperature(command)
command.actor._reference_focus = ReferenceFocus(
focus=fit_data["xmin"],
fwhm=fit_data["ymin"],
temperature=bench_temperature,
timestamp=time(),
)

Expand Down Expand Up @@ -269,7 +272,7 @@ async def get_from_temperature(
focus_model = command.actor.config["focus.model"]
new_focus = focus_model["a"] * temperature + focus_model["b"]

return new_focus + offset
return round(new_focus + offset, 2)

async def get_bench_temperature(self, command: GuiderCommand) -> float:
"""Returns the current bench temperature."""
Expand All @@ -279,7 +282,7 @@ async def get_bench_temperature(self, command: GuiderCommand) -> float:
if telem_command.status.did_fail:
raise RuntimeError("Failed retrieving temperature from telemetry.")

return telem_command.replies.get("sensor1")["temperature"]
return round(telem_command.replies.get("sensor1")["temperature"], 2)

async def get_focus_position(self, command: GuiderCommand) -> float:
"""Returns the current focus position."""
Expand All @@ -288,17 +291,17 @@ async def get_focus_position(self, command: GuiderCommand) -> float:
if cmd.status.did_fail:
raise RuntimeError("Failed retrieving position from focuser.")

return cmd.replies.get("Position")
return round(cmd.replies.get("Position"), 2)

async def goto_focus_position(self, command: GuiderCommand, focus_position: float):
"""Moves the focuser to a position."""

cmd = await command.send_command(
self.foc_actor,
f"moveAbsolute {focus_position} DT",
f"moveAbsolute {round(focus_position, 3)} DT",
)
if cmd.status.did_fail:
raise RuntimeError(f"Failed reaching focus {focus_position:.2f} DT.")
raise RuntimeError(f"Failed reaching focus {focus_position:.3f} DT.")
if cmd.replies.get("AtLimit") is True:
raise RuntimeError("Hit a limit while focusing.")

Expand Down

0 comments on commit 13ba7cc

Please sign in to comment.