Coder Social home page Coder Social logo

Comments (2)

cutright avatar cutright commented on June 15, 2024

Good catch. I think the decimal precision with a str call may be an issue in some cases though (i.e., trailing zeros)?

I think the simplest fix is to remove the sets_of_points_keys all together, and then sort all_z_values before the thickness calculation.

sets_of_points_keys = list(sets_of_points)
sets_of_points_keys.sort()
all_z_values = [round(float(z), 2) for z in sets_of_points_keys]
thicknesses = np.abs(np.diff(all_z_values))
if len(thicknesses):
thicknesses = np.append(thicknesses, np.min(thicknesses))
else:
thicknesses = np.array([MIN_SLICE_THICKNESS])

So remove lines 253-254 and change line 256 to this:

all_z_values = sorted([round(float(z), 2) for z in sets_of_points])

That said, the code feels sloppy to me, I'll probably clean it up a bit before pushing.

I only found one use of this thickness calculation in DVHA (surface area), and even there it only used the minimum value. Thankfully, this is a pretty minimal impact to DVHA users.

shapely_roi = get_shapely_from_sets_of_points(sets_of_points)
slice_count = len(shapely_roi["z"])
area = 0.0
polygon = shapely_roi["polygon"]
z = shapely_roi["z"]
thickness = min(shapely_roi["thickness"])

from dvh-analytics.

cutright avatar cutright commented on June 15, 2024

I only did one test import so far. All surface area calculations were identical except for my external ROI, which was way off.

I still think this can be done more concisely, but at least this avoids calling index based on type-converted values.

roi_slices = {"z": [], "thickness": [], "polygon": []}
sets_of_points_keys = list(sets_of_points) # lock in for-loop order
z_values = list(map(float, sets_of_points_keys))
# Get the thickness of each slice
order = get_sorted_indices(z_values)
thickness = np.abs(np.diff([z_values[i] for i in order]))
if len(thickness):
thickness = np.append(thickness, np.min(thickness))
else:
thickness = np.array([MIN_SLICE_THICKNESS])
for i, z in enumerate(sets_of_points_keys):
polygon = points_to_shapely_polygon(sets_of_points[z])
if polygon:
if tolerance is not None:
polygon = polygon.simplify(tolerance, preserve_topology)
roi_slices["z"].append(round(float(z), 2))
roi_slices["thickness"].append(thickness[order[i]])
roi_slices["polygon"].append(polygon)
return roi_slices

from dvh-analytics.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.