Skip to content
Open
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
27 changes: 17 additions & 10 deletions neuron_morphology/layered_point_depths/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,15 @@ def step_from_node(

Returns
-------
The depth of the intersection between the path walked and the given surface
depth: depth of the intersection between the path walked and the given surface
path_dist: the path distance from start to the intersection point

"""

retry_step = False
cur_pos = np.array(list(pos))
path_dist = 0
path = [cur_pos]

for _ in range(max_iter):
if not retry_step:
Expand All @@ -154,7 +157,7 @@ def step_from_node(

base_step = np.squeeze([dx, dy])
if np.any(np.isnan(base_step)):
return None
raise ValueError("Path is outside of interpolator domain.")
base_step = base_step / np.linalg.norm(base_step)
step = adaptive_scale * step_size * base_step

Expand All @@ -178,15 +181,19 @@ def step_from_node(
if test_dist < dist:
dist = test_dist
closest_pt = test_pt
intersection_pt = list(closest_pt.coords)
intersection_pt = list(closest_pt.coords)[0]
else:
intersection_pt = list(intersection.coords)
return float(depth_interp(intersection_pt[0]))
intersection_pt = list(intersection.coords)[0]
path_dist += np.linalg.norm(intersection_pt-cur_pos)
path.append(intersection_pt)
return float(depth_interp(intersection_pt)), path_dist

cur_pos = next_pos
path_dist += np.linalg.norm(step)
path.append(next_pos)
retry_step = False

return None # uneccessary, but satisfies linter :/
raise ValueError("Path failed to intersect surface.")


def get_node_intersections(
Expand Down Expand Up @@ -267,10 +274,10 @@ def get_node_intersections(
"depth": depth,
"local_layer_pia_side_depth": step_from_node(
pos, depth_interp, dx_interp, dy_interp, pia, step_size, max_iter
),
)[0],
"local_layer_wm_side_depth": step_from_node(
pos, depth_interp, dx_interp, dy_interp, wm, -step_size, max_iter
),
)[0],
"point_type": node["type"]
}

Expand Down Expand Up @@ -362,7 +369,7 @@ def main():
args = cp.deepcopy(parser.args)
logging.getLogger().setLevel(args.pop("log_level"))

output = main(**args)
output = run_layered_point_depths(**args)
output.update({"inputs": parser.args})

parser.output(output)
Expand Down
8 changes: 4 additions & 4 deletions neuron_morphology/lims_apical_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ def convert_coords_str(coords_str: str, resolution=None):


def get_data(query):
host = os.getenv("DBHOST")
dbname = os.getenv("DBNAME")
user = os.getenv("DBREADER")
password = os.getenv("DBPASSWORD")
host = os.getenv("LIMS_HOST")
dbname = os.getenv("LIMS_DBNAME")
user = os.getenv("LIMS_USER")
password = os.getenv("LIMS_PASSWORD")
conn_str = f'host={host} dbname={dbname} user={user} password={password}'

data = {}
Expand Down
56 changes: 29 additions & 27 deletions neuron_morphology/snap_polygons/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,29 @@ def run_snap_polygons(
"""Finds and returns close fit boundaries. May write diagnostic images as
a side effect.
"""

if len(layer_polygons)==0:
raise ValueError("No polygons provided.")
# setup input geometries
geometries = Geometries()
geometries.register_polygons(layer_polygons)

# setup cortex boundaries
hull = geometries.convex_hull()
pia = trim_to_close(hull, surface_distance_threshold, pia_surface["path"])
white_matter = trim_to_close(
hull, surface_distance_threshold, wm_surface["path"]
)

geometries.register_surface("pia", pia)
geometries.register_surface("wm", white_matter)

pia_wm_vertices = get_vertices_from_two_lines(
pia.coords[:], white_matter.coords[:]
)
bounds = shapely.geometry.polygon.Polygon(pia_wm_vertices)

if pia_surface is not None and wm_surface is not None:
hull = geometries.convex_hull()
pia = trim_to_close(hull, surface_distance_threshold, pia_surface["path"])
white_matter = trim_to_close(
hull, surface_distance_threshold, wm_surface["path"]
)
geometries.register_surface("pia", pia)
geometries.register_surface("wm", white_matter)
pia_wm_vertices = get_vertices_from_two_lines(
pia.coords[:], white_matter.coords[:]
)
# is this ever a good idea? seems like it may cut too much
bounds = shapely.geometry.polygon.Polygon(pia_wm_vertices)
else:
bounds = geometries.convex_hull()

multipolygon_resolver = partial(
select_largest_subpolygon,
error_threshold=multipolygon_error_threshold
Expand All @@ -69,8 +72,8 @@ def run_snap_polygons(
boundaries = find_vertical_surfaces(
result_geos.polygons,
layer_order,
pia=geometries.surfaces["pia"],
white_matter=geometries.surfaces["wm"]
pia=geometries.surfaces.get("pia"),
white_matter=geometries.surfaces.get("wm")
)
result_geos.register_surfaces(boundaries)

Expand All @@ -83,20 +86,19 @@ def run_snap_polygons(
return results


class Parser(ArgSchemaParser):
"""An ArgschemaParser that can pull data from LIMS
"""
default_sources = \
ArgSchemaParser.default_sources + (FromLimsSource,)
default_schema=InputParameters
default_output_schema=OutputParameters

def main():
"""CLI entrypoint for snapping polygons
"""

class Parser(ArgSchemaParser):
"""An ArgschemaParser that can pull data from LIMS
"""
default_configurable_sources = \
ArgSchemaParser.default_configurable_sources + [FromLimsSource]

parser = Parser(
schema_type=InputParameters,
output_schema_type=OutputParameters
)
parser = Parser()

args = cp.deepcopy(parser.args)
logging.getLogger().setLevel(args.pop("log_level"))
Expand Down
Loading