Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve name of dataset #122

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions scripts/register_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
resample_roi_image,
show_image,
)
from hipct_reg.inventory import Dataset, load_datasets, save_datasets
from hipct_reg.inventory import RegDataset, load_datasets, save_datasets
from hipct_reg.registration import run_registration
from hipct_reg.types import RegistrationInput

Expand All @@ -39,7 +39,7 @@
DATASETS = {d.name: d for d in load_datasets()}


def register(ds: Dataset) -> tuple[RegistrationInput, sitk.Similarity3DTransform]:
def register(ds: RegDataset) -> tuple[RegistrationInput, sitk.Similarity3DTransform]:
"""
Register a single dataset.

Expand Down Expand Up @@ -113,7 +113,7 @@ def plot_central_slice(
ax.grid(color="k")


def keep_dataset(d: Dataset) -> bool:
def keep_dataset(d: RegDataset) -> bool:
"""
Whether to keep a dataset for listing in the registration widget.
"""
Expand Down
2 changes: 1 addition & 1 deletion scripts/update_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def select_parent(

if d.name not in datasets_reg_names:
# Create new dataset
datasets_reg_names[d.name] = hipct_reg.inventory.Dataset(
datasets_reg_names[d.name] = hipct_reg.inventory.RegDataset(
name=d.name, parent_name=parent.name
)

Expand Down
10 changes: 5 additions & 5 deletions src/hipct_reg/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
INVENTORY_FILE = Path(__file__).parent / "reg_inventory.csv"


class Dataset(BaseModel):
class RegDataset(BaseModel):
"""
A dataset that can be, or has been registered.
"""
Expand Down Expand Up @@ -146,7 +146,7 @@ def neuroglancer_link(self) -> str:
return link


def save_datasets(datasets: list[Dataset]) -> None:
def save_datasets(datasets: list[RegDataset]) -> None:
"""
Save a list of datasets to the .csv inventory file.
"""
Expand All @@ -155,17 +155,17 @@ def save_datasets(datasets: list[Dataset]) -> None:
df.to_csv(INVENTORY_FILE, index=False, lineterminator="\n")


def load_datasets() -> list[Dataset]:
def load_datasets() -> list[RegDataset]:
"""
Load a list of datasets from the .csv inventory file.
"""
df = pd.read_csv(INVENTORY_FILE, na_filter=False)

def parse_row(row: "pd.Series[Any]") -> Dataset:
def parse_row(row: "pd.Series[Any]") -> RegDataset:
d = dict(row)
for key in d:
if d[key] == "":
d[key] = None
return Dataset(**d)
return RegDataset(**d)

return [parse_row(row) for i, row in df.iterrows()]