FITS Wrangler
The fitsWrangler/ directory contains a standalone utility library for
creating and reformatting FITS files into formats compatible with the METIS
pipeline. It is largely superseded by the main simulation framework in
Simulations/, but is kept for reference and may still be useful for
one-off file manipulation tasks.
Note
For new simulation work, use the Simulations/ framework instead.
The fitsWrangler is retained as a lower-level utility for cases where you
need to build FITS files by hand, outside of the ScopeSim pipeline.
Purpose
The fitsWrangler decouples the format of METIS FITS files from the code that generates the pixel data. It can:
Create minimal, empty FITS files with the correct extensions and header keywords for any METIS pipeline recipe.
Take ScopeSim output (or any other source), copy data and headers, add ESO-compliant extension names and
HDUCLASSkeywords, and write a new file.Take data and headers from multiple sources, combine them, and produce a single pipeline-compliant FITS file.
Create processed FITS files with science, error, and quality extensions.
Module Reference
The module lives at fitsWrangler/fitsWrangler.py and exposes three
functions.
makeBasicParameters(mode, instrument)
Create a parameter structure that describes the FITS file to be produced.
This structure is passed to createImage() to actually write the file.
Arguments:
mode (str) – one of:
|
Raw data: one science extension per detector. |
|
Processed data: science + error + quality extensions per detector. |
instrument (str) – one of:
|
2048x2048 |
Single 2D image (LM-band detector). |
|
2048x2048 |
Single 2D image (N-band detector). |
|
2048x2048 |
Single 2D spectral image (long-slit). |
|
2048x2048 |
Four 2D images (one per IFU detector). |
|
2048x2048x500 |
Four 3D cubes (one per IFU detector). |
|
2048 |
Single 1D spectrum. |
Returns: a dict with the following structure:
parms = {
"instrument": [str, ...], # detector name(s)
"defaultSize": [int, ...], # numpy array shape for empty data
"primary": {
"header": None or fits.Header,
"keywords": None or dict,
},
"data": [ # list of 1 (imaging) or 4 (IFU)
{
"data": None or np.ndarray,
"header": None or fits.Header,
"keywords": None or dict,
},
...
],
"error": None or [...], # same structure as data (processed only)
"quality": None or [...], # same structure as data (processed only)
}
For raw mode, error and quality are None.
For processed mode, they mirror the data list.
createImage(outFile, parms)
Write a FITS file to disk based on the parameter structure.
Arguments:
outFile(str) – output file path.parms(dict) – parameter structure frommakeBasicParameters(), optionally modified.
Behaviour:
Creates a
PrimaryHDUand applies headers/keywords fromparms["primary"].For each entry in
parms["data"]:If
dataisNone, creates a zero-filled array of shapeparms["defaultSize"].Otherwise uses the provided numpy array.
Copies any provided header, then applies keyword overrides.
Forces ESO-compliant extension metadata (see Extension Keywords Set by fitsWrangler below).
For processed files (
errorandqualitynotNone), appends matching error and quality extensions with appropriateHDUCLASSvalues.Writes the assembled
HDUListtooutFile, overwriting if it exists.
updateHeader(HDU, parms)
Internal helper. Copies keywords from a provided header, then overlays any
keywords from the keywords dict onto the HDU.
Arguments:
HDU– anastropy.io.fitsHDU object.parms(dict) – a single entry from the parameter structure (e.g.parms["data"][0]), containingheaderandkeywordsfields.
Extension Keywords Set by fitsWrangler
createImage() forces the following keywords on every image extension it
writes, ensuring the output conforms to the ESO FITS standard for METIS:
Keyword |
Example value |
Description |
|---|---|---|
|
|
Extension name, format |
|
|
HDU class: always |
|
|
Flavour of the extension: |
|
(empty) |
Sub-flavour. Set to |
For processed files, the additional error and quality extensions use:
Extension |
|
|
|
|---|---|---|---|
Science |
|
(empty) |
|
Error |
|
|
|
Quality |
|
|
|
Complete FITS Keyword Reference
This section catalogues every FITS header keyword referenced across the
simulation framework – both in the fitsWrangler and in the main
Simulations/ code. Keywords use the ESO HIERARCH convention where the
full HIERARCH path is shown; aliases (shorthand names used in YAML templates
or internally) are noted.
Observation Metadata
FITS Keyword |
YAML / Internal Alias |
Description |
|---|---|---|
|
|
Modified Julian Date of the observation. Written by
|
|
– |
Instrument name ( |
|
– |
Target name. Set in static calibration files. |
|
– |
Right ascension of target. |
|
– |
Declination of target. |
Data Product Classification (DPR)
These keywords classify every FITS file by category, technique, and type. They are the primary keywords used by the ESO Data Processing System (EDPS) to route files to the correct pipeline recipe.
FITS Keyword |
YAML Alias |
Description |
|---|---|---|
|
|
Data product category. Values: |
|
|
Observation technique. Values: |
|
|
Observation type. Values: |
Instrument Configuration (INS)
FITS Keyword |
YAML Alias |
Description |
|---|---|---|
|
– |
Instrument mode string. Derived from |
|
– |
Optical element 1 (apodizer). Set for HCI modes (e.g. |
|
– |
Optical element 3 (vortex / slit). Set for HCI and LSS modes. For LSS, contains the slit name. |
|
– |
Optical element 5 (Lyot stop / APP). Set for HCI modes
(e.g. |
|
– |
Optical element 6 (IFU filter). Set for RAVC IFU mode. |
|
– |
Optical element 15 (pupil mask). Set for pupil imaging modes
( |
The tech to INS MODE mapping applied by updateHeaders():
|
|
Notes |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Derived Keywords (DRS)
DRS keywords are derived aliases used by the EDPS to match and organise
files without parsing complex HIERARCH trees. They are set by ScopeSim and/or
updateHeaders().
FITS Keyword |
YAML Alias |
Description |
|---|---|---|
|
|
Active filter name (e.g. |
|
|
Active ND filter (e.g. |
|
|
Slit identifier for LSS modes. Copied from |
|
– |
IFU filter/grating. Set for IFU and RAVC,IFU modes by
|
|
– |
Coronagraph mask string. Composite value set for HCI modes, e.g.
|
Detector Keywords (DET)
FITS Keyword |
YAML Alias |
Description |
|---|---|---|
|
|
Detector integration time in seconds (float). |
|
|
Number of integrations per exposure (int). |
Observation Block / Template Keywords
FITS Keyword |
YAML / Internal Alias |
Description |
|---|---|---|
|
|
Template name (e.g. |
|
|
Exposure number within the template (auto-incremented). |
|
|
Start time of the template. |
WCU / Sequence Keywords
FITS Keyword |
YAML Alias |
Description |
|---|---|---|
|
– |
Set to |
Product Classification (PRO) – Static Calibrations
These keywords appear in the static calibration files generated by
makeCalibPrototypes.py. PRO CATG identifies the product; PRO TECH
and PRO TYPE further classify it.
|
Description |
|---|---|
|
Reference standard star spectrum catalogue. |
|
Multi-star flux standard catalogue. |
|
Synthetic transmission curve (LM band). |
|
Synthetic transmission curve (N band). |
|
Adaptive optics PSF model (30x30 image). |
|
Atmospheric line catalogue (HITRAN-based). |
|
Atmospheric profile (height, pressure, temperature, molecular mixing ratios). |
|
LM-band distortion solution (polynomial coefficients). |
|
N-band distortion solution (polynomial coefficients). |
|
LM-band initial wavelength guess (polynomial coefficients). |
|
N-band initial wavelength guess (polynomial coefficients). |
|
Line Spread Function kernel (pixel vs intensity). |
|
WCU laser frequency table. |
|
WCU pinhole mask position table (x, y). |
|
Detector persistence map (per-band: LM, N, IFU). |
Additional static calibration keywords on persistence map files:
Keyword |
Example / Description |
|---|---|
|
|
|
|
|
|
|
|
|
|
HDU Extension Keywords (all files)
Keyword |
Description |
|---|---|
|
Extension name. For raw: |
|
Always |
|
|
|
Empty, |
DO Category (do.catg)
The do.catg field in YAML templates maps to the output filename prefix and
is used to classify raw data files. It is not a FITS keyword itself but
determines the filename pattern METIS.{do.catg}.{date}.fits. See
Workflow Summary for a complete list of DO categories per workflow.
Usage Examples
Creating an empty LM raw image
from fitsWrangler import fitsWrangler as fw
parms = fw.makeBasicParameters("raw", "lm")
parms["data"][0]["keywords"]["filter"] = "Mp"
fw.createImage("lm_empty.fits", parms)
Converting ScopeSim output
from astropy.io import fits
from fitsWrangler import fitsWrangler as fw
hdul = fits.open("scopesim_output.fits")
parms = fw.makeBasicParameters("raw", "lss")
parms["primary"]["header"] = hdul[0].header
parms["data"][0]["header"] = hdul[1].header
parms["data"][0]["data"] = hdul[1].data
fw.createImage("lss_raw.fits", parms)
Creating a processed file with error and quality
import numpy as np
from astropy.io import fits
from fitsWrangler import fitsWrangler as fw
hdul = fits.open("scopesim_output.fits")
parms = fw.makeBasicParameters("processed", "lss")
parms["primary"]["header"] = hdul[0].header
parms["data"][0]["header"] = hdul[1].header
parms["data"][0]["data"] = hdul[1].data
parms["error"][0]["header"] = hdul[1].header
parms["error"][0]["data"] = np.sqrt(np.abs(hdul[1].data))
parms["quality"][0]["header"] = hdul[1].header
parms["quality"][0]["data"] = (hdul[1].data * 0.0 + 1).astype(int)
fw.createImage("lss_processed.fits", parms)