imgMS package
Submodules
imgMS.MSData module
- class imgMS.MSData.ElementalMap(matrix=None, dx=None, dy=None)
Bases:
object- create_xy()
Create values of x and y axis from dx and dy.
- flip(axis=None)
Flip matrix of image.
- Parameters:
axis (str) – Axis along which to flip over. The default, axis=None,
axes (will flip over all of the) –
vertically (axis=0 flip matrix) –
:param : :param axis=1 flip matrixhorizontally.:
- quantify_map(slope, intercept=0)
Quantify elemental map.
- Parameters:
slope (float) – Slope of linear regression for quantification.
intercept (float) – Intercept of linear regression for quantification.
- read_matrix(path, el)
Import created map from excel, where each isotope is on one list.
- Parameters:
path (str) – Path to excel file.
el (str) – Name of isotope to import.
- rotate()
Rotate map by 90 degrees.
- write_matrix(path, el)
Save created map to excel, where each isotope is on one list.
- Parameters:
path (str) – Path to excel file.
el (str) – Name of isotope to export. Will be used as sheet name.
- class imgMS.MSData.Isotope(isotope_name, ms_data=None, logger=None)
Bases:
objectExtract specific Isotope data from MSData object.
- Parameters:
isotope_name (str) – Isotope to extract from MSData (i.e. Li7)
ms_data (MSData) – MS data to extract from.
- Returns:
data – data interpreted as an array.
- Return type:
array
- average_intensity(despiked=True, bcgcor_method='all', method='intensity')
Calculate average intensity for peaks in selected Isotope.
- Parameters:
bcgcor_method (str) – Method of background calculation. Possible options are [None, ‘all’, ‘beginning’, ‘end’]. Default is ‘all’.
despiked (bool) – State of data to be corrected. If True use despiked data, else use original. Default is True.
method (str) – Method to get average peaks. Possible options are [‘intensity’, ‘integral’]. Default is ‘intensity’.
- bcg_correction(method='all', despiked=True)
Calculate bacground correction for selected Isotope.
- Parameters:
method (str) – Method of background calculation. Possible options are [‘all’, ‘beginning’, ‘end’]. Default is ‘all’.
despiked (bool) – State of data to be corrected. If True use despiked data, else use original. Default is True.
- despike(win=3, treshold=10)
Removes high outliers of the data using rolling mean and standard deviation. Replace values that are greater than n standard deviations above the mean with the mean adjacent values.
- Parameters:
win (int) – Window for rolling mean.
tresholds (int) – Multiplier of std above which values will be replaced.
- detection_limit(method='intensity', scale='all', ablation_time=60)
Calculate limit of detection for isotope.
- Parameters:
method (str) – Possible methods [‘integral’,’intensity’]. LoD must be calculates same way as average of isotopes.
scale (str) – Possible methods [‘beginning’, ‘all’]. LoD must be calculates same way as average of isotopes.
ablation_time (int) – Time in seconds of one ablation. Necessary only for method ‘integral’.
- element()
Returns name of the element.
- elemental_distribution(despiked=False, bcgcor_method='all', dx=1, dy=1)
Creates ElementalMap from Isotope data.
- Parameters:
despiked (bool (Optional)) – State of data to be corrected. If True use despiked data, false use original. Default is False.
bcgcor_method (str (Optional)) – Method of background calculation. Possible options are [None, ‘all’, ‘beginning’, ‘end’]. Default is ‘all’.
dx (float) – X-axis distance between two values, usually in μm. Can be calculated by (scan speed [μm/s]/ integration time [s])
dy (float) – Y-axis distance between two values, usually in μm. Distance between two lines, usually equal to ablation spot size.)
- quantify(srm_name='NIST610', drift_correction=True)
Calculate quantification of average peaks in Isotope.
- Parameters:
srm_name (str) – Name of the standard reference material to be used for quantification. Must be in SRM file.
- class imgMS.MSData.MSData(datareader=None, logger=None)
Bases:
objectLA-ICP-MS data structure. Primary object for LA-ICP-MS data reduction with imgMS.
- Parameters:
datareader (MSEval.DataReader) – Object for reading and import of LA-ICP-MS data.
logger (logger class (optional)) – If logger is pssed all methods of MSData will log in the activity.
- IS_correction()
Calculates correction for each element given in internal standard correction from PARAM file.
- Returns:
corrected data – dict of internal standards used for correction as keys and DataFrames where index are peak names and columns are isotopes with values in ppm.
- Return type:
dict
- TS_correction(suma=1000000, skip_isotopes=[], return_oxides=False)
Calculates total sum correction [1] using coefficients given in PARAM file. If coefficients in PARAM file are not given, uses default values. Default values assume all elements are in most common oxide form.
[1] Liu, Y., Hu, Z., Gao, S., Günther, D., Xu, J., Gao, C. and Chen, H., 2008. In situ analysis of major and trace elements of anhydrous minerals by LA-ICP-MS without applying an internal standard. Chemical Geology, 257(1-2), pp.34-43.
- Parameters:
suma (float) – Total sum of measured elements in ppm used for correction. Normally is equal to 100% (default).
skip_isotopes (list) – List of isotopes to be skipped, in total sum correction one element can’t be measured on multiple isotopes.
return_oxides (bool) – If True return data in oxide form as was used for total sum correction. Default is False.
- Returns:
corrected data – DataFrame where index are peak names and columns are isotopes with values in ppm.
- Return type:
DataFrame
- average_isotopes(despiked=True, bcgcor_method='all', method='intensity')
Calculate average value for all peaks for all isotopes.
- Parameters:
bcgcor_method (str) – Method of background calculation. Possible options are [None, ‘all’, ‘beginning’, ‘end’]. Default is ‘all’.
despiked (bool) – If True use despiked data, else use original. Default is True.
method (str) – Method to get average peaks. Possible options are [‘intensity’, ‘integral’]. Default is ‘intensity’.
- Returns:
data – DF where index are peak names and columns are isotopes
- Return type:
DataFrame
- create_isotopes()
- create_maps(despiked=False, bcgcor_method='all', dx=1, dy=1)
Create elemental distribution matrix for all isotopes.
- Parameters:
despiked (bool) – If True use despiked data, else use original. Default is False.
bcgcor_method (str) – Method of background calculation. Possible options are [None, ‘all’, ‘beginning’, ‘end’]. Default is ‘all’.
dx (float) – X-axis distance between two values, usually in μm. Can be calculated by (scan speed [μm/s]/ integration time [s])
dy (float) – Y-axis distance between two values, usually in μm. Distance between two lines, usually equal to ablation spot size.)
- detection_limit(method='intensity', scale='all', ablation_time=60)
Calculate detection limit for all isotopes.
- Parameters:
method (str) – Possible methods [‘integral’,’intensity’]. LoD must be calculates same way as average of isotopes.
scale (str) – Possible methods [‘beginning’, ‘all’]. LoD must be calculates same way as average of isotopes.
ablation_time (int) – Time in seconds of one ablation. Necessary only for method ‘integral’.
- export(path)
Export all data to excel file.
- Parameters:
path (str) – Path to excel file where to save data.
- export_matrices(path, quantified=False)
Export all elemental distribution data to excel file. Each isotope will be a matrix on one sheet.
- Parameters:
path (str) – Path to excel file where to save data.
- formated_export(path, table='quantified')
Export all data to excel file in a formated style, containing means, sd, max and min for repeated samples.
- Parameters:
path (str) – Path to excel file where to save data.
- graph(ax=None, logax=False, el=None, *args, **kwargs)
Create matplotlib graph of intensity in time for ablation and highlights peaks and background signal if the peaks are already identifyied.
- Parameters:
ax (matplotlib axes (optional)) – Axes to plot in, if not specified, create new ax.
logax (bool (optional)) – If True use logarythmic x axes. Default False.
el (str (optional)) – Element to plot. If not specified plot all measured elements.
*args – All other plotting arguments to be passed to matplotlib.pyplot.plot.
**kwargs – All other plotting arguments to be passed to matplotlib.pyplot.plot.
- import_matrices(path)
Import all elemental distribution data from excel file. Each isotope will be a matrix on one sheet.
- Parameters:
path (str) – Path to the excel file.
- quantify_isotopes(srm_name='NIST610', drift_correction=True)
Calculate quantified value for all peaks for all isotopes.
- Parameters:
srm_name (str) – Standard reference material used for quantification. The name must be at least one of the peaks and listed in SRM file.
- Returns:
data – Quantified data in DF where index are peak names and columns are isotopes
- Return type:
DataFrame
- quantify_maps(slopes, intercepts)
Calculate quantification for elemental distribution matrix for all isotopes.
- Parameters:
intercepts (dict) – Dict of intercepts for each isotope.
slopes (dict) – Dict of slopes for each isotope.
- read_param(path)
Import excel file with additional parameters (names of peaks, internal standard values, total sum correction coefficients) for data reduction. A sample PARAM file can be found in data folder.
- Parameters:
path (str) – Path to excel param file.
- read_srms(path='./SRM.xlsx')
Import excel file with standard reference values. Default file is part of the imgMS package and contains values for NIST610, NIST612 and NIST 614.
- Parameters:
path (str) – Path to excel SRM file.
- report()
Clean all data in MSData. Replace values lower than limit of detection. If the value is above LoD, round to specific decimal place.
- select(method='treshold', selector=None, s=60, sdmul=10, iolite=None)
Selects starts and ends of peaks using imgMS.Selector.
- Parameters:
method (str (optional)) – Name of the method to be used for identifying peaks. Possible options are ‘treshold’ and ‘iolite’. Default is ‘treshold’.
selector (MSEval.Selector (optional)) – Class for identifying peaks. If Selector is passed none of the other parameters are necessary. If not, Selector is created by selected settings.
s (float (optional)) – Start of the first peak in seconds from the start of analysis. Default is 60. Necessary if Selector is not passed and used for synchronisation of data with iolite.
sdmul (float (optional)) – Coeficient by which a standard deviation of background is multiplied to calculate treshold. Only used if method = treshold.
iolite (MSEval.Iolite (optional)) – Iolite class holding data from .Iolite file. Necessary if method = Iolite and Selector not passed.
- set_names(names)
Sets list of names of peaks. The name of SRM must be equal to the name in SRM file.
- Parameters:
names (list) – List of names.
- time_to_number(time, integration_time=None)
Takes time in seconds returns number of measured values. The result depends on integration time of MS method.
- Parameters:
time (float) – Time in seconds to be converted into number of values in data.
integration_time (float (optional)) – Integration time of LA-ICP-MS measurement. If not specified will be calculated from data.
- class imgMS.MSData.Peak(isotope, bounds)
Bases:
objectSeparate one peak of isotope data.
- Parameters:
isotope (MSData.Isotope) – Isotope to use for peak extraction.
bounds (set) – Set of 2 values, start and end of peak.
imgMS.MSEval module
- class imgMS.MSEval.Background(isotope, laser_on, laser_off, width=0.8, offset=0.15)
Bases:
objectClass for calculating and visualising background.
- Parameters:
isotope (MSData.Isotope) – Isotope from which background is calculated
laser_on (list) – List of sets, where each set has 2 values (start of the laser and end of the laser.) indicating when the laser was fireing.
laser_off (list) – List of sets, where each set has 2 values (end of the laser and start of the laser.) indicating when the laser wasn’t fireing.
offset (float (Optional)) – Parameter for outlier removal. 1-offset = upper treshold for percentile filtering. Accepts values between 0 and 1. Default is 0.15.
width (float (Optional)) – Parameter for outlier removal. Width od returned values, where 1-offset-width = lower treshold for percentile filtering. Accepts values between 0 and 1. Default is 0.8.
- class imgMS.MSEval.DataReader(filename, filetype=None, instrument=None)
Bases:
objectReads data into pandas Dataframe from a file.
- Parameters:
filename (str) – Path to file to read.
filetype (str) – Type of the file to read. If not specified, csv is used. Possible options are csv, xlsx and asc.
instrument (str) – Type of the instrument used for measurement. If not specified, raw data is expected. Possible options are Agilent, and Element.
- read(filename, filetype, instrument)
Reads data into pandas Dataframe from a file.
- Parameters:
filename (str) – Path to file to read.
filetype (str) – Type of the file to read. If not specified, csv is used. Possible options are csv, xlsx and asc.
instrument (str) – Type of the instrument used for measurement. If not specified, raw data is expected. Possible options are Agilent, MC Nu-Sapphire, and Element.
- Returns:
data – data as a dataframe, which can be passed to MSData.
- Return type:
dataframe
- class imgMS.MSEval.Iolite(path)
Bases:
objectClass holding Iolite data.
- Parameters:
path (str) – Path to Iolite .csv file.
- names_from_iolite()
Return peak names from iolite.
- on_and_off_times()
- read_iolite(path)
Read Iolite file.
- Parameters:
path (str) – Path to Iolite .csv file.
- class imgMS.MSEval.Param(path, logger=None)
Bases:
objectClass holding meta data and parameters of analysis.
- Parameters:
path (str) – Path to param .xlsx file.
- read_is_coef()
Read sheet with internal standard coefficients from Param file.
- Returns:
internal_std – DataFrame with internal standard coefficients.
- Return type:
DataFrame
- read_names()
Read sheet with peak names from Param file.
- Returns:
names – List of peak names.
- Return type:
list
- read_ts_coef()
Read sheet with total sum correction coefficients from Param file.
- Returns:
internal_std – DataFrame with total sum correction coefficients .
- Return type:
dict
- class imgMS.MSEval.Selector(ms_data, s=60, sdmul=10, iolite=None, logger=None)
Bases:
objectClass for peak and background identification.
- Parameters:
ms_data (MSData) – Mass spectrometry data class, for which the selector will be used.
s (float (Optional)) – Start of first peak in seconds for synchronisation with Iolite data if using method Iolite or for calculation of backround standard deviation if using method treshold. Default is 60s.
sdmul (int (Optional)) – Multiplier for backround standard deviation in method treshold. Default is 10.
iolite (MSEval.Iolite (Optional)) – Iolite class, only necessary if method is Iolite. Default is None.
logger (logger class (optional)) – If logger is pssed all methods of Selector will log in the activity.
- create_on_off(starts, ends)
From starts and ends of ablation create laser_on and laser_off with skipped values.
- create_selector_iolite()
Select starts and ends of ablation using iolite file.
- create_selector_treshold()
Select starts and ends of ablation based on selected element or sum of all using treshold calculated from background.
- set_skip(bcg_s=None, bcg_e=None, sig_s=None, sig_e=None)
Set time skipped on start and end of background and ablation in seconds.
imgMS.MSStats module
- class imgMS.MSStats.interactive_average(elmap)
Bases:
objectCreates interactive graph for the selection of the area of interest and calculates basic stats as mean, std, median, min and max. The values can be printed or saved as an excel file.
- Parameters:
elmap (elmap class from imgMS) – Data of elemental image of one isotope stored as numpy array.
- export_stats(filename, sheetname='Sheet1')
- get_attr()
- onSelect(verts)
- stats(array, indices)
- updateArray(array, indices)
imgMS.side_functions module
- imgMS.side_functions.correction(data, elem, internal_std)
Calculates internal standard correction.
- Parameters:
data (DataFrame) – DataFrame with quantified values where columns are measured isotopes
el (str) – Element used as internal standard
internal_std (DataFrame) – DataFrame of values of internal standard where columns are elements for correction and each row represents one measurement e.g. Spot.
- imgMS.side_functions.elem_resolution(elem)
formatting of element name to remove resolution for ELEMENT2 instrument
- imgMS.side_functions.element_formater(elem, lst_of_elems)
matches the given element format to the one used in list
- imgMS.side_functions.element_strip(elem)
formatting of element name to match colnames of reference material
- imgMS.side_functions.formatted_export(frame, path)
- imgMS.side_functions.get_diff_lst(iolite)
return list of times in seconds from start to every start and end of laser ablation for spots
- imgMS.side_functions.get_diff_lst_line(iolite)
return list of times in seconds from start to every start and end of laser ablation for lines
- imgMS.side_functions.get_difference(start, now)
return time in seconds between 2 timestamps
- imgMS.side_functions.get_index(data, time)
return closest index of MS time given time in seconds
- imgMS.side_functions.get_logger(pathname)
Create log file similar to Ilaps-GUI log file
- Parameters:
pathname (str) –
created. (Path to a log file(.txt). If file doesn't exists it is) –
- imgMS.side_functions.get_timestamp(strTime)
format string time from iolite to timestamp
- imgMS.side_functions.multivariate_outliers(df, cols=['Na2O (%)', 'MgO (%)', 'Al2O3 (%)', 'SiO2 (%)', 'P2O5 (%)', 'K2O (%)', 'CaO (%)', 'MnO (%)', 'Fe2O3 (%)', 'CuO (%)'], threshold=3)
- imgMS.side_functions.plot_data(data, isotopes=None, ax=None, *args, **kwargs)
Create a plot of MS time dependant data.
- Parameters:
data (DataFrame) – Dataframe of ms data where column names are names of measured isotopes and index is time.
isotopes (list) – List of isotopes to plot. (Optional)
ax (matplotlib axes) – Matplotlib axes to show the plot. (Optional)
- imgMS.side_functions.remove_outliers(data, offset, width)
Function to filter data by percentile value.
- Parameters:
data (nparray) – array of data
offset (float) – 1-offset = upper treshold for percentile filtering. Accepts values between 0 and 1.
width (float) – Width od returned values, where 1-offset-width = lower treshold for percentile filtering. Accepts values between 0 and 1.
- Returns:
data_out – Filtered data.
- Return type:
nparray
- imgMS.side_functions.report(x, LoD, elem)
Replace values lower than limit of detection. If the value is above LoD, round to specific decimal place.
- imgMS.side_functions.z_score_method(df, variable_name, threshold=3)