# JWST program 2640 NIRSpec MSA spectra (Westerlund 2)

Source data: `../mastDownload/JWST/jw02640-o001_s*_nirspec_*/` (this project's
own MAST download tree, shared with the archive-checklist workflow described
in the parent `CLAUDE.md`). 131 MSA sources, target `WESTERLUND2-DIST-CORE-FULL`.
All 131 have a CLEAR/PRISM spectrum (0.6-5.3 um, R~100); 47 of those also have
G140M/F100LP (0.97-1.84 um) and G395M/F290LP (2.87-5.10 um) at R~1000. There
is no G235M for this program -- PRISM alone covers the range a G235M would
occupy, at lower resolution, rather than leaving a gap.

Cloned from the program 6927 portal (`../nirspec_6927/`, see its
`PORTAL_BLUEPRINT.md`) at the user's request. Not everything transferred
unchanged -- see "What differs from 6927" below.

## Contents

| path | what |
| --- | --- |
| `pngs/` | per-source spectrum plots, PDF + PNG: plain, `_nb` (narrowband: F182M/F212N/F405N/F410M/F466N), `_bb` (broadband: F115W/F200W/F277W/F444W) |
| `pngs/gallery_2640*.html` | gallery browsers (all / narrowband / broadband) |
| `nirspec_2640_map.html` | interactive Aladin Lite sky map over a wd2 NIRCam HiPS; hover/click a source to see its spectrum |
| `nirspec_2640_colorcolor.html` | color-color/color-magnitude diagrams: static wd2 catalog density background, dynamic spectroscopic sources |
| `nirspec_2640_specviewer.html` | zoomable/pannable spectrum browser, detected lines labelled |
| `nirspec_2640_pvgallery.html` | position-wavelength gallery (L3 only -- see below) |
| `nirspec_2640_line_detections.ecsv` | H2 / H I / He I / [Fe II] line measurements |
| `pv/` | position-wavelength diagrams from the L3 s2d, one per source |
| `nirspec_2640_slits.ecsv` | shutter corners and dither footprint per source |
| `nirspec_2640_synthphot.ecsv` | synthesized photometry + wd2 catalog crossmatch |
| `ccd_bg_*.png` | catalog density backgrounds, one per color-color/CMD diagram |
| `specdata/` | one compact JSON spectrum per source, loaded on demand by the viewer |
| `nirspec_2640_sources.ecsv`, `.json` | source positions + product paths backing the map |
| `nirspec_2640_ice_lines.ecsv`, `.fits` | ice + gas absorption depth catalog |
| `linefits/` | per-source continuum/optical-depth diagnostic plots |
| `index.html` | landing page, auto-degrades to whatever exists on disk |

## Scripts

All in `/orange/adamginsburg/jwst/brick/analysis/`, named `NIRSpec_2640_*.py`,
run from this directory:

```bash
python /orange/adamginsburg/jwst/brick/analysis/NIRSpec_2640_Spectra.py
python /orange/adamginsburg/jwst/brick/analysis/NIRSpec_2640_IceLines.py
python /orange/adamginsburg/jwst/brick/analysis/NIRSpec_2640_LineID.py
python /orange/adamginsburg/jwst/brick/analysis/NIRSpec_2640_SpecViewer.py
python /orange/adamginsburg/jwst/brick/analysis/NIRSpec_2640_PV.py
python /orange/adamginsburg/jwst/brick/analysis/NIRSpec_2640_ColorColor.py
python /orange/adamginsburg/jwst/brick/analysis/NIRSpec_2640_AladinMap.py
python /orange/adamginsburg/jwst/brick/analysis/NIRSpec_2640_PVGallery.py
python /orange/adamginsburg/jwst/brick/analysis/NIRSpec_2640_Index.py
```

Run in roughly this order: Spectra first (everything imports its
`group_by_source`/`load_source`), then IceLines/LineID (LineID before
SpecViewer, which imports it), PV before AladinMap (AladinMap reads
`nirspec_2640_slits.ecsv`), AladinMap before PVGallery (reads
`nirspec_2640_sources.json`), Index last (counts everything else off disk).

## What differs from 6927

- **Grating set.** PRISM + G140M + G395M, not three medium gratings. See
  `NIRSpec_2640_Spectra.py`'s docstring for the coverage/overlap
  consequences, and `NIRSpec_2640_LineID.py`'s for why line detection runs at
  two different resolving powers (R=1000 for 47 sources, R~100 for 84).
- **Filter sets.** wd2 has no F356W; the broadband panel uses F182M/F212N/
  F405N/F410M/F466N and F115W/F200W/F277W/F444W (`nb`/`bb`, not `2221`/`1182`
  -- those names are Brick-program-specific and don't apply here).
- **Photometry catalog.** `/orange/adamginsburg/jwst/wd2/catalogs/basic_merged_indivexp_photometry_tables_merged_resbgsub_m8_dedup.fits`
  (41289 rows), not the Brick catalog. It has no `good_<filter>` column;
  `NIRSpec_2640_ColorColor.py` builds an equivalent from `mask_<filter>` +
  `is_saturated_<filter>` -- see that script's docstring. 52/131 sources
  matched a catalog counterpart within 0.3" (6927: 46/56); a much more
  crowded field plausibly explains the lower fraction, unconfirmed.
- **Sky imagery.** Two wd2 HiPS trees are published under
  `avm_images/` (asinh 2.12/2.00/1.87 and 4.10/4.05/3.35 RGB); more RGB
  variants exist locally under `/orange/adamginsburg/jwst/wd2/pngs_2640/*_hips`
  but are not yet published there.
- **Global continuum fit (deferred, not built).** 6927's
  `NIRSpec_6927_GlobalContinuum.py` fits a red-clump-giant stellar atmosphere
  (T_eff prior 4000-5000 K) reddened by a Galactic-Centre extinction law
  (CT06_MWGC/F11_MWGC). Neither assumption holds for Westerlund 2 -- a young
  massive-star cluster at a different Galactic location and extinction
  regime, not reddened bulge giants. The blueprint's own "mistakes that cost
  time" table records exactly this failure mode (wrong stellar-population
  prior silently biasing a fit); building this component would need a real
  characterization of the wd2 target population and an appropriate
  extinction law first, not a copy-paste of 6927's priors.
- **SEDs/cutouts, L2 reprocessing (deferred, not built).** `sed_figures/`
  needs a new SED-fitting run against wd2 photometry for all 131 sources
  (6927's figures were pre-generated externally); L2 products
  (`NIRSpec_2640_PV_L2.py`/`PV_NoBgsub.py`/`PV_NoNod.py` analogs) need a
  download decision and the same `NRS_AUTOFLAT`/`NRS_AUTOWAVE` exposure
  filtering 6927's README documents. Both are real, scoped-down follow-ups,
  not skipped silently -- see the build report for what each needs.
- **StackByAV, IceColumns (not built).** Straightforward ports once the
  above are settled; deferred for time, not for any 2640-specific reason.

## Ice/gas catalog, line identification

Same feature definitions, band strengths, and CO gas/ice discriminant as
6927 -- see `../nirspec_6927/README.md` for the physics. Detection rates are
markedly lower here (32/131 H2O vs 28/56 saturated at 6927), consistent with
Westerlund 2 being a young massive-star cluster/HII region rather than a
deeply embedded Galactic Centre sightline: strong H I recombination emission
(Br-alpha, Pa-beta, Pa-gamma) dominates the line catalog (148/186 detections)
where 6927 was H2-rotational-ladder dominated.
