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

save metadata of aws result files to firebase #201

Closed
wants to merge 67 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
711bd8e
Working variable count distributions
mogres Aug 16, 2023
8a00bbd
* add radius to molecules array
mogres Sep 8, 2023
c5aa16b
Test recipe and config for variable size
mogres Sep 8, 2023
de95dfe
add radius to ingredient array dict
mogres Sep 12, 2023
9bcd67f
turn off resolving inheritance while uploading
rugeli Sep 12, 2023
5c14f8a
able to upload recipes having "inherit" key
rugeli Sep 12, 2023
dde4a72
get download and pack to work, refactors needed
rugeli Sep 15, 2023
316fee7
add test variable size recipe
meganrm Sep 15, 2023
945eccb
create packed objects class
meganrm Sep 15, 2023
283015e
Merge branch 'feature/variable_size' of https://github.com/mesoscope/…
meganrm Sep 15, 2023
7db8bec
removing .molecules
meganrm Sep 15, 2023
8eb3190
pack variable size ingredient successfully
meganrm Sep 20, 2023
a23bdde
Merge branch 'main' of https://github.com/mesoscope/cellpack into fea…
meganrm Sep 20, 2023
fb3dcb9
pack sphere_tree ingredient
meganrm Sep 20, 2023
4c47c8c
DRY code
meganrm Sep 20, 2023
3b97426
store ingredient in packed object
meganrm Sep 21, 2023
b665e77
change to compartment_id
meganrm Sep 21, 2023
7836419
cleanup
meganrm Sep 21, 2023
5541d22
add second example
meganrm Sep 21, 2023
49446bc
Merge branch 'main' of https://github.com/mesoscope/cellpack into fea…
rugeli Sep 25, 2023
00628e9
refactors
rugeli Sep 26, 2023
c8bcccf
Merge branch 'main' of https://github.com/mesoscope/cellpack into fea…
rugeli Sep 27, 2023
d161baa
Merge branch 'feature/run-recipes-from-firebase' into feature/run-inh…
rugeli Sep 27, 2023
3d82959
Merge branch 'feature/run-inherited-objects' of https://github.com/me…
rugeli Oct 3, 2023
00601e3
initial draft
rugeli Oct 4, 2023
5318f33
reorder methods in firebase handler
rugeli Oct 5, 2023
eac5704
avoid initializing app twice
rugeli Oct 5, 2023
1539654
modularize firebase handler
rugeli Oct 5, 2023
e58dbe5
modularize AWSHandler & refactors
rugeli Oct 6, 2023
d5207c5
* fixed broken image export
mogres Oct 6, 2023
aae4e49
fix flake8 linting errors
mogres Oct 9, 2023
d4084c4
Update cellpack/autopack/ingredient/Ingredient.py
meganrm Oct 9, 2023
ca1464d
Update cellpack/autopack/ingredient/Ingredient.py
meganrm Oct 9, 2023
41a300e
Update cellpack/tests/packing-configs/test_variable_count_config.json
meganrm Oct 9, 2023
9d3e0cd
Update cellpack/autopack/ingredient/Ingredient.py
meganrm Oct 9, 2023
75c870c
Update cellpack/autopack/ingredient/Ingredient.py
meganrm Oct 9, 2023
eadb2e6
Update cellpack/autopack/utils.py
meganrm Oct 9, 2023
862d2e5
get ingredient directly
meganrm Oct 9, 2023
c0741ba
revert change to static method
meganrm Oct 9, 2023
67b59e3
Merge branch 'feature/results-in-memory' of https://github.com/mesosc…
meganrm Oct 9, 2023
ec51ab4
fix test
meganrm Oct 9, 2023
d480893
* use kwargs to overload voxelization function
mogres Oct 10, 2023
9065f17
fix tests
mogres Oct 10, 2023
e9dc5b6
removed afvi from `get_partners` which was erroring out
mogres Oct 10, 2023
4be3fed
remove `afvi` argument causing partner packing to break
mogres Oct 11, 2023
ee214e3
add get methods for packed objects
meganrm Oct 11, 2023
6430603
Merge branch 'feature/results-in-memory' of https://github.com/mesosc…
meganrm Oct 11, 2023
1605221
move when we store compartments in packed_objects
meganrm Oct 11, 2023
4a887de
change radius
meganrm Oct 11, 2023
25d9839
use ingredient stored for compartment
meganrm Oct 11, 2023
fe89fb7
fix linting
mogres Oct 12, 2023
c975872
pack sphere trees successfully and plot in 2D
meganrm Oct 12, 2023
5d9ecae
Merge branch 'feature/results-in-memory' of https://github.com/mesosc…
meganrm Oct 12, 2023
9105668
fix/S3 uploads and new browser tabs handling (#203)
rugeli Oct 12, 2023
d35738d
format fixed
meganrm Oct 12, 2023
5da57e0
Fix gradient inversion (#196)
mogres Oct 13, 2023
aae7ed1
Merge pull request #193 from mesoscope/feature/results-in-memory
meganrm Oct 13, 2023
7e2c633
Merge branch 'main' of https://github.com/mesoscope/cellpack into fea…
rugeli Oct 17, 2023
0d577fe
Merge branch 'feature/run-recipes-from-firebase' of https://github.co…
rugeli Oct 17, 2023
44c3cb2
formatting
rugeli Oct 17, 2023
7c0aae3
testing and refactor
rugeli Oct 23, 2023
e6777dd
initial draft
rugeli Oct 4, 2023
c14dfbc
reorder methods in firebase handler
rugeli Oct 5, 2023
ad7c7c4
avoid initializing app twice
rugeli Oct 5, 2023
7f7f0f7
modularize firebase handler
rugeli Oct 5, 2023
1c8ac68
modularize AWSHandler & refactors
rugeli Oct 6, 2023
82f7f7f
Merge branch 'feature/save-metadata' of https://github.com/mesoscope/…
rugeli Oct 23, 2023
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,6 @@ cellpack/tests/outputs/
# data
data/
**/converted/*

# credentials
.creds
19 changes: 16 additions & 3 deletions cellpack/autopack/AWSHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ class AWSHandler(object):
Handles all the AWS S3 operations
"""

# class attributes
_session_created = False
_s3_client = None

def __init__(
self,
bucket_name,
Expand All @@ -18,12 +22,21 @@ def __init__(
):
self.bucket_name = bucket_name
self.folder_name = sub_folder_name
session = boto3.Session()
self.s3_client = session.client(
# Create a session if one does not exist
if not AWSHandler._session_created:
self._create_session(region_name)
AWSHandler._session_created = True
else:
# use the existing session
self.s3_client = AWSHandler._s3_client

def _create_session(self, region_name):
AWSHandler._s3_client = boto3.client(
"s3",
endpoint_url=f"https://s3.{region_name}.amazonaws.com",
region_name=region_name,
)
self.s3_client = AWSHandler._s3_client

def get_aws_object_key(self, object_name):
if self.folder_name is not None:
Expand Down Expand Up @@ -82,4 +95,4 @@ def save_file(self, file_path):
"""
file_name = self.upload_file(file_path)
if file_name:
return self.create_presigned_url(file_name)
return file_name, self.create_presigned_url(file_name)
49 changes: 3 additions & 46 deletions cellpack/autopack/Analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def getDistanceFrom(self, target, parents=None, **options):
objects : list of object or list of points
"""
# get distance from object to the target.
# all object are in h.molecules and orga.molecules
# all object are in env.packed_objects
# get options

if type(target) == list or type(target) == tuple:
Expand Down Expand Up @@ -447,23 +447,6 @@ def rectangle_circle_area(self, bbox, center, radius):
area = bbox[0][1] ** 2
return area

def getAxeValue(self, ingrname, axe=0):
ingredient_positions = [
self.env.molecules[i][0][axe]
for i in range(len(self.env.molecules))
if self.env.molecules[i][2].name == ingrname
]
return ingredient_positions

def getAxesValues(self, positions):
pp = numpy.array(positions).transpose()
if len(positions) == 0:
return 1, 1, 1
px = pp[0]
py = pp[1]
pz = pp[2]
return px, py, pz

def getVolumeShell(self, bbox, radii, center):
# rectangle_circle_area
volumes = []
Expand All @@ -473,9 +456,6 @@ def getVolumeShell(self, bbox, radii, center):
r2 = radii[i + 1]
v1 = self.g.calc_volume(r1, box_size0 / 2.0)
v2 = self.g.calc_volume(r2, box_size0 / 2.0)
# if v1 == 0 or v2 == 0 :
# volumes.append((4./3.)*numpy.pi*(numpy.power(r2,3)-numpy.power(r1, 3)))
# else :
volumes.append(v2 - v1)
return volumes

Expand Down Expand Up @@ -1774,7 +1754,7 @@ def pack(
t2 = time()
run_time = t2 - t1
print(f"time to run pack_grid for {self.env.place_method}: {run_time:0.2f}")
print(f"num placed: {len(self.env.molecules)}")
print(f"num placed: {len(self.env.packed_objects.get_ingredients())}")
if show_plotly_plot:
min_bound, max_bound = self.env.get_bounding_box_limits()
width = max_bound - min_bound
Expand All @@ -1787,7 +1767,7 @@ def pack(
range=[min_bound[1] - 0.2 * width[1], max_bound[1] + 0.2 * width[1]]
)
self.plotly.update_title(
f"{self.env.place_method} took {str(round(t2 - t1, 2))}s, packed {len(self.env.molecules)}"
f"{self.env.place_method} took {str(round(t2 - t1, 2))}s, packed {len(self.env.packed_objects.get_ingredients())}"
)
self.plotly.make_grid_heatmap(self.env)
self.plotly.add_ingredient_positions(self.env)
Expand Down Expand Up @@ -1875,29 +1855,6 @@ def plot_one_result_2d(
plt.close() # closes the current figure
return ingrpos

# res=plotOneResult(None,filename="results_seed_8.json")

def plot_one_result_3D(self, filename, width=1000.0):
plt.close("all") # closes the current figure
pos = []
s = []
c = []
for i in range(len(self.env.molecules)):
m = self.env.molecules[i]
pos.append(numpy.array(m[0]).tolist())
s.append(m[2].encapsulating_radius ** 2)
c.append(m[2].color)
fig = plt.figure()
ax = fig.gca(projection="3d")
x, y, z = numpy.array(pos).transpose()
ax.scatter(x, y, z, s=s, c=c)
ax.legend()
ax.set_xlim3d(0, width)
ax.set_ylim3d(0, width)
ax.set_zlim3d(0, width)
plt.savefig(filename)
return x, y, z, s, c

def set_ingredient_color(self, ingr):
"""
Sets the color of an ingredient
Expand Down
35 changes: 28 additions & 7 deletions cellpack/autopack/Compartment.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@
import cellpack.autopack as autopack
from cellpack.autopack import transformation as tr, binvox_rw
from cellpack.autopack.BaseGrid import gridPoint
from cellpack.autopack.interface_objects.packed_objects import (
PackedObject,
PackedObjects,
)
from .Recipe import Recipe
from .ray import (
makeMarchingCube,
Expand Down Expand Up @@ -138,6 +142,7 @@ def __init__(self, name, object_info):
self.ref_obj = None
self.meshType = None
self.representations = object_info["representations"]
self.packed_objects = PackedObjects()
if self.representations.has_mesh():
self.gname = self.representations.get_mesh_name()
self.meshType = self.representations.get_mesh_format()
Expand Down Expand Up @@ -172,7 +177,6 @@ def __init__(self, name, object_info):
# is added to a Environment. Positivefor surface pts
# negative for interior points
# self.parent = None
self.molecules = []
# list of ( (x,y,z), rotation, ingredient) triplet generated by fill
self.overwriteSurfacePts = True
# do we discretize surface point per edges
Expand Down Expand Up @@ -207,7 +211,6 @@ def reset(self):
# list of grid point indices on compartment surface
self.surfacePoints = None
self.surfacePointsNormals = {} # will be point index:normal
# self.molecules = []

def transformMesh(self, pos, rotation):
rot = tr.matrix_from_quaternion(rotation).transpose()
Expand Down Expand Up @@ -266,6 +269,17 @@ def initialize_shape(self, mesh_store):
self.encapsulating_radius = radius
self.radius = mesh_store.get_smallest_radius(self.gname, center)

def store_packed_object(self, env):
packed_object = PackedObject(
position=[0, 0, 0],
rotation=numpy.identity(4),
radius=self.radius,
pt_index=-1,
ingredient=self,
is_compartment=True,
)
env.packed_objects.add(packed_object)

def addShapeRB(self, env):
# in case our shape is a regular primitive
if self.stype == "capsule":
Expand Down Expand Up @@ -503,10 +517,10 @@ def setInnerRecipe(self, recipe):
self.innerRecipe.number = self.number
recipe.compartment = self # weakref.ref(self)
for ingr in recipe.ingredients:
ingr.compNum = -self.number
ingr.compartment_id = -self.number
if hasattr(ingr, "compMask"):
if not ingr.compMask:
ingr.compMask = [ingr.compNum]
ingr.compMask = [ingr.compartment_id]

def setSurfaceRecipe(self, recipe):
"""set the inner recipe that define the ingredient to pack at the surface"""
Expand All @@ -516,7 +530,7 @@ def setSurfaceRecipe(self, recipe):
self.surfaceRecipe.number = self.number
recipe.compartment = self # weakref.ref(self)
for ingr in recipe.ingredients:
ingr.compNum = self.number
ingr.compartment_id = self.number

def getCenter(self):
"""get the center of the mesh (vertices barycenter)"""
Expand Down Expand Up @@ -3200,12 +3214,19 @@ def create_voxelization(
voxel_size,
image_size,
position,
mesh_store,
hollow=False,
**kwargs,
):
"""
Creates a voxelization mask at the position of the compartment
"""
if "mesh_store" not in kwargs:
raise RuntimeError(
"mesh_store must be provided for compartment voxelization"
)

mesh_store = kwargs["mesh_store"]
hollow = kwargs.get("hollow", False)

relative_position = position - bounding_box[0]
mask = self.create_voxelized_mask(
*image_size,
Expand Down
16 changes: 15 additions & 1 deletion cellpack/autopack/DBRecipeHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ def should_write(self, db, recipe_data):
# found a match, so shouldn't write
return False, db.doc_id(doc)
else:
# deeply compare resolved regions data
self.resolve_db_regions(db_data, db)
self.resolve_local_regions(local_data, recipe_data, db)
difference = DeepDiff(
Expand Down Expand Up @@ -525,7 +526,7 @@ def _get_recipe_id(self, recipe_data):
"""
recipe_name = recipe_data["name"]
recipe_version = recipe_data["version"]
key = f"{recipe_name}_v-{recipe_version}"
key = f"{recipe_name}_v_{recipe_version}"
return key

def upload_collections(self, recipe_meta_data, recipe_data):
Expand Down Expand Up @@ -573,6 +574,19 @@ def upload_recipe(self, recipe_meta_data, recipe_data):
key = self._get_recipe_id(recipe_to_save)
self.upload_data("recipes", recipe_to_save, key)

def upload_result_metadata(self, file_name, url):
"""
Upload the metadata of the result file to the database.
"""
if self.db:
username = self.db.get_username()
timestamp = self.db.create_timestamp()
self.db.update_or_create(
"results",
file_name,
{"user": username, "timestamp": timestamp, "url": url.split("?")[0]},
)


class DBRecipeLoader(object):
"""
Expand Down
Loading
Loading