Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Plotting FIDs and spectra from a DataArray

plot_fid/plot_spectra now take a chemical_shift/time-dimensioned xr.DataArray directly — how do I see that without loading a real scan?

xmris.simulate_fid() builds exactly the kind of DataArray MRSSeries/RawMRISeries produce from real data — time-dimensioned, with reference_frequency/carrier_ppm in .attrs — so it’s the fixture of choice here: fully synthetic, seeded, no scanner file needed.

FunctionWhat it does here
plot_fid()plots the simulated FID against its time coord
plot_spectra()plots the phased spectrum against its chemical_shift coord

1. Simulate 5 repetitions of a FID

Two peaks — a big one at 4.68 ppm (water), a smaller one at 3.0 ppm — damped, phased, with a touch of noise so the plot doesn’t look artificially perfect. Simulating 5 noisy repetitions and stacking them along a new average dim gives one dataset that covers both the single-spectrum case below and the multi-line case later on this page — the same data throughout, not two different fixtures:

Loading...

simulate_fid always returns a time-dimensioned DataArray — the same shape RawMRISeries.fids produces from a real scan — so everything below works identically against either source.

2. Plot the FID — data= is the whole call

No header, no dwelltime/deadtime: the time coord already carries the axis, in seconds, and plot_fid converts it to ms for display.

<Figure size 900x600 with 1 Axes>

3. FFT, phase, plot — no phasing inside the plot call

plot_spectra only plots; phasing happens upstream through the xmr accessor, the same chain MRSSeries.phase_avg_spec uses on real data:

<Figure size 900x600 with 1 Axes>

4. Several FIDs and spectra at once, with custom labels

An extra dim beyond time/chemical_shift becomes one line per slice — no loop needed. The 5 repetitions simulated in step 1 are exactly that shape already; passing labels overrides the default "FID N"/"Spectrum N" naming:

<Figure size 900x600 with 1 Axes>
<Figure size 900x600 with 1 Axes>

5. Manual arrays still work

Both functions keep the old array-based call as a fallback — for data with no DataArray to begin with. data takes priority whenever both are given:

<Figure size 900x600 with 1 Axes>