From 029c926a399b80cecb88d510f35426561e4e6116 Mon Sep 17 00:00:00 2001 From: Agustin Corbat Date: Tue, 23 Jul 2024 16:50:47 +0200 Subject: [PATCH] Add the option to choose alignment channel by name --- ashlar/filepattern.py | 9 ++++++++- ashlar/fileseries.py | 9 ++++++++- ashlar/scripts/ashlar.py | 5 +++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/ashlar/filepattern.py b/ashlar/filepattern.py index 6b678153..b56bf02c 100644 --- a/ashlar/filepattern.py +++ b/ashlar/filepattern.py @@ -98,6 +98,13 @@ def tile_rc(self, i): row = i // self.width + self.row_offset col = i % self.width + self.col_offset return row, col + + def get_from_channel_map(self, c): + if isinstance(c, int): + return self.channel_map[c] + if c in list(self.channel_map.values()): + return c + raise Exception(f"{c} was notrecognized as a channel") class FilePatternReader(reg.Reader): @@ -119,5 +126,5 @@ def read(self, series, c): def filename(self, series, c): row, col = self.metadata.tile_rc(series) - c = self.metadata.channel_map[c] + c = self.metadata.get_from_channel_map(c) return self.pattern.format(row=row, col=col, channel=c) diff --git a/ashlar/fileseries.py b/ashlar/fileseries.py index 876db0e3..a2d166c0 100644 --- a/ashlar/fileseries.py +++ b/ashlar/fileseries.py @@ -186,10 +186,17 @@ def tile_rc(self, i): if self.layout == "snake" and col % 2 == 1: row = self.height - 1 - row return row, col + + def get_from_channel_map(self, c): + if isinstance(c, int): + return self.channel_map[c] + if c in list(self.channel_map.values()): + return c + raise Exception(f"{c} was notrecognized as a channel") def filename(self, series, c): well, series = self.all_series[self.active_series[series]] - c = self.channel_map[c] + c = self.get_from_channel_map(c) components = self.filename_components[well, series, c] return self.pattern.format(**components) diff --git a/ashlar/scripts/ashlar.py b/ashlar/scripts/ashlar.py index 663fbac2..faa287bf 100644 --- a/ashlar/scripts/ashlar.py +++ b/ashlar/scripts/ashlar.py @@ -33,10 +33,11 @@ def main(argv=sys.argv): " exist."), ) parser.add_argument( - '-c', '--align-channel', dest='align_channel', type=int, + '-c', '--align-channel', dest='align_channel', default='0', metavar='CHANNEL', help=('Reference channel number for image alignment. Numbering starts' - ' at 0.'), + ' at 0. If fileseries or filepattern is used, it may be channel' + ' name.'), ) parser.add_argument( '--flip-x', default=False, action='store_true',