Skip to content

Commit

Permalink
Use Formatter V2
Browse files Browse the repository at this point in the history
  • Loading branch information
timj committed Jun 28, 2024
1 parent a433652 commit 3b266f2
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions python/lsst/atmospec/formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 3b266f2

Please sign in to comment.