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

feat: 2D phase correction #2671

Merged
merged 23 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
4e8811b
refactor: scale ratio function
hamed-musallam Sep 26, 2023
47013f2
refactor: integrals scale for integrals and ranges tools
hamed-musallam Sep 26, 2023
5a70a4b
chore: update nmr-load-save
hamed-musallam Oct 6, 2023
2e5b0fd
feat: phase correction traces for both directions
hamed-musallam Sep 15, 2023
8d8bcbc
feat: display spectrum vertically for the vertical phase correction
hamed-musallam Sep 19, 2023
a9c1a04
feat: delete the phase correction trace
hamed-musallam Sep 21, 2023
2f832b2
refactor: one phase correction pivot point
hamed-musallam Sep 21, 2023
e73aed5
feat: set two dimension pivot point
hamed-musallam Sep 21, 2023
ceb172d
refactor: phase traces
hamed-musallam Sep 25, 2023
49b022b
feat: scale 2D phase correction traces
hamed-musallam Sep 25, 2023
1b0a5ac
refactor: rename phase traces components directory
hamed-musallam Sep 25, 2023
a4f303b
refactor: slicing function to slice imaginary and/or real data
hamed-musallam Sep 25, 2023
efe9066
feat: phase correction 1d traces
hamed-musallam Sep 25, 2023
ffbea75
chore: added 2D spectrum with quadrants
jobo322 Sep 25, 2023
7ff8b3e
refactor: slicing function
hamed-musallam Sep 25, 2023
19fd7e4
fix: slicing 1d left trace clip width and its container's zindex
hamed-musallam Sep 25, 2023
d6bb029
refactor: set z-index to 9 for crosshair and brush and label pointers
hamed-musallam Sep 25, 2023
09b4cbd
refactor: phase correction tool name and id
hamed-musallam Oct 6, 2023
b0330cc
chore: fix eslint
hamed-musallam Sep 21, 2023
0e0c5bc
chore: update dependencies
hamed-musallam Oct 16, 2023
8eeb827
test: query the ranges integrals correctly
hamed-musallam Oct 16, 2023
0682a1a
chore: fix ml-matrix
targos Oct 20, 2023
6f86d00
chore: fix types
hamed-musallam Oct 20, 2023
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
1,581 changes: 781 additions & 800 deletions package-lock.json

Large diffs are not rendered by default.

51 changes: 26 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"react-dom": ">=18.0.0"
},
"dependencies": {
"@blueprintjs/core": "^5.3.3",
"@blueprintjs/core": "^5.5.1",
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@lukeed/uuid": "^2.0.1",
Expand All @@ -70,7 +70,7 @@
"file-saver": "^2.0.5",
"filelist-utils": "^1.10.2",
"formik": "^2.4.5",
"immer": "^10.0.2",
"immer": "^10.0.3",
"jszip": "^3.10.1",
"lodash": "^4.17.21",
"ml-airpls": "^1.0.2",
Expand All @@ -81,17 +81,17 @@
"ml-baseline-correction-regression": "^1.0.2",
"ml-conrec": "^5.0.2",
"ml-gsd": "^12.1.3",
"ml-matrix": "^6.10.5",
"ml-spectra-processing": "^12.5.1",
"ml-matrix": "^6.10.6",
"ml-spectra-processing": "^12.6.0",
"ml-stat": "^1.3.3",
"multiplet-analysis": "^2.1.2",
"nmr-correlation": "^2.3.3",
"nmr-load-save": "^0.21.0",
"nmr-processing": "^11.1.1",
"nmr-load-save": "^0.22.2",
"nmr-processing": "^11.3.0",
"nmredata": "^0.9.7",
"numeral": "^2.0.6",
"openchemlib": "^8.5.0",
"openchemlib-utils": "^5.3.0",
"openchemlib": "^8.7.1",
"openchemlib-utils": "^5.4.0",
"papaparse": "^5.4.1",
"re-resizable": "6.9.11",
"react-d3-utils": "^1.0.0",
Expand All @@ -110,41 +110,42 @@
"react-transition-group": "^4.4.5",
"react-use": "^17.4.0",
"smart-array-filter": "^4.0.2",
"yup": "^1.3.1"
"yup": "^1.3.2"
},
"devDependencies": {
"@babel/plugin-transform-modules-commonjs": "^7.23.0",
"@babel/preset-react": "^7.22.15",
"@babel/preset-typescript": "^7.23.0",
"@playwright/test": "^1.38.1",
"@babel/preset-typescript": "^7.23.2",
"@playwright/test": "^1.39.0",
"@simbathesailor/use-what-changed": "^2.0.0",
"@types/d3": "^7.4.1",
"@types/node": "^20.7.0",
"@types/papaparse": "^5.3.9",
"@types/react": "^18.2.23",
"@types/react-dom": "^18.2.8",
"@types/react-table": "^7.7.16",
"@types/d3": "^7.4.2",
"@types/lodash": "^4.14.200",
"@types/node": "^20.8.7",
"@types/papaparse": "^5.3.10",
"@types/react": "^18.2.29",
"@types/react-dom": "^18.2.14",
"@types/react-table": "^7.7.17",
"@vitejs/plugin-react-swc": "^3.4.0",
"@vitest/coverage-v8": "^0.34.5",
"@vitest/coverage-v8": "^0.34.6",
"cross-env": "^7.0.3",
"cspell": "^7.3.6",
"eslint": "^8.50.0",
"cspell": "^7.3.8",
"eslint": "^8.51.0",
"eslint-config-cheminfo-react": "^10.0.0",
"eslint-config-cheminfo-typescript": "^12.0.4",
"modern-normalize": "^2.0.0",
"postcss-styled-syntax": "^0.5.0",
"prettier": "^3.0.3",
"rc-menu": "^9.12.0",
"rc-menu": "^9.12.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.16.0",
"react-router-dom": "^6.17.0",
"rimraf": "^5.0.5",
"rollup-plugin-analyzer": "^4.0.0",
"serve": "^14.2.1",
"stylelint": "^15.10.3",
"stylelint": "^15.11.0",
"stylelint-config-standard": "^34.0.0",
"typescript": "^5.2.2",
"vite": "^4.4.9",
"vitest": "^0.34.5"
"vite": "^4.5.0",
"vitest": "^0.34.6"
}
}
41 changes: 41 additions & 0 deletions public/data/brukerFolders/alphaIonone.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"data": {
"spectra": [
{
"sourceSelector": {
"files": [
"data/brukerFolders/alphaIonone.zip/alphaIonone/3/acqu2s",
"data/brukerFolders/alphaIonone.zip/alphaIonone/3/acqus",
"data/brukerFolders/alphaIonone.zip/alphaIonone/3/pdata/1/procs",
"data/brukerFolders/alphaIonone.zip/alphaIonone/3/pdata/1/proc2s",
"data/brukerFolders/alphaIonone.zip/alphaIonone/3/pdata/1/2rr",
"data/brukerFolders/alphaIonone.zip/alphaIonone/3/pdata/1/2ri",
"data/brukerFolders/alphaIonone.zip/alphaIonone/3/pdata/1/2ir",
"data/brukerFolders/alphaIonone.zip/alphaIonone/3/pdata/1/2ii"
]
},
"filters": [],
"display": {
"isPositiveVisible": true,
"isNegativeVisible": true,
"isVisible": true,
"dimension": 2
},
"zones": {
"values": [],
"options": {}
}
}
],
"molecules": [],
"source": {
"baseURL": "",
"entries": [
{
"relativePath": "data/brukerFolders/alphaIonone.zip"
}
]
}
},
"version": 4
}
Binary file added public/data/brukerFolders/alphaIonone.zip
Binary file not shown.
1 change: 1 addition & 0 deletions src/component/1d-2d/tools/BrushX.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const styles: Record<'container', CSSProperties> = {
position: 'absolute',
top: '0px',
left: '0px',
zIndex: 9,
},
};

Expand Down
2 changes: 2 additions & 0 deletions src/component/1d-2d/tools/BrushXY.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const styles: Record<'container', CSSProperties> = {
top: '0px',
left: '0px',
zoom: '100%',
zIndex: 9,
},
};

Expand All @@ -21,6 +22,7 @@ const allowTools = new Set([
options.peakPicking.id,
options.integral.id,
options.phaseCorrection.id,
options.phaseCorrectionTwoDimensions.id,
options.baselineCorrection.id,
options.rangePicking.id,
options.zonePicking.id,
Expand Down
2 changes: 2 additions & 0 deletions src/component/1d-2d/tools/CrossLinePointer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const allowTools = new Set([
options.apodization.id,
options.equalizer.id,
options.baselineCorrection.id,
options.phaseCorrectionTwoDimensions.id,
options.zonePicking.id,
options.slicing.id,
options.integral.id,
Expand Down Expand Up @@ -68,6 +69,7 @@ function CrossLinePointer() {
overflow: 'visible',
width: 2 * width,
height: 2 * height,
zIndex: 9,
}}
>
<svg width={2 * width} height={2 * height}>
Expand Down
2 changes: 2 additions & 0 deletions src/component/1d/Chart1D.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { PeakEditionProvider } from './peaks/PeakEditionManager';
import Peaks from './peaks/Peaks';
import PeaksShapes from './peaks/PeaksShapes';
import Ranges from './ranges/Ranges';
import RangesIntegrals from './ranges/RangesIntegrals';
import BaseLineZones from './tool/BaseLineZones';

function Chart1D({ mode, width, height, margin, displayerKey }) {
Expand Down Expand Up @@ -45,6 +46,7 @@ function Chart1D({ mode, width, height, margin, displayerKey }) {
<ApodizationLine />
<IntegralsSeries />
<Peaks peaksSource="peaks" />
<RangesIntegrals />
<Ranges />
<Peaks peaksSource="ranges" />
<JGraph />
Expand Down
31 changes: 16 additions & 15 deletions src/component/1d/Viewer1D.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -289,30 +289,30 @@ function Viewer1D({ emptyText = undefined }: Viewer1DProps) {

const handleZoom = useCallback<OnZoom>(
(event) => {
dispatch({ type: 'SET_ZOOM', payload: { event, selectedTool } });
dispatch({ type: 'SET_ZOOM', payload: { event } });
},
[dispatch, selectedTool],
[dispatch],
);

const mouseClick = useCallback<OnClick>(
(position) => {
(event) => {
if (!scaleState.scaleX) return;

const xPPM = scaleState.scaleX().invert(position.x);
const xPPM = scaleState.scaleX().invert(event.x);

const propagateEvent = () => {
Events.emit('mouseClick', {
...position,
...event,
xPPM,
});
};

if (position.shiftKey) {
if (event.shiftKey) {
switch (selectedTool) {
case options.peakPicking.id:
dispatch({
type: 'ADD_PEAK',
payload: position,
payload: event,
});
break;
case options.editRange.id:
Expand All @@ -330,20 +330,21 @@ function Viewer1D({ emptyText = undefined }: Viewer1DProps) {
payload: { cutValue: xPPM },
});
break;
default:
break;
}
} else {
switch (selectedTool) {

case options.phaseCorrection.id:
dispatch({
type: 'SET_VERTICAL_INDICATOR_X_POSITION',
type: 'SET_ONE_DIMENSION_PIVOT_POINT',
payload: {
position: position.x,
value: event.x,
},
});
break;

break;
default:
break;
}
} else {
switch (selectedTool) {
default:
}
}
Expand Down
65 changes: 51 additions & 14 deletions src/component/1d/integral/IntegralsSeries.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,45 @@
import { xyIntegral, xyMaxY } from 'ml-spectra-processing';
import { Spectrum1D } from 'nmr-load-save';
import { Integral as IntegralType } from 'nmr-processing';

import { useChartData } from '../../context/ChartContext';

import Integral from './Integral';
import useSpectrum from '../../hooks/useSpectrum';

import { Integration } from './Integration';

const emptyData = { integrals: {}, info: {}, display: {} };

function IntegralsSeries() {
export interface IntegralData extends IntegralType {
x: Float64Array;
y: Float64Array;
}

export default function IntegralsSeries() {
const {
displayerKey,
view: {
spectra: { activeTab: nucleus },
},
} = useChartData();
const integrals = useIntegrals();

if (!integrals) return null;

return (
<g clipPath={`url(#${displayerKey}clip-chart-1d)`} className="integrals">
{integrals.values.map((integral) => (
<Integration
nucleus={nucleus}
key={integral.id}
integral={integral}
max={integrals.max}
/>
))}
</g>
);
}

function useIntegrals() {
const spectrum = useSpectrum(emptyData) as Spectrum1D;

if (
Expand All @@ -25,15 +50,27 @@ function IntegralsSeries() {
return null;
}

return (
<g clipPath={`url(#${displayerKey}clip-chart-1d)`}>
<g className="integrals">
{spectrum.integrals.values.map((integral) => (
<Integral nucleus={nucleus} key={integral.id} integral={integral} />
))}
</g>
</g>
);
}
let max = Number.NEGATIVE_INFINITY;
const values: IntegralData[] = [];

export default IntegralsSeries;
const {
data: { x, re },
integrals,
} = spectrum;
for (const integral of integrals?.values || []) {
const { from, to } = integral;
const integralData = xyIntegral(
{ x, y: re },
{
from,
to,
reverse: true,
},
);
values.push({ ...integral, ...integralData } as IntegralData);
const value = xyMaxY(integralData);
if (value > max) max = value;
}

return { max, values };
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { Integral as IntegralType } from 'nmr-processing';

import { useActiveSpectrumIntegralsViewState } from '../../hooks/useActiveSpectrumIntegralsViewState';
import useIntegralPath from '../../hooks/useIntegralPath';
import { usePanelPreferences } from '../../hooks/usePanelPreferences';

import IntegralResizable from './IntegralResizable';
import { IntegralData } from './IntegralsSeries';

interface IntegralProps {
integral: IntegralType;
integral: IntegralData;
nucleus: string;
max: number;
}

function Integral({ integral, nucleus }: IntegralProps) {
const path = useIntegralPath(integral);
export function Integration({ integral, nucleus, max }: IntegralProps) {
const { x, y } = integral;
const { scaleRatio } = useActiveSpectrumIntegralsViewState();
const path = useIntegralPath({ x, y, max, scaleRatio });
const integralPreferences = usePanelPreferences('integrals', nucleus);

return (
Expand All @@ -31,5 +34,3 @@ function Integral({ integral, nucleus }: IntegralProps) {
</g>
);
}

export default Integral;
Loading
Loading