4
$\begingroup$

I have a spectrometer which is generating time-series data every 100ms. I'd like to analyze/plot this data in Mathematica, but I'm not certain the best way to do it.

It's in this form:

   | 300 | 301 | ... | 700|
0  | y0  | y1  | ... | yn |
100| ... | ... | ... | ...|

I can import the data and extract it just fine

data = Import["testingdata.txt","TSV"];
wavelength = data[[30,3;;]];
unixtime = data[[31;;,2]];
absorbance = data[[31;;,3;;]];

Where the file headers take up rows 1;;29.

Naively using ListPlot to plot absorbance does provide a time series result, but I was wondering if there's a way to create a TimeSeries object to store this multidimensional data (TimeSeries Documentation). Looking at the Docs, it looks like I would have to create a TimeSeries object for each wavelength in my spectrum, which is not ideal. Is there a better way to do this? I see that the TemporalData function is a more generalized version of TimeSeries but it doesn't seem to have support for {t_i,v_i1,v_i2...} data.

Edit 1: Per @Domen's comment, TimeSeries does support arrays:

ts = TimeSeries[Transpose[{unixtime,absorbance}]]

Edit 2: I created a 3D plot showing essentially how I'd like to visualize the data, but I want to condense it down to 2D. enter image description here

$\endgroup$
2
  • 1
    $\begingroup$ How exactly do you want to analyze data? Your objective(s) will determine what is the best way to store and represent your data. As stated in the documentation, The values vi can be scalars or arrays of any dimension, but must all be of equal dimensionality. Therefore, you can store all the absorbance values in one TimeSeries object. ts = TimeSeries[Transpose[{unixtime, absorbance}]] $\endgroup$
    – Domen
    Oct 25, 2022 at 17:03
  • $\begingroup$ For the analysis, I'd like to look at the time evolution of the system. I think I can do that pretty easily without using the TimeSeries function by just iterating using Table, but I'd like to visualize the data in a ListPlot where the x axis is wavelength, and all of the absorbance traces are coplotted and colored according to their timestamp. $\endgroup$ Oct 25, 2022 at 18:59

1 Answer 1

7
$\begingroup$

TemporalData is exactly what you need. You just need to put your data in the proper format. Start from separating your time staps:

times = Range[0, 1000, 100];

Then put values as a List of Lists (matrix), for example some made up values:

values = Table[k + RandomReal[1, 11], {k, 5}]

enter image description here

Now your data are constructed as

data = TemporalData[values, {times}]

Alternatively, because your time stamps are regular you could just do:

data = TemporalData[values, {0, 1000, 100}]

Now plot (note, you can also use DateListPlot if your time stamps are in a proper time-unit format):

ListLinePlot[data, PlotTheme -> "Business"]

enter image description here

$\endgroup$
1
  • $\begingroup$ I'm not certain this is exactly what I want. When I apply this method to the data, it plots with time as the x axis instead of wavelength, which results in some very odd plots. I think I may be overcomplicating things by trying to make my data into a TimeSeries or TemporalData object. The plot that I added to the question shows essentially how I'd like the data to end up when plotted. $\endgroup$ Oct 27, 2022 at 17:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.