lvm-tools 0.0.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lvm_tools-0.0.2/.gitignore +169 -0
- lvm_tools-0.0.2/LICENSE +21 -0
- lvm_tools-0.0.2/PKG-INFO +42 -0
- lvm_tools-0.0.2/README.md +28 -0
- lvm_tools-0.0.2/pyproject.toml +40 -0
- lvm_tools-0.0.2/src/lvm_tools/__init__.py +10 -0
- lvm_tools-0.0.2/src/lvm_tools/_version.py +21 -0
- lvm_tools-0.0.2/src/lvm_tools/config/__init__.py +1 -0
- lvm_tools-0.0.2/src/lvm_tools/config/data_config.py +206 -0
- lvm_tools-0.0.2/src/lvm_tools/config/validation.py +58 -0
- lvm_tools-0.0.2/src/lvm_tools/data/__init__.py +1 -0
- lvm_tools-0.0.2/src/lvm_tools/data/coordinates.py +73 -0
- lvm_tools-0.0.2/src/lvm_tools/data/helper.py +56 -0
- lvm_tools-0.0.2/src/lvm_tools/data/tile.py +168 -0
- lvm_tools-0.0.2/src/lvm_tools/fit_data/__init__.py +1 -0
- lvm_tools-0.0.2/src/lvm_tools/fit_data/builder.py +51 -0
- lvm_tools-0.0.2/src/lvm_tools/fit_data/clipping.py +37 -0
- lvm_tools-0.0.2/src/lvm_tools/fit_data/filtering.py +129 -0
- lvm_tools-0.0.2/src/lvm_tools/fit_data/fit_data.py +140 -0
- lvm_tools-0.0.2/src/lvm_tools/fit_data/normalisation.py +48 -0
- lvm_tools-0.0.2/src/lvm_tools/fit_data/processing.py +79 -0
- lvm_tools-0.0.2/src/lvm_tools/physical_properties/__init__.py +1 -0
- lvm_tools-0.0.2/src/lvm_tools/physical_properties/barycentric_corr.py +11 -0
- lvm_tools-0.0.2/src/lvm_tools/py.typed +0 -0
- lvm_tools-0.0.2/src/lvm_tools/utils/__init__.py +1 -0
- lvm_tools-0.0.2/src/lvm_tools/utils/mask.py +40 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
# vscode
|
|
2
|
+
.vscode/
|
|
3
|
+
|
|
4
|
+
# MacOS
|
|
5
|
+
*.DS_Store
|
|
6
|
+
|
|
7
|
+
# Byte-compiled / optimized / DLL files
|
|
8
|
+
__pycache__/
|
|
9
|
+
*.py[cod]
|
|
10
|
+
*$py.class
|
|
11
|
+
|
|
12
|
+
# C extensions
|
|
13
|
+
*.so
|
|
14
|
+
|
|
15
|
+
# Distribution / packaging
|
|
16
|
+
.Python
|
|
17
|
+
build/
|
|
18
|
+
develop-eggs/
|
|
19
|
+
dist/
|
|
20
|
+
downloads/
|
|
21
|
+
eggs/
|
|
22
|
+
.eggs/
|
|
23
|
+
lib/
|
|
24
|
+
lib64/
|
|
25
|
+
parts/
|
|
26
|
+
sdist/
|
|
27
|
+
var/
|
|
28
|
+
wheels/
|
|
29
|
+
share/python-wheels/
|
|
30
|
+
*.egg-info/
|
|
31
|
+
.installed.cfg
|
|
32
|
+
*.egg
|
|
33
|
+
src/lvm_tools/_version.py
|
|
34
|
+
# MANIFEST
|
|
35
|
+
|
|
36
|
+
# PyInstaller
|
|
37
|
+
# Usually these files are written by a python script from a template
|
|
38
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
39
|
+
*.manifest
|
|
40
|
+
*.spec
|
|
41
|
+
|
|
42
|
+
# Installer logs
|
|
43
|
+
pip-log.txt
|
|
44
|
+
pip-delete-this-directory.txt
|
|
45
|
+
|
|
46
|
+
# Unit test / coverage reports
|
|
47
|
+
htmlcov/
|
|
48
|
+
.tox/
|
|
49
|
+
.nox/
|
|
50
|
+
.coverage
|
|
51
|
+
.coverage.*
|
|
52
|
+
.cache
|
|
53
|
+
nosetests.xml
|
|
54
|
+
coverage.xml
|
|
55
|
+
*.cover
|
|
56
|
+
*.py,cover
|
|
57
|
+
.hypothesis/
|
|
58
|
+
.pytest_cache/
|
|
59
|
+
cover/
|
|
60
|
+
|
|
61
|
+
# Translations
|
|
62
|
+
*.mo
|
|
63
|
+
*.pot
|
|
64
|
+
|
|
65
|
+
# Django stuff:
|
|
66
|
+
*.log
|
|
67
|
+
local_settings.py
|
|
68
|
+
db.sqlite3
|
|
69
|
+
db.sqlite3-journal
|
|
70
|
+
|
|
71
|
+
# Flask stuff:
|
|
72
|
+
instance/
|
|
73
|
+
.webassets-cache
|
|
74
|
+
|
|
75
|
+
# Scrapy stuff:
|
|
76
|
+
.scrapy
|
|
77
|
+
|
|
78
|
+
# Sphinx documentation
|
|
79
|
+
docs/_build/
|
|
80
|
+
|
|
81
|
+
# PyBuilder
|
|
82
|
+
.pybuilder/
|
|
83
|
+
target/
|
|
84
|
+
|
|
85
|
+
# Jupyter Notebook
|
|
86
|
+
.ipynb_checkpoints
|
|
87
|
+
|
|
88
|
+
# IPython
|
|
89
|
+
profile_default/
|
|
90
|
+
ipython_config.py
|
|
91
|
+
|
|
92
|
+
# pyenv
|
|
93
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
94
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
95
|
+
# .python-version
|
|
96
|
+
|
|
97
|
+
# pipenv
|
|
98
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
99
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
100
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
101
|
+
# install all needed dependencies.
|
|
102
|
+
#Pipfile.lock
|
|
103
|
+
|
|
104
|
+
# poetry
|
|
105
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
106
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
107
|
+
# commonly ignored for libraries.
|
|
108
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
109
|
+
#poetry.lock
|
|
110
|
+
|
|
111
|
+
# pdm
|
|
112
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
113
|
+
#pdm.lock
|
|
114
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
115
|
+
# in version control.
|
|
116
|
+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
|
|
117
|
+
.pdm.toml
|
|
118
|
+
.pdm-python
|
|
119
|
+
.pdm-build/
|
|
120
|
+
|
|
121
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
122
|
+
__pypackages__/
|
|
123
|
+
|
|
124
|
+
# Celery stuff
|
|
125
|
+
celerybeat-schedule
|
|
126
|
+
celerybeat.pid
|
|
127
|
+
|
|
128
|
+
# SageMath parsed files
|
|
129
|
+
*.sage.py
|
|
130
|
+
|
|
131
|
+
# Environments
|
|
132
|
+
.env
|
|
133
|
+
.venv
|
|
134
|
+
env/
|
|
135
|
+
venv/
|
|
136
|
+
ENV/
|
|
137
|
+
env.bak/
|
|
138
|
+
venv.bak/
|
|
139
|
+
|
|
140
|
+
# Spyder project settings
|
|
141
|
+
.spyderproject
|
|
142
|
+
.spyproject
|
|
143
|
+
|
|
144
|
+
# Rope project settings
|
|
145
|
+
.ropeproject
|
|
146
|
+
|
|
147
|
+
# mkdocs documentation
|
|
148
|
+
/site
|
|
149
|
+
|
|
150
|
+
# mypy
|
|
151
|
+
.mypy_cache/
|
|
152
|
+
.dmypy.json
|
|
153
|
+
dmypy.json
|
|
154
|
+
|
|
155
|
+
# Pyre type checker
|
|
156
|
+
.pyre/
|
|
157
|
+
|
|
158
|
+
# pytype static type analyzer
|
|
159
|
+
.pytype/
|
|
160
|
+
|
|
161
|
+
# Cython debug symbols
|
|
162
|
+
cython_debug/
|
|
163
|
+
|
|
164
|
+
# PyCharm
|
|
165
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
166
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
167
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
168
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
169
|
+
#.idea/
|
lvm_tools-0.0.2/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Thomas Hilder
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
lvm_tools-0.0.2/PKG-INFO
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: lvm_tools
|
|
3
|
+
Version: 0.0.2
|
|
4
|
+
Summary: Lazily read/encapsulate LVM DRP data in a modular way
|
|
5
|
+
Author-email: Tom Hilder <Thomas.Hilder@monash.edu>
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Requires-Python: >=3.13
|
|
8
|
+
Requires-Dist: astropy>=7.1.0
|
|
9
|
+
Requires-Dist: dask>=2025.7.0
|
|
10
|
+
Requires-Dist: numpy>=2.3.2
|
|
11
|
+
Requires-Dist: scipy>=1.16.1
|
|
12
|
+
Requires-Dist: xarray>=2025.7.1
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
|
|
15
|
+
# lvm_tools
|
|
16
|
+
|
|
17
|
+
Lightweight wrapper of [LVM DRP](https://github.com/sdss/lvmdrp) data with an emphasis on modularity. Allows for lazy reading via [`dask`](https://www.dask.org), especially useful for fitting large models. Designed for use with spectrospatial models via [`spectracles`](https://github.com/TomHilder/spectracles) but probably useful for other things too.
|
|
18
|
+
|
|
19
|
+
Feel free to contact me personally if you have any questions at all.
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
TODO
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
TODO
|
|
28
|
+
|
|
29
|
+
## Citation
|
|
30
|
+
|
|
31
|
+
TODO
|
|
32
|
+
|
|
33
|
+
## Help
|
|
34
|
+
|
|
35
|
+
TODO
|
|
36
|
+
|
|
37
|
+
## TODO
|
|
38
|
+
|
|
39
|
+
- [ ] repr for FitData
|
|
40
|
+
- [ ] Logging/hashing
|
|
41
|
+
- [ ] Cache
|
|
42
|
+
- [ ] OptConfig
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# lvm_tools
|
|
2
|
+
|
|
3
|
+
Lightweight wrapper of [LVM DRP](https://github.com/sdss/lvmdrp) data with an emphasis on modularity. Allows for lazy reading via [`dask`](https://www.dask.org), especially useful for fitting large models. Designed for use with spectrospatial models via [`spectracles`](https://github.com/TomHilder/spectracles) but probably useful for other things too.
|
|
4
|
+
|
|
5
|
+
Feel free to contact me personally if you have any questions at all.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
TODO
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
TODO
|
|
14
|
+
|
|
15
|
+
## Citation
|
|
16
|
+
|
|
17
|
+
TODO
|
|
18
|
+
|
|
19
|
+
## Help
|
|
20
|
+
|
|
21
|
+
TODO
|
|
22
|
+
|
|
23
|
+
## TODO
|
|
24
|
+
|
|
25
|
+
- [ ] repr for FitData
|
|
26
|
+
- [ ] Logging/hashing
|
|
27
|
+
- [ ] Cache
|
|
28
|
+
- [ ] OptConfig
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "lvm_tools"
|
|
3
|
+
dynamic = ["version"]
|
|
4
|
+
description = "Lazily read/encapsulate LVM DRP data in a modular way"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
authors = [{ name = "Tom Hilder", email = "Thomas.Hilder@monash.edu" }]
|
|
7
|
+
requires-python = ">=3.13"
|
|
8
|
+
dependencies = [
|
|
9
|
+
"astropy>=7.1.0",
|
|
10
|
+
"dask>=2025.7.0",
|
|
11
|
+
"numpy>=2.3.2",
|
|
12
|
+
"scipy>=1.16.1",
|
|
13
|
+
"xarray>=2025.7.1",
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
[build-system]
|
|
17
|
+
requires = ["hatchling", "hatch-vcs"]
|
|
18
|
+
build-backend = "hatchling.build"
|
|
19
|
+
|
|
20
|
+
[tool.hatch.build]
|
|
21
|
+
include = ["src/lvm_tools/py.typed"]
|
|
22
|
+
exclude = ["**/__pycache__/**"]
|
|
23
|
+
|
|
24
|
+
[tool.hatch.build.targets.sdist]
|
|
25
|
+
include = ["src/**", "README.md", "LICENSE"]
|
|
26
|
+
|
|
27
|
+
[tool.hatch.build.targets.wheel]
|
|
28
|
+
packages = ["src/lvm_tools"]
|
|
29
|
+
|
|
30
|
+
[tool.hatch.build.hooks.vcs]
|
|
31
|
+
version-file = "src/lvm_tools/_version.py"
|
|
32
|
+
|
|
33
|
+
[tool.hatch.version]
|
|
34
|
+
source = "vcs"
|
|
35
|
+
|
|
36
|
+
[tool.hatch.version.raw-options]
|
|
37
|
+
local_scheme = "no-local-version"
|
|
38
|
+
|
|
39
|
+
[tool.ruff]
|
|
40
|
+
line-length = 99 # Sorry PEP8 I'm a rebel
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
from lvm_tools.config.data_config import DataConfig
|
|
2
|
+
from lvm_tools.data.tile import LVMTile, LVMTileCollection
|
|
3
|
+
from lvm_tools.fit_data.builder import FitDataBuilder
|
|
4
|
+
|
|
5
|
+
__all__ = [
|
|
6
|
+
"LVMTile",
|
|
7
|
+
"LVMTileCollection",
|
|
8
|
+
"DataConfig",
|
|
9
|
+
"FitDataBuilder",
|
|
10
|
+
]
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# file generated by setuptools-scm
|
|
2
|
+
# don't change, don't track in version control
|
|
3
|
+
|
|
4
|
+
__all__ = ["__version__", "__version_tuple__", "version", "version_tuple"]
|
|
5
|
+
|
|
6
|
+
TYPE_CHECKING = False
|
|
7
|
+
if TYPE_CHECKING:
|
|
8
|
+
from typing import Tuple
|
|
9
|
+
from typing import Union
|
|
10
|
+
|
|
11
|
+
VERSION_TUPLE = Tuple[Union[int, str], ...]
|
|
12
|
+
else:
|
|
13
|
+
VERSION_TUPLE = object
|
|
14
|
+
|
|
15
|
+
version: str
|
|
16
|
+
__version__: str
|
|
17
|
+
__version_tuple__: VERSION_TUPLE
|
|
18
|
+
version_tuple: VERSION_TUPLE
|
|
19
|
+
|
|
20
|
+
__version__ = version = '0.0.2'
|
|
21
|
+
__version_tuple__ = version_tuple = (0, 0, 2)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""config - subpackage for configurations used in data processing before fitting."""
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"""data_config.py - Objects for specifying configuration of data processing before fitting."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import asdict, dataclass
|
|
6
|
+
|
|
7
|
+
import numpy as np
|
|
8
|
+
|
|
9
|
+
from lvm_tools.config.validation import (
|
|
10
|
+
validate_apply_mask,
|
|
11
|
+
validate_excl_strategy,
|
|
12
|
+
validate_fib_status_incl,
|
|
13
|
+
validate_norm_strategy,
|
|
14
|
+
validate_offset,
|
|
15
|
+
validate_range,
|
|
16
|
+
validate_scale,
|
|
17
|
+
)
|
|
18
|
+
from lvm_tools.data.tile import LVMTileLike
|
|
19
|
+
from lvm_tools.fit_data.filtering import (
|
|
20
|
+
BAD_FLUX_THRESHOLD,
|
|
21
|
+
ExcludeStrategy,
|
|
22
|
+
FibreStatus,
|
|
23
|
+
)
|
|
24
|
+
from lvm_tools.fit_data.normalisation import NormaliseStrategy
|
|
25
|
+
from lvm_tools.fit_data.processing import get_normalisations, get_αδ_ranges, process_tile_data
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@dataclass(frozen=True)
|
|
29
|
+
class DataConfig:
|
|
30
|
+
"""
|
|
31
|
+
Configuration object for data processing before fitting.
|
|
32
|
+
|
|
33
|
+
args:
|
|
34
|
+
λ_range: tuple[float, float] - Wavelength range to include.
|
|
35
|
+
α_range: tuple[float, float] - Right Ascension range to include.
|
|
36
|
+
δ_range: tuple[float, float] - Declination range to include.
|
|
37
|
+
nans_strategy: ExcludeStrategy - Strategy for handling NaN values.
|
|
38
|
+
F_bad_strategy: ExcludeStrategy - Strategy for handling bad flux values. For "pixel", the flux range is applied to each pixel. For "spaxel", the flux range is applied to the median of all pixels in a spaxel.
|
|
39
|
+
F_range: tuple[float, float] - Flux range to include.
|
|
40
|
+
fibre_status_include: tuple[FibreStatus] - Fibre status values to include.
|
|
41
|
+
apply_mask: bool - Whether to apply a mask to the data.
|
|
42
|
+
normalise_F_strategy: NormaliseStrategy - Strategy for normalising flux data.
|
|
43
|
+
normalise_F_offset: float - Offset for normalising flux data.
|
|
44
|
+
normalise_F_scale: float - Scale for normalising flux data.
|
|
45
|
+
normalise_αδ_strategy: NormaliseStrategy - Strategy for normalising α and δ data.
|
|
46
|
+
normalise_αδ_offset: float - Offset for normalising α and δ data.
|
|
47
|
+
normalise_αδ_scale: float - Scale for normalising α and δ data.
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
# Data clipping ranges (aka choose data of interest)
|
|
51
|
+
λ_range: tuple[float, float] = (-np.inf, np.inf)
|
|
52
|
+
α_range: tuple[float, float] = (-np.inf, np.inf)
|
|
53
|
+
δ_range: tuple[float, float] = (-np.inf, np.inf)
|
|
54
|
+
# Bad data ranges and strategies (aka exclude bad data)
|
|
55
|
+
nans_strategy: ExcludeStrategy = "pixel"
|
|
56
|
+
F_bad_strategy: ExcludeStrategy = "spaxel"
|
|
57
|
+
F_range: tuple[float, float] = (BAD_FLUX_THRESHOLD, np.inf)
|
|
58
|
+
# Handling of flagged data
|
|
59
|
+
fibre_status_include: tuple[FibreStatus] = (0,)
|
|
60
|
+
apply_mask: bool = True
|
|
61
|
+
# Normalisation
|
|
62
|
+
normalise_F_strategy: NormaliseStrategy = "max only"
|
|
63
|
+
normalise_F_offset: float = 0.0
|
|
64
|
+
normalise_F_scale: float = 1.0
|
|
65
|
+
normalise_αδ_strategy: NormaliseStrategy = "padded"
|
|
66
|
+
normalise_α_offset: float = 0.0
|
|
67
|
+
normalise_α_scale: float = 1.0
|
|
68
|
+
normalise_δ_offset: float = 0.0
|
|
69
|
+
normalise_δ_scale: float = 1.0
|
|
70
|
+
|
|
71
|
+
def __post_init__(self) -> None:
|
|
72
|
+
validate_range(self.λ_range)
|
|
73
|
+
validate_range(self.α_range)
|
|
74
|
+
validate_range(self.δ_range)
|
|
75
|
+
validate_excl_strategy(self.nans_strategy)
|
|
76
|
+
validate_excl_strategy(self.F_bad_strategy)
|
|
77
|
+
validate_range(self.F_range)
|
|
78
|
+
validate_fib_status_incl(self.fibre_status_include)
|
|
79
|
+
validate_apply_mask(self.apply_mask)
|
|
80
|
+
validate_norm_strategy(self.normalise_F_strategy)
|
|
81
|
+
validate_norm_strategy(self.normalise_αδ_strategy)
|
|
82
|
+
validate_offset(self.normalise_F_offset)
|
|
83
|
+
validate_scale(self.normalise_F_scale)
|
|
84
|
+
validate_norm_strategy(self.normalise_αδ_strategy)
|
|
85
|
+
validate_offset(self.normalise_α_offset)
|
|
86
|
+
validate_scale(self.normalise_α_scale)
|
|
87
|
+
validate_offset(self.normalise_δ_offset)
|
|
88
|
+
validate_scale(self.normalise_δ_scale)
|
|
89
|
+
|
|
90
|
+
@staticmethod
|
|
91
|
+
def default() -> DataConfig:
|
|
92
|
+
return DataConfig()
|
|
93
|
+
|
|
94
|
+
@staticmethod
|
|
95
|
+
def from_tiles(
|
|
96
|
+
tiles: LVMTileLike,
|
|
97
|
+
λ_range: tuple[float, float] = (-np.inf, np.inf),
|
|
98
|
+
**overrides,
|
|
99
|
+
) -> DataConfig:
|
|
100
|
+
# λ_range cannot be set automatically
|
|
101
|
+
α_range, δ_range = get_αδ_ranges(tiles)
|
|
102
|
+
|
|
103
|
+
# Instantiate a data config with calc'd + default + overrides
|
|
104
|
+
config_dict = DataConfig(λ_range=λ_range, α_range=α_range, δ_range=δ_range).to_dict()
|
|
105
|
+
config = DataConfig.from_dict(config_dict | overrides)
|
|
106
|
+
|
|
107
|
+
# Clip and filter the data
|
|
108
|
+
ds = process_tile_data(tiles, config)
|
|
109
|
+
|
|
110
|
+
# Calculate the normalisation parameters
|
|
111
|
+
(
|
|
112
|
+
(normalise_F_offset, normalise_F_scale),
|
|
113
|
+
(normalise_α_offset, normalise_α_scale),
|
|
114
|
+
(normalise_δ_offset, normalise_δ_scale),
|
|
115
|
+
) = get_normalisations(ds, config)
|
|
116
|
+
|
|
117
|
+
# We want a square domain in the α, δ plane
|
|
118
|
+
norm_αδ_scale = max(normalise_α_scale, normalise_δ_scale)
|
|
119
|
+
|
|
120
|
+
# Update the config with the calculated values
|
|
121
|
+
norm_overrides = {
|
|
122
|
+
"normalise_F_offset": normalise_F_offset,
|
|
123
|
+
"normalise_F_scale": normalise_F_scale,
|
|
124
|
+
"normalise_α_offset": normalise_α_offset,
|
|
125
|
+
"normalise_α_scale": norm_αδ_scale,
|
|
126
|
+
"normalise_δ_offset": normalise_δ_offset,
|
|
127
|
+
"normalise_δ_scale": norm_αδ_scale,
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
# Merge partial config + norm + user overrides, with user overrides taking precedence
|
|
131
|
+
return DataConfig.from_dict(config.to_dict() | norm_overrides | overrides)
|
|
132
|
+
|
|
133
|
+
@staticmethod
|
|
134
|
+
def from_dict(config: dict) -> DataConfig:
|
|
135
|
+
if len(config) != len(DataConfig.default().to_dict()):
|
|
136
|
+
raise ValueError("config has the wrong number of entries.")
|
|
137
|
+
return DataConfig(**config)
|
|
138
|
+
|
|
139
|
+
def to_dict(self) -> dict:
|
|
140
|
+
return asdict(self)
|
|
141
|
+
|
|
142
|
+
def __repr__(self) -> str:
|
|
143
|
+
def format_tuple(t):
|
|
144
|
+
"""Format tuple with floats to 2 decimal places or scientific notation if very small."""
|
|
145
|
+
formatted = []
|
|
146
|
+
for x in t:
|
|
147
|
+
if isinstance(x, float):
|
|
148
|
+
if abs(x) < 1e-3 and x != 0:
|
|
149
|
+
formatted.append(f"{x:.2e}")
|
|
150
|
+
else:
|
|
151
|
+
formatted.append(f"{x:.2f}")
|
|
152
|
+
else:
|
|
153
|
+
formatted.append(str(x))
|
|
154
|
+
return f"({', '.join(formatted)})"
|
|
155
|
+
|
|
156
|
+
def format_float(f):
|
|
157
|
+
"""Format float to 2 decimal places, or scientific notation if very small."""
|
|
158
|
+
if abs(f) < 1e-3 and f != 0:
|
|
159
|
+
return f"{f:.2e}"
|
|
160
|
+
else:
|
|
161
|
+
return f"{f:.2f}"
|
|
162
|
+
|
|
163
|
+
lines = [f"{self.__class__.__name__}("]
|
|
164
|
+
|
|
165
|
+
lines = [f"{self.__class__.__name__} ({hex(id(self))}):"]
|
|
166
|
+
|
|
167
|
+
pad = 26
|
|
168
|
+
|
|
169
|
+
# Data clipping ranges
|
|
170
|
+
lines.append(" Data clipping ranges:")
|
|
171
|
+
lines.append(f" {'λ_range:':{pad}}{format_tuple(self.λ_range)}")
|
|
172
|
+
lines.append(f" {'α_range:':{pad}}{format_tuple(self.α_range)}")
|
|
173
|
+
lines.append(f" {'δ_range:':{pad}}{format_tuple(self.δ_range)}")
|
|
174
|
+
|
|
175
|
+
# Bad data handling
|
|
176
|
+
lines.append(" Bad data handling:")
|
|
177
|
+
lines.append(f" {'nans_strategy:':{pad}}'{self.nans_strategy}'")
|
|
178
|
+
lines.append(f" {'F_bad_strategy:':{pad}}'{self.F_bad_strategy}'")
|
|
179
|
+
lines.append(f" {'F_range:':{pad}}{format_tuple(self.F_range)}")
|
|
180
|
+
|
|
181
|
+
# Flagged data handling
|
|
182
|
+
lines.append(" Flagged data handling:")
|
|
183
|
+
lines.append(f" {'fibre_status_include:':{pad}}{self.fibre_status_include}")
|
|
184
|
+
lines.append(f" {'apply_mask:':{pad}}{self.apply_mask}")
|
|
185
|
+
|
|
186
|
+
# Flux normalisation
|
|
187
|
+
lines.append(" Flux normalisation:")
|
|
188
|
+
lines.append(f" {'normalise_F_strategy:':{pad}}'{self.normalise_F_strategy}'")
|
|
189
|
+
lines.append(
|
|
190
|
+
f" {'normalise_F_offset:':{pad}}{format_float(self.normalise_F_offset)}"
|
|
191
|
+
)
|
|
192
|
+
lines.append(f" {'normalise_F_scale:':{pad}}{format_float(self.normalise_F_scale)}")
|
|
193
|
+
|
|
194
|
+
# Coordinate normalisation
|
|
195
|
+
lines.append(" Coordinate normalisation:")
|
|
196
|
+
lines.append(f" {'normalise_αδ_strategy:':{pad}}'{self.normalise_αδ_strategy}'")
|
|
197
|
+
lines.append(
|
|
198
|
+
f" {'normalise_α_offset:':{pad}}{format_float(self.normalise_α_offset)}"
|
|
199
|
+
)
|
|
200
|
+
lines.append(f" {'normalise_α_scale:':{pad}}{format_float(self.normalise_α_scale)}")
|
|
201
|
+
lines.append(
|
|
202
|
+
f" {'normalise_δ_offset:':{pad}}{format_float(self.normalise_δ_offset)}"
|
|
203
|
+
)
|
|
204
|
+
lines.append(f" {'normalise_δ_scale:':{pad}}{format_float(self.normalise_δ_scale)}")
|
|
205
|
+
|
|
206
|
+
return "\n".join(lines)
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"""validation.py - Validation functions for data processing configuration."""
|
|
2
|
+
|
|
3
|
+
from typing import get_args
|
|
4
|
+
|
|
5
|
+
import numpy as np
|
|
6
|
+
|
|
7
|
+
from lvm_tools.fit_data.filtering import ExcludeStrategy, FibreStatus
|
|
8
|
+
from lvm_tools.fit_data.normalisation import NormaliseStrategy
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def validate_range(x_range: tuple[float, float]) -> None:
|
|
12
|
+
# if not isinstance(x_range, tuple):
|
|
13
|
+
# raise TypeError("Data range must be in a tuple.")
|
|
14
|
+
if len(x_range) != 2:
|
|
15
|
+
raise ValueError(
|
|
16
|
+
"Data range must be a tuple with exactly two values (min, max)."
|
|
17
|
+
)
|
|
18
|
+
if x_range[1] < x_range[0]:
|
|
19
|
+
raise ValueError("Requested data range restriction has max < min.")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def validate_excl_strategy(strategy: ExcludeStrategy) -> None:
|
|
23
|
+
if strategy not in get_args(ExcludeStrategy):
|
|
24
|
+
raise ValueError(f"Unknown exclusion strategy: {strategy}")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def validate_norm_strategy(strategy: NormaliseStrategy) -> None:
|
|
28
|
+
if strategy not in get_args(NormaliseStrategy):
|
|
29
|
+
raise ValueError(f"Unknown normalisation strategy: {strategy}")
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def validate_fib_status_incl(fibre_status_include: tuple[FibreStatus]) -> None:
|
|
33
|
+
# if not isinstance(fibre_status_include, tuple):
|
|
34
|
+
# raise TypeError("fibre_status_include must be a tuple.")
|
|
35
|
+
for fs in fibre_status_include:
|
|
36
|
+
if fs not in get_args(FibreStatus):
|
|
37
|
+
raise ValueError(f"Unknown fibre status: {fs}")
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def validate_offset(offset: float) -> None:
|
|
41
|
+
if not isinstance(offset, (float, np.floating)):
|
|
42
|
+
raise TypeError("offset must be float.")
|
|
43
|
+
if not np.isfinite(offset):
|
|
44
|
+
raise Exception("Bad offset (nan or infty).")
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def validate_scale(scale: float) -> None:
|
|
48
|
+
if not isinstance(scale, (float, np.floating)):
|
|
49
|
+
raise TypeError("scale must be float.")
|
|
50
|
+
if not np.isfinite(scale):
|
|
51
|
+
raise Exception("Bad scale (nan or infty).")
|
|
52
|
+
if scale <= 0:
|
|
53
|
+
raise Exception("Scale is not positive, but it must be.")
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def validate_apply_mask(apply_mask: bool) -> None:
|
|
57
|
+
if not isinstance(apply_mask, bool):
|
|
58
|
+
raise TypeError("apply_mask must be a boolean.")
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""data - subpackage for reading and encapsulating LVM data."""
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"""coordinates.py - observation time and location extraction for LVM data processing."""
|
|
2
|
+
|
|
3
|
+
# NOTE: Code is generated by an LLM and may not be fully robust.
|
|
4
|
+
|
|
5
|
+
import astropy.units as u
|
|
6
|
+
from astropy.coordinates import EarthLocation
|
|
7
|
+
from astropy.io.fits import Header
|
|
8
|
+
from astropy.time import Time
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def get_mjd(header: Header) -> float:
|
|
12
|
+
# Method 1: Use INTSTART and INTEND if available (most precise)
|
|
13
|
+
if "INTSTART" in header and "INTEND" in header:
|
|
14
|
+
start_time = Time(header["INTSTART"], format="isot")
|
|
15
|
+
end_time = Time(header["INTEND"], format="isot")
|
|
16
|
+
mid_time = start_time + (end_time - start_time) / 2
|
|
17
|
+
# print(header["MJD"])
|
|
18
|
+
# mid_time = Time(header["MJD"], format="mjd")
|
|
19
|
+
# print(mid_time.mjd)
|
|
20
|
+
# print()
|
|
21
|
+
|
|
22
|
+
# Validation: check against header EXPTIME
|
|
23
|
+
# calculated_exptime = (end_time - start_time).to(u.second).value
|
|
24
|
+
# header_exptime = header.get("EXPTIME", 0.0)
|
|
25
|
+
# if abs(calculated_exptime - header_exptime) > 1.0: # Allow 1s tolerance
|
|
26
|
+
# print(
|
|
27
|
+
# f" WARNING: Calculated exptime ({calculated_exptime:.1f}s) differs from header EXPTIME ({header_exptime}s)"
|
|
28
|
+
# )
|
|
29
|
+
|
|
30
|
+
return mid_time.mjd
|
|
31
|
+
|
|
32
|
+
# # Method 2: Use OBSTIME + EXPTIME/2 as fallback
|
|
33
|
+
# elif "OBSTIME" in header and "EXPTIME" in header:
|
|
34
|
+
# start_time = Time(header["OBSTIME"], format="isot")
|
|
35
|
+
# exptime = header["EXPTIME"] * u.second
|
|
36
|
+
# mid_time = start_time + exptime / 2
|
|
37
|
+
|
|
38
|
+
# return mid_time.mjd
|
|
39
|
+
|
|
40
|
+
# # Method 3: Use header MJD + EXPTIME/2 (least precise, integer MJD)
|
|
41
|
+
# elif "MJD" in header and "EXPTIME" in header:
|
|
42
|
+
# mjd_start = header["MJD"] # This appears to be integer MJD
|
|
43
|
+
# exptime_days = header["EXPTIME"] / 86400.0 # Convert seconds to days
|
|
44
|
+
# mjd_mid = mjd_start + exptime_days / 2
|
|
45
|
+
|
|
46
|
+
# return mjd_mid
|
|
47
|
+
|
|
48
|
+
else:
|
|
49
|
+
raise ValueError("Could not find sufficient time information in header")
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def get_observatory_code(header: Header) -> str:
|
|
53
|
+
observatory = header.get("OBSERVAT", "").strip()
|
|
54
|
+
|
|
55
|
+
# Just return the observatory code string
|
|
56
|
+
# You can convert to EarthLocation later when needed
|
|
57
|
+
known_observatories = ["LCO"] # Add other LVM observatory codes as needed
|
|
58
|
+
|
|
59
|
+
if observatory in known_observatories:
|
|
60
|
+
return observatory
|
|
61
|
+
else:
|
|
62
|
+
raise ValueError(
|
|
63
|
+
f"Unknown observatory: {observatory}. Known observatories: {known_observatories}"
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def get_observatory_location(observatory: str) -> EarthLocation:
|
|
68
|
+
# LCO = Las Campanas Observatory
|
|
69
|
+
if observatory == "LCO":
|
|
70
|
+
return EarthLocation.of_site("Las Campanas Observatory")
|
|
71
|
+
else:
|
|
72
|
+
# Add other observatories as needed
|
|
73
|
+
raise ValueError(f"Unknown observatory: {observatory}")
|