Analyses
The Analyses object represents the Analyses tab in the Chemotion user interface. It contains all measurement data and metadata associated with the elements
API Classes
- class chemotion_api.elements.abstract_element.AnalysesList(conn: Connection)
List of
chemotion_api.elements.abstract_element.Analyses.Usage:
>>> from chemotion_api import Instance >>> import logging >>> try: >>> instance = Instance('http(d)://xxx.xxx.xxx').test_connection().login('<USER>', "<PASSWORD>") >>> except ConnectionError as e: >>> logging.error(f"A connection to Chemotion ({instance.host_url}) cannot be established") >>> s = instance.get_sample(1) >>> # Download of all analysis files of data set 'V2024_08_23' from 'Analyses MT 1' >>> analyses = s.analyses.by_name('Analyses MT 1') >>> dataset = analyses.dataset_by_name('V2024_08_23') >>> os.makedirs('./TO_DEL', exist_ok=True) >>> for atta in dataset.attachments: >>> atta.save_file('./dataset_files') >>> # Change value in the metadate set >>> dataset['General Information']['Label'] = 'V2024_08_23' >>> # Create a new >>> ana = s.analyses.add_analyses("Analyses MT 2") >>> ana.add_dataset('./V2024_08_24.json') >>> s.save()
- class chemotion_api.elements.abstract_element.Analyses(data: dict, session: Connection)
An analysis consists of a list of metadata schemas and associated data files. The schemas can be edited. And the files can be read and saved to your local device
- add_dataset(file_path: str) Dataset
Loads a datafile up and creates a new dataset. The Chemotion Instance will convert the date file and create a metadate set accordingly. However, this process only works if a Converter profile has been created
- Parameters:
file_path – the path on your local device to the datafile
- Returns:
A new Dataset object
- clean_up_after_save()
Do not use this methode! It is automatically used after the element is saved!
- dataset_by_name(name: str) Dataset
Find a dataset by its name.
- Parameters:
name – Name of the dataset
- Returns:
A Dataset object
- property is_new: bool
Returns true if the analyses has not been saved yet.
- Type:
return
- preview_image() bytes | None
Loads the image used as preview for the analyses.
Usage:
>>> from chemotion_api import Instance >>> import logging >>> try: >>> instance = Instance('http(d)://xxx.xxx.xxx').test_connection().login('<USER>', "<PASSWORD>") >>> except ConnectionError as e: >>> logging.error(f"A connection to Chemotion ({instance.host_url}) cannot be established") >>> s = instance.get_sample(1) >>> # Loads analysis 'Analyses MT 1' >>> analyses = s.analyses.by_name('Analyses MT 1') >>> with open('./img.svg', 'wb+') as f: >>> f.write(analyses.preview_image()) >>> s.save()
- Raises:
ConnectionError – If the request fails
- Returns:
byte representation of an image
- save_attachments()
Do not use this methode! It is automatically used before the element is saved!
- to_json()
A savable representation of the Analyses :return: Json representation
- class chemotion_api.elements.abstract_element.Dataset(session: Connection, json_data: dict, attachments: MutableAttachments | None = None)
A Dataset is an object that consists of a metadata set and a measurement file. If all components have been configured correctly in Chemotion, a BagIT container is created when a new file is uploaded. This container is then used to automatically fill in the metadata set and forward the measurement data to ChemSpectra.
Usage:
>>> from chemotion_api import Instance >>> import logging >>> try: >>> instance = Instance('http(d)://xxx.xxx.xxx').test_connection().login('<USER>', "<PASSWORD>") >>> except ConnectionError as e: >>> logging.error(f"A connection to Chemotion ({instance.host_url}) cannot be established") >>> s = instance.get_sample(1) >>> # Loads dataset V2024_08_23 from 'Analyses MT 1' >>> d1 = s.analyses.by_name('Analyses MT 1').dataset_by_name('V2024_08_23') >>> # Write BagIT zip and metadata set as xlsx file >>> d1.write_data_set_xlsx('./CWD') >>> d1.write_zip('./CWD')
- property attachments: MutableAttachments
- A list of all attached files. It contains the BagIt, the ChemSpectra results
as well as the measurement file
- Returns:
A mutable attachment File
- to_clean_json()
Cleans the data as perpetration to be saved
- write_data_set_xlsx(destination='')
Writes the metadata set as xlsx.
- Parameters:
destination – Director where the BagIT should be saved to.
- Returns:
Abs filepath of the BagIT zip.
- write_zip(destination='')
Writes the BagIT zip file.
- Parameters:
destination – Director where the BagIT should be saved to
- Returns:
Abs filepath of the BagIT zip