galfit-builder 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.
- galfit_builder-0.1.0/PKG-INFO +285 -0
- galfit_builder-0.1.0/README.md +257 -0
- galfit_builder-0.1.0/pyproject.toml +70 -0
- galfit_builder-0.1.0/setup.cfg +4 -0
- galfit_builder-0.1.0/src/galfit_builder/__init__.py +36 -0
- galfit_builder-0.1.0/src/galfit_builder/builders/__init__.py +30 -0
- galfit_builder-0.1.0/src/galfit_builder/builders/build_devauc.py +50 -0
- galfit_builder-0.1.0/src/galfit_builder/builders/build_edgedisk.py +62 -0
- galfit_builder-0.1.0/src/galfit_builder/builders/build_expdisk.py +53 -0
- galfit_builder-0.1.0/src/galfit_builder/builders/build_ferrer.py +55 -0
- galfit_builder-0.1.0/src/galfit_builder/builders/build_gaussian.py +53 -0
- galfit_builder-0.1.0/src/galfit_builder/builders/build_king.py +65 -0
- galfit_builder-0.1.0/src/galfit_builder/builders/build_moffat.py +54 -0
- galfit_builder-0.1.0/src/galfit_builder/builders/build_nuker.py +65 -0
- galfit_builder-0.1.0/src/galfit_builder/builders/build_psf.py +33 -0
- galfit_builder-0.1.0/src/galfit_builder/builders/build_sersic.py +51 -0
- galfit_builder-0.1.0/src/galfit_builder/builders/build_sky.py +71 -0
- galfit_builder-0.1.0/src/galfit_builder/builders/builder_utils.py +21 -0
- galfit_builder-0.1.0/src/galfit_builder/builders/component_builder.py +104 -0
- galfit_builder-0.1.0/src/galfit_builder/builders/region_utils.py +175 -0
- galfit_builder-0.1.0/src/galfit_builder/components/__init__.py +30 -0
- galfit_builder-0.1.0/src/galfit_builder/components/base.py +70 -0
- galfit_builder-0.1.0/src/galfit_builder/components/devauc.py +48 -0
- galfit_builder-0.1.0/src/galfit_builder/components/edgedisk.py +106 -0
- galfit_builder-0.1.0/src/galfit_builder/components/expdisk.py +82 -0
- galfit_builder-0.1.0/src/galfit_builder/components/ferrer.py +135 -0
- galfit_builder-0.1.0/src/galfit_builder/components/gaussian.py +108 -0
- galfit_builder-0.1.0/src/galfit_builder/components/king.py +108 -0
- galfit_builder-0.1.0/src/galfit_builder/components/moffat.py +122 -0
- galfit_builder-0.1.0/src/galfit_builder/components/nuker.py +105 -0
- galfit_builder-0.1.0/src/galfit_builder/components/psf.py +48 -0
- galfit_builder-0.1.0/src/galfit_builder/components/sersic.py +84 -0
- galfit_builder-0.1.0/src/galfit_builder/components/sky.py +67 -0
- galfit_builder-0.1.0/src/galfit_builder/config/__init__.py +5 -0
- galfit_builder-0.1.0/src/galfit_builder/config/loader.py +15 -0
- galfit_builder-0.1.0/src/galfit_builder/constraints/__init__.py +5 -0
- galfit_builder-0.1.0/src/galfit_builder/constraints/constraint_builder.py +199 -0
- galfit_builder-0.1.0/src/galfit_builder/controls/__init__.py +5 -0
- galfit_builder-0.1.0/src/galfit_builder/controls/controls.py +159 -0
- galfit_builder-0.1.0/src/galfit_builder/io/__init__.py +12 -0
- galfit_builder-0.1.0/src/galfit_builder/io/parse_regions.py +13 -0
- galfit_builder-0.1.0/src/galfit_builder/masking/__init__.py +1 -0
- galfit_builder-0.1.0/src/galfit_builder/masking/region_mask.py +27 -0
- galfit_builder-0.1.0/src/galfit_builder/pipeline/__init__.py +1 -0
- galfit_builder-0.1.0/src/galfit_builder/pipeline/cutout.py +337 -0
- galfit_builder-0.1.0/src/galfit_builder/pipeline/freeze.py +342 -0
- galfit_builder-0.1.0/src/galfit_builder/pipeline/run.py +137 -0
- galfit_builder-0.1.0/src/galfit_builder/pipeline/to_regions.py +236 -0
- galfit_builder-0.1.0/src/galfit_builder.egg-info/PKG-INFO +285 -0
- galfit_builder-0.1.0/src/galfit_builder.egg-info/SOURCES.txt +53 -0
- galfit_builder-0.1.0/src/galfit_builder.egg-info/dependency_links.txt +1 -0
- galfit_builder-0.1.0/src/galfit_builder.egg-info/entry_points.txt +5 -0
- galfit_builder-0.1.0/src/galfit_builder.egg-info/requires.txt +9 -0
- galfit_builder-0.1.0/src/galfit_builder.egg-info/top_level.txt +1 -0
- galfit_builder-0.1.0/tests/test_component_builders.py +71 -0
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: galfit-builder
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Convert DS9 region files to GALFIT feedme input files
|
|
5
|
+
Author: James Kulp
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/jameskulp/galfit-builder
|
|
8
|
+
Project-URL: Issues, https://github.com/jameskulp/galfit-builder/issues
|
|
9
|
+
Keywords: astronomy,galfit,ds9,regions,galaxy fitting
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering :: Astronomy
|
|
18
|
+
Requires-Python: >=3.10
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
Requires-Dist: numpy>=1.20
|
|
21
|
+
Requires-Dist: astropy>=5.0
|
|
22
|
+
Requires-Dist: regions>=0.7
|
|
23
|
+
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
25
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
26
|
+
Requires-Dist: mypy; extra == "dev"
|
|
27
|
+
Requires-Dist: ruff; extra == "dev"
|
|
28
|
+
|
|
29
|
+
# galfit-builder
|
|
30
|
+
|
|
31
|
+
A Python CLI toolkit for GALFIT galaxy fitting. Convert DS9 region files to GALFIT feedme files, freeze fitted components, cut/rotate images, and convert results back to regions for visualization.
|
|
32
|
+
|
|
33
|
+
## Installation
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pip install galfit-builder
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Quick Start
|
|
40
|
+
|
|
41
|
+
1. Copy the example config and edit for your data:
|
|
42
|
+
```bash
|
|
43
|
+
cp $(python -c "import galfit_builder; print(galfit_builder.__path__[0])")/config/example_config.toml config.toml
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
2. Draw regions in DS9, save as `regions.reg`
|
|
47
|
+
|
|
48
|
+
3. Generate feedme:
|
|
49
|
+
```bash
|
|
50
|
+
galfit-builder config.toml
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
4. Run GALFIT:
|
|
54
|
+
```bash
|
|
55
|
+
galfit output_galfit.feedme
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
5. Visualize results:
|
|
59
|
+
```bash
|
|
60
|
+
galfit-to-regions config.toml galfit.01
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## CLI Tools
|
|
64
|
+
|
|
65
|
+
### galfit-builder
|
|
66
|
+
|
|
67
|
+
Convert DS9 regions to a GALFIT feedme file.
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
galfit-builder config.toml # generate feedme
|
|
71
|
+
galfit-builder config.toml -c # also generate constraints file
|
|
72
|
+
galfit-builder config.toml -o custom.feedme # custom output name
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### galfit-freeze
|
|
76
|
+
|
|
77
|
+
Freeze components outside green polygon regions. Lock down fitted components while working on a specific area.
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
galfit-freeze output.feedme regions.reg # freeze only
|
|
81
|
+
galfit-freeze output.feedme regions.reg -i image.fits -c config.toml # add new components
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Draw a green polygon in DS9 around the area you want to fit. Components inside remain free; components outside are frozen.
|
|
85
|
+
|
|
86
|
+
### galfit-cutout
|
|
87
|
+
|
|
88
|
+
Rotate and cut FITS images based on a DS9 box region. Smaller cutouts run faster in GALFIT.
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
galfit-cutout box.reg -s science.fits -e sigma.fits -p psf.fits
|
|
92
|
+
galfit-cutout box.reg -s science.fits -v # sigma is inverse variance
|
|
93
|
+
galfit-cutout box.reg -s science.fits --prefix rot_ # custom output prefix
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### galfit-to-regions
|
|
97
|
+
|
|
98
|
+
Convert GALFIT output back to DS9 regions for visualization.
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
galfit-to-regions config.toml galfit.01 # GALFIT output file
|
|
102
|
+
galfit-to-regions config.toml output.feedme # or feedme file
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Configuration
|
|
106
|
+
|
|
107
|
+
### Minimal Config
|
|
108
|
+
|
|
109
|
+
```toml
|
|
110
|
+
[input]
|
|
111
|
+
region_file = "regions.reg"
|
|
112
|
+
|
|
113
|
+
[galfit_input_controls]
|
|
114
|
+
working_dir = "."
|
|
115
|
+
input_data_image = "science.fits"
|
|
116
|
+
psf_image = "psf.fits"
|
|
117
|
+
zeropoint = 25.0
|
|
118
|
+
plate_scale = [0.03, 0.03]
|
|
119
|
+
fit_region = [1, 500, 1, 500]
|
|
120
|
+
conv_box = [100, 100]
|
|
121
|
+
display_type = "regular"
|
|
122
|
+
mode = 0
|
|
123
|
+
|
|
124
|
+
[galfit_output_controls]
|
|
125
|
+
version_outputs = true
|
|
126
|
+
overwrite = false
|
|
127
|
+
|
|
128
|
+
[region_colors]
|
|
129
|
+
green = "sersic"
|
|
130
|
+
red = "devauc"
|
|
131
|
+
cyan = "gaussian"
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Region Color Mapping
|
|
135
|
+
|
|
136
|
+
DS9 region colors determine GALFIT component types:
|
|
137
|
+
|
|
138
|
+
| Color | Component | Description |
|
|
139
|
+
|---------|-----------|-------------|
|
|
140
|
+
| green | sersic | Sersic profile |
|
|
141
|
+
| red | devauc | de Vaucouleurs (n=4) |
|
|
142
|
+
| blue | ferrer | Ferrer profile |
|
|
143
|
+
| cyan | gaussian | 2D Gaussian |
|
|
144
|
+
| yellow | moffat | Moffat profile |
|
|
145
|
+
| magenta | king | King profile |
|
|
146
|
+
| white | nuker | Nuker profile |
|
|
147
|
+
| orange | expdisk | Exponential disk |
|
|
148
|
+
| pink | edgedisk | Edge-on disk |
|
|
149
|
+
|
|
150
|
+
Point regions become PSF components regardless of color.
|
|
151
|
+
|
|
152
|
+
### The "auto" Keyword
|
|
153
|
+
|
|
154
|
+
Use `"auto"` for smart defaults:
|
|
155
|
+
|
|
156
|
+
```toml
|
|
157
|
+
sigma_image = "auto" # writes "none" — let GALFIT estimate
|
|
158
|
+
background = "auto" # compute sky from image edges
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Sky Component
|
|
162
|
+
|
|
163
|
+
Sky is added automatically as component 1. Disable with:
|
|
164
|
+
|
|
165
|
+
```toml
|
|
166
|
+
[defaults.sky]
|
|
167
|
+
include = false
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
Or configure:
|
|
171
|
+
|
|
172
|
+
```toml
|
|
173
|
+
[defaults.sky]
|
|
174
|
+
include = true
|
|
175
|
+
background = "auto" # or a number like 100.5
|
|
176
|
+
dsky_dx = 0.0
|
|
177
|
+
dsky_dy = 0.0
|
|
178
|
+
background_freeze = false
|
|
179
|
+
dsky_dx_freeze = true
|
|
180
|
+
dsky_dy_freeze = true
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Constraints
|
|
184
|
+
|
|
185
|
+
Generate parameter constraints with `-c`:
|
|
186
|
+
|
|
187
|
+
```bash
|
|
188
|
+
galfit-builder config.toml -c
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
Configure in TOML:
|
|
192
|
+
|
|
193
|
+
```toml
|
|
194
|
+
[constraints.sersic]
|
|
195
|
+
n = "0.5 to 8" # hard limits
|
|
196
|
+
q = "0.1 to 1"
|
|
197
|
+
re_scale = 0.1 # re constrained to [re*0.1, re/0.1]
|
|
198
|
+
mag = "10 to 35"
|
|
199
|
+
x = "-5 5" # offset from initial: +/- 5 pixels
|
|
200
|
+
y = "-5 5"
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Component Defaults
|
|
204
|
+
|
|
205
|
+
Set default parameters and freeze states:
|
|
206
|
+
|
|
207
|
+
```toml
|
|
208
|
+
[defaults.sersic]
|
|
209
|
+
sersic_index = 2.5
|
|
210
|
+
mag_freeze = false
|
|
211
|
+
sersic_index_freeze = false
|
|
212
|
+
axis_ratio_freeze = false
|
|
213
|
+
pos_angle_freeze = false
|
|
214
|
+
|
|
215
|
+
[defaults.psf]
|
|
216
|
+
mag_freeze = false
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## Workflow Example
|
|
220
|
+
|
|
221
|
+
**Initial fit:**
|
|
222
|
+
```bash
|
|
223
|
+
# Draw ellipses/points in DS9, save as regions.reg
|
|
224
|
+
galfit-builder config.toml
|
|
225
|
+
galfit output_galfit.feedme
|
|
226
|
+
galfit-to-regions config.toml galfit.01
|
|
227
|
+
# Load galfit.01.reg in DS9 to see fitted positions
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
**Iterative refinement:**
|
|
231
|
+
```bash
|
|
232
|
+
# Draw green polygon around area to refine
|
|
233
|
+
# Adjust regions inside polygon
|
|
234
|
+
galfit-freeze galfit.01 regions.reg -i science.fits -c config.toml
|
|
235
|
+
galfit frozen_galfit.01.feedme
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
**Working with cutouts:**
|
|
239
|
+
```bash
|
|
240
|
+
# Draw box region in DS9 for cutout area
|
|
241
|
+
galfit-cutout box.reg -s science.fits -e sigma.fits -p psf.fits
|
|
242
|
+
# Edit config to point to cutout_* files
|
|
243
|
+
galfit-builder config.toml
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
## Python API
|
|
247
|
+
|
|
248
|
+
```python
|
|
249
|
+
from galfit_builder.config.loader import load_config
|
|
250
|
+
from galfit_builder.io.parse_regions import read_regions
|
|
251
|
+
from galfit_builder.builders.component_builder import build_components
|
|
252
|
+
from galfit_builder.controls.controls import GalfitControls
|
|
253
|
+
from astropy.io import fits
|
|
254
|
+
|
|
255
|
+
config = load_config("config.toml")
|
|
256
|
+
regions = read_regions("regions.reg")
|
|
257
|
+
image_data = fits.getdata("science.fits")
|
|
258
|
+
|
|
259
|
+
components = build_components(regions, image_data, config)
|
|
260
|
+
|
|
261
|
+
controls = GalfitControls.from_config(config)
|
|
262
|
+
print(controls.to_galfit())
|
|
263
|
+
for comp in components:
|
|
264
|
+
print(comp.to_galfit())
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
## Supported Components
|
|
268
|
+
|
|
269
|
+
| Component | Region | Key Parameters |
|
|
270
|
+
|-----------|--------|----------------|
|
|
271
|
+
| sersic | Ellipse | magnitude, effective radius, sersic index, axis ratio, PA |
|
|
272
|
+
| psf | Point | magnitude |
|
|
273
|
+
| devauc | Ellipse | magnitude, effective radius, axis ratio, PA |
|
|
274
|
+
| expdisk | Ellipse | magnitude, scale radius, axis ratio, PA |
|
|
275
|
+
| gaussian | Ellipse | magnitude, FWHM, axis ratio, PA |
|
|
276
|
+
| moffat | Ellipse | magnitude, FWHM, powerlaw, axis ratio, PA |
|
|
277
|
+
| king | Ellipse | surface brightness, core radius, tidal radius, alpha |
|
|
278
|
+
| nuker | Ellipse | surface brightness, break radius, alpha, beta, gamma |
|
|
279
|
+
| ferrer | Ellipse | surface brightness, outer radius, alpha, beta |
|
|
280
|
+
| edgedisk | Ellipse | surface brightness, scale height, scale length, PA |
|
|
281
|
+
| sky | N/A | background, dsky/dx, dsky/dy |
|
|
282
|
+
|
|
283
|
+
## License
|
|
284
|
+
|
|
285
|
+
MIT
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
# galfit-builder
|
|
2
|
+
|
|
3
|
+
A Python CLI toolkit for GALFIT galaxy fitting. Convert DS9 region files to GALFIT feedme files, freeze fitted components, cut/rotate images, and convert results back to regions for visualization.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install galfit-builder
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
1. Copy the example config and edit for your data:
|
|
14
|
+
```bash
|
|
15
|
+
cp $(python -c "import galfit_builder; print(galfit_builder.__path__[0])")/config/example_config.toml config.toml
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
2. Draw regions in DS9, save as `regions.reg`
|
|
19
|
+
|
|
20
|
+
3. Generate feedme:
|
|
21
|
+
```bash
|
|
22
|
+
galfit-builder config.toml
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
4. Run GALFIT:
|
|
26
|
+
```bash
|
|
27
|
+
galfit output_galfit.feedme
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
5. Visualize results:
|
|
31
|
+
```bash
|
|
32
|
+
galfit-to-regions config.toml galfit.01
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## CLI Tools
|
|
36
|
+
|
|
37
|
+
### galfit-builder
|
|
38
|
+
|
|
39
|
+
Convert DS9 regions to a GALFIT feedme file.
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
galfit-builder config.toml # generate feedme
|
|
43
|
+
galfit-builder config.toml -c # also generate constraints file
|
|
44
|
+
galfit-builder config.toml -o custom.feedme # custom output name
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### galfit-freeze
|
|
48
|
+
|
|
49
|
+
Freeze components outside green polygon regions. Lock down fitted components while working on a specific area.
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
galfit-freeze output.feedme regions.reg # freeze only
|
|
53
|
+
galfit-freeze output.feedme regions.reg -i image.fits -c config.toml # add new components
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Draw a green polygon in DS9 around the area you want to fit. Components inside remain free; components outside are frozen.
|
|
57
|
+
|
|
58
|
+
### galfit-cutout
|
|
59
|
+
|
|
60
|
+
Rotate and cut FITS images based on a DS9 box region. Smaller cutouts run faster in GALFIT.
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
galfit-cutout box.reg -s science.fits -e sigma.fits -p psf.fits
|
|
64
|
+
galfit-cutout box.reg -s science.fits -v # sigma is inverse variance
|
|
65
|
+
galfit-cutout box.reg -s science.fits --prefix rot_ # custom output prefix
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### galfit-to-regions
|
|
69
|
+
|
|
70
|
+
Convert GALFIT output back to DS9 regions for visualization.
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
galfit-to-regions config.toml galfit.01 # GALFIT output file
|
|
74
|
+
galfit-to-regions config.toml output.feedme # or feedme file
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Configuration
|
|
78
|
+
|
|
79
|
+
### Minimal Config
|
|
80
|
+
|
|
81
|
+
```toml
|
|
82
|
+
[input]
|
|
83
|
+
region_file = "regions.reg"
|
|
84
|
+
|
|
85
|
+
[galfit_input_controls]
|
|
86
|
+
working_dir = "."
|
|
87
|
+
input_data_image = "science.fits"
|
|
88
|
+
psf_image = "psf.fits"
|
|
89
|
+
zeropoint = 25.0
|
|
90
|
+
plate_scale = [0.03, 0.03]
|
|
91
|
+
fit_region = [1, 500, 1, 500]
|
|
92
|
+
conv_box = [100, 100]
|
|
93
|
+
display_type = "regular"
|
|
94
|
+
mode = 0
|
|
95
|
+
|
|
96
|
+
[galfit_output_controls]
|
|
97
|
+
version_outputs = true
|
|
98
|
+
overwrite = false
|
|
99
|
+
|
|
100
|
+
[region_colors]
|
|
101
|
+
green = "sersic"
|
|
102
|
+
red = "devauc"
|
|
103
|
+
cyan = "gaussian"
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Region Color Mapping
|
|
107
|
+
|
|
108
|
+
DS9 region colors determine GALFIT component types:
|
|
109
|
+
|
|
110
|
+
| Color | Component | Description |
|
|
111
|
+
|---------|-----------|-------------|
|
|
112
|
+
| green | sersic | Sersic profile |
|
|
113
|
+
| red | devauc | de Vaucouleurs (n=4) |
|
|
114
|
+
| blue | ferrer | Ferrer profile |
|
|
115
|
+
| cyan | gaussian | 2D Gaussian |
|
|
116
|
+
| yellow | moffat | Moffat profile |
|
|
117
|
+
| magenta | king | King profile |
|
|
118
|
+
| white | nuker | Nuker profile |
|
|
119
|
+
| orange | expdisk | Exponential disk |
|
|
120
|
+
| pink | edgedisk | Edge-on disk |
|
|
121
|
+
|
|
122
|
+
Point regions become PSF components regardless of color.
|
|
123
|
+
|
|
124
|
+
### The "auto" Keyword
|
|
125
|
+
|
|
126
|
+
Use `"auto"` for smart defaults:
|
|
127
|
+
|
|
128
|
+
```toml
|
|
129
|
+
sigma_image = "auto" # writes "none" — let GALFIT estimate
|
|
130
|
+
background = "auto" # compute sky from image edges
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Sky Component
|
|
134
|
+
|
|
135
|
+
Sky is added automatically as component 1. Disable with:
|
|
136
|
+
|
|
137
|
+
```toml
|
|
138
|
+
[defaults.sky]
|
|
139
|
+
include = false
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Or configure:
|
|
143
|
+
|
|
144
|
+
```toml
|
|
145
|
+
[defaults.sky]
|
|
146
|
+
include = true
|
|
147
|
+
background = "auto" # or a number like 100.5
|
|
148
|
+
dsky_dx = 0.0
|
|
149
|
+
dsky_dy = 0.0
|
|
150
|
+
background_freeze = false
|
|
151
|
+
dsky_dx_freeze = true
|
|
152
|
+
dsky_dy_freeze = true
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Constraints
|
|
156
|
+
|
|
157
|
+
Generate parameter constraints with `-c`:
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
galfit-builder config.toml -c
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Configure in TOML:
|
|
164
|
+
|
|
165
|
+
```toml
|
|
166
|
+
[constraints.sersic]
|
|
167
|
+
n = "0.5 to 8" # hard limits
|
|
168
|
+
q = "0.1 to 1"
|
|
169
|
+
re_scale = 0.1 # re constrained to [re*0.1, re/0.1]
|
|
170
|
+
mag = "10 to 35"
|
|
171
|
+
x = "-5 5" # offset from initial: +/- 5 pixels
|
|
172
|
+
y = "-5 5"
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Component Defaults
|
|
176
|
+
|
|
177
|
+
Set default parameters and freeze states:
|
|
178
|
+
|
|
179
|
+
```toml
|
|
180
|
+
[defaults.sersic]
|
|
181
|
+
sersic_index = 2.5
|
|
182
|
+
mag_freeze = false
|
|
183
|
+
sersic_index_freeze = false
|
|
184
|
+
axis_ratio_freeze = false
|
|
185
|
+
pos_angle_freeze = false
|
|
186
|
+
|
|
187
|
+
[defaults.psf]
|
|
188
|
+
mag_freeze = false
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## Workflow Example
|
|
192
|
+
|
|
193
|
+
**Initial fit:**
|
|
194
|
+
```bash
|
|
195
|
+
# Draw ellipses/points in DS9, save as regions.reg
|
|
196
|
+
galfit-builder config.toml
|
|
197
|
+
galfit output_galfit.feedme
|
|
198
|
+
galfit-to-regions config.toml galfit.01
|
|
199
|
+
# Load galfit.01.reg in DS9 to see fitted positions
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
**Iterative refinement:**
|
|
203
|
+
```bash
|
|
204
|
+
# Draw green polygon around area to refine
|
|
205
|
+
# Adjust regions inside polygon
|
|
206
|
+
galfit-freeze galfit.01 regions.reg -i science.fits -c config.toml
|
|
207
|
+
galfit frozen_galfit.01.feedme
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
**Working with cutouts:**
|
|
211
|
+
```bash
|
|
212
|
+
# Draw box region in DS9 for cutout area
|
|
213
|
+
galfit-cutout box.reg -s science.fits -e sigma.fits -p psf.fits
|
|
214
|
+
# Edit config to point to cutout_* files
|
|
215
|
+
galfit-builder config.toml
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## Python API
|
|
219
|
+
|
|
220
|
+
```python
|
|
221
|
+
from galfit_builder.config.loader import load_config
|
|
222
|
+
from galfit_builder.io.parse_regions import read_regions
|
|
223
|
+
from galfit_builder.builders.component_builder import build_components
|
|
224
|
+
from galfit_builder.controls.controls import GalfitControls
|
|
225
|
+
from astropy.io import fits
|
|
226
|
+
|
|
227
|
+
config = load_config("config.toml")
|
|
228
|
+
regions = read_regions("regions.reg")
|
|
229
|
+
image_data = fits.getdata("science.fits")
|
|
230
|
+
|
|
231
|
+
components = build_components(regions, image_data, config)
|
|
232
|
+
|
|
233
|
+
controls = GalfitControls.from_config(config)
|
|
234
|
+
print(controls.to_galfit())
|
|
235
|
+
for comp in components:
|
|
236
|
+
print(comp.to_galfit())
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
## Supported Components
|
|
240
|
+
|
|
241
|
+
| Component | Region | Key Parameters |
|
|
242
|
+
|-----------|--------|----------------|
|
|
243
|
+
| sersic | Ellipse | magnitude, effective radius, sersic index, axis ratio, PA |
|
|
244
|
+
| psf | Point | magnitude |
|
|
245
|
+
| devauc | Ellipse | magnitude, effective radius, axis ratio, PA |
|
|
246
|
+
| expdisk | Ellipse | magnitude, scale radius, axis ratio, PA |
|
|
247
|
+
| gaussian | Ellipse | magnitude, FWHM, axis ratio, PA |
|
|
248
|
+
| moffat | Ellipse | magnitude, FWHM, powerlaw, axis ratio, PA |
|
|
249
|
+
| king | Ellipse | surface brightness, core radius, tidal radius, alpha |
|
|
250
|
+
| nuker | Ellipse | surface brightness, break radius, alpha, beta, gamma |
|
|
251
|
+
| ferrer | Ellipse | surface brightness, outer radius, alpha, beta |
|
|
252
|
+
| edgedisk | Ellipse | surface brightness, scale height, scale length, PA |
|
|
253
|
+
| sky | N/A | background, dsky/dx, dsky/dy |
|
|
254
|
+
|
|
255
|
+
## License
|
|
256
|
+
|
|
257
|
+
MIT
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "galfit-builder"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Convert DS9 region files to GALFIT feedme input files"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = {text = "MIT"}
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
authors = [
|
|
13
|
+
{name = "James Kulp"}
|
|
14
|
+
]
|
|
15
|
+
keywords = ["astronomy", "galfit", "ds9", "regions", "galaxy fitting"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 3 - Alpha",
|
|
18
|
+
"Intended Audience :: Science/Research",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.10",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Topic :: Scientific/Engineering :: Astronomy",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
dependencies = [
|
|
28
|
+
"numpy>=1.20",
|
|
29
|
+
"astropy>=5.0",
|
|
30
|
+
"regions>=0.7",
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
[project.optional-dependencies]
|
|
34
|
+
dev = [
|
|
35
|
+
"pytest>=7.0",
|
|
36
|
+
"pytest-cov",
|
|
37
|
+
"mypy",
|
|
38
|
+
"ruff",
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
[project.scripts]
|
|
42
|
+
galfit-builder = "galfit_builder.pipeline.run:main"
|
|
43
|
+
galfit-freeze = "galfit_builder.pipeline.freeze:main"
|
|
44
|
+
galfit-cutout = "galfit_builder.pipeline.cutout:main"
|
|
45
|
+
galfit-to-regions = "galfit_builder.pipeline.to_regions:main"
|
|
46
|
+
|
|
47
|
+
[project.urls]
|
|
48
|
+
Homepage = "https://github.com/jameskulp/galfit-builder"
|
|
49
|
+
Issues = "https://github.com/jameskulp/galfit-builder/issues"
|
|
50
|
+
|
|
51
|
+
[tool.setuptools.packages.find]
|
|
52
|
+
where = ["src"]
|
|
53
|
+
|
|
54
|
+
[tool.pytest.ini_options]
|
|
55
|
+
testpaths = ["tests"]
|
|
56
|
+
pythonpath = ["src"]
|
|
57
|
+
|
|
58
|
+
[tool.mypy]
|
|
59
|
+
python_version = "3.10"
|
|
60
|
+
warn_return_any = true
|
|
61
|
+
warn_unused_ignores = true
|
|
62
|
+
strict = false
|
|
63
|
+
|
|
64
|
+
[tool.ruff]
|
|
65
|
+
line-length = 100
|
|
66
|
+
target-version = "py310"
|
|
67
|
+
|
|
68
|
+
[tool.ruff.lint]
|
|
69
|
+
select = ["E", "F", "W", "I", "UP"]
|
|
70
|
+
ignore = ["E501"]
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""
|
|
2
|
+
galfit_builder - Convert DS9 region files to GALFIT feedme files.
|
|
3
|
+
|
|
4
|
+
Usage:
|
|
5
|
+
from galfit_builder import build_components, load_config, GalfitControls
|
|
6
|
+
|
|
7
|
+
config = load_config("config.toml")
|
|
8
|
+
components = build_components(regions, image_data, config)
|
|
9
|
+
|
|
10
|
+
# Optionally add sky
|
|
11
|
+
components = build_components(regions, image_data, config, add_sky=True)
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from galfit_builder.config.loader import load_config
|
|
15
|
+
from galfit_builder.controls.controls import GalfitControls
|
|
16
|
+
|
|
17
|
+
__version__ = "0.1.0"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def __getattr__(name: str):
|
|
21
|
+
"""Lazy import for modules that require optional dependencies."""
|
|
22
|
+
if name == "build_components":
|
|
23
|
+
from galfit_builder.builders.component_builder import build_components
|
|
24
|
+
return build_components
|
|
25
|
+
if name == "read_regions":
|
|
26
|
+
from galfit_builder.io.parse_regions import read_regions
|
|
27
|
+
return read_regions
|
|
28
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
__all__ = [
|
|
32
|
+
"build_components",
|
|
33
|
+
"load_config",
|
|
34
|
+
"GalfitControls",
|
|
35
|
+
"read_regions",
|
|
36
|
+
]
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""Component builders for converting regions to GALFIT components."""
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def __getattr__(name: str):
|
|
5
|
+
"""Lazy import to avoid requiring regions at import time."""
|
|
6
|
+
if name in ("build_components", "infer_component_type", "build_single_component"):
|
|
7
|
+
from galfit_builder.builders.component_builder import (
|
|
8
|
+
build_components,
|
|
9
|
+
infer_component_type,
|
|
10
|
+
build_single_component,
|
|
11
|
+
)
|
|
12
|
+
if name == "build_components":
|
|
13
|
+
return build_components
|
|
14
|
+
if name == "build_single_component":
|
|
15
|
+
return build_single_component
|
|
16
|
+
return infer_component_type
|
|
17
|
+
|
|
18
|
+
if name == "build_sky":
|
|
19
|
+
from galfit_builder.builders.build_sky import build_sky
|
|
20
|
+
return build_sky
|
|
21
|
+
|
|
22
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
__all__ = [
|
|
26
|
+
"build_components",
|
|
27
|
+
"build_single_component",
|
|
28
|
+
"build_sky",
|
|
29
|
+
"infer_component_type",
|
|
30
|
+
]
|