Skip to content

Commit

Permalink
Merge branch 'maxgamill-sheffield/800-better-tracing' into maxgamill-…
Browse files Browse the repository at this point in the history
…sheffield/topology
  • Loading branch information
MaxGamill-Sheffield authored Sep 11, 2024
2 parents 6f9464a + 0a51d25 commit a98c65e
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion tests/resources/minicircle_default_all_statistics.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
molecule_number,centre_x,centre_y,radius_min,radius_max,radius_mean,radius_median,height_min,height_max,height_median,height_mean,volume,area,area_cartesian_bbox,smallest_bounding_width,smallest_bounding_length,smallest_bounding_area,aspect_ratio,threshold,max_feret,min_feret,contour_length,circular,end_to_end_distance,image,basename
grain_number,centre_x,centre_y,radius_min,radius_max,radius_mean,radius_median,height_min,height_max,height_median,height_mean,volume,area,area_cartesian_bbox,smallest_bounding_width,smallest_bounding_length,smallest_bounding_area,aspect_ratio,threshold,max_feret,min_feret,contour_length,circular,end_to_end_distance,image,basename
0,18.72534751358894,96.56689212959863,5.918489103781348,20.866157242818016,15.491706069705224,16.218426875142722,0.7452716544633669,3.8599067676448637,2.0391347095418917,1.9481343856971967,1220.4045823987904,626.4478422837515,1137.465287450162,24.292634523076288,40.8496256505361,992.3450263329557,1.6815642458100555,upper,41.33420255276943,24.126052806347744,113.16428314861125,False,12.929293977622509,minicircle.spm,tests/resources
1,400.2920881110063,93.12806953798491,0.7643280440003184,21.96855256891761,13.999840272706289,14.792429582135073,0.7454383438304222,3.179159623594896,2.131409254934984,1.984183560332176,1263.808882457969,636.9415147489642,1186.0290274635886,27.45053797699605,39.09250720831134,1073.1103537377423,1.4241071428571428,upper,39.14797897350707,27.45053797699605,115.66050824497863,False,21.47066537827239,minicircle.spm,tests/resources
2,218.26129518646468,172.6865624592939,8.312817001643236,28.4840908864891,17.761201297555598,16.374812395420516,0.7458769816768294,3.0837823469355783,1.965905358311789,1.8574106218419255,1152.692145851135,620.5909088147954,1618.9540263772524,24.48642216522931,54.1892216956022,1326.9001592437185,2.2130314232902033,upper,54.20767776942792,24.48642216522931,90.27296454772564,True,0.0,minicircle.spm,tests/resources
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
molecule_number,centre_x,centre_y,radius_min,radius_max,radius_mean,radius_median,height_min,height_max,height_median,height_mean,volume,area,area_cartesian_bbox,smallest_bounding_width,smallest_bounding_length,smallest_bounding_area,aspect_ratio,threshold,max_feret,min_feret,contour_lengths,circular,end_to_end_distance,image,basename
grain_number,centre_x,centre_y,radius_min,radius_max,radius_mean,radius_median,height_min,height_max,height_median,height_mean,volume,area,area_cartesian_bbox,smallest_bounding_width,smallest_bounding_length,smallest_bounding_area,aspect_ratio,threshold,max_feret,min_feret,contour_lengths,circular,end_to_end_distance,image,basename
0,18.72534751358894,96.56689212959863,5.918489103781348,20.866157242818016,15.491706069705224,16.218426875142722,0.7452716544633669,3.8599067676448637,2.0391347095418917,1.9481343856971967,1220.4045823987904,626.4478422837515,1137.465287450162,24.292634523076288,40.8496256505361,992.3450263329557,1.6815642458100555,upper,41.33420255276943,24.126052806347744,113.16428314861125,False,12.929293977622509,minicircle.spm,parent_dir/child_dir_1
1,400.2920881110063,93.12806953798491,0.7643280440003184,21.96855256891761,13.999840272706289,14.792429582135073,0.7454383438304222,3.179159623594896,2.131409254934984,1.984183560332176,1263.808882457969,636.9415147489642,1186.0290274635886,27.45053797699605,39.09250720831134,1073.1103537377423,1.4241071428571428,upper,39.14797897350707,27.45053797699605,115.66050824497863,False,21.47066537827239,minicircle.spm,parent_dir/child_dir_1
2,218.26129518646468,172.6865624592939,8.312817001643236,28.4840908864891,17.761201297555598,16.374812395420516,0.7458769816768294,3.0837823469355783,1.965905358311789,1.8574106218419255,1152.692145851135,620.5909088147954,1618.9540263772524,24.48642216522931,54.1892216956022,1326.9001592437185,2.2130314232902033,upper,54.20767776942792,24.48642216522931,90.27296454772564,True,0.0,minicircle.spm,parent_dir/child_dir_1
Expand All @@ -19,4 +19,4 @@ molecule_number,centre_x,centre_y,radius_min,radius_max,radius_mean,radius_media
4,460.81528892859257,458.61529179058647,8.335567737084954,28.018485456887074,16.951505396530333,16.480914927347325,0.746481994571252,3.1528255105319674,2.161743197106236,1.9909999302468957,1282.72695409673,644.2626815851593,1616.513637431854,21.77853967542204,52.651771534465524,1146.678695344614,2.417598806860552,upper,53.354603407833075,21.77853967542204,69.81455411588722,True,0.0,minicircle.spm,parent_dir/child_dir_3/child_dir_4
5,419.7119810116665,456.33581467682035,10.647572346135227,24.867679326046783,18.230207187178145,18.820514568860247,0.7460540784349388,3.0467196263335836,2.133687174437284,1.9766412306722034,1370.9164026533533,693.5585382822055,1625.2990376352882,35.0742080078125,42.9782548828125,1507.4282515725488,1.2253521126760563,upper,45.96616961337843,33.74603230760295,101.81981258840132,True,0.0,minicircle.spm,parent_dir/child_dir_3/child_dir_4
6,90.92468996474322,469.0147359066234,4.419162608876172,25.241879915828346,16.11511146882466,16.417253423698206,0.7465371311191019,2.9364197117159456,2.109230218842712,1.9584847703176893,1300.0143666342835,663.7857931483459,1600.1630314976853,21.15084957523595,49.01725079602158,1036.7564981782668,2.317507418397626,upper,49.08311284848621,21.150849575235945,104.65035017927731,False,14.128829241433397,minicircle.spm,parent_dir/child_dir_3/child_dir_4
7,19.82883778582696,501.3507324051849,2.0456794027695278,25.469796537814755,16.062271878609476,16.64728658159786,0.7453685468075075,2.9898919464281057,2.1262758767778243,1.9713545047879897,1210.4153300219657,614.0018586622199,1366.617809423065,20.435629724999576,50.04784121900791,1022.7591516872169,2.4490481522956324,upper,50.15772087935355,20.435629724999572,102.53757918370543,False,20.559070147820183,minicircle.spm,parent_dir/child_dir_3/child_dir_4
7,19.82883778582696,501.3507324051849,2.0456794027695278,25.469796537814755,16.062271878609476,16.64728658159786,0.7453685468075075,2.9898919464281057,2.1262758767778243,1.9713545047879897,1210.4153300219657,614.0018586622199,1366.617809423065,20.435629724999576,50.04784121900791,1022.7591516872169,2.4490481522956324,upper,50.15772087935355,20.435629724999572,102.53757918370543,False,20.559070147820183,minicircle.spm,parent_dir/child_dir_3/child_dir_4
4 changes: 2 additions & 2 deletions tests/resources/toposum_all_statistics_single_directory.csv
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
molecule_number,centre_x,centre_y,radius_min,radius_max,radius_mean,radius_median,height_min,height_max,height_median,height_mean,volume,area,area_cartesian_bbox,smallest_bounding_width,smallest_bounding_length,smallest_bounding_area,aspect_ratio,threshold,max_feret,min_feret,contour_lengths,circular,end_to_end_distance,image,basename
grain_number,centre_x,centre_y,radius_min,radius_max,radius_mean,radius_median,height_min,height_max,height_median,height_mean,volume,area,area_cartesian_bbox,smallest_bounding_width,smallest_bounding_length,smallest_bounding_area,aspect_ratio,threshold,max_feret,min_feret,contour_lengths,circular,end_to_end_distance,image,basename
0,18.72534751358894,96.56689212959863,5.918489103781348,20.866157242818016,15.491706069705224,16.218426875142722,0.7452716544633669,3.8599067676448637,2.0391347095418917,1.9481343856971967,1220.4045823987904,626.4478422837515,1137.465287450162,24.292634523076288,40.8496256505361,992.3450263329557,1.6815642458100555,upper,41.33420255276943,24.126052806347744,113.16428314861125,False,12.929293977622509,minicircle.spm,parent_dir/child_dir_1
1,400.2920881110063,93.12806953798491,0.7643280440003184,21.96855256891761,13.999840272706289,14.792429582135073,0.7454383438304222,3.179159623594896,2.131409254934984,1.984183560332176,1263.808882457969,636.9415147489642,1186.0290274635886,27.45053797699605,39.09250720831134,1073.1103537377423,1.4241071428571428,upper,39.14797897350707,27.45053797699605,115.66050824497863,False,21.47066537827239,minicircle.spm,parent_dir/child_dir_1
2,218.26129518646468,172.6865624592939,8.312817001643236,28.4840908864891,17.761201297555598,16.374812395420516,0.7458769816768294,3.0837823469355783,1.965905358311789,1.8574106218419255,1152.692145851135,620.5909088147954,1618.9540263772524,24.48642216522931,54.1892216956022,1326.9001592437185,2.2130314232902033,upper,54.20767776942792,24.48642216522931,90.27296454772564,True,0.0,minicircle.spm,parent_dir/child_dir_1
3,355.54577234597997,205.39047003798598,3.831028441204673,26.063358292346482,15.634060432623288,16.31508035180588,0.7465813555290715,3.0963156353164862,2.1071407754684124,1.9808092358135478,1227.8220203536634,619.858792131176,1715.837467509566,18.33396629476008,49.71584972217502,911.4887131217141,2.7116800000000003,upper,49.779221921977296,18.333966294760085,94.20205530696366,False,29.246475434864198,minicircle.spm,parent_dir/child_dir_1
4,301.3416206102413,211.61756844725574,10.256489210615582,25.29455404248287,18.031900182444964,18.452561215234933,0.7452246436395157,2.997930729110457,1.8882842984021164,1.828628948414764,1324.0432939099048,724.0634000996846,1739.50924027993,33.10304661739775,44.076669063566506,1459.0720307508554,1.3314988669472319,upper,44.12416912122865,33.103046617397744,95.99042452161821,True,0.0,minicircle.spm,parent_dir/child_dir_1
5,432.9621809446219,215.2885822162342,2.880805118744918,23.596602791673394,15.320545978528381,15.933506166242601,0.7464484840406989,3.239939630220636,2.1660416821287702,2.0180826496579956,1247.971329684413,618.394558763937,1273.8830294979284,20.832593986797836,45.91657123529629,956.5612858108079,2.2040736388562476,upper,46.20710214165134,20.832593986797836,92.98492331644334,False,22.535415228865716,minicircle.spm,parent_dir/child_dir_1
6,194.45265142078358,231.24213759821308,9.00198665937126,23.654796974035794,17.933819108767963,18.10868586793719,0.7477364070983863,2.8897474559397125,2.0249157366744233,1.9043852670799726,1304.0718754493323,684.7731380787716,1559.408536109533,29.68436723824748,45.552010816510666,1352.182617517924,1.5345454545454542,upper,46.14368163530131,29.68436723824747,97.49636171317444,True,0.0,minicircle.spm,parent_dir/child_dir_1
7,390.2341825538701,273.9228450843562,2.083432106712806,25.56974100134752,16.749517580670158,18.505450010697373,0.7453047159088426,3.0346042893430605,2.2166123872313888,2.035879305318322,1448.2703377768753,711.3733775836133,1792.9537581841535,22.849351267189622,49.22624872637181,1124.787848714915,2.1543827722171667,upper,49.462004789149276,22.849351267189622,113.36677817432933,False,22.627275592624265,minicircle.spm,parent_dir/child_dir_1
7,390.2341825538701,273.9228450843562,2.083432106712806,25.56974100134752,16.749517580670158,18.505450010697373,0.7453047159088426,3.0346042893430605,2.2166123872313888,2.035879305318322,1448.2703377768753,711.3733775836133,1792.9537581841535,22.849351267189622,49.22624872637181,1124.787848714915,2.1543827722171667,upper,49.462004789149276,22.849351267189622,113.36677817432933,False,22.627275592624265,minicircle.spm,parent_dir/child_dir_1
4 changes: 2 additions & 2 deletions tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_melt_data():
df_to_melt = {
"Image": ["im1", "im1", "im1", "im2", "im2", "im3", "im3"],
"threshold": ["above", "above", "above", "below", "below", "above", "above"],
"molecule_number": [0, 1, 2, 0, 1, 0, 1],
"grain_number": [0, 1, 2, 0, 1, 0, 1],
"basename": ["super/sub1", "super/sub1", "super/sub1", "super/sub1", "super/sub1", "super/sub2", "super/sub2"],
"area": [10, 20, 30, 40, 50, 60, 70],
}
Expand All @@ -33,7 +33,7 @@ def test_melt_data():
melted_data = TopoSum.melt_data(df=df_to_melt, stat_to_summarize="area", var_to_label={"area": "AREA"})

expected = {
"molecule_number": [0, 1, 2, 0, 1, 0, 1],
"grain_number": [0, 1, 2, 0, 1, 0, 1],
"basename": ["super/sub1", "super/sub1", "super/sub1", "super/sub1", "super/sub1", "super/sub2", "super/sub2"],
"variable": ["AREA", "AREA", "AREA", "AREA", "AREA", "AREA", "AREA"],
"value": [10, 20, 30, 40, 50, 60, 70],
Expand Down
2 changes: 1 addition & 1 deletion topostats/summary_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ csv_file: ./all_statistics.csv
savefig_format: png
pickle_plots: True # Save plots to a Python pickle
var_to_label: null # Optional YAML file that maps variable names to labels, uses topostats/var_to_label.yaml if null
molecule_id: molecule_number
molecule_id: grain_number
image_id: image
# If both hist and kde are True they are plotted on the same graph, if you only want one you MUST set the other to False
kde: True
Expand Down
4 changes: 2 additions & 2 deletions topostats/tracing/disordered_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,8 @@ def trace_image_disordered( # pylint: disable=too-many-arguments,too-many-local
grainstats_additions[cropped_image_index] = {
"image": filename,
"grain_number": cropped_image_index,
"grain_endpoints": any(conv_pruned_skeleton[conv_pruned_skeleton == 2]),
"grain_crossings": any(conv_pruned_skeleton[conv_pruned_skeleton == 3]),
"grain_endpoints": (conv_pruned_skeleton == 2).sum(),
"grain_junctions": (conv_pruned_skeleton == 3).sum(),
"total_branch_lengths": skan_df["branch-distance"].sum(),
}

Expand Down
2 changes: 1 addition & 1 deletion topostats/tracing/dnatracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1606,7 +1606,7 @@ def pad_bounding_box(array_shape: tuple, bounding_box: list, pad_width: int) ->
# pbar.update()
# try:
# results = pd.DataFrame.from_dict(results, orient="index")
# results.index.name = "molecule_number"
# results.index.name = "grain_number"
# except ValueError as error:
# LOGGER.error("No grains found in any images, consider adjusting your thresholds.")
# LOGGER.error(error)
Expand Down
4 changes: 2 additions & 2 deletions topostats/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
ALL_STATISTICS_COLUMNS = (
"image",
"basename",
"molecule_number",
"grain_number",
"area",
"area_cartesian_bbox",
"aspect_ratio",
Expand Down Expand Up @@ -265,7 +265,7 @@ def get_thresholds( # noqa: C901
return thresholds


def create_empty_dataframe(columns: set = ALL_STATISTICS_COLUMNS, index: str = "molecule_number") -> pd.DataFrame:
def create_empty_dataframe(columns: set = ALL_STATISTICS_COLUMNS, index: str = "grain_number") -> pd.DataFrame:
"""
Create an empty data frame for returning when no results are found.
Expand Down

0 comments on commit a98c65e

Please sign in to comment.