Skip to content

Commit

Permalink
Thchang/1546 exporting full resolution data in the spatial profiler (#…
Browse files Browse the repository at this point in the history
…1865)

* exporting original data when showing decimated data in the plotting of Spatial Profiler

* modified change log

* modified property name

* minor refactoring

* minor refactoring
  • Loading branch information
TienHao authored May 27, 2022
1 parent ad03bf5 commit 8d7e02c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Added missing vector overlay and image fitting options in the View menu ([#1848](https://github.com/CARTAvis/carta-frontend/issues/1848)).
* Hide code snippet option in the View menu when code snippet is disabled in the preferences ([#1856](https://github.com/CARTAvis/carta-frontend/issues/1856)).
* Fixed the rotation anchor offset of line regions ([#1739](https://github.com/CARTAvis/carta-frontend/issues/1739)).
* Fixed issue with exporting decimated data instead of full resolution data in spatial profiler ([#1546](https://github.com/CARTAvis/carta-frontend/issues/1546))

## [3.0.0-beta.3]

Expand Down
6 changes: 4 additions & 2 deletions src/components/Shared/LinePlot/LinePlotComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export interface LinePlotInsideTextMarker {
export class LinePlotComponentProps {
width?: number;
height?: number;
data?: {x: number; y: number; z?: number}[];
data?: Point2D[];
comments?: string[];
xMin?: number;
xMax?: number;
Expand Down Expand Up @@ -122,6 +122,7 @@ export class LinePlotComponentProps {
insideTexts?: LinePlotInsideTextMarker[];
order?: number;
multiPlotPropsMap?: Map<string, MultiPlotProps>;
fullResolutionData?: Point2D[];
}

// Maximum time between double clicks
Expand Down Expand Up @@ -660,7 +661,8 @@ export class LinePlotComponent extends React.Component<LinePlotComponentProps> {
// data part
rows.push("# x\ty");
const useScientificForm = plotName === "histogram" || this.props.tickTypeX === TickType.Scientific;
rows = rows.concat(this.props.data.map(o => (useScientificForm ? `${toExponential(o.x, 10)}\t${toExponential(o.y, 10)}` : `${o.x}\t${toExponential(o.y, 10)}`)));
const data = this.props.fullResolutionData?.length > 0 ? this.props.fullResolutionData : this.props.data;

This comment has been minimized.

Copy link
@crocka

crocka Dec 23, 2022

Contributor

this.props.fullResolutionData?.length is always larger than 0, because it is initialized with new Array(N).

This comment has been minimized.

Copy link
@crocka

crocka Dec 23, 2022

Contributor

Please take a look at #2072 to see if it is an acceptable solution.

rows = rows.concat(data.map(o => (useScientificForm ? `${toExponential(o.x, 10)}\t${toExponential(o.y, 10)}` : `${o.x}\t${toExponential(o.y, 10)}`)));

exportTsvFile(imageName, plotName, `${comment}\n${rows.join("\n")}\n`);
}
Expand Down
14 changes: 11 additions & 3 deletions src/components/SpatialProfiler/SpatialProfilerComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class SpatialProfilerComponent extends React.Component<WidgetProps> {
}
}

@computed get plotData(): {values: Array<Point2D>; smoothingValues: Array<Point2D>; xMin: number; xMax: number; yMin: number; yMax: number; yMean: number; yRms: number} {
@computed get plotData(): {values: Array<Point2D>; fullResolutionValues: Array<Point2D>; smoothingValues: Array<Point2D>; xMin: number; xMax: number; yMin: number; yMax: number; yMean: number; yRms: number} {
if (!this.frame || !this.width || !this.profileStore) {
return null;
}
Expand Down Expand Up @@ -115,13 +115,15 @@ export class SpatialProfilerComponent extends React.Component<WidgetProps> {
let ySum2 = 0;
let yCount = 0;

let values: Array<{x: number; y: number}>;
let values: Array<Point2D>;
let fullResolutionValues: Array<Point2D>;
let smoothingValues: Array<{x: number; y: number}>;
let N: number;

if (this.lineAxis) {
N = coordinateData.values.length;
values = new Array(N);
fullResolutionValues = new Array(N);
let xArray: number[] = new Array(N);
const numPixels = this.width;
const decimationFactor = Math.round(N / numPixels);
Expand All @@ -144,6 +146,8 @@ export class SpatialProfilerComponent extends React.Component<WidgetProps> {
xArray[i] = x;
if (decimationFactor <= 1) {
values[i] = {x, y};
} else {
fullResolutionValues[i] = {x, y};
}
}
if (decimationFactor > 1) {
Expand Down Expand Up @@ -192,15 +196,18 @@ export class SpatialProfilerComponent extends React.Component<WidgetProps> {
}
} else {
// Decimated data
fullResolutionValues = new Array(N);
for (let i = 0; i < N; i++) {
const val = coordinateData.values[i + xMin];
const x = coordinateData.start + i + xMin;
if (isFinite(val)) {
yMin = Math.min(yMin, val);
yMax = Math.max(yMax, val);
yCount++;
ySum += val;
ySum2 += val * val;
}
fullResolutionValues[i] = {x, y: val};
}
values = this.widgetStore.smoothingStore.getDecimatedPoint2DArray(xArray, coordinateData.values, decimationFactor, xMin, xMax);
}
Expand All @@ -223,7 +230,7 @@ export class SpatialProfilerComponent extends React.Component<WidgetProps> {
yMax += range * VERTICAL_RANGE_PADDING;
}

return {values: values, smoothingValues, xMin, xMax, yMin, yMax, yMean, yRms};
return {values: values, fullResolutionValues, smoothingValues, xMin, xMax, yMin, yMax, yMean, yRms};
}
}

Expand Down Expand Up @@ -488,6 +495,7 @@ export class SpatialProfilerComponent extends React.Component<WidgetProps> {
const currentPlotData = this.plotData;
if (currentPlotData) {
linePlotProps.data = currentPlotData.values;
linePlotProps.fullResolutionData = currentPlotData.fullResolutionValues;

// set line color
let primaryLineColor = getColorForTheme(widgetStore.primaryLineColor);
Expand Down

0 comments on commit 8d7e02c

Please sign in to comment.