Skip to content

Commit

Permalink
Change data-type to datatype (#196)
Browse files Browse the repository at this point in the history
* Change data-type to datatype on CLI argument.

* Change data-type to datatype in docs.

* Make other small changes in code documentation.

* Fix tests.

* Replace data_type with datatype everywhere.

* Fix the space case data type to datatype.

* Fix missed case in README.md
  • Loading branch information
JoeZiminski authored Oct 5, 2023
1 parent 25d91f0 commit fe05459
Show file tree
Hide file tree
Showing 17 changed files with 263 additions and 272 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Datashuttle includes tools for automated generation and transfer of neuroscience

* Manage files across multiple data-collection computers by synchronising all data to with a centrally stored project.

* Simplify data transfers by selecting only a sub-set of data to move (e.g. specific subjects, sessions or data types)
* Simplify data transfers by selecting only a sub-set of data to move (e.g. specific subjects, sessions or datatypes)

See the [DataShuttle Documentation](https://datashuttle.neuroinformatics.dev) to get started or join the [Zulip chat](https://neuroinformatics.zulipchat.com/#narrow/stream/405999-DataShuttle) to discuss any questions, comments or feedback.

Expand Down
13 changes: 5 additions & 8 deletions datashuttle/command_line_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,11 +613,10 @@ def construct_parser():
nargs="+",
type=str,
required=False,
help="Optional: (str, single or multiple) (selection of data types, or 'all')",
help="Optional: (str, single or multiple) (selection of datatypes, or 'all')",
)
make_sub_folders_parser.add_argument(
"--data-type",
"--data_type",
"--datatype",
"-dt",
type=str,
nargs="+",
Expand Down Expand Up @@ -659,13 +658,12 @@ def construct_parser():
help=help("required_str_single_or_multiple_or_all"),
)
upload_parser.add_argument(
"--data-type",
"--data_type",
"--datatype",
"-dt",
type=str,
nargs="+",
required=False,
help="Optional: (str, single or multiple) (selection of data types, or 'all') (default 'all')",
help="Optional: (str, single or multiple) (selection of datatypes, or 'all') (default 'all')",
)
upload_parser.add_argument(
"--dry-run",
Expand Down Expand Up @@ -732,8 +730,7 @@ def construct_parser():
help=help("required_str_single_or_multiple_or_all"),
)
download_parser.add_argument(
"--data-type",
"--data_type",
"--datatype",
"-dt",
type=str,
nargs="+",
Expand Down
16 changes: 8 additions & 8 deletions datashuttle/configs/canonical_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ def get_canonical_config_dict() -> dict:
"show_transfer_progress": None,
}

data_type_configs = get_data_types(as_dict=True)
config_dict.update(data_type_configs)
datatype_configs = get_datatypes(as_dict=True)
config_dict.update(datatype_configs)

return config_dict


def get_data_types(as_dict: bool = False):
def get_datatypes(as_dict: bool = False):
"""
Canonical list of data_type flags. This is used
Canonical list of datatype flags. This is used
to define get_canonical_config_dict() as well
as in testing.
"""
Expand All @@ -63,7 +63,7 @@ def get_flags() -> List[str]:
Return all configs that are bool flags. This is used in
testing and type checking config inputs.
"""
return get_data_types() + [
return get_datatypes() + [
"overwrite_old_files",
"show_transfer_progress",
]
Expand Down Expand Up @@ -151,10 +151,10 @@ def check_dict_values_raise_on_fail(config_dict: Configs) -> None:
"with no ~ syntax."
)

if not any([config_dict[key] for key in get_data_types()]):
if not any([config_dict[key] for key in get_datatypes()]):
utils.log_and_raise_error(
f"At least one data type must be True in "
f"configs, from: {' '.join(get_data_types())}."
f"At least one datatype must be True in "
f"configs, from: {' '.join(get_datatypes())}."
)

# Check SSH settings
Expand Down
14 changes: 7 additions & 7 deletions datashuttle/configs/canonical_folders.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from datashuttle.utils.folder_class import Folder


def get_data_type_folders(cfg: Configs) -> dict:
def get_datatype_folders(cfg: Configs) -> dict:
"""
This function holds the canonical folders
managed by datashuttle.
Expand All @@ -23,12 +23,12 @@ def get_data_type_folders(cfg: Configs) -> dict:
When adding a new folder, the
key should be the canonical key used to refer
to the data_type in datashuttle and SWC-BIDs.
to the datatype in datashuttle and SWC-BIDs.
The value is a Folder() class instance with
the required fields
name : The display name for the data_type, that will
name : The display name for the datatype, that will
be used for making and transferring files in practice.
This should always match the canonical name, but left as
an option for rare cases in which advanced users want to change it.
Expand Down Expand Up @@ -80,8 +80,8 @@ def get_non_sub_names():
return [
"all_ses",
"all_non_ses",
"all_data_type",
"all_ses_level_non_data_type",
"all_datatype",
"all_ses_level_non_datatype",
]


Expand All @@ -93,8 +93,8 @@ def get_non_ses_names():
return [
"all_sub",
"all_non_sub",
"all_data_type",
"all_ses_level_non_data_type",
"all_datatype",
"all_ses_level_non_datatype",
]


Expand Down
48 changes: 24 additions & 24 deletions datashuttle/configs/config_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(

self.top_level_folder: str

self.data_type_folders: dict
self.datatype_folders: dict
self.logging_path: Path
self.hostkeys_path: Path
self.ssh_key_path: Path
Expand Down Expand Up @@ -300,67 +300,67 @@ def make_and_get_logging_path(self) -> Path:
folders.make_folders(logging_path)
return logging_path

def init_data_type_folders(self):
def init_datatype_folders(self):
""""""
self.data_type_folders = canonical_folders.get_data_type_folders(self)
self.datatype_folders = canonical_folders.get_datatype_folders(self)

def get_data_type_items(
self, data_type: Union[str, list]
def get_datatype_items(
self, datatype: Union[str, list]
) -> Union[ItemsView, zip]:
"""
Get the .items() structure of the data type, either all of
them (stored in self.data_type_folders) or as a single item.
Get the .items() structure of the datatype, either all of
them (stored in self.datatype_folders) or as a single item.
"""
if isinstance(data_type, str):
data_type = [data_type]
if isinstance(datatype, str):
datatype = [datatype]

items: Union[ItemsView, zip]

if "all" in data_type:
items = self.data_type_folders.items()
if "all" in datatype:
items = self.datatype_folders.items()
else:
items = zip(
data_type,
[self.data_type_folders[key] for key in data_type],
datatype,
[self.datatype_folders[key] for key in datatype],
)

return items

def items_from_data_type_input(
def items_from_datatype_input(
self,
local_or_central: str,
data_type: Union[list, str],
datatype: Union[list, str],
sub: str,
ses: Optional[str] = None,
) -> Union[ItemsView, zip]:
"""
Get the list of data_types to transfer, either
Get the list of datatypes to transfer, either
directly from user input, or by searching
what is available if "all" is passed.
Parameters
----------
see _transfer_data_type() for parameters.
see _transfer_datatype() for parameters.
"""
base_folder = self.get_base_folder(local_or_central)

if data_type not in [
if datatype not in [
"all",
["all"],
"all_data_type",
["all_data_type"],
"all_datatype",
["all_datatype"],
]:
data_type_items = self.get_data_type_items(
data_type,
datatype_items = self.get_datatype_items(
datatype,
)
else:
data_type_items = folders.search_data_folders_sub_or_ses_level(
datatype_items = folders.search_data_folders_sub_or_ses_level(
self,
base_folder,
local_or_central,
sub,
ses,
)

return data_type_items
return datatype_items
28 changes: 14 additions & 14 deletions datashuttle/datashuttle.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def _set_attributes_after_config_load(self) -> None:

self._make_project_metadata_if_does_not_exist()

self.cfg.init_data_type_folders()
self.cfg.init_datatype_folders()

# -------------------------------------------------------------------------
# Public Folder Makers
Expand Down Expand Up @@ -159,7 +159,7 @@ def make_sub_folders(
self,
sub_names: Union[str, list],
ses_names: Optional[Union[str, list]] = None,
data_type: str = "all",
datatype: str = "all",
) -> None:
"""
Create a subject / session folder tree in the project
Expand All @@ -178,12 +178,12 @@ def make_sub_folders(
(if not already, these will be prefixed with
"ses-"). If no session is provided, no session-level
folders are made.
data_type :
The data_type to make in the sub / ses folders.
(e.g. "ephys", "behav", "histology"). Only data_types
datatype :
The datatype to make in the sub / ses folders.
(e.g. "ephys", "behav", "histology"). Only datatypes
that are enabled in the configs (e.g. use_behav) will be
created. If "all" is selected, folders will be created
for all data_type enabled in config. Use empty string "" for
for all datatype enabled in config. Use empty string "" for
none.
Notes
Expand All @@ -204,7 +204,7 @@ def make_sub_folders(
Examples
--------
project.make_sub_folders("sub-001", data_type="all")
project.make_sub_folders("sub-001", datatype="all")
project.make_sub_folders("sub-002@TO@005",
["ses-001", "ses-002"],
Expand Down Expand Up @@ -251,7 +251,7 @@ def make_sub_folders(
self.cfg,
sub_names,
ses_names,
data_type,
datatype,
log=True,
)

Expand Down Expand Up @@ -294,7 +294,7 @@ def upload(
self,
sub_names: Union[str, list],
ses_names: Union[str, list],
data_type: str = "all",
datatype: str = "all",
dry_run: bool = False,
init_log: bool = True,
) -> None:
Expand All @@ -313,15 +313,15 @@ def upload(
be prefixed with "sub-", or the prefix will be
automatically added. "@*@" can be used as a wildcard.
"all" will search for all sub-folders in the
data type folder to upload.
datatype folder to upload.
ses_names :
a session name / list of session names, similar to
sub_names but requiring a "ses-" prefix.
dry_run :
perform a dry-run of upload. This will output as if file
transfer was taking place, but no files will be moved. Useful
to check which files will be moved on data transfer.
data_type :
datatype :
see make_sub_folders()
init_log :
Expand Down Expand Up @@ -357,7 +357,7 @@ def upload(
"upload",
sub_names,
ses_names,
data_type,
datatype,
dry_run,
log=True,
)
Expand All @@ -368,7 +368,7 @@ def download(
self,
sub_names: Union[str, list],
ses_names: Union[str, list],
data_type: str = "all",
datatype: str = "all",
dry_run: bool = False,
init_log: bool = True,
) -> None:
Expand All @@ -393,7 +393,7 @@ def download(
"download",
sub_names,
ses_names,
data_type,
datatype,
dry_run,
log=True,
)
Expand Down
Loading

0 comments on commit fe05459

Please sign in to comment.