From 3b266f2ae406bcdd60a08ec6cc30af5833a6fcc2 Mon Sep 17 00:00:00 2001 From: Tim Jenness Date: Fri, 28 Jun 2024 16:08:22 -0700 Subject: [PATCH] Use Formatter V2 --- python/lsst/atmospec/formatters.py | 49 ++++++++++++++++-------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/python/lsst/atmospec/formatters.py b/python/lsst/atmospec/formatters.py index 1cc9cdb..b90278a 100644 --- a/python/lsst/atmospec/formatters.py +++ b/python/lsst/atmospec/formatters.py @@ -23,40 +23,45 @@ 'SpectractorImageFormatter', 'SpectractorFitParametersFormatter'] -from lsst.daf.butler.formatters.file import FileFormatter +from typing import Any +from lsst.resources import ResourcePath +from lsst.daf.butler import FormatterV2 from spectractor.extractor.spectrum import Spectrum from spectractor.extractor.images import Image from spectractor.fit.fitter import read_fitparameter_json, write_fitparameter_json -class SpectractorSpectrumFormatter(FileFormatter): - extension = '.fits' - unsupportedParameters = None +class SpectractorSpectrumFormatter(FormatterV2): + default_extension = '.fits' + unsupported_parameters = None + can_read_from_local_file = True - def _readFile(self, path, pytype=None): - return Spectrum(path) + def read_from_local_file(self, uri: ResourcePath, component: str | None = None) -> Any: + return Spectrum(uri.ospath) - def _writeFile(self, inMemoryDataset): - inMemoryDataset.save_spectrum(self.fileDescriptor.location.path) + def write_local_file(self, in_memory_dataset: Any, uri: ResourcePath) -> None: + in_memory_dataset.save_spectrum(uri.ospath) -class SpectractorImageFormatter(FileFormatter): - extension = '.fits' - unsupportedParameters = None +class SpectractorImageFormatter(FormatterV2): + default_extension = '.fits' + unsupported_parameters = None + can_read_from_local_file = True - def _readFile(self, path, pytype=None): - return Image(path) + def read_from_local_file(self, uri: ResourcePath, component: str | None = None) -> Any: + return Image(uri.ospath) - def _writeFile(self, inMemoryDataset): - inMemoryDataset.save_image(self.fileDescriptor.location.path) + def write_local_file(self, in_memory_dataset: Any, uri: ResourcePath) -> None: + in_memory_dataset.save_image(uri.ospath) -class SpectractorFitParametersFormatter(FileFormatter): - extension = '.json' - unsupportedParameters = None +class SpectractorFitParametersFormatter(FormatterV2): + default_extension = '.json' + unsupported_parameters = None + can_read_from_local_file = True - def _readFile(self, path, pytype=None): - return read_fitparameter_json(path) + def read_from_local_file(self, uri: ResourcePath, component: str | None = None) -> Any: + return read_fitparameter_json(uri.ospath) - def _writeFile(self, inMemoryDataset): - write_fitparameter_json(self.fileDescriptor.location.path, inMemoryDataset) + def write_local_file(self, in_memory_dataset: Any, uri: ResourcePath) -> None: + write_fitparameter_json(uri.ospath, in_memory_dataset)