SpecProc 1.0.0__py3-none-any.whl

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 (61) hide show
  1. specproc/__init__.py +9 -0
  2. specproc/calib_data/linelists/FeAr.dat +375 -0
  3. specproc/calib_data/linelists/README +79 -0
  4. specproc/calib_data/linelists/airvac.cl +61 -0
  5. specproc/calib_data/linelists/argon.dat +161 -0
  6. specproc/calib_data/linelists/ctiohear.dat +106 -0
  7. specproc/calib_data/linelists/ctiohenear.dat +146 -0
  8. specproc/calib_data/linelists/cuar.dat +459 -0
  9. specproc/calib_data/linelists/henear.dat +93 -0
  10. specproc/calib_data/linelists/henearhres.dat +300 -0
  11. specproc/calib_data/linelists/idhenear.dat +127 -0
  12. specproc/calib_data/linelists/krypton.dat +109 -0
  13. specproc/calib_data/linelists/lowskylines.dat +577 -0
  14. specproc/calib_data/linelists/ohlines.dat +268 -0
  15. specproc/calib_data/linelists/skylines.dat +1385 -0
  16. specproc/calib_data/linelists/thar-noao.dat +4169 -0
  17. specproc/calib_data/linelists/thar.dat +3057 -0
  18. specproc/calib_data/linelists/thorium.dat +3057 -0
  19. specproc/calib_data/linelists/vacidhenear.dat +127 -0
  20. specproc/calib_data/linelists/vacthar.dat +3057 -0
  21. specproc/calib_data/linelists/vacthorium.dat +3057 -0
  22. specproc/calib_data/linelists/xenon.dat +89 -0
  23. specproc/calib_data/telescopes/lijiang24hrs/lijiang24_hrs_thar_lines.csv +550 -0
  24. specproc/calib_data/telescopes/xinglong216bfosc/BFOSC/345/256/232/346/240/207/347/201/257/350/260/261/350/256/244/350/257/201/346/211/213/345/206/214v171118.pdf +0 -0
  25. specproc/calib_data/telescopes/xinglong216bfosc//346/212/245/345/221/212/345/233/276.docx +0 -0
  26. specproc/calib_data/telescopes/xinglong216hrs/216HRS /347/201/257/350/260/261/350/257/201/350/256/244/346/226/207/344/273/266.pdf +0 -0
  27. specproc/calib_data/telescopes/xinglong216hrs/wlcalib_20211123011_A.png +0 -0
  28. specproc/calib_data/telescopes/xinglong216hrs/xinglong216_thar_lines.csv +517 -0
  29. specproc/config/__init__.py +1 -0
  30. specproc/config/config_manager.py +431 -0
  31. specproc/core/__init__.py +1 -0
  32. specproc/core/basic_reduction.py +615 -0
  33. specproc/core/data_structures.py +525 -0
  34. specproc/core/de_blazing.py +210 -0
  35. specproc/core/extraction.py +375 -0
  36. specproc/core/flat_correction.py +1255 -0
  37. specproc/core/line_identification.py +302 -0
  38. specproc/core/order_stitching.py +187 -0
  39. specproc/core/order_tracing.py +1587 -0
  40. specproc/core/processing_pipeline.py +1183 -0
  41. specproc/core/scattered_light.py +654 -0
  42. specproc/core/slit_pipeline.py +762 -0
  43. specproc/core/wave_calibration.py +961 -0
  44. specproc/gui/__init__.py +1 -0
  45. specproc/gui/line_identifier.py +731 -0
  46. specproc/gui/main_window.py +2315 -0
  47. specproc/gui/settings_dialog.py +946 -0
  48. specproc/main.py +388 -0
  49. specproc/plotting/__init__.py +1 -0
  50. specproc/plotting/spectra_plotter.py +483 -0
  51. specproc/utils/__init__.py +1 -0
  52. specproc/utils/airvac.py +123 -0
  53. specproc/utils/fits_io.py +269 -0
  54. specproc/utils/image_processing.py +426 -0
  55. specproc/utils/overscan.py +600 -0
  56. specproc-1.0.0.dist-info/METADATA +668 -0
  57. specproc-1.0.0.dist-info/RECORD +61 -0
  58. specproc-1.0.0.dist-info/WHEEL +5 -0
  59. specproc-1.0.0.dist-info/entry_points.txt +5 -0
  60. specproc-1.0.0.dist-info/licenses/LICENSE +674 -0
  61. specproc-1.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,668 @@
1
+ Metadata-Version: 2.4
2
+ Name: SpecProc
3
+ Version: 1.0.0
4
+ Summary: A spectral processing tool
5
+ Author-email: "Niu, Hubiao" <niuhubiao@xao.ac.cn>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/yourusername/specproc
8
+ Project-URL: Repository, https://github.com/yourusername/specproc
9
+ Keywords: spectroscopy,FITS,data-reduction
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.6
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: numpy
16
+ Requires-Dist: scipy
17
+ Requires-Dist: astropy
18
+ Requires-Dist: matplotlib
19
+ Requires-Dist: PyQt5
20
+ Requires-Dist: configparser
21
+ Dynamic: license-file
22
+
23
+ # SpecProc: PyQt GUI for Spectrograph Data Reduction
24
+
25
+ ![SpecProc GUI](docs/SpecProc.png)
26
+
27
+ A complete PyQt-based graphical interface for reducing slit/chelle spectrograph FITS data.
28
+
29
+ ## Table of Contents
30
+
31
+ - [Features](#features)
32
+ - [Installation](#installation)
33
+ - [Quick Start](#quick-start)
34
+ - [Configuration](#configuration)
35
+ - [Processing Pipeline](#processing-pipeline)
36
+ - [Usage](#usage)
37
+ - [Calibration Data](#calibration-data)
38
+ - [Troubleshooting](#troubleshooting)
39
+ - [Documentation](#documentation)
40
+
41
+ ## Features
42
+
43
+ ### Complete Reduction Pipeline
44
+
45
+ **8-stage automated spectral reduction**:
46
+
47
+ 1. **Basic Pre-processing** - Overscan, bias subtraction, and cosmic ray correction
48
+ 2. **Apertures Tracing** - Master flat generation and echelle aperture tracing
49
+ 3. **Scattered Light Subtraction** - Inter-aperture background modeling and removal (astropy convolution or spline)
50
+ 4. **2D Flat-Field Correction** - 2D pixel flat correction
51
+ 5. **1D Spectrum Extraction** - 1D spectrum extraction for each aperture (sum or optimal)
52
+ 6. **De-blazing** - Blaze function correction
53
+ 7. **Wavelength Calibration** - Wavelength calibration applied to both sum and optimal de-blazed 1D spectra
54
+ 8. **Order Stitching** - Merge overlapping neighboring orders into a continuous 1D spectrum
55
+
56
+ ### Interactive GUI
57
+
58
+ PyQt5-based user interface with:
59
+ - File management for bias, flat, and science frames
60
+ - Real-time progress tracking
61
+ - Processing logs and diagnostics
62
+ - One-click pipeline execution or step-by-step processing
63
+
64
+ ### Key Features
65
+
66
+ - **Configuration-Driven**: INI-format configuration files for easy parameter adjustment
67
+ - **Generic Spectrograph Support**: Configurable for different echelle spectrographs
68
+ - **Flexible Output**: Control which intermediate results to save
69
+ - **Command Line Interface**: Alternative to GUI for batch processing
70
+
71
+ ## Installation
72
+
73
+ Choose one of the following installation methods:
74
+
75
+ ### Method 1: Using pip
76
+
77
+ Install SpecProc directly from PyPI.
78
+
79
+ ```bash
80
+ # Install SpecProc
81
+ pip install specproc
82
+
83
+ # Launch application
84
+ specproc
85
+ ```
86
+
87
+ **Notes:**
88
+ - Requires Python 3.7+
89
+ - Dependencies will be automatically installed from PyPI
90
+ - Installation is permanent; uninstall with `pip uninstall specproc`
91
+
92
+ ### Method 2: Using conda
93
+
94
+ Conda provides a complete environment with all dependencies. Two installation options:
95
+
96
+ #### Option 2.1: Install in existing conda environment
97
+
98
+ ```bash
99
+ # Activate your conda environment
100
+ conda activate your_environment
101
+
102
+ # Install SpecProc from conda-forge
103
+ conda install -c conda-forge specproc
104
+
105
+ # Launch application
106
+ specproc
107
+ ```
108
+
109
+ #### Option 2.2: Create new conda environment
110
+
111
+ ```bash
112
+ # Create new conda environment for SpecProc
113
+ conda create -n specproc python=3.8
114
+ conda activate specproc
115
+
116
+ # Install SpecProc and all dependencies
117
+ conda install -c conda-forge specproc
118
+
119
+ # Launch application
120
+ specproc
121
+ ```
122
+
123
+ **Notes:**
124
+ - Recommended for users who want an isolated environment
125
+ - All dependencies are managed by conda
126
+ - Python 3.7-3.11 are supported
127
+
128
+ ### Method 3: Installing from Source
129
+
130
+ Run the installation script to install SpecProc and all dependencies from local source.
131
+
132
+ ```bash
133
+ # Navigate to SpecProc directory
134
+ cd /path/to/SpecProc
135
+
136
+ # Make the script executable (if needed)
137
+ chmod +x install.sh
138
+
139
+ # Run installation script
140
+ ./install.sh
141
+
142
+ # Launch application
143
+ specproc
144
+ ```
145
+
146
+ **Notes:**
147
+ - Installation script handles all dependencies automatically
148
+ - Detects available package manager (pip or conda)
149
+ - Installs SpecProc to your system
150
+ - Use this method for automated setup from local source
151
+
152
+ ## Quick Start
153
+
154
+ ### Working Directory Setup
155
+
156
+ **Important**: SpecProc should be run in your working directory, NOT in the source code directory.
157
+
158
+ ### Correct Workflow
159
+
160
+ ```bash
161
+ # 1. Create your working directory (e.g., for an observation project)
162
+ mkdir -p /myworkspace
163
+ cd /myworkspace
164
+
165
+ # 2. Create subdirectories for data processing
166
+ mkdir -p 20241102_hrs output
167
+
168
+ # 3. Copy/move FITS data files to 20241102_hrs directory
169
+ cp /somewhere/bias_*.fits ./20241102_hrs/
170
+ cp /somewhere/flat_*.fits ./20241102_hrs/
171
+ cp /somewhere/thar_*.fits ./20241102_hrs/
172
+ cp /somewhere/science_*.fits ./20241102_hrs/
173
+
174
+ # 4. Create user config file (optional)
175
+ cp /path/to/SpecProc/src/specproc/config/default_config.cfg ./specproc.cfg
176
+
177
+ # 5. Run SpecProc in your working directory
178
+ specproc --config ./specproc.cfg
179
+ ```
180
+
181
+ ### Directory Structure
182
+
183
+ **Working directory** (where you process data):
184
+ ```
185
+ /myworkspace/ # Your working directory
186
+ ├── 20241102_hrs/ # Input FITS files
187
+ │ ├── bias_*.fits
188
+ │ ├── flat_*.fits
189
+ │ ├── thar_*.fits # ThAr lamp spectrum
190
+ │ └── science_*.fits # Science images
191
+ ├── output/ # Processing results (auto-created)
192
+ │ ├── step1_basic/ # Step 1: Basic pre-processing
193
+ │ │ ├── overscan_corrected/ # Overscan-corrected images and diagnostic plots
194
+ │ │ ├── bias_subtracted/ # Master bias and bias-corrected images
195
+ │ │ └── cosmic_corrected/ # Cosmic ray corrected science images (if enabled)
196
+ │ ├── step2_flat/ # Step 2: Master flat field, blaze profiles, and diagnostic plots
197
+ │ ├── step3_background/ # Step 3: Background model and diagnostic plots
198
+ │ ├── step5_extraction/ # Step 5: Extracted 1D spectra and diagnostic plots
199
+ │ ├── step6_deblazing/ # Step 6: De-blazed spectra and diagnostic plots (if saved)
200
+ │ └── step7_wavelength/ # Step 7: Final wavelength calibrated 1D spectra and plots
201
+ │ └── step8_stitching/ # Step 8: Final stitched continuous 1D spectra and plots
202
+ ├── specproc.cfg # User config file (optional)
203
+ └── ...
204
+ ```
205
+
206
+ **Note**:
207
+ - ❌ Do NOT run `specproc` in SpecProc source directory (`/path/to/SpecProc`)
208
+ - ✅ Run `specproc` in your working directory
209
+ - ✅ `rawdata` and `output` will be created in your working directory
210
+
211
+ ## Configuration
212
+
213
+ ### Config File Types
214
+
215
+ #### Default Configuration
216
+
217
+ **Location**: `SpecProc/src/specproc/config/default_config.cfg`
218
+ **Purpose**: Provides default parameter values
219
+ **Modification**: Not recommended to modify directly
220
+
221
+ #### User Configuration
222
+
223
+ **Location**: `specproc.cfg` in working directory
224
+ **Purpose**: Override default configuration, customize parameters
225
+ **Priority**: User config > Default config
226
+
227
+ ### Path Configuration
228
+
229
+ #### Data Paths
230
+
231
+ ```ini
232
+ [data]
233
+ # Raw FITS data directory path
234
+ # Example: If running in /myworkspace/ and rawdata_path=20241102_hrs,
235
+ # data will be loaded from /myworkspace/20241102_hrs/
236
+ #
237
+ # Path behavior:
238
+ # - rawdata_path = /data/20241102_hrs → Absolute path, loads from /data/20241102_hrs/
239
+ # - rawdata_path = ./20241102_hrs → Relative path, loads from working_directory/20241102_hrs/
240
+ # - rawdata_path = 20241102_hrs → Same as above, also relative to working directory
241
+ # (e.g., if working in /myworkspace/, loads from /myworkspace/20241102_hrs/)
242
+ #
243
+ # Examples (assuming working directory is /myworkspace/):
244
+ # rawdata_path = ./20241102_hrs → Data from /myworkspace/20241102_hrs/
245
+ # rawdata_path = 20241102_hrs → Same as above, data from /myworkspace/20241102_hrs/
246
+ # rawdata_path = /data/20241102_hrs → Data from /data/20241102_hrs/
247
+ rawdata_path = ./20241102_hrs
248
+ ```
249
+
250
+ #### Output Path
251
+
252
+ ```ini
253
+ [reduce]
254
+ # Output directory path for all processing results
255
+ # Example: If running in /myworkspace/ and output=output,
256
+ # results will be saved in /myworkspace/output/
257
+ #
258
+ # Path behavior:
259
+ # - output_path = /data/output → Absolute path, saves to /data/output/
260
+ # - output_path = ./output → Relative path, saves to working_directory/output/
261
+ # - output_path = output → Same as above, also relative to working directory
262
+ # (e.g., if working in /myworkspace/, saves to /myworkspace/output/)
263
+ #
264
+ # Examples (assuming working directory is /myworkspace/):
265
+ # output_path = ./output → Results to /myworkspace/output/
266
+ # output_path = output → Same as above, results to /myworkspace/output/
267
+ # output_path = /data/output → Results to /data/output/
268
+ #
269
+ # Output directory structure:
270
+ # output/
271
+ # ├── step1_basic/ # Step 1: Basic pre-processing
272
+ # │ ├── overscan_corrected/ # Overscan-corrected images
273
+ # │ ├── bias_subtracted/ # Master bias and bias-corrected images
274
+ # │ └── cosmic_corrected/ # Cosmic ray corrected science images (if enabled)
275
+ # ├── step2_flat/ # Step 2: Master flat field with blaze profiles
276
+ # ├── step3_background/ # Step 3: Background model
277
+ # ├── step5_extraction/ # Step 5: Extracted 1D spectra (pixel space)
278
+ # ├── step6_deblazing/ # Step 6: De-blazed spectra (if saved)
279
+ # └── step7_wavelength/ # Step 7: Final wavelength calibrated 1D spectra
280
+ output_path = output
281
+
282
+ #### Path Examples
283
+
284
+ ```bash
285
+ # Assume working directory is /myworkspace/
286
+ cd /myworkspace/
287
+
288
+ # Config file (relative path example):
289
+ [data]
290
+ rawdata_path = ./20241102_hrs
291
+ [reduce]
292
+ output_path = ./output
293
+
294
+ # Actual paths used:
295
+ # Input: /myworkspace/20241102_hrs/
296
+ # Output: /myworkspace/output/
297
+
298
+ # Config file (absolute path example):
299
+ [data]
300
+ rawdata_path = /data/20241102_hrs
301
+ [reduce]
302
+ output_path = /data/output
303
+
304
+ # Actual paths used:
305
+ # Input: /data/20241102_hrs/
306
+ # Output: /data/output/
307
+ ```
308
+
309
+ ### Intermediate Results Saving
310
+
311
+ Control which processing steps to save intermediate results:
312
+
313
+ ```ini
314
+ [reduce.save_intermediate]
315
+ # Whether to save intermediate results for each step
316
+ # Set to 'yes' or 'no' for each step independently
317
+ # Default is 'yes' for all steps
318
+ save_overscan = yes # Step 1: Overscan correction (saves to output/step1_basic/overscan_corrected/)
319
+ save_bias = yes # Step 1: Bias correction (saves to output/step1_basic/bias_subtracted/)
320
+ save_flat = yes # Step 2: Flat fielding (saves master flat to output/step2_flat/)
321
+ save_background = yes # Step 3: Background subtraction (saves model to output/step3_background/)
322
+ save_cosmic = yes # Step 1: Cosmic ray correction (saves to output/step1_basic/cosmic_corrected/)
323
+ save_extraction = yes # Step 5: Spectrum extraction (saves to output/step5_extraction/)
324
+ save_deblaze = yes # Step 6: De-blazing (saves to output/step6_deblazing/)
325
+ save_wlcalib = yes # Step 7: Wavelength calibration (saves solution to output/step7_wavelength/)
326
+ ```
327
+
328
+ **Effect**:
329
+ - If a step is set to `no`, the corresponding output subdirectory will NOT be created
330
+ - Final spectra are always saved to `output/step8_final_spectra/` regardless of these settings
331
+ - Diagnostic plots can be saved in corresponding step subdirectories
332
+ - In GUI, there should be corresponding checkboxes to enable/disable saving
333
+ - Default: All steps save intermediate results
334
+
335
+ ### Telescope and Calibration Configuration
336
+
337
+ ```ini
338
+ [telescope]
339
+ # Telescope name for calibration lookup
340
+ name = xinglong216hrs
341
+
342
+ # Spectrograph instrument name
343
+ instrument = hrs
344
+
345
+ [telescope.linelist]
346
+ # Lamp linelist type
347
+ linelist_type = ThAr
348
+
349
+ # Path to linelist files
350
+ linelist_path = calib_data/linelists/
351
+
352
+ # Specific linelist file to use (optional)
353
+ # For Xinglong 2.16m HRS: thar-noao.dat is recommended
354
+ linelist_file = thar-noao.dat
355
+
356
+ # Use pre-identified calibration files (optional)
357
+ use_precomputed_calibration = yes
358
+ calibration_path = calib_data/telescopes/xinglong216hrs/
359
+
360
+ # Specific calibration file to use (optional)
361
+ # Use latest: wlcalib_20211123011_A.fits
362
+ calibration_file = wlcalib_20211123011_A.fits
363
+ ```
364
+
365
+ ## Processing Pipeline
366
+
367
+ ### Stage Descriptions
368
+
369
+ #### STEP 1: Basic Pre-processing
370
+ - **Input**: Raw FITS files (bias, flat, ThAr, science)
371
+ - **Processing**:
372
+ - Extract overscan region (readout bias area)
373
+ - Calculate median or polynomial fit
374
+ - Subtract overscan bias from image
375
+ - Combine multiple bias frames (mean/median)
376
+ - Generate master bias
377
+ - Subtract master bias from science/flat/ThAr images
378
+ - Detect and remove cosmic rays using L.A.Cosmic (science images only)
379
+ - **Output**: Pre-processed images (overscan, bias, cosmic-ray corrected)
380
+ - **Note**: Fundamental corrections applied to prepare data for tracing and extraction.
381
+
382
+ #### STEP 2: Apertures Tracing
383
+ - **Input**: Pre-processed flat frames
384
+ - **Processing**:
385
+ - Combine flat frames
386
+ - Generate master flat
387
+ - Detect echelle apertures
388
+ - Fit polynomial traces for each aperture
389
+ - Extract blaze profiles
390
+ - **Output**: Master flat, apertures, and blaze profiles
391
+ - **Note**: Provides apertures and blaze profiles for later stages
392
+
393
+ #### STEP 3: Scattered Light Subtraction
394
+ - **Input**: Pre-processed science image
395
+ - **Processing**:
396
+ - Estimate background scattered light using 2D convolution or splines
397
+ - Subtract background model from science image
398
+ - **Output**: Background subtracted image
399
+ - **Note**: Removes inter-aperture stray light.
400
+
401
+ #### STEP 4: 2D Flat-Field Correction
402
+ - **Input**: Background subtracted science image
403
+ - **Processing**:
404
+ - Generate 2D pixel-to-pixel flat correction map
405
+ - Apply 2D flat correction to science image
406
+ - **Output**: 2D Flat-fielded image
407
+ - **Note**: Corrects for pixel-to-pixel sensitivity variations.
408
+
409
+ #### STEP 5: 1D Spectrum Extraction
410
+ - **Input**: 2D Flat-fielded image
411
+ - **Processing**:
412
+ - Extract 1D spectrum for each aperture
413
+ - Method: Sum extraction or Optimal extraction (Horne 1986)
414
+ - Calculate extraction errors
415
+ - **Output**: SpectraSet (pixel space)
416
+ - **Note**: Converts 2D traces to 1D pixel space spectra.
417
+
418
+ #### STEP 6: De-blazing
419
+ - **Input**: Extracted 1D spectra (pixel space)
420
+ - **Processing**:
421
+ - Read flat spectrum blaze function (in pixel space)
422
+ - Match apertures
423
+ - Divide by blaze function: F_corrected(λ) = F_observed(λ) / B(λ)
424
+ - Normalize to unit continuum
425
+ - **Output**: De-blazed spectra
426
+ - **Note**: Corrects for the blaze function of the spectrograph grating. Must be performed after wavelength calibration.
427
+
428
+ #### STEP 7: Wavelength Calibration
429
+ - **Input**: De-blazed 1D spectra (pixel space)
430
+ - **Processing**:
431
+ - Step 1: Calibrate ThAr lamp spectrum
432
+ - Extract 1D spectrum
433
+ - Identify emission lines
434
+ - Fit 2D wavelength polynomial: λ(x,y) = Σ p_ij·x^i·y^j
435
+ - Step 2: Apply to science spectra
436
+ - Convert pixel coordinates to wavelength units
437
+ - **Output**: Wavelength-calibrated 1D spectra
438
+ - **Note**: Establishes the physical wavelength scale for each order.
439
+
440
+
441
+ ## Usage
442
+
443
+ ### GUI Mode (Default)
444
+
445
+ ```bash
446
+ # Launch GUI (default mode)
447
+ specproc
448
+
449
+ # Or explicitly specify GUI mode
450
+ specproc --mode gui
451
+
452
+ # With custom config file
453
+ specproc --config /path/to/config.cfg
454
+ ```
455
+
456
+ **GUI Workflow**:
457
+ 1. Select bias files
458
+ 2. Select flat files
459
+ 3. Select calibration files (ThAr lamp)
460
+ 4. Select science files
461
+ 5. Click "Run Full Pipeline" or execute stages step-by-step
462
+ 6. View progress in real-time
463
+ 7. Check results in output directory
464
+
465
+ ### CLI Mode (Command Line)
466
+
467
+ ```bash
468
+ # Run CLI mode
469
+ specproc --mode cli
470
+
471
+ # Or with custom config file
472
+ specproc --mode cli --config /path/to/config.cfg
473
+
474
+ # Or select a packaged telescope profile by name, and process data with it
475
+ specproc --mode cli --config XL216_hrs 20241102_hrs
476
+
477
+ # Without input data, the named profile is copied to ./specproc.cfg instead
478
+ # of being used directly, so it can be reviewed/customized first
479
+ specproc --config MSTG193_slit
480
+ ```
481
+
482
+ **Telescope profiles**: SpecProc ships one `default_config_<profile>.cfg` file
483
+ per supported telescope/instrument under `src/specproc/config/` (e.g.
484
+ `XL216_hrs` for the Xinglong 2.16m HRS, `MSTG193_slit` for the Muztagh-Ata
485
+ 1.93m slit spectrograph). Passing the profile name to `--config` resolves it
486
+ to that packaged file automatically — no need to type the full path. Run
487
+ `specproc --help` to see the list of available profiles.
488
+
489
+ **Slit mode** (`[telescope] instrument = slit`, used by `MSTG193_slit`): a
490
+ separate single-aperture pipeline (`core/slit_pipeline.py`) replaces the echelle
491
+ stages: overscan/bias → pixel flat → cosmic rays → star trace + sky subtraction →
492
+ sum/optimal extraction → 1-D wavelength solution. Frame types are taken from file
493
+ names (`frame_type_source = filename`; bias / flat / FeAr / dark, rest = science).
494
+ Run the red and blue cameras separately (one directory each). Wavelength
495
+ calibration needs `[slit] identification_file` (pixel, wavelength rows; candidate
496
+ pixels are written to `step7_wavelength/<lamp frame>_peaks.csv`) or `wave_start`/`wave_end`
497
+ hints; otherwise spectra are saved on a pixel axis.
498
+
499
+ Slit-mode output layout (same numbering as HRS; steps not needed are omitted):
500
+ `step1_basic/{overscan_corrected,bias_subtracted,cosmic_corrected}`, `step2_trace` (slit trace of the master flat: centre and both edges, plus each
501
+ science frame's trace = flat centre line + a constant star offset; the same trace
502
+ is applied to the science and lamp frames),
503
+ `step4_flat_corrected` (master/pixel flat and flat-fielded images), `step5_extraction`
504
+ (sky-subtracted images and 1-D spectra of the targets, every lamp frame and the master flat,
505
+ all extracted along the master-flat trace), `step7_wavelength`. No scattered-light
506
+ (step3) or de-blazing (step6) directories are created.
507
+
508
+ **Extraction aperture (slit mode)**: with `[slit] aperture_mode = auto` the spatial FWHM of each
509
+ science frame is measured from the profile stacked along the whole dispersion axis
510
+ (usable for faint targets); the median over frames sets the extraction half-width
511
+ (`aperture_fwhm_factor` × FWHM, default 1.7) and the start of the sky region
512
+ (`sky_fwhm_factor` × FWHM, default 3). If the FWHM cannot be measured the fixed
513
+ `extract_half_width` / `sky_inner_offset` are used; `aperture_mode = fixed` always uses them.
514
+
515
+ **1-D SNR (slit mode)**: SNR is estimated at 25/50/75 % of the effective spectral
516
+ range (window ±`snr_half_window` px; signal = median flux, noise = standard deviation
517
+ of the residual to a quadratic fit). SNR is a dimensionless ratio, labelled
518
+ `SNR=xx@position`: the position is in pixels before wavelength calibration
519
+ (`step5_extraction/*_spec_pixel.pdf`) and in Å after it (`step7_wavelength/*_spec_wave.pdf`).
520
+ Values are annotated on the plots and stored as `SNRPxx`/`SNRWxx` keywords in the `*_spec.fits` table.
521
+
522
+ **CLI Workflow**:
523
+ 1. Follow prompts to select files
524
+ 2. Select processing stages (0-7, or Enter for all)
525
+ 3. Monitor console progress
526
+ 4. Check results in output directory
527
+
528
+ ## Calibration Data
529
+
530
+ ### Directory Structure
531
+
532
+ ```
533
+ calib_data/
534
+ ├── linelists/ # Lamp emission line catalogs
535
+ │ ├── thar-noao.dat # ThAr lamp lines (Xinglong 2.16m HRS recommended)
536
+ │ ├── thar.dat # Standard ThAr lamp lines
537
+ │ ├── FeAr.dat # FeAr lamp lines
538
+ └── ...
539
+ └── telescopes/ # Telescope-specific calibration files
540
+ ├── generic/ # Generic configuration template
541
+ └── xinglong216hrs/ # Xinglong 2.16m telescope
542
+ ├── wlcalib_20141103049.fits
543
+ ├── wlcalib_20171202012.fits
544
+ ├── wlcalib_20190905028_A.fits
545
+ └── wlcalib_20211123011_A.fits
546
+ ```
547
+
548
+ ### Lamp Line Lists
549
+
550
+ **Available linelist files**:
551
+ - `thar-noao.dat` - ThAr lamp lines (Xinglong 2.16m HRS recommended)
552
+ - `thar.dat` - Standard ThAr lamp lines
553
+ - `FeAr.dat` - FeAr lamp lines
554
+
555
+ **Supported lamp types**:
556
+ - `ThAr` - Thorium-Argon (most common for echelle spectrographs)
557
+ - `FeAr` - Iron-Argon
558
+ - `Ar` - Argon
559
+ - `Ne` - Neon
560
+ - `He` - Helium
561
+ - `Fe` - Iron
562
+
563
+ ### Telescope Calibrations
564
+
565
+ **Available calibration files for Xinglong 2.16m HRS**:
566
+ - `wlcalib_20141103049.fits` - 2014-11-03 04:50
567
+ - `wlcalib_20171202012.fits` - 2017-12-02 01:20
568
+ - `wlcalib_20190905028_A.fits` - 2019-09-05 02:50 (version A)
569
+ - `wlcalib_20211123011_A.fits` - 2021-11-23 01:10 (version A) - **Latest**
570
+
571
+ ### Configuration
572
+
573
+ ```ini
574
+ [telescope]
575
+ name = xinglong216hrs
576
+ instrument = hrs
577
+
578
+ [telescope.linelist]
579
+ linelist_type = ThAr
580
+ linelist_path = calib_data/linelists/
581
+ linelist_file = thar-noao.dat
582
+ use_precomputed_calibration = yes
583
+ calibration_path = calib_data/telescopes/xinglong216hrs/
584
+ calibration_file = wlcalib_20211123011_A.fits
585
+ ```
586
+
587
+ ## Troubleshooting
588
+
589
+ ### ImportError: No module named 'PyQt5'
590
+
591
+ ```bash
592
+ # Install PyQt5
593
+ pip install PyQt5
594
+ ```
595
+
596
+ ### specproc command not found
597
+
598
+ ```bash
599
+ conda activate specproc
600
+ pip install -e .
601
+ ```
602
+
603
+ ### Configuration file not found
604
+
605
+ ```bash
606
+ # Copy default config
607
+ cp /path/to/SpecProc/src/specproc/config/default_config.cfg ./specproc.cfg
608
+ ```
609
+
610
+ ### Large file errors on GitHub
611
+
612
+ **Error**: `File exceeds GitHub's file size limit of 100.00 MB`
613
+
614
+ **Solution**: Large FITS files should not be committed. Use `.gitignore` to exclude them.
615
+
616
+ **Prevent future additions**:
617
+ - Add output directories to `.gitignore`
618
+ - Run SpecProc in separate working directory, not in source directory
619
+
620
+ ## Documentation
621
+
622
+ - See [calib_data/README.md](calib_data/README.md) for calibration data configuration
623
+ - See [README_CN.md](README_CN.md) for Chinese documentation
624
+ - See [PIPELINE_FLOWCHART.md](PIPELINE_FLOWCHART.md) for detailed processing workflow
625
+
626
+ ## Project Structure
627
+
628
+ ```
629
+ SpecProc/
630
+ ├── README.md # Main documentation
631
+ ├── README_CN.md # Main documentation (Chinese)
632
+ ├── specproc.cfg.example # Example user configuration
633
+ ├── install.sh # Installation script
634
+ ├── requirements.txt # Python dependencies
635
+ ├── run.py # Main entry point
636
+ ├── setup.py # Installation configuration
637
+ ├── LICENSE # License
638
+ ├── .gitignore # Git ignore rules
639
+ ├── src/
640
+ │ └── specproc/ # Source code
641
+ │ ├── calib_data/ # Calibration data
642
+ │ │ ├── linelists/
643
+ │ │ └── telescopes/
644
+ │ ├── default_config.cfg # Default configuration
645
+ │ ├── gui/ # GUI modules
646
+ │ ├── core/ # Core processing
647
+ │ ├── config/ # Configuration management
648
+ │ ├── utils/ # Utility functions
649
+ │ └── plotting/ # Plotting functions
650
+ └── test_*.py # Test files
651
+ ```
652
+
653
+ ## License
654
+
655
+ See LICENSE file for details.
656
+
657
+ ## Contributing
658
+
659
+ Contributions are welcome! Please feel free to submit a Pull Request.
660
+
661
+ ## Acknowledgments
662
+
663
+ - Inspired by [gamse](https://github.com/wangleon/gamse) package
664
+ - Built with PyQt5, NumPy, SciPy and Astropy
665
+
666
+ ## Support
667
+
668
+ For issues and questions, please open an issue on GitHub.