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

Adding grid_file_path to recipe metadata for uploads #268

Merged
merged 2 commits into from
Jul 1, 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
10 changes: 0 additions & 10 deletions cellpack/autopack/loaders/recipe_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,6 @@ def _sanitize_format_version(recipe_data):
format_version = recipe_data["format_version"]
return format_version

def get_only_recipe_metadata(self):
recipe_meta_data = {
"format_version": self.recipe_data["format_version"],
"version": self.recipe_data["version"],
"name": self.recipe_data["name"],
"bounding_box": self.recipe_data["bounding_box"],
"composition": {},
}
return recipe_meta_data

def _migrate_version(self, old_recipe):
converted = False
if old_recipe["format_version"] == "1.0":
Expand Down
21 changes: 20 additions & 1 deletion cellpack/bin/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,25 @@
from cellpack.autopack.loaders.recipe_loader import RecipeLoader


def get_recipe_metadata(loader):
"""
Extracts and returns essential metadata from a recipe for uploading
"""
try:
recipe_meta_data = {
"format_version": loader.recipe_data["format_version"],
"version": loader.recipe_data["version"],
"name": loader.recipe_data["name"],
"bounding_box": loader.recipe_data["bounding_box"],
"composition": {},
}
if "grid_file_path" in loader.recipe_data:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: should we check for all keys in loader.recipe_data and add them to the recipe_meta_data (except composition)? This way we won't have to do a special check for grid_file_path or any new keys we add to the recipe down the line.

Copy link
Collaborator Author

@rugeli rugeli Jun 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for asking! I was thinking the same approach: iterating over recipe data and recording every key except for objects, representations, etc., to make the uploading more programmatic. However I went with specified keys(for now) so we get to fully control which keys are displayed and needed in the metadata. Helping to prevent errors during data handling.

And you're right, if there will be more new top-layer keys, we should think about a more dynamic way to manage it.

recipe_meta_data["grid_file_path"] = loader.recipe_data["grid_file_path"]
return recipe_meta_data
except KeyError as e:
sys.exit(f"Recipe metadata is missing. {e}")


def upload(
recipe_path,
db_id=DATABASE_IDS.FIREBASE,
Expand All @@ -23,7 +42,7 @@ def upload(
if FirebaseHandler._initialized:
recipe_loader = RecipeLoader(recipe_path)
recipe_full_data = recipe_loader._read(resolve_inheritance=False)
recipe_meta_data = recipe_loader.get_only_recipe_metadata()
recipe_meta_data = get_recipe_metadata(recipe_loader)
recipe_db_handler = DBUploader(db_handler)
recipe_db_handler.upload_recipe(recipe_meta_data, recipe_full_data)
else:
Expand Down
Loading