astropy-hdf5io 0.1.0__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.
- astropy_hdf5io-0.1.0/CHANGELOG.md +29 -0
- astropy_hdf5io-0.1.0/CONTRIBUTING.md +142 -0
- astropy_hdf5io-0.1.0/LICENSE +28 -0
- astropy_hdf5io-0.1.0/MANIFEST.in +6 -0
- astropy_hdf5io-0.1.0/PKG-INFO +396 -0
- astropy_hdf5io-0.1.0/README.md +354 -0
- astropy_hdf5io-0.1.0/pyproject.toml +91 -0
- astropy_hdf5io-0.1.0/setup.cfg +4 -0
- astropy_hdf5io-0.1.0/src/astropy_hdf5io/__init__.py +54 -0
- astropy_hdf5io-0.1.0/src/astropy_hdf5io/_coordinates.py +359 -0
- astropy_hdf5io-0.1.0/src/astropy_hdf5io/_group_utils.py +552 -0
- astropy_hdf5io-0.1.0/src/astropy_hdf5io/_munch_utils.py +40 -0
- astropy_hdf5io-0.1.0/src/astropy_hdf5io/_quantity.py +70 -0
- astropy_hdf5io-0.1.0/src/astropy_hdf5io/_skycoord.py +51 -0
- astropy_hdf5io-0.1.0/src/astropy_hdf5io/_table.py +564 -0
- astropy_hdf5io-0.1.0/src/astropy_hdf5io/_time.py +114 -0
- astropy_hdf5io-0.1.0/src/astropy_hdf5io.egg-info/PKG-INFO +396 -0
- astropy_hdf5io-0.1.0/src/astropy_hdf5io.egg-info/SOURCES.txt +26 -0
- astropy_hdf5io-0.1.0/src/astropy_hdf5io.egg-info/dependency_links.txt +1 -0
- astropy_hdf5io-0.1.0/src/astropy_hdf5io.egg-info/requires.txt +15 -0
- astropy_hdf5io-0.1.0/src/astropy_hdf5io.egg-info/top_level.txt +1 -0
- astropy_hdf5io-0.1.0/tests/test_coordinates.py +469 -0
- astropy_hdf5io-0.1.0/tests/test_group_utils.py +329 -0
- astropy_hdf5io-0.1.0/tests/test_quantity.py +120 -0
- astropy_hdf5io-0.1.0/tests/test_recursive.py +210 -0
- astropy_hdf5io-0.1.0/tests/test_skycoord.py +55 -0
- astropy_hdf5io-0.1.0/tests/test_table.py +578 -0
- astropy_hdf5io-0.1.0/tests/test_time.py +254 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.1.0] - 2026-02-16
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Initial release
|
|
12
|
+
- Support for `astropy.units.Quantity` serialization
|
|
13
|
+
- Support for `astropy.time.Time` serialization
|
|
14
|
+
- Support for `astropy.coordinates.SkyCoord` serialization
|
|
15
|
+
- Support for coordinate representations and differentials
|
|
16
|
+
- Support for `astropy.table.Table` and `QTable`
|
|
17
|
+
- Support for `astropy.timeseries.TimeSeries`
|
|
18
|
+
- Comprehensive test suite with 62 tests
|
|
19
|
+
- Documentation and examples
|
|
20
|
+
|
|
21
|
+
### Features
|
|
22
|
+
- Automatic registration of serializers on import
|
|
23
|
+
- Metadata preservation for tables and columns
|
|
24
|
+
- Support for masked columns
|
|
25
|
+
- Support for nested structures (dicts, lists)
|
|
26
|
+
- Unicode string handling
|
|
27
|
+
- Logarithmic unit support (magnitudes, decibels)
|
|
28
|
+
|
|
29
|
+
[0.1.0]: https://github.com/liamh/astropy-hdf5io/releases/tag/v0.1.0
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# Contributing to astropy-hdf5io
|
|
2
|
+
|
|
3
|
+
Thank you for considering contributing to astropy-hdf5io!
|
|
4
|
+
|
|
5
|
+
## Development Setup
|
|
6
|
+
|
|
7
|
+
1. Fork the repository on GitHub
|
|
8
|
+
2. Clone your fork:
|
|
9
|
+
```bash
|
|
10
|
+
git clone https://github.com/liamh/astropy-hdf5io.git
|
|
11
|
+
cd astropy-hdf5io
|
|
12
|
+
```
|
|
13
|
+
3. Install in development mode:
|
|
14
|
+
```bash
|
|
15
|
+
pip install -e ".[dev]"
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Making Changes
|
|
19
|
+
|
|
20
|
+
1. Create a new branch:
|
|
21
|
+
```bash
|
|
22
|
+
git checkout -b feature/your-feature-name
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
2. Make your changes and add tests
|
|
26
|
+
|
|
27
|
+
3. Run the test suite:
|
|
28
|
+
```bash
|
|
29
|
+
pytest tests/ -v
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
4. Format your code:
|
|
33
|
+
```bash
|
|
34
|
+
black src/ tests/
|
|
35
|
+
ruff check src/ tests/
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
5. Commit your changes:
|
|
39
|
+
```bash
|
|
40
|
+
git commit -m "Add feature: description"
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
6. Push to your fork:
|
|
44
|
+
```bash
|
|
45
|
+
git push origin feature/your-feature-name
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
7. Open a Pull Request on GitHub
|
|
49
|
+
|
|
50
|
+
## Testing
|
|
51
|
+
|
|
52
|
+
All new features must include tests. We aim for high test coverage.
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
# Run tests
|
|
56
|
+
pytest tests/ -v
|
|
57
|
+
|
|
58
|
+
# Run tests with coverage
|
|
59
|
+
pytest tests/ --cov=astropy_hdf5io --cov-report=html
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Code Style
|
|
63
|
+
|
|
64
|
+
We use:
|
|
65
|
+
|
|
66
|
+
- Black for code formatting
|
|
67
|
+
- Ruff for linting
|
|
68
|
+
- Type hints where appropriate
|
|
69
|
+
|
|
70
|
+
## Documentation
|
|
71
|
+
|
|
72
|
+
Update documentation when adding new features:
|
|
73
|
+
|
|
74
|
+
- Add docstrings to all public functions/classes
|
|
75
|
+
- Update README.md with usage examples
|
|
76
|
+
- Update CHANGELOG.md
|
|
77
|
+
|
|
78
|
+
## Adding Support for New AstroPy Types
|
|
79
|
+
|
|
80
|
+
If you want to add serialization support for a new AstroPy type:
|
|
81
|
+
|
|
82
|
+
1. Create a new file in `src/astropy_hdf5io/` (e.g., `_newtype.py`)
|
|
83
|
+
|
|
84
|
+
2. Implement serialization by monkey-patching a `to_hdf5` method:
|
|
85
|
+
```python
|
|
86
|
+
def _newtype_to_hdf5(self, hdf5_handle):
|
|
87
|
+
"""Serialize NewType to HDF5"""
|
|
88
|
+
hdf5_handle['type_tag'] = 'astropy_hdf5io.NewType'
|
|
89
|
+
# Store data...
|
|
90
|
+
|
|
91
|
+
NewType.to_hdf5 = _newtype_to_hdf5
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
3. Implement deserialization using `@subscribe_hdf5`:
|
|
95
|
+
```python
|
|
96
|
+
from fsc.hdf5_io import subscribe_hdf5
|
|
97
|
+
|
|
98
|
+
@subscribe_hdf5('astropy_hdf5io.NewType', check_on_load=False)
|
|
99
|
+
class _NewTypeDeserializer:
|
|
100
|
+
@classmethod
|
|
101
|
+
def from_hdf5(cls, hdf5_handle):
|
|
102
|
+
"""Deserialize NewType from HDF5"""
|
|
103
|
+
# Load data...
|
|
104
|
+
return NewType(...)
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
4. Import your module in `src/astropy_hdf5io/__init__.py`
|
|
108
|
+
|
|
109
|
+
5. Add comprehensive tests in `tests/test_newtype.py`
|
|
110
|
+
|
|
111
|
+
6. Update README.md with examples
|
|
112
|
+
|
|
113
|
+
## Reporting Bugs
|
|
114
|
+
|
|
115
|
+
Please include:
|
|
116
|
+
|
|
117
|
+
- Python version
|
|
118
|
+
- astropy version
|
|
119
|
+
- fsc.hdf5-io version
|
|
120
|
+
- Minimal code to reproduce the issue
|
|
121
|
+
- Expected vs actual behavior
|
|
122
|
+
- Full error traceback
|
|
123
|
+
|
|
124
|
+
## Feature Requests
|
|
125
|
+
|
|
126
|
+
Open an issue describing:
|
|
127
|
+
|
|
128
|
+
- What AstroPy type/feature you'd like supported
|
|
129
|
+
- Your use case
|
|
130
|
+
- Example of how you'd like it to work
|
|
131
|
+
|
|
132
|
+
## Code Review Process
|
|
133
|
+
|
|
134
|
+
All submissions require review. We use GitHub pull requests for this purpose.
|
|
135
|
+
|
|
136
|
+
## Questions?
|
|
137
|
+
|
|
138
|
+
Feel free to open an issue for discussion before starting work on major features.
|
|
139
|
+
|
|
140
|
+
## Code of Conduct
|
|
141
|
+
|
|
142
|
+
Be respectful and constructive in all interactions. We're all here to make astronomy software better!
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026, astropy-hdf5io contributors
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
|
7
|
+
|
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
+
list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
|
13
|
+
and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
16
|
+
contributors may be used to endorse or promote products derived from
|
|
17
|
+
this software without specific prior written permission.
|
|
18
|
+
|
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
20
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
21
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
22
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
23
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
24
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
25
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
26
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
27
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
28
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: astropy-hdf5io
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: HDF5 serialization support for AstroPy objects using fsc.hdf5-io
|
|
5
|
+
Author-email: astropy-hdf5io contributors <838019+liamh@users.noreply.github.com>
|
|
6
|
+
Maintainer-email: "Liam M. Healy" <838019+liamh@users.noreply.github.com>
|
|
7
|
+
License: BSD-3-Clause
|
|
8
|
+
Project-URL: Homepage, https://github.com/liamh/astropy-hdf5io
|
|
9
|
+
Project-URL: Documentation, https://astropy-hdf5io.readthedocs.io/
|
|
10
|
+
Project-URL: Repository, https://github.com/liamh/astropy-hdf5io.git
|
|
11
|
+
Project-URL: Issues, https://github.com/liamh/astropy-hdf5io/issues
|
|
12
|
+
Project-URL: Changelog, https://github.com/liamh/astropy-hdf5io/blob/main/CHANGELOG.md
|
|
13
|
+
Keywords: astropy,hdf5,serialization,astronomy,astrophysics,io,data
|
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
|
15
|
+
Classifier: Intended Audience :: Science/Research
|
|
16
|
+
Classifier: License :: OSI Approved :: BSD License
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Topic :: Scientific/Engineering :: Astronomy
|
|
23
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
24
|
+
Classifier: Operating System :: OS Independent
|
|
25
|
+
Requires-Python: >=3.9
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
License-File: LICENSE
|
|
28
|
+
Requires-Dist: astropy>=5.0
|
|
29
|
+
Requires-Dist: fsc.hdf5-io>=1.0
|
|
30
|
+
Requires-Dist: h5py>=3.0
|
|
31
|
+
Requires-Dist: numpy>=1.20
|
|
32
|
+
Provides-Extra: munch
|
|
33
|
+
Requires-Dist: munch>=2.5; extra == "munch"
|
|
34
|
+
Provides-Extra: dev
|
|
35
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
36
|
+
Requires-Dist: pytest-cov>=4.0; extra == "dev"
|
|
37
|
+
Requires-Dist: black>=23.0; extra == "dev"
|
|
38
|
+
Requires-Dist: ruff>=0.1.0; extra == "dev"
|
|
39
|
+
Requires-Dist: mypy>=1.0; extra == "dev"
|
|
40
|
+
Requires-Dist: munch>=2.5; extra == "dev"
|
|
41
|
+
Dynamic: license-file
|
|
42
|
+
|
|
43
|
+
# astropy-hdf5io
|
|
44
|
+
|
|
45
|
+
[](https://badge.fury.io/py/astropy-hdf5io)
|
|
46
|
+
[](https://github.com/liamh/astropy-hdf5io/actions)
|
|
47
|
+
[](https://opensource.org/licenses/BSD-3-Clause)
|
|
48
|
+
|
|
49
|
+
HDF5 serialization support for AstroPy objects using `fsc.hdf5-io`.
|
|
50
|
+
|
|
51
|
+
## Features
|
|
52
|
+
|
|
53
|
+
- **Seamless integration** with `fsc.hdf5-io` for saving/loading AstroPy objects to HDF5
|
|
54
|
+
- **Hierarchical organization** with group-level save/load and recursive dict/Munch support
|
|
55
|
+
- **Comprehensive type support** including:
|
|
56
|
+
- `Quantity` (with units, including logarithmic units)
|
|
57
|
+
- `Time` (all formats and scales)
|
|
58
|
+
- `SkyCoord` and coordinate frames
|
|
59
|
+
- `Table`, `QTable`, and `TimeSeries`
|
|
60
|
+
- Coordinate representations and differentials
|
|
61
|
+
- `EarthLocation`, `Angle`, `Longitude`, `Latitude`, `Distance`
|
|
62
|
+
- **Metadata preservation** for tables and columns
|
|
63
|
+
- **Nested structures** support (tables in dicts/lists)
|
|
64
|
+
- **Masked columns** support
|
|
65
|
+
|
|
66
|
+
## Installation
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
pip install astropy-hdf5io
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Requirements
|
|
73
|
+
|
|
74
|
+
- Python ≥ 3.9
|
|
75
|
+
- astropy ≥ 5.0
|
|
76
|
+
- fsc.hdf5-io ≥ 1.0
|
|
77
|
+
- h5py ≥ 3.0
|
|
78
|
+
- numpy ≥ 1.20
|
|
79
|
+
|
|
80
|
+
## Quick Start
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
import astropy.units as u
|
|
84
|
+
from astropy.table import QTable
|
|
85
|
+
from astropy.time import Time
|
|
86
|
+
from astropy.coordinates import SkyCoord
|
|
87
|
+
from fsc.hdf5_io import save, load
|
|
88
|
+
|
|
89
|
+
# Just import astropy_hdf5io to enable serialization
|
|
90
|
+
import astropy_hdf5io
|
|
91
|
+
|
|
92
|
+
# Create AstroPy objects
|
|
93
|
+
distance = 1171 * u.Mpc
|
|
94
|
+
time = Time('2023-01-01T00:00:00')
|
|
95
|
+
coord = SkyCoord(ra=10.68458*u.degree, dec=41.26917*u.degree, distance=distance)
|
|
96
|
+
|
|
97
|
+
# Save to HDF5
|
|
98
|
+
save(distance, 'distance.hdf5')
|
|
99
|
+
save(time, 'time.hdf5')
|
|
100
|
+
save(coord, 'coord.hdf5')
|
|
101
|
+
|
|
102
|
+
# Load from HDF5
|
|
103
|
+
loaded_distance = load('distance.hdf5')
|
|
104
|
+
loaded_time = load('time.hdf5')
|
|
105
|
+
loaded_coord = load('coord.hdf5')
|
|
106
|
+
|
|
107
|
+
print(loaded_distance) # 1171.0 Mpc
|
|
108
|
+
print(loaded_time) # 2023-01-01 00:00:00.000
|
|
109
|
+
print(loaded_coord) # <SkyCoord ...>
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Examples
|
|
113
|
+
|
|
114
|
+
### Working with Quantities
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
import astropy.units as u
|
|
118
|
+
from fsc.hdf5_io import save, load
|
|
119
|
+
import astropy_hdf5io
|
|
120
|
+
|
|
121
|
+
# Scalar and array quantities
|
|
122
|
+
distance = 42.0 * u.pc
|
|
123
|
+
velocities = [100, 200, 300] * u.km / u.s
|
|
124
|
+
|
|
125
|
+
save(distance, 'distance.hdf5')
|
|
126
|
+
save(velocities, 'velocities.hdf5')
|
|
127
|
+
|
|
128
|
+
loaded_distance = load('distance.hdf5')
|
|
129
|
+
loaded_velocities = load('velocities.hdf5')
|
|
130
|
+
|
|
131
|
+
# Complex units work too!
|
|
132
|
+
luminosity = 1e10 * u.solLum
|
|
133
|
+
flux = 1.2e-15 * u.erg / u.s / u.cm**2
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Working with Times
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
from astropy.time import Time
|
|
140
|
+
from fsc.hdf5_io import save, load
|
|
141
|
+
import astropy_hdf5io
|
|
142
|
+
|
|
143
|
+
# Different time formats
|
|
144
|
+
t_iso = Time('2023-01-01T12:00:00')
|
|
145
|
+
t_jd = Time(2459945.5, format='jd')
|
|
146
|
+
t_mjd = Time(59945.0, format='mjd')
|
|
147
|
+
|
|
148
|
+
# Different time scales
|
|
149
|
+
t_utc = Time('2023-01-01', scale='utc')
|
|
150
|
+
t_tai = Time('2023-01-01', scale='tai')
|
|
151
|
+
|
|
152
|
+
save(t_iso, 'time.hdf5')
|
|
153
|
+
loaded = load('time.hdf5')
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Working with Coordinates
|
|
157
|
+
|
|
158
|
+
```python
|
|
159
|
+
from astropy.coordinates import SkyCoord
|
|
160
|
+
import astropy.units as u
|
|
161
|
+
from fsc.hdf5_io import save, load
|
|
162
|
+
import astropy_hdf5io
|
|
163
|
+
|
|
164
|
+
# 2D coordinates
|
|
165
|
+
coord_2d = SkyCoord(ra=10.68*u.degree, dec=41.27*u.degree, frame='icrs')
|
|
166
|
+
|
|
167
|
+
# 3D coordinates with distance
|
|
168
|
+
coord_3d = SkyCoord(ra=10.68*u.degree, dec=41.27*u.degree,
|
|
169
|
+
distance=770*u.kpc, frame='icrs')
|
|
170
|
+
|
|
171
|
+
# Arrays of coordinates
|
|
172
|
+
coords = SkyCoord(ra=[10, 20, 30]*u.degree,
|
|
173
|
+
dec=[40, 50, 60]*u.degree)
|
|
174
|
+
|
|
175
|
+
save(coord_3d, 'coord.hdf5')
|
|
176
|
+
loaded = load('coord.hdf5')
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### Working with Tables
|
|
180
|
+
|
|
181
|
+
```python
|
|
182
|
+
from astropy.table import Table, QTable
|
|
183
|
+
import astropy.units as u
|
|
184
|
+
from fsc.hdf5_io import save, load
|
|
185
|
+
import astropy_hdf5io
|
|
186
|
+
|
|
187
|
+
# Regular Table
|
|
188
|
+
t = Table({
|
|
189
|
+
'name': ['Star A', 'Star B', 'Star C'],
|
|
190
|
+
'magnitude': [10.5, 12.3, 11.8],
|
|
191
|
+
'distance': [100, 150, 120]
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
# QTable with Quantities
|
|
195
|
+
qt = QTable({
|
|
196
|
+
'name': ['Galaxy 1', 'Galaxy 2'],
|
|
197
|
+
'redshift': [0.1, 0.2],
|
|
198
|
+
'distance': [500, 1000] * u.Mpc,
|
|
199
|
+
'flux': [1.2e-15, 8.5e-16] * u.erg / u.s / u.cm**2
|
|
200
|
+
})
|
|
201
|
+
|
|
202
|
+
# Add metadata
|
|
203
|
+
qt.meta['telescope'] = 'HST'
|
|
204
|
+
qt.meta['observer'] = 'J. Smith'
|
|
205
|
+
qt['distance'].info.description = 'Luminosity distance'
|
|
206
|
+
|
|
207
|
+
save(qt, 'galaxies.hdf5')
|
|
208
|
+
loaded = load('galaxies.hdf5')
|
|
209
|
+
|
|
210
|
+
print(loaded.meta['telescope']) # 'HST'
|
|
211
|
+
print(loaded['distance'].info.description) # 'Luminosity distance'
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### Working with TimeSeries
|
|
215
|
+
|
|
216
|
+
```python
|
|
217
|
+
from astropy.timeseries import TimeSeries
|
|
218
|
+
from astropy.time import Time
|
|
219
|
+
import astropy.units as u
|
|
220
|
+
from fsc.hdf5_io import save, load
|
|
221
|
+
import astropy_hdf5io
|
|
222
|
+
|
|
223
|
+
times = Time(['2023-01-01T00:00:00',
|
|
224
|
+
'2023-01-01T01:00:00',
|
|
225
|
+
'2023-01-01T02:00:00'])
|
|
226
|
+
|
|
227
|
+
ts = TimeSeries(time=times)
|
|
228
|
+
ts['flux'] = [100, 120, 110] * u.Jy
|
|
229
|
+
ts['temperature'] = [5800, 5850, 5820] * u.K
|
|
230
|
+
|
|
231
|
+
ts.meta['target'] = 'Variable Star XYZ'
|
|
232
|
+
|
|
233
|
+
save(ts, 'timeseries.hdf5')
|
|
234
|
+
loaded = load('timeseries.hdf5')
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
### Complex Nested Structures
|
|
238
|
+
|
|
239
|
+
```python
|
|
240
|
+
from astropy.table import QTable
|
|
241
|
+
from astropy.time import Time
|
|
242
|
+
from astropy.coordinates import SkyCoord
|
|
243
|
+
import astropy.units as u
|
|
244
|
+
from fsc.hdf5_io import save, load
|
|
245
|
+
import astropy_hdf5io
|
|
246
|
+
|
|
247
|
+
# Complex nested data structure
|
|
248
|
+
observation_data = {
|
|
249
|
+
'metadata': {
|
|
250
|
+
'telescope': 'VLT',
|
|
251
|
+
'observer': 'J. Smith',
|
|
252
|
+
'date': Time('2023-01-01')
|
|
253
|
+
},
|
|
254
|
+
'targets': [
|
|
255
|
+
SkyCoord(ra=10*u.degree, dec=40*u.degree, distance=1000*u.pc),
|
|
256
|
+
SkyCoord(ra=20*u.degree, dec=50*u.degree, distance=2000*u.pc)
|
|
257
|
+
],
|
|
258
|
+
'photometry': QTable({
|
|
259
|
+
'time': Time(['2023-01-01', '2023-01-02']),
|
|
260
|
+
'flux': [1.2, 1.5] * u.Jy,
|
|
261
|
+
'magnitude': [18.5, 18.3]
|
|
262
|
+
})
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
save(observation_data, 'observation.hdf5')
|
|
266
|
+
loaded = load('observation.hdf5')
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
## How It Works
|
|
270
|
+
|
|
271
|
+
`astropy-hdf5io` extends `fsc.hdf5-io` by:
|
|
272
|
+
|
|
273
|
+
1. **Monkey-patching** `to_hdf5()` methods onto AstroPy classes
|
|
274
|
+
2. **Registering deserializers** using the `@subscribe_hdf5` decorator
|
|
275
|
+
3. **Preserving metadata** including units, coordinate frames, and table information
|
|
276
|
+
|
|
277
|
+
Simply importing `astropy_hdf5io` automatically registers all serializers. After that, you can use `fsc.hdf5_io.save()` and `fsc.hdf5_io.load()` with AstroPy objects seamlessly.
|
|
278
|
+
|
|
279
|
+
## Supported Types
|
|
280
|
+
|
|
281
|
+
### Units and Quantities
|
|
282
|
+
- `astropy.units.Quantity` (including logarithmic units like magnitudes)
|
|
283
|
+
|
|
284
|
+
### Time
|
|
285
|
+
- `astropy.time.Time` (all formats: ISO, JD, MJD, etc.)
|
|
286
|
+
|
|
287
|
+
### Coordinates
|
|
288
|
+
- `astropy.coordinates.SkyCoord`
|
|
289
|
+
- `astropy.coordinates.Angle`
|
|
290
|
+
- `astropy.coordinates.Longitude`
|
|
291
|
+
- `astropy.coordinates.Latitude`
|
|
292
|
+
- `astropy.coordinates.Distance`
|
|
293
|
+
- `astropy.coordinates.EarthLocation`
|
|
294
|
+
|
|
295
|
+
### Representations
|
|
296
|
+
- `CartesianRepresentation`
|
|
297
|
+
- `SphericalRepresentation`
|
|
298
|
+
- `CylindricalRepresentation`
|
|
299
|
+
- `PhysicsSphericalRepresentation`
|
|
300
|
+
|
|
301
|
+
### Differentials
|
|
302
|
+
- `CartesianDifferential`
|
|
303
|
+
- `SphericalDifferential`
|
|
304
|
+
- `SphericalCosLatDifferential`
|
|
305
|
+
- `CylindricalDifferential`
|
|
306
|
+
|
|
307
|
+
### Tables
|
|
308
|
+
- `astropy.table.Table` (including masked columns)
|
|
309
|
+
- `astropy.table.QTable` (with Quantity columns)
|
|
310
|
+
- `astropy.timeseries.TimeSeries`
|
|
311
|
+
|
|
312
|
+
### Groups
|
|
313
|
+
|
|
314
|
+
`astropy-hdf5io` provides utilities for organizing data in group hierarchies in the HDF5 file:
|
|
315
|
+
|
|
316
|
+
```python
|
|
317
|
+
from astropy_hdf5io import save_to_group, load_from_group, print_tree
|
|
318
|
+
from astropy.coordinates import SkyCoord
|
|
319
|
+
import astropy.units as u
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
# Save to nested groups
|
|
323
|
+
coord = SkyCoord(ra=10*u.degree, dec=40*u.degree, distance=1000*u.pc)
|
|
324
|
+
save_to_group(coord, 'astronomy.h5', 'observations/targets/ngc1234')
|
|
325
|
+
|
|
326
|
+
# Load from specific group
|
|
327
|
+
loaded = load_from_group('astronomy.h5', 'observations/targets/ngc1234')
|
|
328
|
+
|
|
329
|
+
# Show structure
|
|
330
|
+
print_tree('astronomy.hdf5')
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
## Development
|
|
334
|
+
|
|
335
|
+
### Setup
|
|
336
|
+
|
|
337
|
+
```bash
|
|
338
|
+
git clone https://github.com/liamh/astropy-hdf5io.git
|
|
339
|
+
cd astropy-hdf5io
|
|
340
|
+
pip install -e ".[dev]"
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
### Running Tests
|
|
344
|
+
|
|
345
|
+
```bash
|
|
346
|
+
pytest tests/ -v
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
### Building Documentation
|
|
350
|
+
|
|
351
|
+
```bash
|
|
352
|
+
cd docs
|
|
353
|
+
make html
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
## Contributing
|
|
357
|
+
|
|
358
|
+
Contributions are welcome! Please:
|
|
359
|
+
|
|
360
|
+
1. Fork the repository
|
|
361
|
+
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
|
|
362
|
+
3. Make your changes and add tests
|
|
363
|
+
4. Run the test suite (`pytest`)
|
|
364
|
+
5. Commit your changes (`git commit -m 'Add amazing feature'`)
|
|
365
|
+
6. Push to the branch (`git push origin feature/amazing-feature`)
|
|
366
|
+
7. Open a Pull Request
|
|
367
|
+
|
|
368
|
+
## License
|
|
369
|
+
|
|
370
|
+
This project is licensed under the BSD 3-Clause License - see the [LICENSE](LICENSE) file for details.
|
|
371
|
+
|
|
372
|
+
## Acknowledgments
|
|
373
|
+
|
|
374
|
+
- Built on top of [fsc.hdf5-io](https://github.com/FrescolinoGroup/pyhdf5io/)
|
|
375
|
+
- Designed for seamless integration with [AstroPy](https://www.astropy.org/)
|
|
376
|
+
- Inspired by the AstroPy community's need for efficient HDF5 storage
|
|
377
|
+
|
|
378
|
+
## Citation
|
|
379
|
+
|
|
380
|
+
If you use this package in your research, please cite:
|
|
381
|
+
|
|
382
|
+
```bibtex
|
|
383
|
+
@software{astropy_hdf5io,
|
|
384
|
+
author = {{astropy-hdf5io contributors}},
|
|
385
|
+
title = {astropy-hdf5io: HDF5 serialization for AstroPy},
|
|
386
|
+
url = {https://github.com/liamh/astropy-hdf5io},
|
|
387
|
+
version = {0.1.0},
|
|
388
|
+
year = {2026}
|
|
389
|
+
}
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
## Support
|
|
393
|
+
|
|
394
|
+
- **Issues**: [GitHub Issues](https://github.com/liamh/astropy-hdf5io/issues)
|
|
395
|
+
- **Discussions**: [GitHub Discussions](https://github.com/liamh/astropy-hdf5io/discussions)
|
|
396
|
+
- **Documentation**: [Read the Docs](https://astropy-hdf5io.readthedocs.io/)
|