Skip to content

Enh/embedded figures - adds a module in gempy/adlibrary to embed non-FITS files (PDFs etc) in astrodata instances and FITS files#516

Open
phirstgemini wants to merge 2 commits intomasterfrom
enh/embedded_figures
Open

Enh/embedded figures - adds a module in gempy/adlibrary to embed non-FITS files (PDFs etc) in astrodata instances and FITS files#516
phirstgemini wants to merge 2 commits intomasterfrom
enh/embedded_figures

Conversation

@phirstgemini
Copy link
Copy Markdown
Contributor

@phirstgemini phirstgemini commented Apr 27, 2026

There's been various discussions in the FITS community about storing non-FITS files (typically but not exclusively PDF / JPG / PNG graphics) inside FITS files. There are various ways to do this with various degrees of support. Consensus usually settles on storing the data in a binary table.

This PR adds:

  • an embedded_files.py module in gempy/adlibrary (with tests) to implement this. This allows capturing such files into an attribute of an astrodata instance and storing them as above in the corresponding FITS file.
  • an extract_files[.py] script in gempy/scripts to easily extract such files from their FITS containers.
  • code in geminidr/core/primitives_spect.py to use the module to capture the arc PDF plot into the processed arc.

The way this is implemented the name of the ad attribute (that becomes the binary table FITS extension) defaults to FIGURES but the name can be specified in the call, and can contain multiple embedded files. There's nothing to stop adding multiple such attributes with different names. It uses variable length byte records to store the file contents, so does not waste space in the binary table if multiple files of different lengths are stored in the same attribute. The table also has columns for filename, size and md5sum to facilitate data integrity checking.

The implementation is simple, and due to the way FITS (and astropy) tables work, it not especially memory efficient for example when adding additional files to an existing table. This could be improved but the figures in question are usually small (~10s of K) compared to available memory so this is not an issue unless a use case arises to manipulate large data files using this mechanism

@phirstgemini phirstgemini self-assigned this Apr 27, 2026
@phirstgemini phirstgemini marked this pull request as ready for review April 27, 2026 19:19
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 27, 2026

Codecov Report

❌ Patch coverage is 72.00000% with 28 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.81%. Comparing base (102d639) to head (9cd9705).

Files with missing lines Patch % Lines
gempy/scripts/extract_files.py 0.00% 20 Missing ⚠️
gempy/adlibrary/embedded_files.py 89.74% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #516      +/-   ##
==========================================
+ Coverage   66.79%   66.81%   +0.02%     
==========================================
  Files         316      318       +2     
  Lines       40195    40295     +100     
==========================================
+ Hits        26848    26923      +75     
- Misses      13347    13372      +25     
Flag Coverage Δ
f2 29.98% <7.00%> (-0.06%) ⬇️
ghost 30.51% <7.00%> (-0.06%) ⬇️
ghost_integ 31.51% <7.00%> (-0.07%) ⬇️
gmos 30.49% <7.00%> (-0.06%) ⬇️
gmosls 36.76% <35.00%> (-0.01%) ⬇️
gnirs 31.67% <7.00%> (-0.07%) ⬇️
gsaoi 24.42% <7.00%> (-0.05%) ⬇️
niri 28.26% <7.00%> (-0.06%) ⬇️
regression 33.79% <7.00%> (-0.07%) ⬇️
slow 45.17% <35.00%> (-0.03%) ⬇️
unit 48.15% <71.00%> (+0.06%) ⬆️
wavecal 25.45% <35.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant