Skip to content

Commit

Permalink
Merge pull request #49 from lsst/tickets/DM-26658
Browse files Browse the repository at this point in the history
DM-26658: Use Formatter V2
  • Loading branch information
timj authored Jul 25, 2024
2 parents a433652 + 12ca30d commit e840506
Showing 1 changed file with 30 additions and 19 deletions.
49 changes: 30 additions & 19 deletions python/lsst/atmospec/formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,40 +23,51 @@
'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):
def read_from_local_file(
self, path: str, component: str | None = None, expected_size: int = -1
) -> Any:
return Spectrum(path)

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):
def read_from_local_file(
self, path: str, component: str | None = None, expected_size: int = -1
) -> Any:
return Image(path)

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):
def read_from_local_file(
self, path: str, component: str | None = None, expected_size: int = -1
) -> Any:
return read_fitparameter_json(path)

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 e840506

Please sign in to comment.