astro-imaging-agent 0.0.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.
Files changed (54) hide show
  1. astro_imaging_agent-0.0.0/AGENTS.md +12 -0
  2. astro_imaging_agent-0.0.0/LICENSE +202 -0
  3. astro_imaging_agent-0.0.0/NOTICE +7 -0
  4. astro_imaging_agent-0.0.0/PKG-INFO +316 -0
  5. astro_imaging_agent-0.0.0/README.md +271 -0
  6. astro_imaging_agent-0.0.0/development.md +113 -0
  7. astro_imaging_agent-0.0.0/examples/pipeline.yaml +15 -0
  8. astro_imaging_agent-0.0.0/pyproject.toml +109 -0
  9. astro_imaging_agent-0.0.0/scripts/check_dist.py +58 -0
  10. astro_imaging_agent-0.0.0/scripts/smoke_dist.py +71 -0
  11. astro_imaging_agent-0.0.0/src/astroagent/__init__.py +5 -0
  12. astro_imaging_agent-0.0.0/src/astroagent/__main__.py +6 -0
  13. astro_imaging_agent-0.0.0/src/astroagent/agent/__init__.py +22 -0
  14. astro_imaging_agent-0.0.0/src/astroagent/agent/executor.py +69 -0
  15. astro_imaging_agent-0.0.0/src/astroagent/agent/models.py +11 -0
  16. astro_imaging_agent-0.0.0/src/astroagent/agent/planner.py +89 -0
  17. astro_imaging_agent-0.0.0/src/astroagent/agent/prompts.py +30 -0
  18. astro_imaging_agent-0.0.0/src/astroagent/agent/providers.py +215 -0
  19. astro_imaging_agent-0.0.0/src/astroagent/analysis/__init__.py +6 -0
  20. astro_imaging_agent-0.0.0/src/astroagent/analysis/background.py +100 -0
  21. astro_imaging_agent-0.0.0/src/astroagent/analysis/quality.py +20 -0
  22. astro_imaging_agent-0.0.0/src/astroagent/analysis/stars.py +116 -0
  23. astro_imaging_agent-0.0.0/src/astroagent/analysis/statistics.py +101 -0
  24. astro_imaging_agent-0.0.0/src/astroagent/cli/__init__.py +1 -0
  25. astro_imaging_agent-0.0.0/src/astroagent/cli/main.py +208 -0
  26. astro_imaging_agent-0.0.0/src/astroagent/errors.py +17 -0
  27. astro_imaging_agent-0.0.0/src/astroagent/io/__init__.py +6 -0
  28. astro_imaging_agent-0.0.0/src/astroagent/io/fits.py +94 -0
  29. astro_imaging_agent-0.0.0/src/astroagent/io/images.py +203 -0
  30. astro_imaging_agent-0.0.0/src/astroagent/io/metadata.py +19 -0
  31. astro_imaging_agent-0.0.0/src/astroagent/models/__init__.py +5 -0
  32. astro_imaging_agent-0.0.0/src/astroagent/models/base.py +7 -0
  33. astro_imaging_agent-0.0.0/src/astroagent/models/image.py +46 -0
  34. astro_imaging_agent-0.0.0/src/astroagent/pipeline/__init__.py +12 -0
  35. astro_imaging_agent-0.0.0/src/astroagent/pipeline/executor.py +170 -0
  36. astro_imaging_agent-0.0.0/src/astroagent/pipeline/models.py +61 -0
  37. astro_imaging_agent-0.0.0/src/astroagent/pipeline/serialization.py +59 -0
  38. astro_imaging_agent-0.0.0/src/astroagent/py.typed +0 -0
  39. astro_imaging_agent-0.0.0/src/astroagent/tools/__init__.py +6 -0
  40. astro_imaging_agent-0.0.0/src/astroagent/tools/background.py +47 -0
  41. astro_imaging_agent-0.0.0/src/astroagent/tools/base.py +64 -0
  42. astro_imaging_agent-0.0.0/src/astroagent/tools/denoise.py +36 -0
  43. astro_imaging_agent-0.0.0/src/astroagent/tools/normalization.py +44 -0
  44. astro_imaging_agent-0.0.0/src/astroagent/tools/registry.py +41 -0
  45. astro_imaging_agent-0.0.0/src/astroagent/tools/stretch.py +49 -0
  46. astro_imaging_agent-0.0.0/tests/conftest.py +45 -0
  47. astro_imaging_agent-0.0.0/tests/test_agent.py +84 -0
  48. astro_imaging_agent-0.0.0/tests/test_analysis.py +136 -0
  49. astro_imaging_agent-0.0.0/tests/test_cli.py +161 -0
  50. astro_imaging_agent-0.0.0/tests/test_io.py +192 -0
  51. astro_imaging_agent-0.0.0/tests/test_pipeline.py +172 -0
  52. astro_imaging_agent-0.0.0/tests/test_provider_transport.py +117 -0
  53. astro_imaging_agent-0.0.0/tests/test_providers.py +202 -0
  54. astro_imaging_agent-0.0.0/tests/test_tools.py +162 -0
@@ -0,0 +1,12 @@
1
+ # Project instructions
2
+
3
+ - Never create a Git commit or push changes unless the user explicitly changes this instruction.
4
+ - Prepare completed changes in the Git staging area. Preserve unrelated existing edits.
5
+ - Use Poetry for dependency management and execution; do not introduce uv.
6
+ - Write meaningful tests for new behavior and bug fixes, using small synthetic images.
7
+ - Run pytest, Ruff formatting/linting, mypy, and package build checks before handing off work.
8
+ - Keep image tools, analysis, pipeline execution, CLI, and planning independent.
9
+ - A saved PipelineDefinition must execute without an agent or an LLM provider.
10
+ - Processing must be deterministic and must preserve relevant FITS metadata.
11
+ - Document public APIs and behavior, including numerical limitations.
12
+ - Do not add GPU processing, external LLM integrations, or unrelated dependencies without a task requiring them.
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,7 @@
1
+ astro-imaging-agent
2
+ Copyright 2026 Alpha Codes s.r.o.
3
+
4
+ Made by Alpha Codes s.r.o.
5
+ Author and maintainer: Ondřej Brůha <ondrej.bruha@alphacodes.eu>
6
+
7
+ Licensed under the Apache License, Version 2.0.
@@ -0,0 +1,316 @@
1
+ Metadata-Version: 2.4
2
+ Name: astro-imaging-agent
3
+ Version: 0.0.0
4
+ Summary: Deterministic astronomical FITS processing with reproducible pipelines and provider-independent planning
5
+ License-Expression: Apache-2.0
6
+ License-File: LICENSE
7
+ License-File: NOTICE
8
+ Keywords: astronomy,fits,image-processing,cli,pipelines
9
+ Author: Ondřej Brůha
10
+ Author-email: ondrej.bruha@alphacodes.eu
11
+ Maintainer: Ondřej Brůha
12
+ Maintainer-email: ondrej.bruha@alphacodes.eu
13
+ Requires-Python: >=3.12,<4.0
14
+ Classifier: Development Status :: 3 - Alpha
15
+ Classifier: Environment :: Console
16
+ Classifier: Intended Audience :: Science/Research
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
21
+ Classifier: Topic :: Scientific/Engineering :: Astronomy
22
+ Classifier: Typing :: Typed
23
+ Provides-Extra: anthropic
24
+ Provides-Extra: gemini
25
+ Provides-Extra: llm
26
+ Provides-Extra: openai
27
+ Requires-Dist: Pillow (>=11.0,<13.0)
28
+ Requires-Dist: PyYAML (>=6.0.2,<7.0)
29
+ Requires-Dist: anthropic (>=0.60,<1.0) ; extra == "anthropic"
30
+ Requires-Dist: anthropic (>=0.60,<1.0) ; extra == "llm"
31
+ Requires-Dist: astropy (>=7.0,<9.0)
32
+ Requires-Dist: google-genai (>=1.30,<3.0) ; extra == "gemini"
33
+ Requires-Dist: google-genai (>=1.30,<3.0) ; extra == "llm"
34
+ Requires-Dist: numpy (>=2.0,<3.0)
35
+ Requires-Dist: openai (>=1.90,<3.0) ; extra == "llm"
36
+ Requires-Dist: openai (>=1.90,<3.0) ; extra == "openai"
37
+ Requires-Dist: photutils (>=2.2,<4.0)
38
+ Requires-Dist: pydantic (>=2.10,<3.0)
39
+ Requires-Dist: pypng (>=0.20220715.0,<1.0)
40
+ Requires-Dist: scipy (>=1.14,<2.0)
41
+ Requires-Dist: tifffile (>=2025.1,<2027.0)
42
+ Requires-Dist: typer (>=0.19,<1.0)
43
+ Description-Content-Type: text/markdown
44
+
45
+ # astro-imaging-agent
46
+
47
+ **Made by Alpha Codes s.r.o.** Author and maintainer: **Ondřej Brůha**
48
+ ([ondrej.bruha@alphacodes.eu](mailto:ondrej.bruha@alphacodes.eu)).
49
+
50
+ `aia` is a Python CLI and modular astronomical image-processing library. It measures
51
+ images, applies deterministic processing tools, and saves replayable YAML pipelines
52
+ with JSON processing reports. The default rule-based planner runs entirely locally.
53
+ Optional OpenAI, Anthropic and Google Gemini planners interpret natural-language goals.
54
+
55
+ The purpose of the LLM integration is **planning and orchestration**.
56
+ A generative model never modifies pixels. The processing engine accepts a validated
57
+ pipeline and remains usable independently of any agent.
58
+
59
+ ## Installation
60
+
61
+ Requires Python **3.12+**. Package name: `astro-imaging-agent`; Python import:
62
+ `astroagent`; CLI command: **`aia`**.
63
+
64
+ After the first PyPI release:
65
+
66
+ ```bash
67
+ python -m pip install astro-imaging-agent
68
+ aia --help
69
+ ```
70
+
71
+ For development from source, see [development.md](development.md). The core runs
72
+ locally; optional LLM planners require their SDK extra and API key.
73
+
74
+ ## Supported image formats
75
+
76
+ | Format | Reading | Writing | Precision and metadata |
77
+ | --- | --- | --- | --- |
78
+ | FITS (`.fit`, `.fits`, `.fts`, also `.gz`) | Mono and unambiguous RGB image HDUs | Mono/RGB | Integer or float; scientific header, WCS, COMMENT and HISTORY preserved; structural, scaling and checksum cards regenerated |
79
+ | TIFF (`.tif`, `.tiff`) | Single mono/RGB image; contiguous or planar RGB | Mono/RGB | Integer or float arrays preserved; own exports embed original metadata and the complete FITS header in ImageDescription |
80
+ | PNG | Mono/RGB, including **16-bit RGB** and opaque palettes | Mono/RGB | uint8 stays 8-bit; uint16/normalized floats export as 16-bit; lossless compression, float quantization |
81
+ | JPEG (`.jpg`, `.jpeg`) | Mono/RGB | Mono/RGB | 8-bit **lossy**, quality 95 with no chroma subsampling |
82
+ | WebP | Single mono/RGB frame | 8-bit RGB | Lossless compression; floats/uint16 quantized to 8-bit; mono exports decode as RGB |
83
+ | BMP | Mono/RGB | Mono/RGB | 8-bit, lossless compression; floats/uint16 quantized to 8-bit |
84
+
85
+ PNG/JPEG/WebP/BMP export accepts float pixels in **0..1**, or unsigned 8/16-bit
86
+ integer input scaled by its dtype range. It never silently stretches raw scientific
87
+ data. Add `normalize` or `stretch` before exporting an unbounded float image.
88
+ TIFF and FITS preserve unbounded floats and negative sky-subtracted residuals.
89
+ Standard raster exports retain original metadata in the processing JSON sidecar;
90
+ they do not embed a FITS header. JPEG/WebP/BMP are display products, not scientific
91
+ intermediates. Alpha channels, animated images, TIFF stacks and non-RGB FITS cubes
92
+ are rejected with a readable error. Ordinary JPEG/WebP/BMP EXIF orientation is applied
93
+ when loading. Existing tone mapping in display images cannot be reliably inferred.
94
+
95
+ FITS RGB is internally `(height, width, 3)`. A cube without an `ASTRCHAX` card
96
+ must have exactly one end axis of length three; a cube with both end axes of length
97
+ three is ambiguous. Own exports declare the NumPy storage channel axis in
98
+ `ASTRCHAX`. Loaded FITS storage orientation is retained, preserving WCS axis mapping.
99
+
100
+ ## CLI examples
101
+
102
+ ```bash
103
+ aia inspect image.fit
104
+ aia inspect image.fit --json
105
+ aia analyze-background image.fit
106
+ aia analyze-stars image.fit --fwhm 3 --threshold-sigma 5
107
+
108
+ aia normalize image.fit normalized.fit
109
+ aia stretch image.fit stretched.fit --method asinh --strength 0.6
110
+ aia denoise image.fit smoothed.fit --sigma 0.8
111
+ aia background-extract image.fit corrected.fit --grid-size 8 --polynomial-degree 2
112
+
113
+ # The output extension selects the format.
114
+ aia stretch image.fit preview.png --strength 0.6
115
+ aia normalize photo.tiff preview.jpg
116
+ aia inspect preview.png --json
117
+
118
+ aia run examples/pipeline.yaml --input image.fit --output processed.fit
119
+ aia agent image.fit "zpracuj tento snímek přirozeně a nepřepal hvězdy" --dry-run --explain
120
+ aia agent image.fit "zpracuj tento obrázek" --output processed.fit --explain
121
+
122
+ aia tools
123
+ aia -v run examples/pipeline.yaml --input image.fit --output processed.fit
124
+ aia -vv inspect missing.fit
125
+ ```
126
+
127
+ Verbosity flags precede the command: `-v` logs steps, `-vv` includes debug tracebacks.
128
+ Expected errors show `Error: ...` with exit code 1; normal execution has no debug logs.
129
+ Single-tool commands can omit the output, defaulting to `<input-stem>.processed.fit`.
130
+ Use `--overwrite` to replace output artifacts; input replacement is always refused.
131
+ `python -m astroagent` provides the same CLI.
132
+
133
+ ## Pipeline and processing reports
134
+
135
+ ```yaml
136
+ version: 1
137
+ steps:
138
+ - tool: background_extract
139
+ params:
140
+ grid_size: 8
141
+ polynomial_degree: 2
142
+ sigma_clipping_threshold: 3.0
143
+ - tool: denoise
144
+ params:
145
+ method: gaussian
146
+ sigma: 0.8
147
+ - tool: stretch
148
+ params:
149
+ method: asinh
150
+ strength: 0.6
151
+ ```
152
+
153
+ Every processing command saves:
154
+
155
+ ```text
156
+ processed.fit
157
+ processed.pipeline.yaml
158
+ processed.processing.json
159
+ ```
160
+
161
+ The saved YAML contains all **resolved defaults**, so changes in future defaults do
162
+ not change the plan. Replay it with `aia run processed.pipeline.yaml --input image.fit
163
+ --output replay.fit`. All steps and parameters are validated before processing starts;
164
+ unknown tools, misspelled fields, unsupported versions and invalid values are rejected.
165
+ The executor stops at the first failure and identifies its step number.
166
+
167
+ The JSON report contains input/output paths, package/dependency versions, pixel
168
+ SHA-256 hashes, resolved pipeline, per-step before/after metrics, elapsed milliseconds,
169
+ warnings and (for agent runs) the request, short explanations, and full analysis of
170
+ the initial/final images. Pixel hashes canonicalize data as little-endian float64
171
+ with shape; the output-file hash identifies the encoded artifact. Raster export
172
+ quantization is also measured separately. Timings are informational and vary between
173
+ runs. Replay equality requires the same inputs, tool versions, parameters and numerical
174
+ environment; cross-platform floating-point bitwise identity is not promised.
175
+
176
+ Outputs are checked for collisions before execution. Each artifact is written
177
+ atomically, but the three-file bundle is not a transaction: a disk failure may leave
178
+ a partial bundle. Intermediate files are not saved.
179
+
180
+ ## Architecture
181
+
182
+ ```text
183
+ src/astroagent/
184
+ models/ ndarray-based AstroImage and shared strict schema model
185
+ io/ FITS/raster adapters and metadata handling
186
+ analysis/ finite statistics, robust background, photutils stars, quality
187
+ tools/ typed deterministic tools and immutable per-executor registry
188
+ pipeline/ Pydantic definitions, YAML/JSON, executor and execution history
189
+ agent/ planner protocols, rules, and analysis/plan/execute orchestration
190
+ cli/ Typer argument parsing, presentation and error boundary
191
+ ```
192
+
193
+ The central boundary is:
194
+
195
+ ```text
196
+ Planner -> PlanResult(PipelineDefinition, explanations)
197
+ -> PipelineExecutor -> ImageTool -> ToolResult
198
+ ```
199
+
200
+ `PipelineExecutor` does not import the agent layer. `AstroImage` is a dataclass so
201
+ large NumPy arrays do not pass through Pydantic. Schemas, metrics, plans and reports
202
+ use Pydantic v2. Tools operate in float64, return new arrays, copy metadata/headers,
203
+ and provide before/after metrics and warnings. There is no global mutable registry.
204
+ SciPy supplies Gaussian filtering and NumPy supplies polynomial fitting; scikit-image
205
+ is not needed for this implementation. Optional future backends (OpenCV, CuPy,
206
+ PyTorch, SEP, astroalign, ccdproc) can live behind new tools/adapters.
207
+
208
+ ## Analysis and numerical behavior
209
+
210
+ - `inspect` reports dimensions `(height, width)`, channels, dtype, finite min/max,
211
+ mean/median/std, percentiles 1/5/50/95/99, saturation and JSON-safe metadata.
212
+ RGB summary values aggregate channel samples. NaN/Inf are excluded with a warning;
213
+ processing rejects them until a future repair/masking tool is provided.
214
+ - Saturation uses `SATURATE`, then the integer dtype ceiling, or 1 for bounded float
215
+ images. Otherwise its fraction is `null` with a warning. It counts **channel samples**,
216
+ not whole RGB pixels. A normalized maximum is not evidence of physical detector
217
+ saturation; saturation fractions after stretching are display-range measurements.
218
+ - Background uses sigma-clipped tile medians and a fitted plane. `sigma` is clipped
219
+ residual noise; `gradient_estimate` is the fitted surface's 95th–5th percentile
220
+ range in input units. RGB analysis uses equal-weight channel averaging.
221
+ - Stars use photutils `DAOStarFinder`. Positive local second moments give approximate
222
+ Gaussian FWHM in pixels, ellipticity `1-b/a`, and eccentricity `sqrt(1-(b/a)^2)`.
223
+ Failed detection or unreliable shapes return `null` and warnings. This is a rough
224
+ quality indicator, not precision PSF fitting or calibrated photometry.
225
+ - Normalize uses one global min/max scale across RGB; constant images map to the
226
+ lower endpoint. The target interval must satisfy `0 <= lower < upper <= 1`.
227
+ - Stretch also uses global endpoints. `black_point` is in input units and must be
228
+ below the maximum. `linear` ignores strength; `asinh` uses
229
+ `gain = 10**(3*strength)-1` and `asinh(gain*x)/asinh(gain)`, with strength zero
230
+ reducing to linear. Strength is in 0..1. Explicit black points can clip shadows.
231
+ - Gaussian denoising uses reflected spatial edges and never mixes RGB channels.
232
+ It softens stars; the report makes that limitation explicit.
233
+ - Background extraction subtracts a total-degree 0–3 polynomial from each channel
234
+ independently. It removes offset as well as gradient and preserves negative
235
+ values. Extended nebulosity, gradients within tiles and crowded fields can bias
236
+ automatic samples; rank-deficient grids are rejected. It is not a full DBE tool.
237
+
238
+ ## Agent flow
239
+
240
+ `AgentExecutor` loads an image, inspects it, estimates sky and stars, then sends only
241
+ `ImageMetrics` and `ToolDescription` schemas to `Planner.create_plan`. The CLI prints
242
+ the pipeline, executes it through the ordinary executor, reanalyzes, and saves all
243
+ artifacts. `--dry-run` displays the plan without writing any files. `--explain`
244
+ displays concise explicit reasons; no hidden model reasoning is stored.
245
+
246
+ `RuleBasedPlanner` compares gradient/noise against the robust 99th–1st percentile
247
+ range: gradient over 15% selects a degree-1 background model, noise over 8% selects
248
+ mild Gaussian denoising, and a dark median suggests an asinh stretch. `ASTRSTR`
249
+ marks images stretched by this tool. Out-of-range non-linear images are normalized.
250
+ Constant images have empty plans. Only advertised tools can be selected.
251
+
252
+ **The rule-based MVP does not understand the free-text request.** It records it for
253
+ provenance and plans from measurements. Its thresholds and linearity inference are
254
+ heuristics, so review `--dry-run --explain` before relying on them. `LLMPlanner` provides the common boundary for `OpenAIPlanner`, `AnthropicPlanner`
255
+ and `GeminiPlanner`; each returns the same validated `PlanResult` and has no access
256
+ to image arrays or engine internals.
257
+
258
+ ## LLM planners
259
+
260
+ Install only the provider you need, or all three:
261
+
262
+ ```bash
263
+ python -m pip install 'astro-imaging-agent[openai]'
264
+ python -m pip install 'astro-imaging-agent[anthropic]'
265
+ python -m pip install 'astro-imaging-agent[gemini]'
266
+ python -m pip install 'astro-imaging-agent[llm]'
267
+ ```
268
+
269
+ Set `OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, or `GEMINI_API_KEY` in your environment.
270
+ Choose a model ID available to your account explicitly; no model is hardcoded:
271
+
272
+ ```bash
273
+ aia agent image.fit "preserve stars and bring out faint detail" --provider openai --model YOUR_GPT_MODEL --dry-run --explain
274
+ aia agent image.fit "natural processing" --provider anthropic --model YOUR_CLAUDE_MODEL --output processed.fit
275
+ aia agent image.fit "remove the sky gradient" --provider gemini --model YOUR_GEMINI_MODEL --dry-run
276
+ ```
277
+
278
+ `--provider rules` is the default. `--timeout` controls SDK request timeout (default
279
+ 60 seconds). LLM dry-run calls the selected provider to generate a plan but never
280
+ writes or processes an image. The provider receives the request, image measurements,
281
+ metadata and tool schemas; image pixels/files and API keys are not included in the
282
+ planning payload. The report records provider and model, while the saved YAML replays
283
+ offline with `aia run`. Planning itself can vary between API calls.
284
+
285
+ OpenAI uses [Responses JSON mode](https://developers.openai.com/api/docs/guides/structured-outputs),
286
+ Claude uses a [forced plan-submission tool call](https://platform.claude.com/docs/en/api/python/messages/create),
287
+ and Gemini uses [Google GenAI JSON generation](https://github.com/googleapis/python-genai).
288
+ Extensible parameter dictionaries are checked locally with Pydantic and the registry;
289
+ provider JSON mode alone does not guarantee schema validity. Malformed, incomplete,
290
+ unknown-tool or invalid-parameter plans are rejected before processing. There is no
291
+ automatic fallback to rules when an API call fails. API errors omit SDK response
292
+ bodies; keys are read from the environment and are never written to artifacts.
293
+ Tests use fake clients and do not make paid API calls.
294
+
295
+ ## Contributing
296
+
297
+ See [development.md](development.md) for Poetry setup, test commands, adding tools,
298
+ versioning, and PyPI/GitHub release configuration.
299
+
300
+ ## MVP scope and next steps
301
+
302
+ Implemented: multi-format I/O, inspection, background/star analysis, normalization,
303
+ linear/asinh stretching, Gaussian denoising, polynomial sky subtraction, tool schemas,
304
+ YAML replay, processing history, rule-based orchestration and packaging automation.
305
+
306
+ Not included: stacking, bias/dark/flat calibration, debayering, plate solving,
307
+ photometric color calibration, neural processing, GPU acceleration or distribution.
308
+ The next useful step is explicit sky/star masks and stronger quality checks for
309
+ crowded fields and nebulosity, followed by dataset-based evaluation of LLM-generated
310
+ plans. Scientific FITS/TIFF artifacts
311
+ should remain the processing intermediates.
312
+
313
+ ## License
314
+
315
+ Apache License 2.0. See [LICENSE](LICENSE) and [NOTICE](NOTICE).
316
+