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:
Collect SOF frames (
RAW, optionalRAW_ERROR/RAW_VARIANCE, optionalRAW_BPM).Convert each input image or cube to a resampling table (
ra,dec,lambda, data, BPM, error) usingResample.image_to_table/Resample.imagelist_to_table.Optionally save that table (
save-table).Build a
ResampleMethodand aResampleOutgridfrom recipe parameters (with WCS-derived defaults where the user leftoutgrid.*at “auto”).Call
Resample.compute(table, method, outgrid, wcs).Save the resulting
hdrl.core.ImageListas DATA / BPM / ERROR extensions under product tagHDRLDEMO_RESAMPLE.
Parameters used by PyHDRL¶
Recipe parameter group |
PyHDRL usage |
|---|---|
|
|
|
|
|
Recipe pre-step on |
|
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 imagelistBPM— integer mask derived from each plane’s BPMERROR— 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