diff --git a/gempy/API/examples_generator.py b/gempy/API/examples_generator.py index b89643423..9428754be 100644 --- a/gempy/API/examples_generator.py +++ b/gempy/API/examples_generator.py @@ -180,7 +180,7 @@ def _generate_anticline_model(compute_model: bool) -> gp.data.GeoModel: ) ) - # Map geological series to surfaces + # Map geological series to surfaces gp.map_stack_to_surfaces( gempy_model=geo_data, mapping_object={"Strat_Series": ('rock2', 'rock1')} diff --git a/gempy/core/data/grid.py b/gempy/core/data/grid.py index 00cd3525b..88d8d25de 100644 --- a/gempy/core/data/grid.py +++ b/gempy/core/data/grid.py @@ -27,8 +27,8 @@ class GridTypes(enum.Flag): # ? What should we do with the extent? - values: Annotated[np.ndarray, Field(exclude=True)] = np.empty((0, 3)) - length: Annotated[np.ndarray, Field(exclude=True)] = np.empty(0) + values: Annotated[np.ndarray, Field(exclude=True)] = dataclasses.field(default_factory=lambda: np.empty((0, 3))) + length: Annotated[np.ndarray, Field(exclude=True)] = dataclasses.field(default_factory=lambda: np.empty(0)) _octree_grid: Optional[RegularGrid] = None _dense_grid: Optional[RegularGrid] = None diff --git a/gempy/core/data/grid_modules/regular_grid.py b/gempy/core/data/grid_modules/regular_grid.py index 07e931018..4b93bb7fc 100644 --- a/gempy/core/data/grid_modules/regular_grid.py +++ b/gempy/core/data/grid_modules/regular_grid.py @@ -16,10 +16,10 @@ class RegularGrid: Class with the methods and properties to manage 3D regular grids where the model will be interpolated. """ - resolution: Annotated[np.ndarray, numpy_array_short_validator] = np.ones((0, 3), dtype='int64') - extent: Annotated[np.ndarray, numpy_array_short_validator] = np.zeros(6, dtype='float64') #: this is the ORTHOGONAL extent. If the grid is rotated, the extent will be different - values: Annotated[np.ndarray, Field(exclude=True)] = np.zeros((0, 3)) - mask_topo: Annotated[np.ndarray, Field(exclude=True)] = np.zeros((0, 3), dtype=bool) + resolution: Annotated[np.ndarray, numpy_array_short_validator] = dataclasses.field(default_factory=lambda: np.ones((0, 3), dtype='int64')) + extent: Annotated[np.ndarray, numpy_array_short_validator] = dataclasses.field(default_factory=lambda: np.zeros(6, dtype='float64')) #: this is the ORTHOGONAL extent. If the grid is rotated, the extent will be different + values: Annotated[np.ndarray, Field(exclude=True)] = dataclasses.field(default_factory=lambda: np.zeros((0, 3))) + mask_topo: Annotated[np.ndarray, Field(exclude=True)] = dataclasses.field(default_factory=lambda: np.zeros((0, 3), dtype=bool)) _transform: Transform | None = None #: If a transform exists, it will be applied to the grid def __init__(self, extent: np.ndarray, resolution: np.ndarray, transform: Optional[Transform] = None): diff --git a/gempy/core/data/grid_modules/topography.py b/gempy/core/data/grid_modules/topography.py index e2822d1b0..470376e1f 100644 --- a/gempy/core/data/grid_modules/topography.py +++ b/gempy/core/data/grid_modules/topography.py @@ -27,9 +27,9 @@ class Topography: source: Optional[str] = None # Fields managed internally - values: short_array_type = field(init=False, default=np.zeros((0, 3))) + values: short_array_type = field(init=False, default_factory=lambda: np.zeros((0, 3))) resolution: Tuple[int, int] = Field(init=True, default=(0, 0)) - raster_shape: Tuple[int, ...] = field(init=False, default=()) + raster_shape: Tuple[int, ...] = field(init=False, default_factory=tuple) _mask_topo: Optional[np.ndarray] = field(init=False, default=None, repr=False) _x: Optional[np.ndarray] = field(init=False, default=None, repr=False) _y: Optional[np.ndarray] = field(init=False, default=None, repr=False) diff --git a/test/test_api/test_initialization_and_compute_api.py b/test/test_api/test_initialization_and_compute_api.py index 6726bef55..a58db6d8c 100644 --- a/test/test_api/test_initialization_and_compute_api.py +++ b/test/test_api/test_initialization_and_compute_api.py @@ -9,10 +9,7 @@ def test_api_create_data(): geo_data = _create_data() - pprint(geo_data) - - return geo_data def _create_data(): diff --git a/test/test_api/test_model_construction_granular.py b/test/test_api/test_model_construction_granular.py index ed643e7fc..f2d1cf327 100644 --- a/test/test_api/test_model_construction_granular.py +++ b/test/test_api/test_model_construction_granular.py @@ -23,46 +23,51 @@ """ def test_read_input_points(): + _, _ = _read_data() + + +def _read_data() -> tuple[SurfacePointsTable, OrientationsTable]: data_path = 'https://raw.githubusercontent.com/cgre-aachen/gempy_data/master/' surface_points_file = pooch.retrieve( url=data_path + "data/input_data/jan_models/model1_surface_points.csv", known_hash="6f1a39ed77e87a4057f03629c946b1876b87e24409cadfe0e1cf7ab1488f69e4" ) - orientations_file = pooch.retrieve( url=data_path + "data/input_data/jan_models/model1_orientations.csv", known_hash="04c307ae23f70252fe54144a2fb95ca7d96584a2d497ea539ed32dfd23e7cd5d" ) - print(pooch.file_hash(surface_points_file)) print(pooch.file_hash(orientations_file)) - surface_points: SurfacePointsTable = read_surface_points( path=surface_points_file, ) - orientations: OrientationsTable = read_orientations( path=orientations_file ) - return surface_points, orientations -def test_create_grid() -> gp.data.Grid: +def test_create_grid(): + _generate_grid() + + +def _generate_grid(): grid: gp.data.Grid = gp.data.Grid( extent=[0, 1000, 0, 1000, 0, 500], resolution=[50, 5, 50] ) - return grid -def test_create_structural_frame() -> StructuralFrame: +def test_create_structural_frame(): # * Structural elements - surface_points, orientations = test_read_input_points() + _create_structural_frame() + + +def _create_structural_frame(): + surface_points, orientations = _read_data() surface_points_groups = surface_points.get_surface_points_by_id_groups() orientations_groups = orientations.get_orientations_by_id_groups() - structural_elements = [] color_gen = ColorsGenerator() for i in range(len(surface_points_groups)): @@ -75,52 +80,52 @@ def test_create_structural_frame() -> StructuralFrame: ) structural_elements.append(structural_element) - # * Structural groups definitions default_formation: Stack = Stack( name="default_formation", elements=structural_elements, structural_relation=gp.data.StackRelationType.ERODE ) - # ? Should I move this to the constructor? structural_frame: StructuralFrame = StructuralFrame( structural_groups=[default_formation], color_gen=color_gen ) - return structural_frame -def test_create_interpolation_options() -> InterpolationOptions: +def test_create_interpolation_options(): + interpolation_options = _generate_interpolation_options() + + +def _generate_interpolation_options(): range_ = 1000.0 interpolation_options: InterpolationOptions = InterpolationOptions.from_args( range=range_, c_o=(range_ ** 2) / 14 / 3, ) - return interpolation_options -def test_create_geomodel() -> GeoModel: +def _create_geomodel() -> GeoModel: geo_model: GeoModel = GeoModel.from_args( name="horizontal", - structural_frame=test_create_structural_frame(), - grid=test_create_grid(), - interpolation_options=test_create_interpolation_options() + structural_frame=_create_structural_frame(), + grid=_generate_grid(), + interpolation_options=_generate_interpolation_options() ) return geo_model def test_structural_frame_surface_points(): - structural_frame: StructuralFrame = test_create_structural_frame() + structural_frame: StructuralFrame = _create_structural_frame() print(structural_frame.surface_points_copy) pass -def test_interpolate_numpy() -> GeoModel: - geo_model: GeoModel = test_create_geomodel() +def _interpolate_numpy() -> GeoModel: + geo_model: GeoModel = _create_geomodel() solutions: gempy_engine.core.data.solutions.Solutions = gempy_engine.compute_model( interpolation_input=geo_model.interpolation_input_copy, @@ -147,11 +152,11 @@ def test_interpolate_numpy() -> GeoModel: def test_interpolate_aesara(): - geo_model: GeoModel = test_create_geomodel() + geo_model: GeoModel = _create_geomodel() def test_plot_input(): - geo_model: GeoModel = test_create_geomodel() + geo_model: GeoModel = _create_geomodel() gp_viewer: gempy_viewer = require_gempy_viewer() # TODO: Add all the plot data in a plot options class @@ -164,7 +169,7 @@ def test_plot_input(): def test_plot_results(): - solved_geo_model: GeoModel = test_interpolate_numpy() + solved_geo_model: GeoModel = _interpolate_numpy() gp_viewer: gempy_viewer = require_gempy_viewer() gp_viewer.plot_2d(