diff --git a/imc2zarr/__init__.py b/imc2zarr/__init__.py index e094bc84c2e4f61f9c3a4446fca9302ff1c89465..ef22a3259fcb70ea5078e5d5762730592f2e1fdc 100644 --- a/imc2zarr/__init__.py +++ b/imc2zarr/__init__.py @@ -18,16 +18,17 @@ _credits__ = [ def imc2zarr(input_path: Path, output_path: Path): - try: - imc2zarr_converter = Imc2Zarr(input_path, output_path) - imc2zarr_converter.convert() - except Exception as err: - print('Error: {}'.format(str(err))) - print('Details: {}'.format(traceback.format_exc())) + imc2zarr_converter = Imc2Zarr(input_path, output_path) + imc2zarr_converter.convert() + return imc2zarr_converter.output_fn @click.command() -@click.argument('input_path') -@click.argument('output_path') +@click.argument("input_path") +@click.argument("output_path") def main(input_path, output_path): - imc2zarr(input_path, output_path) + try: + imc2zarr(input_path, output_path) + except Exception as err: + print("Error: {}".format(str(err))) + print("Details: {}".format(traceback.format_exc())) diff --git a/imc2zarr/converter.py b/imc2zarr/converter.py index 9c07e6749e24b2010f24b69020cf8563bffa379b..abd1d96d1529276c8c6e561dc730a6904f24da1b 100644 --- a/imc2zarr/converter.py +++ b/imc2zarr/converter.py @@ -14,19 +14,18 @@ class Imc2Zarr: self.output_dir = Path(output_dir) def convert(self): - try: - with closing(ImcRaw(self.input_dir)) as imc: - # assign output filename based on IMC run timestamp - input_name = self.input_dir.name - if self.input_dir.is_file(): - input_name = input_name[:-len(self.input_dir.suffix)] - self.output_fn = self.output_dir.joinpath('{}_{}.zarr'.format(input_name, imc.code)) - # save acquisitions into Zarr - self._convert2zarr(imc) - # save raw met and snapshots - self._save_auxiliary_data(imc) - except Exception as e: - raise e + with closing(ImcRaw(self.input_dir)) as imc: + # assign output filename based on IMC run timestamp + input_name = self.input_dir.name + if self.input_dir.is_file(): + input_name = input_name[: -len(self.input_dir.suffix)] + self.output_fn = self.output_dir.joinpath( + "{}_{}".format(input_name, imc.code) + ) + # save acquisitions into Zarr + self._convert2zarr(imc) + # save raw met and snapshots + self._save_auxiliary_data(imc) def _convert2zarr(self, imc: ImcRaw): ds = xr.Dataset()