Skip to content

Commit

Permalink
Merge pull request #684 from int-brain-lab/removeOldFunctions
Browse files Browse the repository at this point in the history
remove prepare_experiment
  • Loading branch information
k1o0 authored Dec 13, 2023
2 parents 9e38c64 + f617813 commit bb1a851
Showing 1 changed file with 0 additions and 57 deletions.
57 changes: 0 additions & 57 deletions ibllib/io/session_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,60 +473,3 @@ def get_remote_stub_name(session_path, device_id=None):
exp_ref = '{date}_{sequence:d}_{subject:s}'.format(**ConversionMixin.path2ref(session_path))
remote_filename = f'{exp_ref}@{device_id}.yaml'
return session_path / '_devices' / remote_filename


def prepare_experiment(session_path, acquisition_description=None, local=None, remote=None, device_id=None, overwrite=False):
"""
Copy acquisition description yaml to the server and local transfers folder.
Parameters
----------
session_path : str, pathlib.Path, pathlib.PurePath
The RELATIVE session path, e.g. subject/2020-01-01/001.
acquisition_description : dict
The data to write to the experiment.description.yaml file.
local : str, pathlib.Path
The path to the local session folders.
>>> C:\iblrigv8_data\cortexlab\Subjects # noqa
remote : str, pathlib.Path
The path to the remote server session folders.
>>> Y:\Subjects # noqa
device_id : str, optional
A device name, if None the TRANSFER_LABEL parameter is used (defaults to this device's
hostname with a unique numeric ID)
overwrite : bool
If true, overwrite any existing file with the new one, otherwise, update the existing file.
"""
if not acquisition_description:
return

# Determine if user passed in arg for local/remote subject folder locations or pull in from
# local param file or prompt user if missing data.
if local is None or remote is None or device_id is None:
params = misc.create_basic_transfer_params(local_data_path=local, remote_data_path=remote, TRANSFER_LABEL=device_id)
local, device_id = (params['DATA_FOLDER_PATH'], params['TRANSFER_LABEL'])
# if the user provides False as an argument, it means the intent is to not copy anything, this
# won't be preserved by create_basic_transfer_params by default
remote = False if remote is False else params['REMOTE_DATA_FOLDER_PATH']

# This is in the docstring but still, if the session Path is absolute, we need to make it relative
if Path(session_path).is_absolute():
session_path = Path(*session_path.parts[-3:])

# First attempt to copy to server
if remote is not False:
remote_session_path = Path(remote).joinpath(session_path)
remote_device_path = get_remote_stub_name(remote_session_path, device_id=device_id)
previous_description = read_params(remote_device_path) if remote_device_path.exists() and not overwrite else {}
try:
write_yaml(remote_device_path, merge_params(previous_description, acquisition_description))
_logger.info(f'Written data to remote device at: {remote_device_path}.')
except Exception as ex:
_logger.warning(f'Failed to write data to remote device at: {remote_device_path}. \n {ex}')

# then create on the local machine
filename = f'_ibl_experiment.description_{device_id}.yaml'
local_device_path = Path(local).joinpath(session_path, filename)
previous_description = read_params(local_device_path) if local_device_path.exists() and not overwrite else {}
write_yaml(local_device_path, merge_params(previous_description, acquisition_description))
_logger.info(f'Written data to local session at : {local_device_path}.')

0 comments on commit bb1a851

Please sign in to comment.