Skip to content

Commit

Permalink
Plot distances during FVC loop (#183)
Browse files Browse the repository at this point in the history
* Add code to plot FVC distances while creating summaryF file

* Add the option to select centroid method, and log it in confSummaryF

* Allow to pass an epoch when loading a design

* Some tweaks to plotting
  • Loading branch information
albireox committed May 5, 2022
1 parent 24b7769 commit 97bf590
Show file tree
Hide file tree
Showing 4 changed files with 310 additions and 5 deletions.
21 changes: 20 additions & 1 deletion python/jaeger/actor/commands/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ async def _load_design(
preload: bool = False,
no_clone: bool = False,
scale: float | None = None,
epoch: float | None = None,
epoch_delay: float = 0.0,
get_paths: bool = True,
):
Expand Down Expand Up @@ -173,7 +174,11 @@ async def _load_design(
try:
# Define the epoch for the configuration.
command.debug(text=f"Epoch delay: {round(epoch_delay, 1)} seconds.")
epoch = Time.now().jd + epoch_delay / 86400.0

if epoch is None:
epoch = float(Time.now().jd)
epoch += epoch_delay / 86400.0

design = await Design.create_async(design_id, epoch=epoch, scale=scale)
except Exception as err:
command.error(error=f"Failed retrieving design: {err}")
Expand Down Expand Up @@ -211,6 +216,11 @@ def configuration():
default=True,
help="Generates and stores the to and from destination paths.",
)
@click.option(
"--epoch",
type=float,
help="Epoch at which to create the configuration, as a Julian Day.",
)
@click.option(
"--epoch-delay",
type=float,
Expand Down Expand Up @@ -269,6 +279,7 @@ async def load(
from_positions: bool = False,
from_preloaded: bool = False,
generate_paths: bool = False,
epoch: float | None = None,
epoch_delay: float = 0.0,
ingest: bool = False,
write_summary: bool = False,
Expand Down Expand Up @@ -314,6 +325,7 @@ async def load(
preload=False,
no_clone=no_clone,
scale=scale,
epoch=epoch,
epoch_delay=epoch_delay,
get_paths=False,
)
Expand Down Expand Up @@ -442,6 +454,11 @@ async def clone(command: Command[JaegerActor], fps: FPS):


@configuration.command(cancellable=True)
@click.option(
"--epoch",
type=float,
help="Epoch at which to create the configuration, as a Julian Day.",
)
@click.option(
"--epoch-delay",
type=float,
Expand Down Expand Up @@ -474,6 +491,7 @@ async def preload(
command: JaegerCommandType,
fps: FPS,
designid: int | None = None,
epoch: float | None = None,
epoch_delay: float = 0.0,
scale: float | None = None,
no_clone: bool = False,
Expand Down Expand Up @@ -501,6 +519,7 @@ async def preload(
preload=True,
no_clone=no_clone,
scale=scale,
epoch=epoch,
epoch_delay=epoch_delay,
)

Expand Down
7 changes: 7 additions & 0 deletions python/jaeger/actor/commands/fvc.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ async def expose(
type=float,
help="Proportional term of the correction.",
)
@click.option(
"--centroid-method",
type=click.Choice(["nudge", "simple", "winpos", "sep"]),
help="The centroid method used to extract sources.",
)
@click.option(
"--use-invkin/--no-use-invkin",
default=True,
Expand All @@ -141,6 +146,7 @@ async def loop(
max_correction: float | None = None,
target_90_percentile: float | None = None,
k: float | None = None,
centroid_method: str | None = None,
use_invkin: bool = True,
no_write_summary: bool = False,
):
Expand Down Expand Up @@ -217,6 +223,7 @@ async def loop(
filename,
positioner_coords,
plot=plot,
centroid_method=centroid_method,
use_new_invkin=use_invkin,
)

Expand Down
29 changes: 25 additions & 4 deletions python/jaeger/fvc.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from jaeger.fps import FPS
from jaeger.ieb import IEB
from jaeger.kaiju import get_path_pair_in_executor, get_robot_grid
from jaeger.plotting import plot_fvc_distances
from jaeger.target.tools import wok_to_positioner
from jaeger.utils import run_in_executor

Expand All @@ -42,6 +43,7 @@


FVC_CONFIG = config["fvc"]
DEFAULT_CENTROID_METHOD = "nudge"


class FVC:
Expand All @@ -57,6 +59,7 @@ class FVC:
raw_hdu: Optional[fits.ImageHDU]
proc_hdu: Optional[fits.ImageHDU]

centroid_method: str | None
fitrms: float
k: float

Expand Down Expand Up @@ -93,6 +96,7 @@ def reset(self):
self.fitrms = -9.99
self.perc_90 = -9.99
self.fvc_percent_reached = -9.99
self.centroid_method = None

def set_command(self, command: Command[JaegerActor]):
"""Sets the command."""
Expand Down Expand Up @@ -193,7 +197,7 @@ def process_fvc_image(
positioner_coords: dict,
fibre_data: Optional[pandas.DataFrame] = None,
fibre_type: str = "Metrology",
use_winpos: bool = True,
centroid_method: str | None = None,
use_new_invkin: bool = True,
plot: bool | str = False,
outdir: str | None = None,
Expand All @@ -217,8 +221,9 @@ def process_fvc_image(
fibre_type
The ``fibre_type`` rows in ``fibre_data`` to use. Defaults to
``fibre_type='Metrology'``.
use_winpos
Whether to use windowed position for centroid extraction.
centroid_method
The centroid method to use, one of ``"nudge"``, ``"sep"``, ``"winpos"``,
or ``"simple"``. Defaults to ``"nudge"``.
use_new_invkin
Use new inverse kinnematic to calculate alpha/beta.
plot
Expand All @@ -239,6 +244,8 @@ def process_fvc_image(
# Reset the instance
self.reset()

centroid_method = centroid_method or DEFAULT_CENTROID_METHOD

path = str(path)
if not os.path.exists(path):
raise FVCError(f"FVC image {path} does not exist.")
Expand Down Expand Up @@ -297,7 +304,8 @@ def process_fvc_image(
)

self.centroids = fvc_transform.extractCentroids()
fvc_transform.fit(newInvKin=use_new_invkin)
fvc_transform.fit(centType=centroid_method, newInvKin=use_new_invkin)
self.centroid_method = centroid_method

assert fvc_transform.positionerTableMeas is not None

Expand Down Expand Up @@ -858,10 +866,23 @@ async def write_summary_F(self):
await configuration_copy.write_summary(
flavour="F",
headers={
"fvc_centroid_method": self.centroid_method or "?",
"fvc_rms": self.fitrms,
"fvc_90_perc": self.perc_90,
"fvc_percent_reached": self.fvc_percent_reached,
"fvc_image_path": self.proc_image_path if self.proc_image_path else "",
},
overwrite=True,
)

# Plot analysis of FVC loop.
if self.proc_image_path:
self.log("Creating FVC plots", level=logging.DEBUG)

outpath = str(self.proc_image_path).replace(".fits", "_distances.pdf")

plot_fvc_distances(
self.fps.configuration,
configuration_copy.assignment_data.fibre_table,
path=outpath,
)

0 comments on commit 97bf590

Please sign in to comment.