diff --git a/Tests/__init__.py b/Tests/__init__.py index 9e94e63..956e0a8 100644 --- a/Tests/__init__.py +++ b/Tests/__init__.py @@ -1,3 +1,29 @@ +import logging import os +import warnings -TEST_DIRECTORY = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) \ No newline at end of file +TEST_DIRECTORY = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + +PROJECT_DIRECTORY = os.getenv('PROJECT_DIR', os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + +# get the logger instance +logger = logging.getLogger("pyVertexModel") + +formatter = logging.Formatter( + "%(levelname)s [%(asctime)s] pyVertexModel: %(message)s", + datefmt="%Y/%m/%d %I:%M:%S %p", +) +console_handler = logging.StreamHandler() +console_handler.setFormatter(formatter) +logger.addHandler(console_handler) + +logger.setLevel(logging.DEBUG) +logger.propagate = False + + +# Function to handle warnings +def warning_handler(message, category, filename, lineno, file=None, line=None): + logger.warning(f'{filename}:{lineno}: {category.__name__}: {message}') + +# Set the warnings' showwarning function to the handler +warnings.showwarning = warning_handler \ No newline at end of file diff --git a/Tests/test_vertexModel.py b/Tests/test_vertexModel.py index 24fe329..9c6622f 100644 --- a/Tests/test_vertexModel.py +++ b/Tests/test_vertexModel.py @@ -12,9 +12,8 @@ from src.pyVertexModel.algorithm.vertexModel import create_tetrahedra from src.pyVertexModel.algorithm.vertexModelBubbles import build_topo, SeedWithBoundingBox, generate_first_ghost_nodes, \ delaunay_compute_entities, VertexModelBubbles -from src.pyVertexModel.algorithm.vertexModelVoronoiFromTimeImage import build_triplets_of_neighs, calculate_neighbours, \ - VertexModelVoronoiFromTimeImage, add_tetrahedral_intercalations, build_2d_voronoi_from_image, \ - populate_vertices_info, calculate_vertices, get_four_fold_vertices, divide_quartets_neighbours, process_image +from src.pyVertexModel.algorithm.vertexModelVoronoiFromTimeImage import build_triplets_of_neighs, \ + VertexModelVoronoiFromTimeImage, add_tetrahedral_intercalations, get_four_fold_vertices, divide_quartets_neighbours, process_image from src.pyVertexModel.geometry.degreesOfFreedom import DegreesOfFreedom from src.pyVertexModel.util.utils import save_backup_vars @@ -239,21 +238,6 @@ def test_build_triplets_of_neighs(self): # Check if triplets of neighbours are correct assert_matrix(triplets_of_neighs_test, mat_info['neighboursVertices']) - def test_calculate_neighbours(self): - """ - Test the calculate_neighbours function. - :return: - """ - # Load data - _, _, mat_info = load_data('calculate_neighbours_wingdisc.mat') - - neighbours_test = calculate_neighbours(mat_info['labelledImg'], 2) - - neighbours_expected = [np.concatenate(neighbours[0]) for neighbours in mat_info['imgNeighbours']] - - # Check if the cells are initialized correctly - np.testing.assert_equal(neighbours_test[1:], neighbours_expected) - def test_obtain_initial_x_and_tetrahedra(self): """ Test the obtain_initial_x_and_tetrahedra function. @@ -266,11 +250,11 @@ def test_obtain_initial_x_and_tetrahedra(self): vModel_test = VertexModelVoronoiFromTimeImage(set_test) file_name = 'LblImg_imageSequence.mat' - test_dir = 'Tests/data/%s' % file_name + test_dir = 'Tests/Tests_data/%s' % file_name if exists(test_dir): Twg_test, X_test = vModel_test.obtain_initial_x_and_tetrahedra(test_dir) else: - Twg_test, X_test = vModel_test.obtain_initial_x_and_tetrahedra('data/%s' % file_name) + Twg_test, X_test = vModel_test.obtain_initial_x_and_tetrahedra('Tests_data/%s' % file_name) # Check if the test and expected are the same assert_matrix(Twg_test, mat_info_expected['Twg'] - 1) @@ -326,83 +310,6 @@ def test_add_tetrahedra_intercalations(self): # Check if the test and expected are the same assert_matrix(Twg, mat_info_expected['Twg']) - def test_build_2d_voronoi_from_image(self): - """ - Test the build_2d_voronoi_from_image function. - :return: - """ - # Load data - _, _, mat_info = load_data('build_2d_voronoi_from_image_wingdisc.mat') - labelled_img = mat_info['labelledImg'] - watershed_img = mat_info['watershedImg'] - main_cells = mat_info['mainCells'][0] - - # Test if initialize geometry function does not change anything - (triangles_connectivity, neighbours_network, cell_edges, vertices_location, border_cells, - border_of_border_cells_and_main_cells) = build_2d_voronoi_from_image(labelled_img, watershed_img, main_cells) - - # Load expected - _, _, mat_info_expected = load_data('build_2d_voronoi_from_image_wingdisc_expected.mat') - - # Assert - np.testing.assert_equal(triangles_connectivity, mat_info_expected['trianglesConnectivity']) - np.testing.assert_equal(neighbours_network, mat_info_expected['neighboursNetwork']) - np.testing.assert_equal([cell_edge+1 for cell_edge in cell_edges if cell_edge is not None], [cell_edge[0] for cell_edge in mat_info_expected['cellEdges']]) - np.testing.assert_equal(border_cells, np.concatenate(mat_info_expected['borderCells'])) - np.testing.assert_equal(border_of_border_cells_and_main_cells, mat_info_expected['borderOfborderCellsAndMainCells'][0]) - - def test_populate_vertices_info(self): - """ - Test the populate_vertices_info function. - :return: - """ - # Load data - _, _, mat_info = load_data('populate_vertices_info_wingdisc.mat') - - # Load data - border_cells_and_main_cells = [border_cell[0] for border_cell in mat_info['borderCellsAndMainCells']] - labelled_img = mat_info['labelledImg'] - img_neighbours_all = [np.concatenate(neighbours[0]) for neighbours in mat_info['imgNeighbours']] - main_cells = mat_info['mainCells'][0] - ratio = 2 - - img_neighbours_all.insert(0, None) - - vertices_info_test = populate_vertices_info(border_cells_and_main_cells, img_neighbours_all, labelled_img, - main_cells, ratio) - - vertices_info_expected_per_cell = [np.concatenate(vertices[0]) for vertices in mat_info['verticesInfo']['PerCell'][0][0] if len(vertices[0][0]) > 0] - vertices_info_expected_edges = [np.concatenate(vertices[0]) for vertices in mat_info['verticesInfo']['edges'][0][0] if len(vertices[0][0]) > 0] - - # Assert - np.testing.assert_equal([vertices + 1 for vertices in vertices_info_test['PerCell'] if vertices is not None], vertices_info_expected_per_cell) - np.testing.assert_equal([np.concatenate(edges) + 1 for edges in vertices_info_test['edges'] if edges is not None], vertices_info_expected_edges) - np.testing.assert_equal(vertices_info_test['connectedCells'], mat_info['verticesInfo']['connectedCells'][0][0]) - - def test_calculate_vertices(self): - """ - Test the calculate_vertices function. - :return: - """ - # Load data - _, _, mat_info = load_data('calculate_vertices_wingdisc.mat') - - # Load data - labelled_img = mat_info['labelledImg'] - img_neighbours_all = [np.concatenate(neighbours[0]) for neighbours in mat_info['neighbours']] - ratio = 2 - - img_neighbours_all.insert(0, None) - - # Test if initialize geometry function does not change anything - vertices_info_test = calculate_vertices(labelled_img, img_neighbours_all, ratio) - - # Load expected - _, _, mat_info_expected = load_data('calculate_vertices_wingdisc_expected.mat') - - # Assert - assert_matrix(vertices_info_test['connectedCells'], mat_info_expected['verticesInfo']['connectedCells'][0][0]) - def test_get_four_fold_vertices(self): """ Test the get_four_fold_vertices function. @@ -453,11 +360,11 @@ def test_process_image(self): """ # Process image file_name = 'LblImg_imageSequence.mat' - test_dir = 'Tests/data/%s' % file_name + test_dir = 'Tests/Tests_data/%s' % file_name if exists(test_dir): _, imgStackLabelled_test = process_image(test_dir) else: - _, imgStackLabelled_test = process_image('data/%s' % file_name) + _, imgStackLabelled_test = process_image('Tests_data/%s' % file_name) # Load expected _, _, mat_info_expected = load_data('process_image_wingdisc_expected.mat') @@ -476,11 +383,11 @@ def test_initialize_voronoi_from_time_image(self): # Test if initialize geometry function does not change anything vModel_test = VertexModelVoronoiFromTimeImage(set_test) file_name = 'voronoi_40cells.pkl' - test_dir = TEST_DIRECTORY + '/Tests/data/%s' % file_name + test_dir = TEST_DIRECTORY + '/Tests/Tests_data/%s' % file_name if exists(test_dir): vModel_test.set.initial_filename_state = test_dir else: - vModel_test.set.initial_filename_state = 'data/%s' % file_name + vModel_test.set.initial_filename_state = 'Tests_data/%s' % file_name vModel_test.initialize() @@ -496,3 +403,63 @@ def test_initialize_voronoi_from_time_image(self): assert_array1D(g_test, mat_info['g']) assert_matrix(K_test, mat_info['K']) + def test_weird_bug_should_not_happen(self): + """ + Test for a weird bug that should not happen. + :return: + """ + # Load data + vModel_test = load_data('vertices_going_wild.pkl') + + # Run for 20 iterations. dt should not decrease to 1e-1 + vModel_test.set.tend = vModel_test.t + 20 * vModel_test.set.dt0 + + # Update tolerance + vModel_test.set.dt_tolerance = 0.25 + + # Run the model + vModel_test.iterate_over_time() + + # Check if it did not converge + self.assertFalse(vModel_test.didNotConverge) + + def test_vertices_shouldnt_be_going_wild(self): + """ + Test for another weird bug that should not happen. + :return: + """ + # Load data + vModel_test = load_data('vertices_going_wild_2.pkl') + + # Run for 10 iterations. dt should not decrease to 1e-1 + vModel_test.set.tend = vModel_test.t + 20 * vModel_test.set.dt0 + + # Update tolerance + vModel_test.set.dt_tolerance = 0.25 + + # Run the model + vModel_test.iterate_over_time() + + # Check if it did not converge + self.assertFalse(vModel_test.didNotConverge) + + def test_vertices_shouldnt_be_going_wild_3(self): + """ + Test for another weird bug that should not happen. + :return: + """ + # Load data + vModel_test = load_data('vertices_going_wild_3.pkl') + + # Run for 10 iterations. dt should not decrease to 1e-1 + vModel_test.set.tend = vModel_test.t + 20 * vModel_test.set.dt0 + + # Update tolerance + vModel_test.set.dt_tolerance = 0.25 + + # Run the model + vModel_test.iterate_over_time() + + # Check if it did not converge + self.assertFalse(vModel_test.didNotConverge) + diff --git a/Tests/tests.py b/Tests/tests.py index bc6b2f8..656c3b2 100644 --- a/Tests/tests.py +++ b/Tests/tests.py @@ -1,36 +1,59 @@ +import logging +import os import unittest +import warnings + import scipy.io import numpy as np from os.path import exists, abspath +from src.pyVertexModel.algorithm.vertexModelVoronoiFromTimeImage import VertexModelVoronoiFromTimeImage from src.pyVertexModel.geometry.geo import Geo from src.pyVertexModel.parameters.set import Set -from src.pyVertexModel.Kg import kg_functions +from src.pyVertexModel.util.utils import load_state def load_data(file_name, return_geo=True): - test_dir = abspath('Tests/data/%s' % file_name) - if exists(test_dir): - mat_info = scipy.io.loadmat(test_dir) - else: - mat_info = scipy.io.loadmat('data/%s' % file_name) + test_dir = abspath('Tests/Tests_data/%s' % file_name) + if file_name.endswith('.mat'): + if exists(test_dir): + mat_info = scipy.io.loadmat(test_dir) + else: + mat_info = scipy.io.loadmat('Tests_data/%s' % file_name) - if return_geo: - if 'Geo' in mat_info.keys(): - geo_test = Geo(mat_info['Geo']) + if return_geo: + if 'Geo' in mat_info.keys(): + geo_test = Geo(mat_info['Geo']) + else: + geo_test = None + + if 'Set' in mat_info.keys(): + set_test = Set(mat_info['Set']) + if set_test.OutputFolder.__eq__(b'') or set_test.OutputFolder is None: + set_test.OutputFolder = '../Result/Test' + else: + set_test = None else: geo_test = None + set_test = None - if 'Set' in mat_info.keys(): - set_test = Set(mat_info['Set']) - if set_test.OutputFolder.__eq__(b'') or set_test.OutputFolder is None: - set_test.OutputFolder = '../Result/Test' + return geo_test, set_test, mat_info + elif file_name.endswith('.pkl'): + v_model = VertexModelVoronoiFromTimeImage(create_output_folder=False) + if exists(test_dir): + load_state(v_model, test_dir) else: - set_test = None + load_state(v_model, 'Tests_data/%s' % file_name) + + # Set parameters to avoid file output during tests + v_model.set.OutputFolder = None + v_model.set.export_images = False + v_model.set.VTK = False + + return v_model else: - geo_test = None - set_test = None + raise FileNotFoundError('File %s not found' % file_name) + - return geo_test, set_test, mat_info def assert_matrix(k_expected, k): diff --git a/Tests_data/Geo_3x3_dofs_expected.mat b/Tests_data/Geo_3x3_dofs_expected.mat new file mode 100644 index 0000000..693213c Binary files /dev/null and b/Tests_data/Geo_3x3_dofs_expected.mat differ diff --git a/Tests_data/Geo_var_3x3_stretch.mat b/Tests_data/Geo_var_3x3_stretch.mat new file mode 100644 index 0000000..425a791 Binary files /dev/null and b/Tests_data/Geo_var_3x3_stretch.mat differ diff --git a/Tests_data/Geo_var_3x3_stretch_Iter6_Kgs_expectedResults.mat b/Tests_data/Geo_var_3x3_stretch_Iter6_Kgs_expectedResults.mat new file mode 100644 index 0000000..1806da6 Binary files /dev/null and b/Tests_data/Geo_var_3x3_stretch_Iter6_Kgs_expectedResults.mat differ diff --git a/Tests_data/Geo_var_3x3_stretch_Iter6_expectedResults.mat b/Tests_data/Geo_var_3x3_stretch_Iter6_expectedResults.mat new file mode 100644 index 0000000..9bfb41b Binary files /dev/null and b/Tests_data/Geo_var_3x3_stretch_Iter6_expectedResults.mat differ diff --git a/Tests_data/Geo_var_3x3_stretch_expectedResults.mat b/Tests_data/Geo_var_3x3_stretch_expectedResults.mat new file mode 100644 index 0000000..f978aa2 Binary files /dev/null and b/Tests_data/Geo_var_3x3_stretch_expectedResults.mat differ diff --git a/Tests_data/Geo_var_cyst.mat b/Tests_data/Geo_var_cyst.mat new file mode 100644 index 0000000..cb003a5 Binary files /dev/null and b/Tests_data/Geo_var_cyst.mat differ diff --git a/Tests_data/Geo_var_cyst_expectedResults_cell1.mat b/Tests_data/Geo_var_cyst_expectedResults_cell1.mat new file mode 100644 index 0000000..2d3d7a7 Binary files /dev/null and b/Tests_data/Geo_var_cyst_expectedResults_cell1.mat differ diff --git a/Tests_data/LblImg_imageSequence.mat b/Tests_data/LblImg_imageSequence.mat new file mode 100644 index 0000000..d266e0b Binary files /dev/null and b/Tests_data/LblImg_imageSequence.mat differ diff --git a/Tests_data/Newton_Raphson_3x3_stretch.mat b/Tests_data/Newton_Raphson_3x3_stretch.mat new file mode 100644 index 0000000..9e43d96 Binary files /dev/null and b/Tests_data/Newton_Raphson_3x3_stretch.mat differ diff --git a/Tests_data/Newton_Raphson_3x3_stretch_expected.mat b/Tests_data/Newton_Raphson_3x3_stretch_expected.mat new file mode 100644 index 0000000..2a5702e Binary files /dev/null and b/Tests_data/Newton_Raphson_3x3_stretch_expected.mat differ diff --git a/Tests_data/Newton_Raphson_Iteration_3x3_stretch_expected.mat b/Tests_data/Newton_Raphson_Iteration_3x3_stretch_expected.mat new file mode 100644 index 0000000..65f1048 Binary files /dev/null and b/Tests_data/Newton_Raphson_Iteration_3x3_stretch_expected.mat differ diff --git a/Tests_data/Newton_Raphson_Iteration_wingdisc.mat b/Tests_data/Newton_Raphson_Iteration_wingdisc.mat new file mode 100644 index 0000000..e8e1006 Binary files /dev/null and b/Tests_data/Newton_Raphson_Iteration_wingdisc.mat differ diff --git a/Tests_data/Newton_Raphson_Iteration_wingdisc_expected.mat b/Tests_data/Newton_Raphson_Iteration_wingdisc_expected.mat new file mode 100644 index 0000000..fe3efc4 Binary files /dev/null and b/Tests_data/Newton_Raphson_Iteration_wingdisc_expected.mat differ diff --git a/Tests_data/Newton_Raphson_ml_divide_3x3_stretch_expected.mat b/Tests_data/Newton_Raphson_ml_divide_3x3_stretch_expected.mat new file mode 100644 index 0000000..31ebccc Binary files /dev/null and b/Tests_data/Newton_Raphson_ml_divide_3x3_stretch_expected.mat differ diff --git a/Tests_data/Newton_Raphson_wingdisc_expected.mat b/Tests_data/Newton_Raphson_wingdisc_expected.mat new file mode 100644 index 0000000..843698b Binary files /dev/null and b/Tests_data/Newton_Raphson_wingdisc_expected.mat differ diff --git a/Tests_data/add_and_rebuild_cells_wingdisc.mat b/Tests_data/add_and_rebuild_cells_wingdisc.mat new file mode 100644 index 0000000..9076917 Binary files /dev/null and b/Tests_data/add_and_rebuild_cells_wingdisc.mat differ diff --git a/Tests_data/add_and_rebuild_cells_wingdisc_expected.mat b/Tests_data/add_and_rebuild_cells_wingdisc_expected.mat new file mode 100644 index 0000000..aa37323 Binary files /dev/null and b/Tests_data/add_and_rebuild_cells_wingdisc_expected.mat differ diff --git a/Tests_data/add_tetrahedra_from_intercalations_wingdisc.mat b/Tests_data/add_tetrahedra_from_intercalations_wingdisc.mat new file mode 100644 index 0000000..5088899 Binary files /dev/null and b/Tests_data/add_tetrahedra_from_intercalations_wingdisc.mat differ diff --git a/Tests_data/add_tetrahedra_from_intercalations_wingdisc_expected.mat b/Tests_data/add_tetrahedra_from_intercalations_wingdisc_expected.mat new file mode 100644 index 0000000..3130f49 Binary files /dev/null and b/Tests_data/add_tetrahedra_from_intercalations_wingdisc_expected.mat differ diff --git a/Tests_data/add_tetrahedra_wingdisc.mat b/Tests_data/add_tetrahedra_wingdisc.mat new file mode 100644 index 0000000..1d535a1 Binary files /dev/null and b/Tests_data/add_tetrahedra_wingdisc.mat differ diff --git a/Tests_data/add_tetrahedra_wingdisc_expected.mat b/Tests_data/add_tetrahedra_wingdisc_expected.mat new file mode 100644 index 0000000..ef3bfae Binary files /dev/null and b/Tests_data/add_tetrahedra_wingdisc_expected.mat differ diff --git a/Tests_data/build_2d_voronoi_from_image_wingdisc.mat b/Tests_data/build_2d_voronoi_from_image_wingdisc.mat new file mode 100644 index 0000000..d13b311 Binary files /dev/null and b/Tests_data/build_2d_voronoi_from_image_wingdisc.mat differ diff --git a/Tests_data/build_2d_voronoi_from_image_wingdisc_expected.mat b/Tests_data/build_2d_voronoi_from_image_wingdisc_expected.mat new file mode 100644 index 0000000..9ae3934 Binary files /dev/null and b/Tests_data/build_2d_voronoi_from_image_wingdisc_expected.mat differ diff --git a/Tests_data/build_cells_cyst.mat b/Tests_data/build_cells_cyst.mat new file mode 100644 index 0000000..a586c82 Binary files /dev/null and b/Tests_data/build_cells_cyst.mat differ diff --git a/Tests_data/build_cells_cyst_expected.mat b/Tests_data/build_cells_cyst_expected.mat new file mode 100644 index 0000000..537c392 Binary files /dev/null and b/Tests_data/build_cells_cyst_expected.mat differ diff --git a/Tests_data/build_face_cyst.mat b/Tests_data/build_face_cyst.mat new file mode 100644 index 0000000..cd2d459 Binary files /dev/null and b/Tests_data/build_face_cyst.mat differ diff --git a/Tests_data/build_face_cyst_expected.mat b/Tests_data/build_face_cyst_expected.mat new file mode 100644 index 0000000..1fe9702 Binary files /dev/null and b/Tests_data/build_face_cyst_expected.mat differ diff --git a/Tests_data/build_globald_ids_wingdisc_expected.mat b/Tests_data/build_globald_ids_wingdisc_expected.mat new file mode 100644 index 0000000..563eea8 Binary files /dev/null and b/Tests_data/build_globald_ids_wingdisc_expected.mat differ diff --git a/Tests_data/build_topo_expected.mat b/Tests_data/build_topo_expected.mat new file mode 100644 index 0000000..8d2d9d3 Binary files /dev/null and b/Tests_data/build_topo_expected.mat differ diff --git a/Tests_data/build_triplets_wingdisc.mat b/Tests_data/build_triplets_wingdisc.mat new file mode 100644 index 0000000..3d57930 Binary files /dev/null and b/Tests_data/build_triplets_wingdisc.mat differ diff --git a/Tests_data/build_x_from_y_wingdisc.mat b/Tests_data/build_x_from_y_wingdisc.mat new file mode 100644 index 0000000..3cb18c3 Binary files /dev/null and b/Tests_data/build_x_from_y_wingdisc.mat differ diff --git a/Tests_data/build_x_from_y_wingdisc_expected.mat b/Tests_data/build_x_from_y_wingdisc_expected.mat new file mode 100644 index 0000000..8da1083 Binary files /dev/null and b/Tests_data/build_x_from_y_wingdisc_expected.mat differ diff --git a/Tests_data/calculate_neighbours_wingdisc.mat b/Tests_data/calculate_neighbours_wingdisc.mat new file mode 100644 index 0000000..3118094 Binary files /dev/null and b/Tests_data/calculate_neighbours_wingdisc.mat differ diff --git a/Tests_data/calculate_vertices_wingdisc.mat b/Tests_data/calculate_vertices_wingdisc.mat new file mode 100644 index 0000000..b381636 Binary files /dev/null and b/Tests_data/calculate_vertices_wingdisc.mat differ diff --git a/Tests_data/calculate_vertices_wingdisc_expected.mat b/Tests_data/calculate_vertices_wingdisc_expected.mat new file mode 100644 index 0000000..89fec45 Binary files /dev/null and b/Tests_data/calculate_vertices_wingdisc_expected.mat differ diff --git a/Tests_data/check_ys_and_faces_have_not_changed_wingdisc.mat b/Tests_data/check_ys_and_faces_have_not_changed_wingdisc.mat new file mode 100644 index 0000000..a183e1c Binary files /dev/null and b/Tests_data/check_ys_and_faces_have_not_changed_wingdisc.mat differ diff --git a/Tests_data/create_tetrahedra_wingdisc.mat b/Tests_data/create_tetrahedra_wingdisc.mat new file mode 100644 index 0000000..e008e42 Binary files /dev/null and b/Tests_data/create_tetrahedra_wingdisc.mat differ diff --git a/Tests_data/delaunay_compute_entities_expected.mat b/Tests_data/delaunay_compute_entities_expected.mat new file mode 100644 index 0000000..adc16d1 Binary files /dev/null and b/Tests_data/delaunay_compute_entities_expected.mat differ diff --git a/Tests_data/delaunay_compute_entities_input.mat b/Tests_data/delaunay_compute_entities_input.mat new file mode 100644 index 0000000..8e89eaa Binary files /dev/null and b/Tests_data/delaunay_compute_entities_input.mat differ diff --git a/Tests_data/delaunay_input_expected.mat b/Tests_data/delaunay_input_expected.mat new file mode 100644 index 0000000..13b9e4c Binary files /dev/null and b/Tests_data/delaunay_input_expected.mat differ diff --git a/Tests_data/delaunay_output_cyst.mat b/Tests_data/delaunay_output_cyst.mat new file mode 100644 index 0000000..821788d Binary files /dev/null and b/Tests_data/delaunay_output_cyst.mat differ diff --git a/Tests_data/flipNM_cyst.mat b/Tests_data/flipNM_cyst.mat new file mode 100644 index 0000000..157ff9f Binary files /dev/null and b/Tests_data/flipNM_cyst.mat differ diff --git a/Tests_data/flipNM_recursive_cyst.mat b/Tests_data/flipNM_recursive_cyst.mat new file mode 100644 index 0000000..a913e18 Binary files /dev/null and b/Tests_data/flipNM_recursive_cyst.mat differ diff --git a/Tests_data/flipNM_recursive_cyst_expected.mat b/Tests_data/flipNM_recursive_cyst_expected.mat new file mode 100644 index 0000000..1b32d31 Binary files /dev/null and b/Tests_data/flipNM_recursive_cyst_expected.mat differ diff --git a/Tests_data/generate_first_ghost_nodes_expected.mat b/Tests_data/generate_first_ghost_nodes_expected.mat new file mode 100644 index 0000000..2443999 Binary files /dev/null and b/Tests_data/generate_first_ghost_nodes_expected.mat differ diff --git a/Tests_data/geo_cyst_expected_extrapolatedYs.mat b/Tests_data/geo_cyst_expected_extrapolatedYs.mat new file mode 100644 index 0000000..c161c19 Binary files /dev/null and b/Tests_data/geo_cyst_expected_extrapolatedYs.mat differ diff --git a/Tests_data/get_dofs_remodel.mat b/Tests_data/get_dofs_remodel.mat new file mode 100644 index 0000000..e4ad92a Binary files /dev/null and b/Tests_data/get_dofs_remodel.mat differ diff --git a/Tests_data/get_four_fold_vertices_wingdisc.mat b/Tests_data/get_four_fold_vertices_wingdisc.mat new file mode 100644 index 0000000..9e425d5 Binary files /dev/null and b/Tests_data/get_four_fold_vertices_wingdisc.mat differ diff --git a/Tests_data/get_node_neighbours_per_domain_wingdisc.mat b/Tests_data/get_node_neighbours_per_domain_wingdisc.mat new file mode 100644 index 0000000..2c56fb6 Binary files /dev/null and b/Tests_data/get_node_neighbours_per_domain_wingdisc.mat differ diff --git a/Tests_data/initialize_cells_cyst_expected.mat b/Tests_data/initialize_cells_cyst_expected.mat new file mode 100644 index 0000000..0c8bbd3 Binary files /dev/null and b/Tests_data/initialize_cells_cyst_expected.mat differ diff --git a/Tests_data/initialize_voronoi_wingdisc.mat b/Tests_data/initialize_voronoi_wingdisc.mat new file mode 100644 index 0000000..83eee65 Binary files /dev/null and b/Tests_data/initialize_voronoi_wingdisc.mat differ diff --git a/Tests_data/kK_test.mat b/Tests_data/kK_test.mat new file mode 100644 index 0000000..3401560 Binary files /dev/null and b/Tests_data/kK_test.mat differ diff --git a/Tests_data/line_search_cyst.mat b/Tests_data/line_search_cyst.mat new file mode 100644 index 0000000..febeea9 Binary files /dev/null and b/Tests_data/line_search_cyst.mat differ diff --git a/Tests_data/obtain_x_and_twg_wingdisc.mat b/Tests_data/obtain_x_and_twg_wingdisc.mat new file mode 100644 index 0000000..ffc4951 Binary files /dev/null and b/Tests_data/obtain_x_and_twg_wingdisc.mat differ diff --git a/Tests_data/populate_vertices_info_wingdisc.mat b/Tests_data/populate_vertices_info_wingdisc.mat new file mode 100644 index 0000000..48d032f Binary files /dev/null and b/Tests_data/populate_vertices_info_wingdisc.mat differ diff --git a/Tests_data/post_flip_wingdisc.mat b/Tests_data/post_flip_wingdisc.mat new file mode 100644 index 0000000..b038804 Binary files /dev/null and b/Tests_data/post_flip_wingdisc.mat differ diff --git a/Tests_data/post_flip_wingdisc_2.mat b/Tests_data/post_flip_wingdisc_2.mat new file mode 100644 index 0000000..078b96b Binary files /dev/null and b/Tests_data/post_flip_wingdisc_2.mat differ diff --git a/Tests_data/post_flip_wingdisc_2_expected.mat b/Tests_data/post_flip_wingdisc_2_expected.mat new file mode 100644 index 0000000..30cd404 Binary files /dev/null and b/Tests_data/post_flip_wingdisc_2_expected.mat differ diff --git a/Tests_data/post_flip_wingdisc_expected.mat b/Tests_data/post_flip_wingdisc_expected.mat new file mode 100644 index 0000000..18221b4 Binary files /dev/null and b/Tests_data/post_flip_wingdisc_expected.mat differ diff --git a/Tests_data/process_image_wingdisc_expected.mat b/Tests_data/process_image_wingdisc_expected.mat new file mode 100644 index 0000000..f919853 Binary files /dev/null and b/Tests_data/process_image_wingdisc_expected.mat differ diff --git a/Tests_data/rebuild_stretch_3x3_expected.mat b/Tests_data/rebuild_stretch_3x3_expected.mat new file mode 100644 index 0000000..774a663 Binary files /dev/null and b/Tests_data/rebuild_stretch_3x3_expected.mat differ diff --git a/Tests_data/rebuild_wingdisc_expected.mat b/Tests_data/rebuild_wingdisc_expected.mat new file mode 100644 index 0000000..d3aabb1 Binary files /dev/null and b/Tests_data/rebuild_wingdisc_expected.mat differ diff --git a/Tests_data/remodelling_intercalating_cells_wingdisc.mat b/Tests_data/remodelling_intercalating_cells_wingdisc.mat new file mode 100644 index 0000000..62caf47 Binary files /dev/null and b/Tests_data/remodelling_intercalating_cells_wingdisc.mat differ diff --git a/Tests_data/remodelling_intercalating_cells_wingdisc_expected.mat b/Tests_data/remodelling_intercalating_cells_wingdisc_expected.mat new file mode 100644 index 0000000..871cd8e Binary files /dev/null and b/Tests_data/remodelling_intercalating_cells_wingdisc_expected.mat differ diff --git a/Tests_data/remove_tetrahedra_wingdisc.mat b/Tests_data/remove_tetrahedra_wingdisc.mat new file mode 100644 index 0000000..74dd62f Binary files /dev/null and b/Tests_data/remove_tetrahedra_wingdisc.mat differ diff --git a/Tests_data/seed_with_bbox_expected.mat b/Tests_data/seed_with_bbox_expected.mat new file mode 100644 index 0000000..197709f Binary files /dev/null and b/Tests_data/seed_with_bbox_expected.mat differ diff --git a/Tests_data/seed_with_bbox_input.mat b/Tests_data/seed_with_bbox_input.mat new file mode 100644 index 0000000..4e7c12c Binary files /dev/null and b/Tests_data/seed_with_bbox_input.mat differ diff --git a/Tests_data/solve_remodelling_step_wingdisc.mat b/Tests_data/solve_remodelling_step_wingdisc.mat new file mode 100644 index 0000000..e7bc636 Binary files /dev/null and b/Tests_data/solve_remodelling_step_wingdisc.mat differ diff --git a/Tests_data/test_gkDet.mat b/Tests_data/test_gkDet.mat new file mode 100644 index 0000000..8367fff Binary files /dev/null and b/Tests_data/test_gkDet.mat differ diff --git a/Tests_data/vertices_going_wild.pkl b/Tests_data/vertices_going_wild.pkl new file mode 100644 index 0000000..bdf9f86 Binary files /dev/null and b/Tests_data/vertices_going_wild.pkl differ diff --git a/Tests_data/vertices_going_wild_2.pkl b/Tests_data/vertices_going_wild_2.pkl new file mode 100644 index 0000000..17715ed Binary files /dev/null and b/Tests_data/vertices_going_wild_2.pkl differ diff --git a/Tests_data/vertices_going_wild_3.pkl b/Tests_data/vertices_going_wild_3.pkl new file mode 100644 index 0000000..fd0cf75 Binary files /dev/null and b/Tests_data/vertices_going_wild_3.pkl differ diff --git a/Tests_data/voronoi_40cells.pkl b/Tests_data/voronoi_40cells.pkl new file mode 100644 index 0000000..885360a Binary files /dev/null and b/Tests_data/voronoi_40cells.pkl differ diff --git a/Tests_data/wing_disc_110.mat b/Tests_data/wing_disc_110.mat new file mode 100644 index 0000000..16fd31d Binary files /dev/null and b/Tests_data/wing_disc_110.mat differ diff --git a/Tests_data/wing_disc_150.mat b/Tests_data/wing_disc_150.mat new file mode 100644 index 0000000..a91d303 Binary files /dev/null and b/Tests_data/wing_disc_150.mat differ diff --git a/src/pyVertexModel/algorithm/vertexModel.py b/src/pyVertexModel/algorithm/vertexModel.py index 0eb1a43..be339f3 100644 --- a/src/pyVertexModel/algorithm/vertexModel.py +++ b/src/pyVertexModel/algorithm/vertexModel.py @@ -429,9 +429,10 @@ def iterate_over_time(self): updating measures, and checking for convergence. :return: """ - temp_dir = os.path.join(self.set.OutputFolder, 'images') - if not os.path.exists(temp_dir): - os.makedirs(temp_dir) + if self.set.OutputFolder is not None: + temp_dir = os.path.join(self.set.OutputFolder, 'images') + if not os.path.exists(temp_dir): + os.makedirs(temp_dir) if self.set.Substrate == 1: self.Dofs.GetDOFsSubstrate(self.geo, self.set) @@ -533,7 +534,7 @@ def iteration_did_not_converged(self): self.set.nu = 10 * self.set.nu0 else: if (self.set.iter >= self.set.MaxIter and - (self.set.dt / self.set.dt0) > 1e-6): + (self.set.dt / self.set.dt0) > self.set.dt_tolerance): self.set.MaxIter = self.set.MaxIter0 self.set.nu = self.set.nu0 self.set.dt = self.set.dt / 2 @@ -615,16 +616,17 @@ def save_v_model_state(self, file_name=None): :param file_name: :return: """ - # Create VTK files for the current state - self.geo.create_vtk_cell(self.set, self.numStep, 'Edges') - self.geo.create_vtk_cell(self.set, self.numStep, 'Cells') - temp_dir = os.path.join(self.set.OutputFolder, 'images') - screenshot(self, temp_dir) - # Save Data of the current step - if file_name is None: - save_state(self, os.path.join(self.set.OutputFolder, 'data_step_' + str(self.numStep) + '.pkl')) - else: - save_state(self, os.path.join(self.set.OutputFolder, file_name + '.pkl')) + if self.set.OutputFolder is not None: + # Create VTK files for the current state + self.geo.create_vtk_cell(self.set, self.numStep, 'Edges') + self.geo.create_vtk_cell(self.set, self.numStep, 'Cells') + temp_dir = os.path.join(self.set.OutputFolder, 'images') + screenshot(self, temp_dir) + # Save Data of the current step + if file_name is None: + save_state(self, os.path.join(self.set.OutputFolder, 'data_step_' + str(self.numStep) + '.pkl')) + else: + save_state(self, os.path.join(self.set.OutputFolder, file_name + '.pkl')) def reset_noisy_parameters(self): """ diff --git a/src/pyVertexModel/parameters/set.py b/src/pyVertexModel/parameters/set.py index 9062c11..560dd39 100644 --- a/src/pyVertexModel/parameters/set.py +++ b/src/pyVertexModel/parameters/set.py @@ -13,6 +13,7 @@ class Set: def __init__(self, mat_file=None): + self.dt_tolerance = 1e-6 self.min_3d_neighbours = None self.periodic_boundaries = True self.frozen_face_centres = False @@ -179,9 +180,8 @@ def check_for_non_used_parameters(self): if not self.brownian_motion: self.brownian_motion_scale = 0 - if self.implicit_method is False: + if not self.implicit_method: self.tol = self.nu - self.tol0 = self.nu/20 if self.Remodelling: self.RemodelStiffness = 0.9 @@ -309,7 +309,7 @@ def bubbles(self): self.check_for_non_used_parameters() def cyst(self): - mat_info = scipy.io.loadmat(os.path.join(PROJECT_DIRECTORY, 'Tests/data/Geo_var_cyst.mat')) + mat_info = scipy.io.loadmat(os.path.join(PROJECT_DIRECTORY, 'Tests_data/Geo_var_cyst.mat')) self.read_mat_file(mat_info['Set']) self.InputGeo = 'Bubbles_Cyst' self.CellHeight = 15 diff --git a/uv.lock b/uv.lock index db6673d..2a26a38 100644 --- a/uv.lock +++ b/uv.lock @@ -1093,6 +1093,7 @@ dependencies = [ { name = "scikit-learn", version = "1.8.0", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.11'" }, { name = "scipy", version = "1.15.3", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.11'" }, { name = "scipy", version = "1.17.0", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.11'" }, + { name = "seaborn" }, { name = "vtk" }, ] @@ -1108,6 +1109,7 @@ requires-dist = [ { name = "scikit-image" }, { name = "scikit-learn" }, { name = "scipy" }, + { name = "seaborn" }, { name = "vtk" }, ] @@ -1513,6 +1515,22 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/a3/bb/bbae36d06c0fd670e8373da67096cd57058b57c9bad7d92969b5e3b730af/scooby-0.11.0-py3-none-any.whl", hash = "sha256:a79663d1a7711eb104e4b2935988ea1ed5f7be6b7288fad23b4fba7462832f9d", size = 19877, upload-time = "2025-11-01T19:22:53.046Z" }, ] +[[package]] +name = "seaborn" +version = "0.13.2" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "matplotlib" }, + { name = "numpy", version = "2.2.6", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.11'" }, + { name = "numpy", version = "2.4.1", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.11'" }, + { name = "pandas", version = "2.3.3", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.11'" }, + { name = "pandas", version = "3.0.0", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.11'" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/86/59/a451d7420a77ab0b98f7affa3a1d78a313d2f7281a57afb1a34bae8ab412/seaborn-0.13.2.tar.gz", hash = "sha256:93e60a40988f4d65e9f4885df477e2fdaff6b73a9ded434c1ab356dd57eefff7", size = 1457696, upload-time = "2024-01-25T13:21:52.551Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/83/11/00d3c3dfc25ad54e731d91449895a79e4bf2384dc3ac01809010ba88f6d5/seaborn-0.13.2-py3-none-any.whl", hash = "sha256:636f8336facf092165e27924f223d3c62ca560b1f2bb5dff7ab7fad265361987", size = 294914, upload-time = "2024-01-25T13:21:49.598Z" }, +] + [[package]] name = "six" version = "1.17.0"