|
| 1 | +# /// script |
| 2 | +# requires-python = ">=3.13" |
| 3 | +# dependencies = ["pyreduce-astro>=0.7b3"] |
| 4 | +# /// |
| 5 | +""" |
| 6 | +MOSAIC VIS spectrograph example. |
| 7 | +
|
| 8 | +The VIS detector is a 4-quadrant mosaic (12788x12394 pixels total). |
| 9 | +Each quadrant is processed as a separate channel: |
| 10 | +- VIS1: lower-left quadrant |
| 11 | +- VIS2: lower-right quadrant |
| 12 | +- VIS3: upper-left quadrant |
| 13 | +- VIS4: upper-right quadrant |
| 14 | +
|
| 15 | +This example processes VIS1. Run with different channel values for other quadrants. |
| 16 | +""" |
| 17 | + |
| 18 | +import os |
| 19 | +from os.path import join |
| 20 | + |
| 21 | +from pyreduce import util |
| 22 | +from pyreduce.configuration import load_config |
| 23 | +from pyreduce.pipeline import Pipeline |
| 24 | + |
| 25 | +# Parameters |
| 26 | +# Change channel to VIS2, VIS3, or VIS4 for other quadrants |
| 27 | +instrument_name = "MOSAIC" |
| 28 | +target = "MOSAIC_VIS" |
| 29 | +night = "" |
| 30 | +channel = "VIS1" |
| 31 | +plot = 1 |
| 32 | + |
| 33 | +# Handle plot environment variables |
| 34 | +if "PYREDUCE_PLOT" in os.environ: |
| 35 | + plot = int(os.environ["PYREDUCE_PLOT"]) |
| 36 | +plot_dir = os.environ.get("PYREDUCE_PLOT_DIR") |
| 37 | +util.set_plot_dir(plot_dir) |
| 38 | + |
| 39 | +# Data location |
| 40 | +data_dir = os.environ.get("REDUCE_DATA", os.path.expanduser("~/REDUCE_DATA")) |
| 41 | +base_dir = join(data_dir, "MOSAIC", "REF_E2E", "VIS") |
| 42 | +output_dir = join(data_dir, "MOSAIC", "reduced", channel) |
| 43 | + |
| 44 | +# File paths (simulated data) |
| 45 | +flat_file = join( |
| 46 | + base_dir, |
| 47 | + "E2E_as_built_FLAT_DIT_20s_MOSAIC_VIS_c01_FOCAL_PLANE_000.fits", |
| 48 | +) |
| 49 | +thar_file = join( |
| 50 | + base_dir, |
| 51 | + "E2E_as_built_ThAr_DIT_20s_MOSAIC_VIS_c01_FOCAL_PLANE.fits", |
| 52 | +) |
| 53 | + |
| 54 | +# Verify files exist |
| 55 | +for fpath in [flat_file, thar_file]: |
| 56 | + if not os.path.exists(fpath): |
| 57 | + raise FileNotFoundError(f"Data file not found: {fpath}") |
| 58 | + |
| 59 | +print(f"FLAT: {flat_file}") |
| 60 | +print(f"ThAr: {thar_file}") |
| 61 | + |
| 62 | +# Load configuration |
| 63 | +config = load_config(None, instrument_name, plot) |
| 64 | + |
| 65 | +# Create pipeline - fiber grouping is handled by config.yaml |
| 66 | +pipe = Pipeline( |
| 67 | + instrument=instrument_name, |
| 68 | + output_dir=output_dir, |
| 69 | + target=target, |
| 70 | + channel=channel, |
| 71 | + night=night, |
| 72 | + config=config, |
| 73 | + plot=plot, |
| 74 | +) |
| 75 | + |
| 76 | +# Run pipeline steps |
| 77 | +pipe.trace_orders([flat_file]) |
| 78 | +pipe.curvature([thar_file]) |
| 79 | +pipe.extract([thar_file, flat_file]) |
| 80 | + |
| 81 | +print("\n=== Running Pipeline ===") |
| 82 | +results = pipe.run() |
| 83 | + |
| 84 | +print("\n=== Results ===") |
| 85 | +orders, column_range = results["trace"] |
| 86 | +print(f"Raw traces: {len(orders)}") |
| 87 | + |
| 88 | +if "trace_groups" in results and results["trace_groups"]: |
| 89 | + group_traces, group_cr = results["trace_groups"] |
| 90 | + print( |
| 91 | + f"Fiber groups: {list(group_traces.keys())[:5]}... ({len(group_traces)} total)" |
| 92 | + ) |
0 commit comments