Coverage for python / lsst / atmospec / formatters.py: 0%
31 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-15 00:15 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-15 00:15 +0000
1# This file is part of atmospec.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <https://www.gnu.org/licenses/>.
22__all__ = ['SpectractorSpectrumFormatter',
23 'SpectractorImageFormatter',
24 'SpectractorFitParametersFormatter']
26from typing import Any
27from lsst.resources import ResourcePath
28from lsst.daf.butler import FormatterV2
29from spectractor.extractor.spectrum import Spectrum
30from spectractor.extractor.images import Image
31from spectractor.fit.fitter import read_fitparameter_json, write_fitparameter_json
34class SpectractorSpectrumFormatter(FormatterV2):
35 default_extension = '.fits'
36 unsupported_parameters = None
37 can_read_from_local_file = True
39 def read_from_local_file(
40 self, path: str, component: str | None = None, expected_size: int = -1
41 ) -> Any:
42 return Spectrum(path)
44 def write_local_file(self, in_memory_dataset: Any, uri: ResourcePath) -> None:
45 in_memory_dataset.save_spectrum(uri.ospath)
48class SpectractorImageFormatter(FormatterV2):
49 default_extension = '.fits'
50 unsupported_parameters = None
51 can_read_from_local_file = True
53 def read_from_local_file(
54 self, path: str, component: str | None = None, expected_size: int = -1
55 ) -> Any:
56 return Image(path)
58 def write_local_file(self, in_memory_dataset: Any, uri: ResourcePath) -> None:
59 in_memory_dataset.save_image(uri.ospath)
62class SpectractorFitParametersFormatter(FormatterV2):
63 default_extension = '.json'
64 unsupported_parameters = None
65 can_read_from_local_file = True
67 def read_from_local_file(
68 self, path: str, component: str | None = None, expected_size: int = -1
69 ) -> Any:
70 return read_fitparameter_json(path)
72 def write_local_file(self, in_memory_dataset: Any, uri: ResourcePath) -> None:
73 write_fitparameter_json(uri.ospath, in_memory_dataset)