Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-26658: Use Formatter V2 #49

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading