|
15 | 15 | # TODO: inverted meshes? |
16 | 16 | # %% |
17 | 17 | import json |
| 18 | +import shutil |
18 | 19 |
|
19 | 20 | import boto3 |
20 | 21 | import pandas as pd |
21 | 22 | from tqdm import tqdm |
22 | 23 |
|
23 | 24 | from cellpack_analysis.lib.file_io import get_datadir_path, get_results_path |
| 25 | +from cellpack_analysis.lib.mesh_tools import invert_mesh_faces |
24 | 26 |
|
25 | 27 | # %% |
26 | 28 | base_datadir = get_datadir_path() |
|
39 | 41 | simularium_path = ( |
40 | 42 | base_datadir / "packing_outputs" / dataset / condition / rule / structure_name / "spheresSST" |
41 | 43 | ) |
| 44 | +figure_path = simularium_path / "figures" |
42 | 45 | # %% |
43 | 46 | records = [] |
44 | 47 | base_s3_mesh_url = ( |
|
47 | 50 | base_s3_simularium_url = "https://cellpack-analysis-data.s3.us-west-2.amazonaws.com/" |
48 | 51 | s3_client = boto3.client("s3") |
49 | 52 | # %% |
50 | | -# Update meshes in s3 bucket |
51 | | -mesh_path = base_datadir / "structure_data" / structure_id / "meshes" |
52 | | -for file_path in tqdm(mesh_path.rglob("*")): |
| 53 | +# Invert and upload meshes to s3 bucket |
| 54 | +invert_meshes = False |
| 55 | +mesh_dir = base_datadir / "structure_data" / structure_id / "meshes" |
| 56 | +for file_path in tqdm(mesh_dir.rglob("*")): |
53 | 57 | if file_path.is_file(): |
| 58 | + # invert mem meshes |
| 59 | + if invert_meshes and "mem" in file_path.name and "original" not in file_path.name: |
| 60 | + orig_mesh_path = file_path.parent / f"{file_path.stem}_original.obj" |
| 61 | + # copy original file with suffix |
| 62 | + shutil.copy( |
| 63 | + file_path, |
| 64 | + orig_mesh_path, |
| 65 | + ) |
| 66 | + invert_mesh_faces(input_mesh_path=orig_mesh_path, output_mesh_path=file_path) |
| 67 | + |
| 68 | + # upload to s3 |
54 | 69 | s3_key = file_path.relative_to(base_datadir).as_posix() |
55 | 70 | s3_client.upload_file(str(file_path), "cellpack-analysis-data", s3_key) |
56 | 71 | s3_client.put_object_acl( |
|
59 | 74 | Key=s3_key, |
60 | 75 | ) |
61 | 76 | # %% |
| 77 | +reupload = False |
62 | 78 | # Update simularium files and upload to s3 |
63 | 79 | for file_path in tqdm(simularium_path.rglob("*.simularium")): |
64 | 80 | # update mesh paths in simularium file |
|
69 | 85 | mapping["geometry"]["url"] = f"{base_s3_mesh_url}{mapping['geometry']['url']}" |
70 | 86 | with open(file_path, "w") as f: |
71 | 87 | json.dump(sim_data, f, indent=2) |
72 | | - # try: |
73 | | - # s3_client.head_object(Bucket="cellpack-analysis-data", Key=s3_key) |
74 | | - # except s3_client.exceptions.ClientError: |
75 | | - # upload to s3 |
| 88 | + |
76 | 89 | s3_key = file_path.relative_to(base_datadir).as_posix() |
77 | | - s3_client.upload_file(str(file_path), "cellpack-analysis-data", s3_key) |
78 | | - s3_client.put_object_acl( |
79 | | - ACL="public-read", |
80 | | - Bucket="cellpack-analysis-data", |
81 | | - Key=s3_key, |
82 | | - ) |
| 90 | + |
| 91 | + should_upload = reupload |
| 92 | + if not reupload: |
| 93 | + try: |
| 94 | + s3_client.head_object(Bucket="cellpack-analysis-data", Key=s3_key) |
| 95 | + should_upload = False |
| 96 | + except s3_client.exceptions.ClientError: |
| 97 | + should_upload = True |
| 98 | + |
| 99 | + if should_upload: |
| 100 | + s3_client.upload_file(str(file_path), "cellpack-analysis-data", s3_key) |
| 101 | + s3_client.put_object_acl( |
| 102 | + ACL="public-read", |
| 103 | + Bucket="cellpack-analysis-data", |
| 104 | + Key=s3_key, |
| 105 | + ) |
| 106 | + |
83 | 107 | s3_path = f"{base_s3_simularium_url}{s3_key}" |
84 | 108 | record = { |
85 | 109 | "File Path": str(s3_path), |
|
0 commit comments