Skip to content

Commit

Permalink
Feature/send config data to analysis (#232)
Browse files Browse the repository at this point in the history
* * use pathlib module for file paths
* send in packing config data directly to analysis

* Process arguments inside `doloop` function
  • Loading branch information
mogres authored Feb 23, 2024
1 parent 2893482 commit f178de3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 47 deletions.
52 changes: 23 additions & 29 deletions cellpack/autopack/Analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from cellpack.autopack.plotly_result import PlotlyAnalysis
from cellpack.autopack.upy import colors as col
from cellpack.autopack.upy.colors import map_colors
from cellpack.autopack.utils import check_paired_key, get_paired_key
from cellpack.autopack.utils import check_paired_key, get_paired_key, get_seed_list
from cellpack.autopack.writers import Writer
from cellpack.autopack.writers.ImageWriter import ImageWriter
import concurrent.futures
Expand Down Expand Up @@ -2342,17 +2342,10 @@ def pack_one_seed(

def doloop(
self,
number_of_packings,
recipe_data,
packing_config_data,
bounding_box,
get_distance_distribution=True,
plot_figures=True,
show_grid=True,
seed_list=None,
config_name="default",
recipe_version="1.0.0",
image_export_options=None,
parallel=False,
save_gradient_data_as_image=False,
):
"""
Runs multiple packings of the same recipe in a loop. This workflow
Expand All @@ -2363,26 +2356,17 @@ def doloop(
Parameters
----------
number_of_packing : int
Number of repeats of a packing. Default: 1
bounding_box : np.ndarray
bounding box from the environment
recipe_data: dict
Dictionary containing recipe data
packing_config_data: dict
Dictionary containing packing configuration data
bounding_box: list
List of two lists containing the minimum and maximum coordinates
of the bounding box
get_distance_distribution: bool
specify whether to calculate distance distributions
render: bool
???
plot_figures: bool
specify whether to save figures generated by the analyses
show_grid: bool
specify whether to display packing grid in browser
fbox_bb: ???
???
seed_list: List
list of seeds to use for the packing (for reproducibility)
config_name: string
name of the configuration used for the packing
recipe_version: string
version of the recipe used for the packing
Whether to calculate and store distance and angle distributions
seed_list: list
List of seeds to use for packings
Outputs
-------
Expand All @@ -2393,6 +2377,16 @@ def doloop(
distributions as applicable for each seed, and a combined image
across seeds
"""
number_of_packings = packing_config_data["number_of_packings"]
plot_figures = packing_config_data.get("save_plot_figures", True)
show_grid = packing_config_data["show_grid_plot"]
image_export_options = packing_config_data.get("image_export_options")
parallel = packing_config_data.get("parallel", False)
save_gradient_data_as_image = packing_config_data.get(
"save_gradient_data_as_image", False
)

seed_list = get_seed_list(packing_config_data, recipe_data)
if seed_list is None:
seed_list = self.getHaltonUnique(number_of_packings)
packing_basename = self.env.base_name
Expand Down
22 changes: 4 additions & 18 deletions cellpack/bin/pack.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fire
from os import path
from pathlib import Path
import logging
import logging.config
import time
Expand All @@ -12,10 +12,9 @@
from cellpack.autopack.loaders.config_loader import ConfigLoader
from cellpack.autopack.loaders.recipe_loader import RecipeLoader
from cellpack.autopack.loaders.analysis_config_loader import AnalysisConfigLoader
from cellpack.autopack.utils import get_seed_list

###############################################################################
log_file_path = path.abspath(path.join(__file__, "../../logging.conf"))
log_file_path = Path(__file__).parent.parent / "logging.conf"
logging.config.fileConfig(log_file_path, disable_existing_loggers=False)
log = logging.getLogger()
###############################################################################
Expand All @@ -30,8 +29,6 @@ def pack(recipe, config_path=None, analysis_config_path=None):
:return: void
"""
log.info(f"Running in {__file__}")

packing_config_data = ConfigLoader(config_path).config
recipe_data = RecipeLoader(
recipe, packing_config_data["save_converted_recipe"]
Expand All @@ -58,21 +55,10 @@ def pack(recipe, config_path=None, analysis_config_path=None):
)
log.info(f"saving to {env.out_folder}")

seed_list = get_seed_list(packing_config_data, recipe_data)

analyze.doloop(
packing_config_data["number_of_packings"],
recipe_data,
packing_config_data,
env.boundingBox,
plot_figures=packing_config_data.get("save_plot_figures", True),
show_grid=packing_config_data["show_grid_plot"],
seed_list=seed_list,
config_name=packing_config_data["name"],
recipe_version=recipe_data["version"],
image_export_options=packing_config_data.get("image_export_options"),
parallel=packing_config_data.get("parallel", False),
save_gradient_data_as_image=packing_config_data.get(
"save_gradient_data_as_image", False
),
)
if analysis_config_path is not None:
analyze.run_analysis_workflow(
Expand Down

0 comments on commit f178de3

Please sign in to comment.