aghplctools package

aghplctools.batch module

aghplctools.batch.batch_convert_signals_to_csv(folder_path: str, *additional_signals, verbose: Union[bool, int] = True)

Iterates through all .D files in the target directory and writes the signals of those files to csv. Additional signals may be specified to “reprocess” the data.

Parameters:
  • folder_path – folder path to iterate through
  • additional_signals – additional signals to process. Supported inputs are agilent specification strings (e.g. ‘DAD1 A, Sig=210,4 Ref=360,100’), DADSignalInfo objects, or dictionaries of keyword arguments for instantiation of DADSignalInfo objects
  • verbose – logging flag or level for function (prints progress info to console)
aghplctools.batch.batch_report_text_to_xlsx(folder: str, watchfor: str = 'Report.TXT')

Batch converts all report text files in a directory to xlsx

Parameters:
  • folder – directory to search
  • watchfor – file name to watch for
aghplctools.batch.pull_hplc_data_from_folder(folder, targets, wiggle=0.01, watchfor='Report.TXT')

Pulls the HPLC integrations for all report files within the specified directory. This function was designed to pull all data from a given day. This method only pulls data which exists in the reports, which can result in asymmetric data for timepoint analysis (i.e. it assumes that subsequent runs are unrelated to others). If the data in a folder are for time-course analysis, use pull_hplc_data_from_folder_timepoint().

Parameters:
  • folder – The folder to search for report files
  • targets – target dictionary of the form {‘name’: [wavelength, retention time], …}
  • wiggle – the wiggle time around retention times
  • watchfor – the name of the report file to watch
Returns:

dictionary of HPLCTarget instances in the format {‘name’: HPLCTarget, …}

Return type:

dict

aghplctools.batch.pull_hplc_data_from_folder_timepoint(folder, wiggle=0.02, watchfor='Report.TXT')

Pulls all HPLC data from a folder assuming that the contents of a folder are from an ordered, time-course run (i.e. the contents of one report are related to the others in the folder). The method will automatically watch for new retention times and will prepopulate appearing values with zeros. The resulting targets will have a consistent number of values across the folder.

Parameters:
  • folder – The folder to search for report files
  • wiggle – the wiggle time around retention times
  • watchfor – the name of the report file to watch
Returns:

dictionary of HPLCTarget instances in the format {wavelength: {retention_time: HPLCTarget, …}, …}

Return type:

dict

aghplctools.config module

Common configuration variables which are consistent across the system

aghplctools.data_types module

class aghplctools.data_types.DADSignal(wavelength: Union[float, unithandler.base.UnitFloat], bandwidth: Union[float, unithandler.base.UnitFloat] = 1.0, reference: Union[DADSignal, aghplctools.data_types.DADSignalInfo, str] = None, name: str = None, spectrum: aghplctools.data_types.DADSpectrum = None)

Bases: aghplctools.data_types.DADSignalInfo

Class describing a DAD signal and its data.

Parameters:
  • wavelength – wavelength for the signal
  • bandwidth – band width for the wavelength (signal is centered on the wavelength with this width)
  • reference – reference information for the signal
  • name – convenience name for the signal
  • spectrum – a DADSpectrum object which will be referenced for retrieving data.
as_data_table() → list

Returns the signal as a list-style data table with appropriate headers and data

Returns:data table
as_iterable_data_table()

Returns an iterable which yields a data table with appropriate headers and data

Returns:data table as iterable
band_string

A string representation of the band specified (e.g. “210 (4) nm”)

bandwidth

band width for the signal band

classmethod create_from_DADSignalInfo(obj: aghplctools.data_types.DADSignalInfo, spectrum: aghplctools.data_types.DADSpectrum) → aghplctools.data_types.DADSignal

generates a DADSignal object from a DADSignalInfo object and a spectrum

mean_referenced_intensities

mean referenced band (mean unreferenced intensities minus the mean intensities of the reference)

mean_unreferenced_intensities

mean unreferenced intensities for the band

reference

reference band for the signal band

retention_times

retention times associated with the intensity array

unreferenced_intensities

unreferenced intensities for the band

wavelength

wavelength for the signal

write_signal_to_csv(filename: str) → str

Writes the signal intensities to the specified csv file.

Parameters:filename – file name to write to
Returns:file path that was written
class aghplctools.data_types.DADSignalInfo(wavelength: Union[float, unithandler.base.UnitFloat], bandwidth: Union[float, unithandler.base.UnitFloat] = 1.0, reference: Union[DADSignalInfo, str] = None, name: str = None)

Bases: object

Class describing a DAD signal and its parameters

Parameters:
  • wavelength – wavelength for the signal
  • bandwidth – band width for the wavelength (signal is centered on the wavelength with this width)
  • reference – reference information for the signal
  • name – convenience name for the signal
DEFAULT_TIME_UNIT = 'min'
DEFAULT_WAVELENGTH_UNIT = 'nm'
agilent_specification_string

the specification string describing this instance (can be passed to create_from_string to reinstantiate)

bandwidth

bandwidth for the signal band

classmethod create_from_agilent_string(string: str, name_override: str = None) → aghplctools.data_types.DADSignalInfo

Creates a class instance from a standard Agilent signal description string (e.g. ‘DAD1 A, Sig=210,4 Ref=360,100’)

Parameters:
  • string – signal description string
  • name_override – override for name specification
Returns:

DADSignal object

classmethod get_values_from_agilent_string(string: str) → dict

Parses a standard Agilent signal description string (e.g. ‘DAD1 A, Sig=210,4 Ref=360,100’) and returns a dictionary of parsed values (can be used to instantiate a DADSignalInfo instance).

Parameters:string – signal description string
Returns:dictionary of parameters
reference

Reference band for the signal band

wavelength

Wavelength for the signal

class aghplctools.data_types.DADSpectrum(filename=None, ftype=None, data=None)

Bases: aston.tracefile.agilent_uv.AgilentCSDAD2

An object describing an Agilent DAD spectrum for a sample. Inherits Aston AgilentCSDAD2 and has additional methods for retrieving band information.

Parameters:
  • filename – target filetype
  • ftype
  • data
classmethod create_from_D_file(file_path: Union[pathlib.Path, str]) → aghplctools.data_types.DADSpectrum

Creates a DADSpectrum instance from an Agilent .D file

Parameters:file_path – path to .D sample file
Returns:interpreted .D file with metadata and loaded UV data
get_band_intensities(wavelength: float, bandwidth: float = 1.0) → numpy.ndarray

Retrieve array of values described by the wavelength and band width described. The returned array will have shape [wavelength, retention time]. The corresponding wavelengths are given by DADSpectrum.get_band_wavelengths and the retention times by DADSpectrum.retention_times.

Parameters:
  • wavelength – wavelength
  • bandwidth – band width
Returns:

array of band intensities

get_band_mean_intensity(wavelength: float, bandwidth: float = 1.0) → numpy.ndarray

Retrieve the intensity array described by the wavelength and bandwidth described. The returned array will be the mean of the intensities in the band (wavelength - bandwidth / 2, wavelength + bandwidth / 2).

Parameters:
  • wavelength – wavelength
  • bandwidth – band width
Returns:

array of mean intensities

get_band_wavelengths(wavelength: float, bandwidth: float = 1.0) → list

Returns a list of wavelengths corresponding to the band specified.

Parameters:
  • wavelength – wavelength
  • bandwidth – band width
Returns:

get_intensities_from_signal(signal: aghplctools.data_types.DADSignalInfo) → numpy.ndarray

Retrieve the intensity array described by the DADSignalInfo object.

Parameters:signal – signal descriptor
Returns:array of mean intensities
maximum_wavelength_array

Array of the wavelengths for the maximum intensity at each retention time

retention_times

retention times corresponding to the data array (min)

total_absorbance_chromatogram

The total absorbance chromatogram for the spectrum (sum of all intensities for each retention time)

wavelengths

list of wavelengths for the DAD

write_to_allotrope(filename: str)
class aghplctools.data_types.HPLCSample(sample_name: str, datetimestamp: Union[str, datetime.datetime], method_name: str, signals: Union[List[aghplctools.data_types.DADSignalInfo], List[aghplctools.data_types.DADSignal], List[str]], spectrum: aghplctools.data_types.DADSpectrum = None, directory: str = None)

Bases: aghplctools.data_types.HPLCSampleInfo

Data class for describing an HPLC sample containing metadata and spectral data.

Parameters:
  • sample_name – name for sample
  • datetimestamp – date and time stamp for when the sample was run
  • method_name – name of method used to run the sample
  • signals – list of signals associated with the run
  • spectrum – DADSpectrum object with loaded data
  • directory – directory path where the sample may be found
add_signal(new_signal: Union[aghplctools.data_types.DADSignalInfo, dict, str]) → aghplctools.data_types.DADSignal

Adds a new signal to the HPLCSample instance.

Parameters:new_signal – new signal to add. Supported inputs are Agilent specification strings (e.g. ‘DAD1 A, Sig=210,4 Ref=360,100’) DADSignalInfo objects or a dictionary of keyword arguments for instantiating the same.
Returns:the created signal
classmethod create_from_D_file(file_path: Union[pathlib.Path, str]) → aghplctools.data_types.HPLCSample

Creates an HPLCSample instance from a .D file.

Parameters:file_path – file path to Agilent .D folder
Returns:instantiated HPLCSample with loaded data
classmethod create_from_acaml(acaml: Union[str, xml.etree.ElementTree.ElementTree]) → aghplctools.data_types.HPLCSampleInfo

not supported for HPLCSample class

write_signals_to_csv(directory: Union[str, pathlib.Path] = None) → List[str]

Writes the signals to csv in the directory specified. If no directory is specified, the csv files will be written to the directory path specified in the directory attribute of the instance.

Parameters:directory – directory path
write_signals_to_xlsx(output_file: str = None) → str

Writes the signals to a single excel file.

Parameters:output_file – target file. If this is not specified
Returns:path to the written file
class aghplctools.data_types.HPLCSampleInfo(sample_name: str, datetimestamp: Union[str, datetime.datetime], method_name: str, signals: Union[List[aghplctools.data_types.DADSignalInfo], List[str]])

Bases: object

Data class for describing an HPLC sample.

Parameters:
  • sample_name – name for sample
  • datetimestamp – date and time stamp for when the sample was run
  • method_name – name of method used to run the sample
  • signals – list of signals associated with the run
as_dict() → dict

Returns the sample data as a dictionary

classmethod create_from_acaml(acaml: Union[str, xml.etree.ElementTree.ElementTree]) → aghplctools.data_types.HPLCSampleInfo

Creates sample structure from an acaml file. (use sequence.acam_ in the desired .D folder)

Parameters:acaml – path to acaml file or parsed element tree root
Returns:parsed Sample instance
date

date which the sample was run on

classmethod get_values_from_acaml(acaml: Union[str, pathlib.Path, xml.etree.ElementTree.ElementTree]) → dict

Gets relevant values from an acaml file. (use sequence.acam_ in the desired .D folder)

Parameters:acaml – path to acaml file or parsed element tree root
Returns:dictionary of values of interest
timestamp

Time of the day when the sample was run

aghplctools.data_types.strptime_agilent_dt(dt_string: str) → datetime.datetime

Performs strptime on Agilent datetime string

Parameters:dt_string – agilent datetime strings
Returns:parsed datetime object

aghplctools.hplc module

class aghplctools.hplc.HPLCTarget(wavelength: float, retention_time: float, name: str = None, wiggle: float = 0.2, zero_pad: int = 0)

Bases: object

A data storage class for tracking an HPLC retention target.

Parameters:
  • wavelength (float) – wavelength to track the target on
  • retention_time (float) – retention time to look for the target
  • name (str) – convenience name
  • wiggle (float) – wiggle value in minutes for finding the target around the retention_time (the window will be [retention_time-wiggle, retention_time+wiggle])
  • zero_pad – adds n zeros to the front of the value lists
add_from_pulled(signals, timepoint=None)

Retrieves values from the output of the pull_hplc_area function and stores them in the instance.

Parameters:
  • signals (dict) – output dictionary from pull_hplc_area
  • timepoint (float) – timepoint to save (if None, the current time will be retrieved)
Returns:

area, height, width, timepoint

Return type:

tuple

add_value(area, width=0.0, height=0.0, timepoint=None)

Adds a value to the tracker lists.

Parameters:
  • area (float) – area to add (required)
  • width (float) – width to add (optional)
  • height (float) – height to add (optional)
  • timepoint (float) – timepoint to use (if None, the current time will be called)
retrieve_index(index)

Retrieves the values of the provided index.

Parameters:index – pythonic list index
Returns:{area, width, height, timepoint}
Return type:dict
retrieve_timepoint(timepoint)

Retrieves the values of the provided timepoint.

Parameters:timepoint (float) – time point to retrieve
Returns:{area, width, height, timepoint}
Return type:dict
aghplctools.hplc.acquiring_filename()

Retrieves the path name of the next Agilent HPLC acquisition (from acquiring.txt)

Returns:file being currently acquired
Return type:str
aghplctools.hplc.find_max_area(signals)

Returns the wavelength and retention time corresponding to the maximum area in a set of HPLC peak data.

Parameters:signals (dict) – dict[wavelength][retention time (float)][width/area/height]
Returns:
aghplctools.hplc.plot(yvalues, xvalues=None, xlabel='injection #', ylabel=None, hline=None)

plots one set of values :param yvalues: list of y values :param xvalues: list of x values (optional) :param xlabel: label for x :param ylabel: label for y :param hline: plot a horizontal line at this value if specified :return:

aghplctools.hplc.stackedplot(rets, xlabel='injection #')

Creates a stacked plot for the dictionary generated by pull_hplc_data_from_folder :param rets: dictionary of retetion times :param xlabel: optional changing of x label

aghplctools.indirect module

tools for indirect run control of ChemStation

aghplctools.indirect.current_file() → str

Returns the current data file name being acquired (next up in the sequence)

Returns:data file name
aghplctools.indirect.current_file_path() → pathlib.Path

Returns the full path for the file name being acquired (next up in the sequence)

Returns:full path to the data file
aghplctools.indirect.current_num_and_file() → Tuple[int, str]

Returns the current number in the sequence and the name of the data file being acquired.

Returns:current file number, current file name
aghplctools.indirect.locate_acquiring_file(*search_path) → pathlib.Path

determines the path for ACQUIRING.TXT

Parameters:search_path – search paths. If not specified, uses CHEMSTATION_DATA_PATH
Returns:file path for ACQUIRING.TXT
aghplctools.indirect.sequence_is_running() → bool

returns whether a sequence is running