Skip to content

Add SPICE image rendering with full PC WCS support - #513

Open
SalimHachemaoui wants to merge 13 commits into
Helioviewer-Project:mainfrom
SalimHachemaoui:feature/full-pc-wcs-support
Open

SalimHachemaoui wants to merge 13 commits into
Helioviewer-Project:mainfrom
SalimHachemaoui:feature/full-pc-wcs-support

Conversation

@SalimHachemaoui

Copy link
Copy Markdown
Contributor

No description provided.

@mudhoney

Copy link
Copy Markdown
Contributor

Hi @SalimHachemaoui

I made couple of tests with rendering of SPICE in our web frontend, I am seeing SPICE images kind of stretched.
I m attaching the screenshot, would you check if there is problem with the rendering?
2023_12_02_18_19_21_AIA_304__SPICE_70 6

@SalimHachemaoui

Copy link
Copy Markdown
Contributor Author

Hi @mudhoney ,
You are right. I reproduced the issue locally and confirmed that the interactive SPICE rendering works correctly, but the generated screenshot does not yet apply the full SPICE WCS geometry.
The screenshot generation uses a separate server-side rendering path that still assumes a single scalar image scale. As a result, the anisotropic X/Y scales and PC matrix are not applied, which causes the stretched vertical image shown in your screenshot.
I am working on this remaining part and will update the PR once screenshot generation renders SPICE consistently with the interactive viewport.
Thanks for identifying and testing this.

@mudhoney

Copy link
Copy Markdown
Contributor

Hi @SalimHachemaoui

Thank you for following up and effort to fix the problem.

I am able to generate the same problem in interactive frontend too also for the screenshots, You can follow this link https://necdet.helioviewer.org/load/d7c388a9aa8efc0812142f2bf7418cf3396501c8ddcb97d663c69f31595ea4e5 to see the problem.

@SalimHachemaoui

Copy link
Copy Markdown
Contributor Author

Hi @mudhoney ,
Thank you for the link. I understand now that the issue is reproducible in both the interactive frontend and the server-generated screenshots on your deployment.
My local interactive test was using a locally modified version of the frontend and @helioviewer/sun, which explains why SPICE appeared correctly there. Those frontend changes are not included in the current API PR.
I am now checking both rendering paths separately:
the client-side WCS transformation used by the interactive frontend;
the server-side composite renderer used for screenshots and movies.
I will avoid pushing the current experimental screenshot fix until both paths use the same SPICE WCS conventions and produce consistent results. Thank you for providing the reproducible state.
image

@dgarciabriseno

dgarciabriseno commented Aug 20, 2026 via email

Copy link
Copy Markdown
Contributor

@dgarciabriseno

Copy link
Copy Markdown
Contributor

@SalimHachemaoui is this still a work in progress?

@SalimHachemaoui

Copy link
Copy Markdown
Contributor Author

@SalimHachemaouiEst-ce encore un travail en cours ?

Hello @dgarciabriseno Yes, this is still a work in progress.
The current PR already adds the backend WCS handling for separate CDELT1/CDELT2 values and the PC/CD matrices, while keeping the existing scalar scale for backward compatibility. The remaining work is to make sure this metadata is actually applied consistently by the rendering paths. In particular, I still need to complete the server-side composite rendering used for screenshots/movies and align it with the client-side rendering changes.

This was referenced Oct 5, 2026
@SalimHachemaoui

Copy link
Copy Markdown
Contributor Author

Update: I pushed commit 616fac1 to this PR. Screenshots and movie frames now apply the full native SPICE WCS geometry, including separate X/Y scales, the PC/CD matrix, reference pixel offsets, the raster Y axis, and 1 AU normalization. This corrects the stretched SPICE strip in generated images. SPICE also uses additive blending over visible background layers.
I added a real SPICE JP2 fixture and regression tests covering screenshots, movie frames, cropping, opacity, an AIA background, and AIA rendering. Locally, 17 tests passed, one LASCO test was skipped, and the SPICE screenshot and frame matched an independent WCS reference.
The interactive viewport requires the corresponding frontend WCS changes, which are outside this API PR. The attached EUI FSI 174 + SPICE 97.7 screenshot illustrates the corrected composite geometry.

2026_01_11_18_19_24_EUI_FSI_174__SPICE_97 7

@dgarciabriseno

Copy link
Copy Markdown
Contributor

@SalimHachemaoui this is looking good from your screenshot. I will pull and check it out.

@mudhoney just refactored how movies are made to massively improve the speed that movies are created, I'm worried those changes may conflict with your changes. @mudhoney can you also check on that part of this PR?

@dgarciabriseno

Copy link
Copy Markdown
Contributor

@SalimHachemaoui do you also have a pull request for https://github.com/Helioviewer-Project/helioviewer.org that goes with this?

@SalimHachemaoui

Copy link
Copy Markdown
Contributor Author

@SalimHachemaoui do you also have a pull request for https://github.com/Helioviewer-Project/helioviewer.org that goes with this?

Hi @dgarciabriseno, yes, the companion frontend PR is [helioviewer.org#719](Helioviewer-Project/helioviewer.org#719). It includes the SPICE 2D WCS rendering changes and the frontend 3D integration.

The 3D implementation also depends on [sun#2](Helioviewer-Project/sun#2). I tested the 2D view and the 3D SPICE patch locally with a build of that sun branch. The frontend PR still needs a published @helioviewer/sun release and a dependency update before its 3D path can be reproduced from a clean install. The remaining validation and export contract work are documented in the frontend PR.

@dgarciabriseno

Copy link
Copy Markdown
Contributor

Thank you Salim, I'll check these out tomorrow.

@dgarciabriseno

dgarciabriseno commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

@mudhoney @SalimHachemaoui

I am getting this error when trying to make a movie.

movies-1  | [Movie:z666n w158 +0.727s] frame 1/121 FAILED (failure 1/3): No image type for layer SOLO/SPICE/intensity/H Ly gamma 97.25 nm

It needs to be added to the grayscale list in FastMovie.php and the WCS logic also needs to be migrated.

src/Movie/FastMovie.php:1016-1019 — add SPICE alongside HMI/MDI/GONG for "no color table"

case 'HMI':
case 'MDI':
case 'GONG':
case 'SPICE':
    break;                                  // grayscale, no colour table

@mudhoney

Copy link
Copy Markdown
Contributor

@dgarciabriseno @SalimHachemaoui
I m editing the branch to add movie support

SalimHachemaoui and others added 4 commits November 20, 2026 20:28
Port of the SPICE screenshot rendering to the movie engine: layerRecipe()
gets a SPICE case, and decodeWcsLayer() places the raster with the same
CD-matrix affine as Image_ImageType_SPICEImage, added onto the layers below.
Movie frames now match screenshots of the same request.
The composite constructors require an EventContext since the events work
on main, so the fixture's null made every test error after the rebase.
@mudhoney
mudhoney force-pushed the feature/full-pc-wcs-support branch from 616fac1 to 50c6a32 Compare November 20, 2026 21:45
@mudhoney

Copy link
Copy Markdown
Contributor

Hi @dgarciabriseno @SalimHachemaoui
I have ported the current SPICE screenshot rendering to fast movies, also fix a test,
I had to rebase with our current main ( PR's main was 15 commits old )
To update your local branches you need to ;

  git fetch https://github.com/SalimHachemaoui/api.git feature/full-pc-wcs-support
  git checkout feature/full-pc-wcs-support
  git reset --hard FETCH_HEAD

^ this should make your branch sync with the code in PR , if you have local edits/commits do git stash or create another branch from your code

Comment thread src/Image/ImageType/SPICEImage.php Outdated
Comment on lines +48 to +69
require_once HV_ROOT_DIR.'/../src/Image/JPEG2000/JP2ImageXMLBox.php';
$header = new Image_JPEG2000_JP2ImageXMLBox($jp2->getFilePath());
$cd = $header->getCDMatrix();
$sun = $header->getRefPixelCoords(); // CRPIX - inverse(CD) * CRVAL

// Use the same 1 AU normalization as the tile metadata. The stored
// scalar scale is |CDELT1| * DSUN/AU, not a second WCS transform.
$factor = $jp2->getScale() / $header->getImagePlateScale() / $roi->imageScale();
$a = $cd[0][0] * $factor;
$b = -$cd[1][0] * $factor;
$c = -$cd[0][1] * $factor;
$d = $cd[1][1] * $factor;
$shift = $options['wcsViewportOffset'] ?? array(0, 0);

// The canonical tile grid uses refPixelX and height-refPixelY.
// Conjugating CD by the Y flip converts FITS Y-up to raster Y-down.
// Keep this origin convention identical to the interactive tile grid;
// neither CROTA nor another rotation is applied after this affine.
$tx = -$a * $sun[0] - $c * ($jp2->getHeight() - $sun[1])
- $roi->left() / $roi->imageScale() - $shift[0];
$ty = -$b * $sun[0] - $d * ($jp2->getHeight() - $sun[1])
- $roi->top() / $roi->imageScale() - $shift[1];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We really need this logic applied generally. Solar Orbiter EUI images currently have rotation that is not handled correctly in the 2D viewport, as well as some other sources that we don't display on the web client due to the same alignment issues.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SalimHachemaoui I will work on generalizing this to other sources.

Daniel Garcia Briseno added 2 commits November 24, 2026 10:29
This logic is used when the code sees that the PC/CD matrix
exists in the header
@dgarciabriseno

Copy link
Copy Markdown
Contributor

We need to use DATE_AVG for SPICE images, not the date from the file name, or the DATE field in the metadata.

@dgarciabriseno

Copy link
Copy Markdown
Contributor

We should also compare SDO with Solar Orbiter at a time that SOLO is near the sun/earth pov.

@SalimHachemaoui

Copy link
Copy Markdown
Contributor Author

We need to use DATE_AVG for SPICE images, not the date from the file name, or the DATE field in the metadata.

Thanks, @dgarciabriseno ! I pushed 91a3a145: SPICE rasters are now indexed by DATE-AVG, while archive paths still use the scan start date. I verified the change on one raster on the IAS test instance; existing rasters haven’t been reindexed.

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.

3 participants