Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thchang/2366 support image coordinates #2388

Merged
merged 40 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
1978fe5
support image coordinates for images with valid WCS headers
TienHao Jun 6, 2024
06d6811
merge dev branch
TienHao Jun 24, 2024
6fe30a5
set labels of pixel frames
TienHao Jun 24, 2024
c576934
disable wcs inputs when the system coordinates is IMG
TienHao Jun 24, 2024
f761d4d
minor change for AST plot speed
TienHao Jul 4, 2024
4d0bf19
fix regression of missing AST grid for no wcs info frame after swithi…
TienHao Jul 4, 2024
e46779d
fix warning of searching radius in degree for pixel coordinate frames
TienHao Jul 4, 2024
1e1ef6f
fix spatial matching for the FrameSet's current frame
TienHao Jul 5, 2024
6a414ad
solve conflicts and merge dev branch
TienHao Jul 10, 2024
c2b410b
fixed relative coordinates for pixel coordinates
TienHao Aug 1, 2024
0e21d63
fixed image coordinates for non-squre pixels images
TienHao Aug 7, 2024
0284e6d
merge dev branch
TienHao Aug 15, 2024
7ca5837
uppercased image system type and minorly refactored
TienHao Aug 21, 2024
4c781db
fixed CatalogOnlineQueryComponent and genRegionWcsProperties
TienHao Aug 21, 2024
b5d1e2d
merge dev branch
TienHao Aug 21, 2024
9476953
fixed the bug of non-wcs images with wcs system in overlay
TienHao Sep 18, 2024
aec3be7
fixed the error of switching system when relative system is activated
TienHao Sep 19, 2024
aecc3bf
changed back switching active frame behaviour
TienHao Sep 19, 2024
2c04589
merge dev branch
TienHao Sep 26, 2024
9835dda
fixed special non-square pixels images
TienHao Sep 26, 2024
a784cc8
added back the frame in Dummy FrameSet
TienHao Nov 6, 2024
2fd7f9b
merge dev branch
TienHao Nov 6, 2024
13365bb
store relative pixel AST Frame in the third frame of wcsInfoShifted A…
TienHao Nov 15, 2024
451e680
fix the plotting of relative image coordinates for secondary images i…
TienHao Nov 21, 2024
017d000
minor fix
TienHao Nov 21, 2024
17afb2f
fix the catalog online query button
TienHao Nov 26, 2024
e9c4455
changelog updated
TienHao Nov 26, 2024
b6892db
modified labels of image coordinates with and without offsets
TienHao Nov 28, 2024
7853cee
fixed spatial matching on append when the image coordinates are selected
TienHao Dec 5, 2024
3454aee
disabled spatial matching in image coordinates if images cannot be ma…
TienHao Dec 6, 2024
cc166ea
merge dev branch
TienHao Dec 10, 2024
b5bda44
added back fix of spatial matching on append
TienHao Dec 12, 2024
d1582f3
disabling spatial matching when switching system between world and im…
TienHao Dec 12, 2024
91e2807
removed the spatial matching restriction of wcs images cannot be matc…
TienHao Dec 12, 2024
554b08c
merge dev branch
TienHao Dec 12, 2024
6032392
modified alert context
TienHao Dec 12, 2024
bacb635
fixed catalog plotting in pixel coordinates
TienHao Dec 17, 2024
e84c014
minor change
TienHao Dec 17, 2024
32d4d18
minor adjustments
TienHao Dec 18, 2024
7bf309e
removed logs
TienHao Dec 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/components/ImageView/Overlay/OverlayComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as _ from "lodash";
import {observer} from "mobx-react";

import {CursorInfo, ImageItem, ImageType, SPECTRAL_TYPE_STRING} from "models";
import {AppStore, OverlayStore, PreferenceStore} from "stores";
import {AppStore, OverlayStore, PreferenceStore, SystemType} from "stores";

import "./OverlayComponent.scss";

Expand Down Expand Up @@ -70,11 +70,11 @@ export class OverlayComponent extends React.Component<OverlayComponentProps> {
const scaleMapping = AST.scaleMap2D(1.0, 1.0 / frame.aspectRatio);
const newFrame = AST.frame(2, "Domain=PIXEL");
AST.addFrame(tempWcsInfo, 1, scaleMapping, newFrame);
AST.setI(tempWcsInfo, "Base", 3);
AST.setI(tempWcsInfo, "Current", 2);
AST.setI(tempWcsInfo, "Base", frame.validWcs ? 3 : 2);
AST.setI(tempWcsInfo, "Current", frame.validWcs ? 2 : 1);
YuHsuan-Hwang marked this conversation as resolved.
Show resolved Hide resolved
}

if (frame.isOffsetCoord) {
if (frame.isOffsetCoord && AppStore.Instance.overlayStore.global.explicitSystem !== SystemType.Image) {
const fovSizeInArcsec = frame.getWcsSizeInArcsec(frame.fovSize);
const viewSize = fovSizeInArcsec.x > fovSizeInArcsec.y ? fovSizeInArcsec.y : fovSizeInArcsec.x;
const factor = 2; // jump factor
Expand Down Expand Up @@ -214,7 +214,7 @@ export class OverlayComponent extends React.Component<OverlayComponentProps> {
const formatStringX = this.props.overlaySettings.numbers.formatStringX;
const formatStyingY = this.props.overlaySettings.numbers.formatStringY;
const explicitSystem = this.props.overlaySettings.global.explicitSystem;
if (formatStringX !== undefined && formatStyingY !== undefined && explicitSystem !== undefined) {
if (formatStringX !== undefined && formatStyingY !== undefined && explicitSystem !== undefined && explicitSystem !== SystemType.Image) {
AST.set(frame.wcsInfo, `Format(${frame.dirX})=${formatStringX}, Format(${frame.dirY})=${formatStyingY}, System=${explicitSystem},` + dirAxesSetting);
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/components/ImageView/Toolbar/ToolbarComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export class ToolbarComponent extends React.Component<ToolbarComponentProps> {
[SystemType.FK4, "FK4"],
[SystemType.Galactic, "GAL"],
[SystemType.Ecliptic, "ECL"],
[SystemType.ICRS, "ICRS"]
[SystemType.ICRS, "ICRS"],
[SystemType.Image, "IMG"]
]);

private static readonly CoordinateSystemTooltip = new Map<SystemType, string>([
Expand Down Expand Up @@ -174,6 +175,7 @@ export class ToolbarComponent extends React.Component<ToolbarComponentProps> {
<MenuItem text={ToolbarComponent.CoordinateSystemName.get(SystemType.Galactic)} onClick={() => this.handleCoordinateSystemClicked(SystemType.Galactic)} />
<MenuItem text={ToolbarComponent.CoordinateSystemName.get(SystemType.Ecliptic)} onClick={() => this.handleCoordinateSystemClicked(SystemType.Ecliptic)} />
<MenuItem text={ToolbarComponent.CoordinateSystemName.get(SystemType.ICRS)} onClick={() => this.handleCoordinateSystemClicked(SystemType.ICRS)} />
<MenuItem text={ToolbarComponent.CoordinateSystemName.get(SystemType.Image)} onClick={() => this.handleCoordinateSystemClicked(SystemType.Image)} />
<FormGroup inline={false} className="offset-group">
<Switch className="offset-switch" disabled={frame.isPVImage || frame.isSwappedZ || frame.isUVImage} checked={frame.isOffsetCoord} onChange={frame.toggleOffsetCoord} label="Offset" />
<Collapse isOpen={frame.isOffsetCoord}>
Expand Down
12 changes: 10 additions & 2 deletions src/components/Shared/CoordNumericInput/CoordNumericInput.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Position, Tooltip} from "@blueprintjs/core";

import {AppStore, NUMBER_FORMAT_LABEL} from "stores";
import {AppStore, NUMBER_FORMAT_LABEL, SystemType} from "stores";
import {CoordinateMode} from "stores/Frame";

import {SafeNumericInput} from "..";
Expand Down Expand Up @@ -131,6 +131,14 @@ export const CoordNumericInput = ({coord, inputType, value, onChange, valueWcs,
if (coord === CoordinateMode.Image) {
return <ImageCoordNumericInput inputType={inputType} value={value} onChange={onChange} disabled={disabled} customPlaceholder={customPlaceholder} />;
} else {
return <WcsCoordNumericInput inputType={inputType} valueWcs={valueWcs} onChangeWcs={onChangeWcs} disabled={disabled || wcsDisabled} customPlaceholder={customPlaceholder} />;
return (
<WcsCoordNumericInput
inputType={inputType}
valueWcs={valueWcs}
onChangeWcs={onChangeWcs}
disabled={disabled || wcsDisabled || AppStore.Instance.overlayStore.global.system === SystemType.Image}
customPlaceholder={customPlaceholder}
/>
);
}
};
2 changes: 2 additions & 0 deletions src/stores/AppStore/AppStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1987,6 +1987,8 @@ export class AppStore {
this.contourDataSource = frame;
}
}

this.overlayStore.setDefaultsFromFrame(this.activeFrame);
YuHsuan-Hwang marked this conversation as resolved.
Show resolved Hide resolved
} else {
this.widgetsStore.updateImageWidgetTitle(this.layoutStore.dockedLayout);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ export class CatalogOnlineQueryConfigStore {

@computed get searchRadiusInDegree(): number {
const activeFrame = this.activeFrame;
if (activeFrame) {
if (activeFrame?.validWcs && OverlayStore.Instance.global.explicitSystem !== SystemType.Image) {
const requiredFrameView = activeFrame.requiredFrameView;
const diagonal1 = this.calculateDistanceFromPixelCoord({x: requiredFrameView.xMax, y: requiredFrameView.yMax}, {x: requiredFrameView.xMin, y: requiredFrameView.yMin}, true);
const diagonal2 = this.calculateDistanceFromPixelCoord({x: requiredFrameView.xMin, y: requiredFrameView.yMax}, {x: requiredFrameView.xMax, y: requiredFrameView.yMin}, true);
Expand Down
16 changes: 11 additions & 5 deletions src/stores/Frame/FrameStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1511,8 +1511,12 @@ export class FrameStore {

updateWcsSystem = (formatStringX: string, formatStyingY: string, explicitSystem: SystemType) => {
if (formatStringX !== undefined && formatStyingY !== undefined && explicitSystem !== undefined) {
if (!(this.isPVImage && this.spectralAxis?.valid) && !(this.isSwappedZ && this.spectralAxis?.valid)) {
if (this.validWcs && this.wcsInfo) {
if (!(this.isPVImage && this.spectralAxis?.valid) && !(this.isSwappedZ && this.spectralAxis?.valid) && this.validWcs && this.wcsInfo) {
if (explicitSystem === SystemType.Image) {
// Use base frame for image coordinates
AST.setI(this.wcsInfo, "Current", 1);
} else {
AST.setI(this.wcsInfo, "Current", 2);
AST.set(this.wcsInfo, `Format(${this.dirX})=${formatStringX}, Format(${this.dirY})=${formatStyingY}, System=${explicitSystem}`);
}
}
Expand Down Expand Up @@ -1925,7 +1929,7 @@ export class FrameStore {
let cursorPosWCS, cursorPosFormatted;
let precisionX = 0;
let precisionY = 0;
if (this.validWcs || this.isYX || this.isPVImage || this.isUVImage || this.isSwappedZ) {
if ((this.validWcs || this.isYX || this.isPVImage || this.isUVImage || this.isSwappedZ) && this.overlayStore.global.explicitSystem !== SystemType.Image) {
// We need to compare X and Y coordinates in both directions
// to avoid a confusing drop in precision at rounding threshold
const offsetBlock = [
Expand Down Expand Up @@ -2181,8 +2185,8 @@ export class FrameStore {
@action private createWcsInfoShifted = () => {
if (this.spatialReference) {
this.spatialReference.createWcsInfoShifted();
} else {
if (this.wcsInfo && this.offsetCenter) {
} else if (this.wcsInfo && this.offsetCenter) {
if (AppStore.Instance.overlayStore.global.explicitSystem !== SystemType.Image) {
const centerInRad = getUnformattedWCSPoint(this.wcsInfo, this.offsetCenter);

if (centerInRad) {
Expand All @@ -2194,6 +2198,8 @@ export class FrameStore {
}
}
}
} else {
this.wcsInfoShifted = AST.createShiftmapPixelFrameset(this.wcsInfo, this.offsetCenter.x, this.offsetCenter.y);
}
}
};
Expand Down
11 changes: 7 additions & 4 deletions src/stores/OverlayStore/OverlayStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export enum SystemType {
FK4 = "FK4",
FK5 = "FK5",
Galactic = "GALACTIC",
ICRS = "ICRS"
ICRS = "ICRS",
Image = "Cartesian"
YuHsuan-Hwang marked this conversation as resolved.
Show resolved Hide resolved
}

export enum NumberFormatType {
Expand Down Expand Up @@ -99,9 +100,11 @@ export class OverlayGlobalSettings {
astString.add("Labelling", this.labelType);
astString.add("Color", AstColorsIndex.GLOBAL);
astString.add("Tol", toFixed(this.tolerance / 100, 2), this.tolerance >= 0.001); // convert to fraction
astString.add("System", this.explicitSystem);
if (typeof this.explicitSystem !== "undefined" && this.explicitSystem !== SystemType.Image) {
astString.add("System", this.explicitSystem);
}

if ((frame?.isXY || frame?.isYX) && !frame?.isPVImage && typeof this.explicitSystem !== "undefined") {
if ((frame?.isXY || frame?.isYX) && !frame?.isPVImage && typeof this.explicitSystem !== "undefined" && this.explicitSystem !== SystemType.Image) {
if (this.system === SystemType.FK4) {
astString.add("Equinox", "1950");
} else {
Expand Down Expand Up @@ -1021,7 +1024,7 @@ export class OverlayStore {
autorun(() => {
this.setFormatsFromSystem();
AppStore.Instance.frames.forEach(frame => {
if (frame?.validWcs && frame?.wcsInfoForTransformation && this.global.explicitSystem) {
if (frame?.validWcs && frame?.wcsInfoForTransformation && this.global.explicitSystem && this.global.explicitSystem !== SystemType.Image) {
AST.set(frame.wcsInfoForTransformation, `System=${this.global.explicitSystem}`);
}
});
Expand Down
28 changes: 21 additions & 7 deletions wasm_src/ast_wrapper/ast_wrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ EMSCRIPTEN_KEEPALIVE AstFrameSet* getFrameFromFitsChan(AstFitsChan* fitschan, bo
return nullptr;
}

AstFrame* pixFrame = static_cast<AstFrame*> astGetFrame(frameSet, 1);
astSet(pixFrame, "Label(1)=X Coordinate,Label(2)=Y Coordinate");

// work around for missing CTYPE1 & CTYPE2
if (checkSkyDomain) {
const char *domain = astGetC(frameSet, "Domain");
Expand Down Expand Up @@ -104,7 +107,7 @@ EMSCRIPTEN_KEEPALIVE AstFrameSet* getSkyFrameSet(AstFrameSet* frameSet)
}

// Create 2D base frame
AstFrame *baseframe = astFrame(2, "Title=Pixel Coordinates,Domain=GRID,Label(1)=Pixel axis 1,Label(2)=Pixel axis 2");
AstFrame *baseframe = astFrame(2, "Title=Pixel Coordinates,Domain=GRID,Label(1)=X Coordinate,Label(2)=Y Coordinate");
if (!baseframe)
{
cout << "Create 2D base frame failed." << endl;
Expand Down Expand Up @@ -180,10 +183,10 @@ EMSCRIPTEN_KEEPALIVE AstFrameSet* createTransformedFrameset(AstFrameSet* wcsinfo
return nullptr;
}

AstFrame* pixFrame = static_cast<AstFrame*> astGetFrame(wcsinfo, 1);
AstFrame* pixFrame = static_cast<AstFrame*> astGetFrame(wcsinfo, AST__BASE);
AstFrame* pixFrameCopy = static_cast<AstFrame*> astCopy(pixFrame);
AstFrame* skyFrame = static_cast<AstFrame*> astGetFrame(wcsinfo, 2);
AstMapping* pixToSkyMapping = static_cast<AstMapping*> astGetMapping(wcsinfo, 1, 2);
AstFrame* skyFrame = static_cast<AstFrame*> astGetFrame(wcsinfo, AST__CURRENT);
AstMapping* pixToSkyMapping = static_cast<AstMapping*> astGetMapping(wcsinfo, AST__BASE, AST__CURRENT);
AstFrameSet* wcsInfoTransformed = astFrameSet(pixFrame, "");

// 2D shifts
Expand Down Expand Up @@ -219,11 +222,22 @@ EMSCRIPTEN_KEEPALIVE AstFrameSet* createShiftmapFrameset(AstFrameSet* wcsinfo, d
return wcsinfoShifted;
}

EMSCRIPTEN_KEEPALIVE AstFrameSet* createShiftmapPixelFrameset(AstFrameSet* wcsinfo, double offsetX, double offsetY)
{
AstFrameSet* wcsinfoShifted = static_cast<AstFrameSet*> astCopy(wcsinfo);

// 2D shifts
double offset[] = {-offsetX, -offsetY};
AstShiftMap* shiftMap = astShiftMap(2, offset, "");

astAddFrame(wcsinfoShifted, AST__BASE, shiftMap, astFrame(2, "Label(1)=X Coordinate,Label(2)=Y Coordinate,Domain=GRID"));

return wcsinfoShifted;
}

EMSCRIPTEN_KEEPALIVE AstFrameSet* initDummyFrame()
{
double offsets[] = {-1, -1};
AstFrameSet* frameSet = astFrameSet(astFrame(2, ""), "");
astAddFrame(frameSet, 1, astShiftMap(2, offsets, ""), astFrame(2, "Label(1)=X Coordinate,Label(2)=Y Coordinate,Domain=PIXEL"));
AstFrameSet* frameSet = astFrameSet(astFrame(2, "Label(1)=X Coordinate,Label(2)=Y Coordinate,Domain=GRID"), "");
return frameSet;
}

Expand Down
1 change: 1 addition & 0 deletions wasm_src/ast_wrapper/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export function setI(obj: AstObject, attrib: string, value: number): void;
export function setD(obj: AstObject, attrib: string, value: number): void;
export function createTransformedFrameset(frameSet: FrameSet, offsetX: number, offsetY: number, angle: number, originX: number, originY: number, scaleX: number, scaleY: number);
export function createShiftmapFrameset(frameSet: FrameSet, offsetX: number, offsetY: number);
export function createShiftmapPixelFrameset(frameSet: FrameSet, offsetX: number, offsetY: number);
// Not exported fillTransformGrid()
export function makeSwappedFrameSet(originFrameSet: FrameSet, dirAxis: number, spectralAxis: number, pixelZ: number, nsample: number): FrameSet;

Expand Down
1 change: 1 addition & 0 deletions wasm_src/ast_wrapper/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ Module.setI = Module.cwrap("setI", null, ["number", "string", "number"]);
Module.setD = Module.cwrap("setD", null, ["number", "string", "number"]);
Module.createTransformedFrameset = Module.cwrap("createTransformedFrameset", "number", ["number", "number", "number", "number", "number", "number", "number", "number"]);
Module.createShiftmapFrameset = Module.cwrap("createShiftmapFrameset", "number", ["number", "number"]);
Module.createShiftmapPixelFrameset = Module.cwrap("createShiftmapPixelFrameset", "number", ["number", "number"]);
Module.fillTransformGrid = Module.cwrap("fillTransformGrid", "number", ["number", "number", "number", "number", "number", "number", "number", "number"]);
Module.pointList = Module.cwrap("pointList", "number", ["number", "number", "number", "number", "number"]);
Module.axPointList = Module.cwrap("axPointList", "number", ["number", "number", "number", "number", "number", "number", "number"]);
Expand Down
Loading