Bence Bence, thank you very much for your prompt answers and help ,Maybe due to the language, my statement may not be very clear
,I have currently export the data to an excel file. Although each value in the file is in a different column, the format I want is to output all the values one by one, and then output the error below values, and then output the LODs one by one with a few blank lines below the LODs is similar to the one published in the article, I don’t know if you can understand it, or I’ll cut a picture for you
Trace element output format problem
chenhongjun
If you could post a picture, that would help me
Bence https://imgur.com/a/pEugUbh Hello Bence, this link is a screenshot , is it possible to output a similar format?
Hi chenhongjun
Yes, it is definitely possible, but it would require a custom export script. This is a good example for the iolite python course, if you wanted to write your own?
Or we could write it for you, but it would take a little while as we're running the python course from next week. Whichever works best for you...
Bence
Dear Bence,Maybe I don’t know how to write this script, thank you for your patience to answer it, and please help me see it when you’re done. :
Bence Hi,Bence,I don't know if you are free and can help me to write a script at present :
Hi @chenhongjun ,
Yes, I can help you write the script. I'll make a start on it and contact you via email. I'll post the result here too, when it's done.
-Bence
Bence Thank you very much, you are very enthusiastic and help me answer a lot of questions
- Edited
Sorry for the delay in getting this to you, but here is a script that you can run to export data in the format you wanted (mean; 1sd; LOD).
You can copy and paste the following into iolite's Python Workspace and click Save As... to save it as a script. You can also call it from the Export View -> Export Script.
Please test it and let me know if you find any problems
-Bence
import pandas as pd
from iolite.QtGui import QFileDialog
from iolite.QtCore import QDir
import sys
def getValuesDF(mode):
"""
Returns a pandas data frame for all selections in all groups (except
Baselines).
The value for each selection to be returned is based on mode:
Mean: mean of selection
OneSD: uncertainty as 1 SD
LOD: LOD (currently just Longerich value)
Returns pandas dataframe with columns as channels, and each row as a
selection
NOTE: The headers are un-named in the returned dataframe. This makes it
easier to concat/append dataframes
"""
df = pd.DataFrame()
selNames = []
for group in data.selectionGroupList():
if group.type == data.Baseline:
continue
for sel in group.selections():
if mode == 'Mean':
res = [data.result(sel, ch).value() for ch in data.timeSeriesList(data.Output)]
elif mode == 'OneSD':
res = [data.result(sel, ch).uncertainty("Basic", "AbsOneStdDev") for ch in data.timeSeriesList(data.Output)]
elif mode == 'LOD':
res = [data.result(sel, ch).longerichLOD() for ch in data.timeSeriesList(data.Output)]
else:
print("ERROR: mode argument must be one of \"Mean\", \"OneSD\", or \"LOD\"")
return
df[sel.name] = res
selNames.append(sel.name)
# Now transpose it so that each selection is a row instead of a column
df = df.transpose()
# And add the sel name as column
df.insert(0, 'Name', selNames)
return df
df_vals = getValuesDF('Mean')
df_vals = df_vals.append(pd.Series(), ignore_index=True)
df_unc = getValuesDF('OneSD')
df_unc = df_unc.append(pd.Series(), ignore_index=True)
df_lod = getValuesDF('LOD')
df_final = pd.concat([df_vals, df_unc, df_lod])
# Add the column headings:
headers = [channel.name for channel in data.timeSeriesList(data.Output)]
headers.insert(0, 'Selection Name')
df_final.set_axis(headers, axis=1, inplace=True)
fname = QFileDialog.getSaveFileName(None, "Save Export Data", QDir.homePath(), "CSV Files (*.csv")
if fname:
df_final.to_csv(fname, index=False)
print(f"Saved to {fname}")
Bence Thank you very much for taking the time to help me write this script, I tried to export the data according to the method you said, but the software prompts an error, I don't know the reason https://imgur.com/sCOAe94
I may have been wrong about using it in the Export View -> Export Script.
Can you please try it in the Python Workspace?
Bence Hi Bence,i have tried it in the Python Workspace But it seems that there are some problems, and the file is not exported. https://imgur.com/we1HWXH Sorry, I am not familiar with Python and don't know what causes this situation.
That's interesting. There must be something about your dataset that I hadn't thought of. Would you mind sending me a copy of the dataset that is causing this issue, and I'll fix it for you?
Many thanks in advance,
Bence
Bence Thank you very much, Bence, I found that I have this problem with different batches of data. I selected two sets of data and sent them to the iolite support mailbox, please check
Bence Hi Bence , do you receive my email?
Yes, sorry. I hope to post an update tomorrow.
Hi chenhongjun ,
Sorry for the delay in updating this. I have found the problem. Here is an updated version. Please let me know if you have any troubles with it:
import pandas as pd
from iolite.QtGui import QFileDialog
from iolite.QtCore import QDir
import sys
def getValuesDF(mode):
"""
Returns a pandas data frame for all selections in all groups (except
Baselines).
The value for each selection to be returned is based on mode:
Mean: mean of selection
OneSD: uncertainty as 1 SD
LOD: LOD (currently just Longerich value)
Returns pandas dataframe with columns as channels, and each row as a
selection
NOTE: The headers are un-named in the returned dataframe. This makes it
easier to concat/append dataframes
"""
df = pd.DataFrame()
selNames = []
for group in data.selectionGroupList():
if group.type == data.Baseline:
continue
counter = 1
for sel in group.selections():
if mode == 'Mean':
res = [data.result(sel, ch).value() for ch in data.timeSeriesList(data.Output)]
elif mode == 'OneSD':
res = [data.result(sel, ch).uncertainty("Basic", "AbsOneStdDev") for ch in data.timeSeriesList(data.Output)]
elif mode == 'LOD':
res = [data.result(sel, ch).longerichLOD() for ch in data.timeSeriesList(data.Output)]
else:
print("ERROR: mode argument must be one of \"Mean\", \"OneSD\", or \"LOD\"")
return
if sel.name in df.columns:
this_sel_name = sel.name + '_' + str(counter)
counter += 1
else:
this_sel_name = sel.name
df[this_sel_name] = res
selNames.append(this_sel_name)
# Now transpose it so that each selection is a row instead of a column
df = df.transpose()
# And add the sel name as column
df.insert(0, 'Name', selNames)
return df
df_vals = getValuesDF('Mean')
df_vals = df_vals.append(pd.Series(), ignore_index=True)
df_unc = getValuesDF('OneSD')
df_unc = df_unc.append(pd.Series(), ignore_index=True)
df_lod = getValuesDF('LOD')
df_final = pd.concat([df_vals, df_unc, df_lod])
# Add the column headings:
headers = [channel.name for channel in data.timeSeriesList(data.Output)]
headers.insert(0, 'Selection Name')
df_final.set_axis(headers, axis=1, inplace=True)
fname = QFileDialog.getSaveFileName(None, "Save Export Data", QDir.homePath(), "CSV Files (*.csv")
if fname:
df_final.to_csv(fname, index=False)
print(f"Saved to {fname}")
-Bence