[style] some docstrings and style fixes
@@ -43,12 +43,6 @@ def load_rdms(fpath: str, sort: bool=True) -> RDMs:
else:
raise ValueError('Unsupported file type')
- desc_info_keys = (
- 'participant',
- 'task_index',
- 'task_name',
- 'experiment_name'
- )
conds = [f.split('.')[0] for f in stimuli]
rdm_descriptors = dict()
@@ -70,7 +64,19 @@ def load_rdms(fpath: str, sort: bool=True) -> RDMs:
return rdms
-def load_rdms_comps_mat(fpath, info: InfoDict) -> Tuple[NDArray, List[str], List[str], List[str], List[int]]:
+def load_rdms_comps_mat(fpath: str, info: InfoDict) -> Tuple[NDArray, List[str], List[str], List[str], List[int]]:
+ """Load rdms components from a Meadows mat file
+
+ Args:
+ fpath (str): full file path
+ info (InfoDict): dictionary describing the file name
+
+ Raises:
+ ValueError: File missing variable: X
+
+ Returns:
+ Tuple[NDArray, List[str], List[str], List[str], List[int]]: tuple of rdms components
+ """
data = loadmat(fpath)
tidx = None
tnames = None
@@ -92,7 +98,21 @@ def load_rdms_comps_mat(fpath, info: InfoDict) -> Tuple[NDArray, List[str], List
return utvs, stimuli, pnames, tnames, tidx
-def load_rdms_comps_json(fpath, info: InfoDict) -> Tuple[NDArray, List[str], List[str], List[str], List[int]]:
+def load_rdms_comps_json(fpath: str, info: InfoDict) -> Tuple[NDArray, List[str], List[str], List[str], List[int]]:
+ """Load rdms components from a Meadows json file
+
+ Args:
+ fpath (str): full file path
+ info (InfoDict): dictionary describing the file name
+
+ Raises:
+ ValueError: Multi-participant json files not supported yet
+ ValueError: Single-task json files not supported yet
+ ValueError: Unexpected structure in json file
+
+ Returns:
+ Tuple[NDArray, List[str], List[str], List[str], List[int]]: tuple of rdms components
+ """
STIM_MISMATCH = 'Varying stimuli among ma tasks, only selecting matching'
if info['participant_scope'] == 'multiple':
@@ -100,7 +120,7 @@ def load_rdms_comps_json(fpath, info: InfoDict) -> Tuple[NDArray, List[str], Lis
if info['task_scope'] == 'single':
raise ValueError('Single-task json files not supported yet')
- with open(fpath) as fhandle:
+ with open(fpath, encoding='utf-8') as fhandle:
data = json.load(fhandle)
if not isinstance(data.get('tasks'), list):
@@ -184,6 +204,14 @@ def extract_filename_segments(fpath: str) -> InfoDict:
def is_petname(segment: str) -> bool:
+ """Check whether the given string matches a name as generated by Petname
+
+ Args:
+ segment (str): potential name
+
+ Returns:
+ bool: True if the string is a petname
+ """
if '-' in segment:
parts = segment.split('-')
if len(parts) == 2:
