Example: resampling (hdrldemo_pyresample)

This page sketches the hdrldemo recipe hdrldemo_pyresample, which wraps hdrl.func.Resample. Algorithm behaviour, methods and outgrids are documented in Image and cube resampling.

Role of the recipe

The recipe implements the “single cloud of points” workflow:

  1. Collect SOF frames (RAW, optional RAW_ERROR / RAW_VARIANCE, optional RAW_BPM).

  2. Convert each input image or cube to a resampling table (ra, dec, lambda, data, BPM, error) using Resample.image_to_table / Resample.imagelist_to_table.

  3. Optionally save that table (save-table).

  4. Build a ResampleMethod and a ResampleOutgrid from recipe parameters (with WCS-derived defaults where the user left outgrid.* at “auto”).

  5. Call Resample.compute(table, method, outgrid, wcs).

  6. Save the resulting hdrl.core.ImageList as DATA / BPM / ERROR extensions under product tag HDRLDEMO_RESAMPLE.

Parameters used by PyHDRL

Recipe parameter group

PyHDRL usage

method and method-specific parameters

ResampleMethod.Nearest / Linear / …

outgrid.*, fieldmargin

ResampleOutgrid.User2D / User3D

subtract-background

Recipe pre-step on hdrl.core.Image

ext-r / ext-e / ext-b

Select the FITS extensions loaded by PyCPL

Reading data into a table

Load PyCPL planes, apply BPM, build an hdrl.core.Image (2D) or hdrl.core.ImageList (cube), then convert with WCS:

dlist = cpl.core.ImageList.load(raw.file, cpl.core.Type.DOUBLE, ext_raw)
# apply BPM; load or synthesise error planes as needed

if len(dlist) == 1:
    him = hdrl.core.Image(dlist[0], error_image)
    table = hdrl.func.Resample.image_to_table(him, wcs)
else:
    hlist = hdrl.core.ImageList(dlist, elist)
    table = hdrl.func.Resample.imagelist_to_table(hlist, wcs)

Multiple RAW frames are concatenated into one table before Resample.compute. Variance frames are converted to errors with a square-root step in the recipe.

Calling PyHDRL

method = hdrl.func.ResampleMethod.Linear(loop_distance, use_errorweights)
# or Nearest, Quadratic, Renka, Drizzle, Lanczos — from recipe "method"

outgrid = hdrl.func.ResampleOutgrid.User2D(
    delta_ra, delta_dec, ra_min, ra_max, dec_min, dec_max, fieldmargin
)
# or User3D(...) when the WCS has three image axes

result = hdrl.func.Resample.compute(table, method, outgrid, wcs)
# result.imlist : hdrl.core.ImageList
# result.hdr    : cpl.core.PropertyList with the output WCS

Saving products

The demo recipe first writes a DFS property-list product header, then appends FITS extensions:

  • DATA — float image or imagelist

  • BPM — integer mask derived from each plane’s BPM

  • ERROR — float error plane(s)

Optional intermediate table:

cpl.dfs.save_table(
    frameset, parameters, frameset, table,
    RECIPE_NAME, applist, PIPE_ID, "hdrldemo_pyresample_table.fits",
)

The final product frame uses tag HDRLDEMO_RESAMPLE.

Minimal core

table = hdrl.func.Resample.image_to_table(hdrl_image, wcs)
method = hdrl.func.ResampleMethod.Linear(1, False)
outgrid = hdrl.func.ResampleOutgrid.Auto2D(delta_ra, delta_dec)
result = hdrl.func.Resample.compute(table, method, outgrid, wcs)
# save result.imlist planes (data / error / bpm) as FITS extensions