flexiznam.camp package

Module contents

flexiznam.camp.sync_data module

File to handle acquisition yaml file and create datasets on flexilims

flexiznam.camp.sync_data.clean_yaml(path_to_yaml)[source]

Read a yaml file and check that it is correctly formatted

This does not do any processing, just make sure that I can read the whole yaml and generate dictionary will all expected fields

Parameters

path_to_yaml (str) – path to the YAML file

Returns

nested dictonary containing entries in the YAML file

Return type

dict

flexiznam.camp.sync_data.create_dataset(dataset_infos, parent, raw_data_folder, verbose=True, error_handling='crash')[source]

Create dictionary of datasets

Parameters
  • dataset_infos – extra information for reading dataset outside of raw_data_folder or adding optional arguments

  • parent (dict) – yaml dictionary of the parent level

  • raw_data_folder (str) – folder where to look for data

  • verbose (bool) – (True) Print info about dataset found

  • error_handling (str) – error if crash otherwise replace the dataset instance by the error message in the output dictionary

Returns

dictionary of dataset instances

Return type

dict

flexiznam.camp.sync_data.create_sample_datasets(parent, raw_data_folder)[source]

Recursively index samples creating a nested dictionary and generate corresponding datasets

Parameters

parent (dict) – Dictonary corresponding to the parent entity

Returns

dictonary of child samples

Return type

dict

flexiznam.camp.sync_data.find_xxerrorxx(yml_file=None, yml_data=None, pattern='XXERRORXX', _output=None)[source]

Utility to find where things went wrong

Look through a yml_file or the corresponding yml_Data dictionary recursively. Returns a dictionary with all entries containing the error pattern

_output is used for recursive calling.

flexiznam.camp.sync_data.parse_yaml(path_to_yaml, raw_data_folder=None, verbose=True)[source]

Read an acquisition yaml and create corresponding datasets

Parameters
  • path_to_yaml (str) – path to the file to parse

  • raw_data_folder (str) – root folder containing the mice folders

  • verbose (bool) – print info while looking for datasets

Returns

A yaml dictionary with dataset classes

Return type

dict

flexiznam.camp.sync_data.read_dataset(name, data)[source]

Read YAML information corresponding to a dataset

Parameters
  • name (str) – the name of the dataset, will be composed with parent names to

  • an identifier (generate) –

  • data (dict) – data for this dataset only

Returns

a formatted dictionary including, ‘dataset_type’, ‘path’, ‘notes’, ‘attributes’ and ‘name’

Return type

dict

flexiznam.camp.sync_data.read_level(yml_level, mandatory_args=('project', 'mouse', 'session'), optional_args=('path', 'notes', 'attributes'), nested_levels=('recordings', 'datasets', 'samples'))[source]

Read one layer of the yml file (i.e. a dictionary)

Parameters
  • yml_level (dict) – a dictionary containing the yml level to analyse (and all sublevels)

  • mandatory_args – arguments that must be in this level

  • optional_args – arguments that are expected but not mandatory, will be None if absent

  • nested_levels – name of any nested level that should not be parsed

Returns

a tuple containing two dictionaries:

level (dict): dictonary of top level attributes nested_levels (dict): dictionary of nested dictonaries

Return type

(tuple)

flexiznam.camp.sync_data.read_recording(name, data)[source]

Read YAML information corresponding to a recording

Parameters
  • name (str) – the name of the recording

  • data (dict) – data for this dataset only

Returns

the recording read from the yaml

Return type

dict

flexiznam.camp.sync_data.read_sample(name, data)[source]

Read YAML information corresponding to a sample

Parameters
  • name (str) – the name of the sample

  • data (dict) – data for this sample only

Returns

the sample read from the yaml

Return type

dict

flexiznam.camp.sync_data.trim_paths(session_data, raw_data_folder)[source]

Parses paths to make them relative to raw_data_folder

Parameters
  • session_data (dict) – dictionary containing children of the session

  • raw_data_folder (str) – part of the path to be omitted from on flexilims

Returns

session_data after trimming the paths

Return type

dict

flexiznam.camp.sync_data.upload_yaml(source_yaml, raw_data_folder=None, verbose=False, log_func=<built-in function print>, flexilims_session=None, conflicts='abort')[source]

Upload data from one yaml to flexilims

Parameters
  • source_yaml (str) – path to clean yaml

  • raw_data_folder (str) – path to the folder containing the data. Default to data_root[‘raw’]

  • verbose (bool) – print progress information

  • log_func – function to deal with warnings and messages

  • flexilims_session (Flexilims) – session to avoid recreating a token

  • conflicts (str) – abort to crash if there is a conflict, skip to ignore and proceed

Returns

dictionary or flexilims ID

flexiznam.camp.sync_data.write_session_data_as_yaml(session_data, target_file=None, overwrite=False)[source]

Write a session_data dictionary into a yaml

Parameters
  • session_data (dict) – dictionary with Dataset instances, as returned by parse_yaml

  • target_file (str) – path to the output file (if None, does not write to disk)

  • overwrite (bool) – replace target file if it already exists (default False)

Returns

the pure yaml dictionary

Return type

dict