diff --git a/discretize/_extensions/tree_ext.pyx b/discretize/_extensions/tree_ext.pyx index 0c5e78da1..0b7ac60e5 100644 --- a/discretize/_extensions/tree_ext.pyx +++ b/discretize/_extensions/tree_ext.pyx @@ -869,8 +869,8 @@ cdef class _TreeMesh: >>> import discretize >>> import matplotlib.pyplot as plt >>> import matplotlib.patches as patches - >>> tree_mesh = discretize.TreeMesh([32, 32, 32]) - >>> tree_mesh.max_level + >>> mesh = discretize.TreeMesh([32, 32, 32]) + >>> mesh.max_level 5 Next we define the bottom points of the prism, its heights, and the level we diff --git a/discretize/base/base_mesh.py b/discretize/base/base_mesh.py index 53c82723e..cf4f39f93 100644 --- a/discretize/base/base_mesh.py +++ b/discretize/base/base_mesh.py @@ -172,6 +172,7 @@ def save(self, file_name="mesh.json", verbose=False, **kwargs): "The filename keyword argument has been deprecated, please use file_name. " "This will be removed in discretize 1.0.0", FutureWarning, + stacklevel=2, ) f = os.path.abspath(file_name) # make sure we are working with abs path with open(f, "w") as outfile: diff --git a/discretize/base/base_regular_mesh.py b/discretize/base/base_regular_mesh.py index 7594ff4ad..c99db35b3 100644 --- a/discretize/base/base_regular_mesh.py +++ b/discretize/base/base_regular_mesh.py @@ -529,6 +529,7 @@ def axis_u(self): "The axis_u property is deprecated, please access as self.orientation[0]. " "This will be removed in discretize 1.0.0.", FutureWarning, + stacklevel=2, ) return self.orientation[0] @@ -539,6 +540,7 @@ def axis_u(self, value): "directly set the self.orientation property. This will be removed in " "discretize 1.0.0.", FutureWarning, + stacklevel=2, ) self.orientation[0] = value @@ -554,6 +556,7 @@ def axis_v(self): "The axis_v property is deprecated, please access as self.orientation[1]. " "This will be removed in discretize 1.0.0.", FutureWarning, + stacklevel=2, ) return self.orientation[1] @@ -564,6 +567,7 @@ def axis_v(self, value): "directly set the self.orientation property. This will be removed in " "discretize 1.0.0.", FutureWarning, + stacklevel=2, ) value = value / np.linalg.norm(value) self.orientation[1] = value @@ -580,6 +584,7 @@ def axis_w(self): "The axis_w property is deprecated, please access as self.orientation[2]. " "This will be removed in discretize 1.0.0.", FutureWarning, + stacklevel=2, ) return self.orientation[2] @@ -590,6 +595,7 @@ def axis_w(self, value): "directly set the self.orientation property. This will be removed in " "discretize 1.0.0.", FutureWarning, + stacklevel=2, ) value = value / np.linalg.norm(value) self.orientation[2] = value @@ -872,6 +878,7 @@ def reshape( "The xType keyword argument has been deprecated, please use x_type. " "This will be removed in discretize 1.0.0", FutureWarning, + stacklevel=2, ) x_type = kwargs["xType"] if "outType" in kwargs: @@ -879,6 +886,7 @@ def reshape( "The outType keyword argument has been deprecated, please use out_type. " "This will be removed in discretize 1.0.0", FutureWarning, + stacklevel=2, ) out_type = kwargs["outType"] if "format" in kwargs: @@ -886,6 +894,7 @@ def reshape( "The format keyword argument has been deprecated, please use return_format. " "This will be removed in discretize 1.0.0", FutureWarning, + stacklevel=2, ) return_format = kwargs["format"] @@ -1039,6 +1048,7 @@ def nCx(self): warnings.warn( "nCx has been deprecated, please access as mesh.shape_cells[0]", FutureWarning, + stacklevel=2, ) return self.shape_cells[0] @@ -1058,6 +1068,7 @@ def nCy(self): warnings.warn( "nCy has been deprecated, please access as mesh.shape_cells[1]", FutureWarning, + stacklevel=2, ) if self.dim < 2: return None @@ -1079,6 +1090,7 @@ def nCz(self): warnings.warn( "nCz has been deprecated, please access as mesh.shape_cells[2]", FutureWarning, + stacklevel=2, ) if self.dim < 3: return None @@ -1099,6 +1111,7 @@ def nNx(self): warnings.warn( "nNx has been deprecated, please access as mesh.shape_nodes[0]", FutureWarning, + stacklevel=2, ) return self.shape_nodes[0] @@ -1118,6 +1131,7 @@ def nNy(self): warnings.warn( "nNy has been deprecated, please access as mesh.shape_nodes[1]", FutureWarning, + stacklevel=2, ) if self.dim < 2: return None @@ -1139,6 +1153,7 @@ def nNz(self): warnings.warn( "nNz has been deprecated, please access as mesh.shape_nodes[2]", FutureWarning, + stacklevel=2, ) if self.dim < 3: return None diff --git a/discretize/base/base_tensor_mesh.py b/discretize/base/base_tensor_mesh.py index 92dacab85..44aa36d50 100644 --- a/discretize/base/base_tensor_mesh.py +++ b/discretize/base/base_tensor_mesh.py @@ -661,6 +661,7 @@ def is_inside(self, pts, location_type="nodes", **kwargs): "The locType keyword argument has been deprecated, please use location_type. " "This will be removed in discretize 1.0.0", FutureWarning, + stacklevel=2, ) location_type = kwargs["locType"] pts = as_array_n_by_dim(pts, self.dim) @@ -783,6 +784,7 @@ def get_interpolation_matrix( # NOQA D102 "The locType keyword argument has been deprecated, please use location_type. " "This will be removed in discretize 1.0.0", FutureWarning, + stacklevel=2, ) location_type = kwargs["locType"] if "zerosOutside" in kwargs: @@ -790,6 +792,7 @@ def get_interpolation_matrix( # NOQA D102 "The zerosOutside keyword argument has been deprecated, please use zeros_outside. " "This will be removed in discretize 1.0.0", FutureWarning, + stacklevel=2, ) zeros_outside = kwargs["zerosOutside"] return self._getInterpolationMat(loc, location_type, zeros_outside) @@ -993,6 +996,7 @@ def innerProductDeriv(v=None): " You should be supplying a vector. " "Use: sdiag(u)*dMdprop", FutureWarning, + stacklevel=2, ) return dMdprop return sdiag(v) * dMdprop @@ -1015,7 +1019,9 @@ def hx(self): please use `mesh.h[0]`. """ warnings.warn( - "hx has been deprecated, please access as mesh.h[0]", FutureWarning + "hx has been deprecated, please access as mesh.h[0]", + FutureWarning, + stacklevel=2, ) return self.h[0] @@ -1032,7 +1038,9 @@ def hy(self): please use `mesh.h[1]`. """ warnings.warn( - "hy has been deprecated, please access as mesh.h[1]", FutureWarning + "hy has been deprecated, please access as mesh.h[1]", + FutureWarning, + stacklevel=2, ) return None if self.dim < 2 else self.h[1] @@ -1049,7 +1057,9 @@ def hz(self): please use `mesh.h[2]`. """ warnings.warn( - "hz has been deprecated, please access as mesh.h[2]", FutureWarning + "hz has been deprecated, please access as mesh.h[2]", + FutureWarning, + stacklevel=2, ) return None if self.dim < 3 else self.h[2] diff --git a/discretize/cylindrical_mesh.py b/discretize/cylindrical_mesh.py index b5c0ddc02..4f596579d 100644 --- a/discretize/cylindrical_mesh.py +++ b/discretize/cylindrical_mesh.py @@ -1680,6 +1680,7 @@ def get_interpolation_matrix( "The locType keyword argument has been deprecated, please use location_type. " "This will be removed in discretize 1.0.0", FutureWarning, + stacklevel=2, ) location_type = kwargs["locType"] if "zerosOutside" in kwargs: @@ -1687,6 +1688,7 @@ def get_interpolation_matrix( "The zerosOutside keyword argument has been deprecated, please use zeros_outside. " "This will be removed in discretize 1.0.0", FutureWarning, + stacklevel=2, ) zeros_outside = kwargs["zerosOutside"] @@ -1879,6 +1881,7 @@ def cartesian_grid(self, location_type="cell_centers", theta_shift=None, **kwarg "The locType keyword argument has been deprecated, please use location_type. " "This will be removed in discretize 1.0.0", FutureWarning, + stacklevel=2, ) location_type = kwargs["locType"] try: @@ -1923,6 +1926,7 @@ def get_interpolation_matrix_cartesian_mesh( "The locType keyword argument has been deprecated, please use location_type. " "This will be removed in discretize 1.0.0", FutureWarning, + stacklevel=2, ) location_type = kwargs["locType"] if "locTypeTo" in kwargs: @@ -1930,6 +1934,7 @@ def get_interpolation_matrix_cartesian_mesh( "The locTypeTo keyword argument has been deprecated, please use location_type_to. " "This will be removed in discretize 1.0.0", FutureWarning, + stacklevel=2, ) location_type_to = kwargs["locTypeTo"] diff --git a/discretize/mixins/mesh_io.py b/discretize/mixins/mesh_io.py index df7aceab6..89a397c6d 100644 --- a/discretize/mixins/mesh_io.py +++ b/discretize/mixins/mesh_io.py @@ -421,6 +421,7 @@ def readUBC(TensorMesh, file_name, directory=""): "TensorMesh.readUBC has been deprecated and will be removed in" "discretize 1.0.0. please use TensorMesh.read_UBC", FutureWarning, + stacklevel=2, ) return TensorMesh.read_UBC(file_name, directory) @@ -615,6 +616,7 @@ def readUBC(TreeMesh, file_name, directory=""): "TensorMesh.readUBC has been deprecated and will be removed in" "discretize 1.0.0. please use TensorMesh.read_UBC", FutureWarning, + stacklevel=2, ) return TreeMesh.read_UBC(file_name, directory) diff --git a/discretize/mixins/mpl_mod.py b/discretize/mixins/mpl_mod.py index aecc1507a..582a7066c 100644 --- a/discretize/mixins/mpl_mod.py +++ b/discretize/mixins/mpl_mod.py @@ -164,7 +164,9 @@ def plot_grid( if "showIt" in kwargs: show_it = kwargs.pop("showIt") warnings.warn( - "showIt has been deprecated, please use show_it", FutureWarning + "showIt has been deprecated, please use show_it", + FutureWarning, + stacklevel=2, ) if ax is not None: @@ -305,26 +307,36 @@ def plot_image( warnings.warn( "pcolorOpts has been deprecated, please use pcolor_opts", FutureWarning, + stacklevel=2, ) if "streamOpts" in kwargs: stream_opts = kwargs.pop("streamOpts") warnings.warn( "streamOpts has been deprecated, please use stream_opts", FutureWarning, + stacklevel=2, ) if "gridOpts" in kwargs: grid_opts = kwargs.pop("gridOpts") warnings.warn( - "gridOpts has been deprecated, please use grid_opts", FutureWarning + "gridOpts has been deprecated, please use grid_opts", + FutureWarning, + stacklevel=2, ) if "showIt" in kwargs: show_it = kwargs.pop("showIt") warnings.warn( - "showIt has been deprecated, please use show_it", FutureWarning + "showIt has been deprecated, please use show_it", + FutureWarning, + stacklevel=2, ) if "vType" in kwargs: v_type = kwargs.pop("vType") - warnings.warn("vType has been deprecated, please use v_type", FutureWarning) + warnings.warn( + "vType has been deprecated, please use v_type", + FutureWarning, + stacklevel=2, + ) # Some Error checking and common defaults if pcolor_opts is None: @@ -539,26 +551,36 @@ def plot_slice( warnings.warn( "pcolorOpts has been deprecated, please use pcolor_opts", FutureWarning, + stacklevel=2, ) if "streamOpts" in kwargs: stream_opts = kwargs["streamOpts"] warnings.warn( "streamOpts has been deprecated, please use stream_opts", FutureWarning, + stacklevel=2, ) if "gridOpts" in kwargs: grid_opts = kwargs["gridOpts"] warnings.warn( - "gridOpts has been deprecated, please use grid_opts", FutureWarning + "gridOpts has been deprecated, please use grid_opts", + FutureWarning, + stacklevel=2, ) if "showIt" in kwargs: show_it = kwargs["showIt"] warnings.warn( - "showIt has been deprecated, please use show_it", FutureWarning + "showIt has been deprecated, please use show_it", + FutureWarning, + stacklevel=2, ) if "vType" in kwargs: v_type = kwargs["vType"] - warnings.warn("vType has been deprecated, please use v_type", FutureWarning) + warnings.warn( + "vType has been deprecated, please use v_type", + FutureWarning, + stacklevel=2, + ) if pcolor_opts is None: pcolor_opts = {} if stream_opts is None: @@ -743,6 +765,7 @@ def plot_3d_slicer( warnings.warn( "pcolorOpts has been deprecated, please use pcolor_opts", FutureWarning, + stacklevel=2, ) # Populate figure @@ -1020,6 +1043,7 @@ def __plot_image_tensor( warnings.warn( "annotationColor has been deprecated, please use annotation_color", FutureWarning, + stacklevel=2, ) if self.dim == 1: @@ -1507,14 +1531,17 @@ def __plot_grid_cyl(self, *args, **kwargs): if not isinstance(ax, list) or len(ax) != 2: warnings.warn( "two axes handles must be provided to plot both theta " - "and z slices through the mesh. Over-writing the axes." + "and z slices through the mesh. Over-writing the axes.", + stacklevel=2, ) ax = None else: # find the one with a polar projection and pass it to the # theta slice, other one to the z-slice polarax = [ - a for a in ax if a.__class__.__name__ == "PolarAxesSubplot" + a + for a in ax + if a.__class__.__name__ in ["PolarAxesSubplot", "PolarAxes"] ] if len(polarax) != 1: warnings.warn( @@ -1526,7 +1553,8 @@ def __plot_grid_cyl(self, *args, **kwargs): for reference, see: http://matplotlib.org/examples/pylab_examples/polar_demo.html https://github.com/matplotlib/matplotlib/issues/312 - """ + """, + stacklevel=2, ) ax = None @@ -1565,7 +1593,8 @@ def __plotGridZSlice(self, *args, **kwargs): # https://github.com/matplotlib/matplotlib/issues/312 ax = kwargs.get("ax", None) if ax is not None: - if ax.__class__.__name__ != "PolarAxesSubplot": + print(ax.__class__.__name__) + if ax.__class__.__name__ not in ["PolarAxesSubplot", "PolarAxes"]: warnings.warn( """ Creating new axes with Polar projection. If you prefer to create your own, please use @@ -1574,7 +1603,8 @@ def __plotGridZSlice(self, *args, **kwargs): for reference, see: http://matplotlib.org/examples/pylab_examples/polar_demo.html https://github.com/matplotlib/matplotlib/issues/312 - """ + """, + stacklevel=2, ) ax = plt.subplot(111, projection="polar") else: @@ -2430,6 +2460,7 @@ def __init__( warnings.warn( "pcolorOpts has been deprecated, please use pcolor_opts", FutureWarning, + stacklevel=2, ) # Add pcolor_opts to self diff --git a/discretize/mixins/vtk_mod.py b/discretize/mixins/vtk_mod.py index 3d278514e..070079f0d 100644 --- a/discretize/mixins/vtk_mod.py +++ b/discretize/mixins/vtk_mod.py @@ -606,7 +606,8 @@ def to_vtk(mesh, models=None): cvtd = pyvista.wrap(cvtd) except ImportError: warnings.warn( - "For easier use of VTK objects, you should install `pyvista` (the VTK interface): pip install pyvista" + "For easier use of VTK objects, you should install `pyvista` (the VTK interface): pip install pyvista", + stacklevel=1, ) return cvtd @@ -622,6 +623,7 @@ def toVTK(mesh, models=None): warnings.warn( "Deprecation Warning: `toVTK` is deprecated, use `to_vtk` instead", category=FutureWarning, + stacklevel=2, ) return InterfaceVTK.to_vtk(mesh, models=models) @@ -788,6 +790,7 @@ def writeVTK(mesh, file_name, models=None, directory=""): warnings.warn( "Deprecation Warning: `writeVTK` is deprecated, use `write_vtk` instead", category=FutureWarning, + stacklevel=2, ) return InterfaceVTK.write_vtk( mesh, file_name, models=models, directory=directory @@ -900,6 +903,7 @@ def readVTK(TensorMesh, file_name, directory=""): warnings.warn( "Deprecation Warning: `readVTK` is deprecated, use `read_vtk` instead", category=FutureWarning, + stacklevel=2, ) return InterfaceTensorread_vtk.read_vtk( TensorMesh, file_name, directory=directory diff --git a/discretize/operators/differential_operators.py b/discretize/operators/differential_operators.py index e62fda0ba..9ef034758 100644 --- a/discretize/operators/differential_operators.py +++ b/discretize/operators/differential_operators.py @@ -679,7 +679,10 @@ def nodal_gradient(self): # NOQA D102 @property def _nodal_laplacian_x_stencil(self): """Stencil for the nodal Laplacian in the x-direction (nodes to nodes).""" - warnings.warn("Laplacian has not been tested rigorously.") + warnings.warn( + "Laplacian has not been tested rigorously.", + stacklevel=3, + ) Dx = ddx(self.shape_cells[0]) Lx = -Dx.T * Dx @@ -693,7 +696,10 @@ def _nodal_laplacian_x_stencil(self): @property def _nodal_laplacian_y_stencil(self): """Stencil for the nodal Laplacian in the y-direction (nodes to nodes).""" - warnings.warn("Laplacian has not been tested rigorously.") + warnings.warn( + "Laplacian has not been tested rigorously.", + stacklevel=3, + ) if self.dim == 1: return None @@ -710,7 +716,10 @@ def _nodal_laplacian_y_stencil(self): @property def _nodal_laplacian_z_stencil(self): """Stencil for the nodal Laplacian in the z-direction (nodes to nodes).""" - warnings.warn("Laplacian has not been tested rigorously.") + warnings.warn( + "Laplacian has not been tested rigorously.", + stacklevel=3, + ) if self.dim == 1 or self.dim == 2: return None @@ -754,7 +763,10 @@ def _nodal_laplacian_z(self): def nodal_laplacian(self): # NOQA D102 # Documentation inherited from discretize.base.BaseMesh if getattr(self, "_nodal_laplacian", None) is None: - warnings.warn("Laplacian has not been tested rigorously.") + warnings.warn( + "Laplacian has not been tested rigorously.", + stacklevel=2, + ) # Compute divergence operator on faces if self.dim == 1: self._nodal_laplacian = self._nodal_laplacian_x @@ -1760,7 +1772,8 @@ def cell_gradient_weak_form_robin(self, alpha=0.0, beta=1.0, gamma=0.0): def cell_gradient_BC(self): """Boundary conditions matrix for the cell gradient operator (Deprecated).""" warnings.warn( - "cell_gradient_BC is deprecated and is not longer used. See cell_gradient" + "cell_gradient_BC is deprecated and is not longer used. See cell_gradient", + stacklevel=2, ) if getattr(self, "_cell_gradient_BC", None) is None: BC = self.set_cell_gradient_BC(self._cell_gradient_BC_list) diff --git a/discretize/operators/inner_products.py b/discretize/operators/inner_products.py index 822037e84..37c5da168 100644 --- a/discretize/operators/inner_products.py +++ b/discretize/operators/inner_products.py @@ -44,6 +44,7 @@ def get_face_inner_product( # NOQA D102 "The invProp keyword argument has been deprecated, please use invert_model. " "This will be removed in discretize 1.0.0", FutureWarning, + stacklevel=2, ) invert_model = kwargs["invProp"] if "invMat" in kwargs: @@ -51,6 +52,7 @@ def get_face_inner_product( # NOQA D102 "The invMat keyword argument has been deprecated, please use invert_matrix. " "This will be removed in discretize 1.0.0", FutureWarning, + stacklevel=2, ) invert_matrix = kwargs["invMat"] if "doFast" in kwargs: @@ -58,6 +60,7 @@ def get_face_inner_product( # NOQA D102 "The doFast keyword argument has been deprecated, please use do_fast. " "This will be removed in discretize 1.0.0", FutureWarning, + stacklevel=2, ) do_fast = kwargs["doFast"] @@ -83,6 +86,7 @@ def get_edge_inner_product( # NOQA D102 "The invProp keyword argument has been deprecated, please use invert_model. " "This will be removed in discretize 1.0.0", FutureWarning, + stacklevel=2, ) invert_model = kwargs["invProp"] if "invMat" in kwargs: @@ -90,6 +94,7 @@ def get_edge_inner_product( # NOQA D102 "The invMat keyword argument has been deprecated, please use invert_matrix. " "This will be removed in discretize 1.0.0", FutureWarning, + stacklevel=2, ) invert_matrix = kwargs["invMat"] if "doFast" in kwargs: @@ -97,6 +102,7 @@ def get_edge_inner_product( # NOQA D102 "The doFast keyword argument has been deprecated, please use do_fast. " "This will be removed in discretize 1.0.0", FutureWarning, + stacklevel=2, ) do_fast = kwargs["doFast"] return self._getInnerProduct( @@ -141,6 +147,7 @@ def _getInnerProduct( "The invProp keyword argument has been deprecated, please use invert_model. " "This will be removed in discretize 1.0.0", FutureWarning, + stacklevel=2, ) invert_model = kwargs["invProp"] if "invMat" in kwargs: @@ -148,6 +155,7 @@ def _getInnerProduct( "The invMat keyword argument has been deprecated, please use invert_matrix. " "This will be removed in discretize 1.0.0", FutureWarning, + stacklevel=2, ) invert_matrix = kwargs["invMat"] if "doFast" in kwargs: @@ -155,6 +163,7 @@ def _getInnerProduct( "The doFast keyword argument has been deprecated, please use do_fast. " "This will be removed in discretize 1.0.0", FutureWarning, + stacklevel=2, ) do_fast = kwargs["doFast"] if projection_type not in ["F", "E"]: @@ -249,6 +258,7 @@ def get_face_inner_product_deriv( # NOQA D102 "The invProp keyword argument has been deprecated, please use invert_model. " "This will be removed in discretize 1.0.0", FutureWarning, + stacklevel=2, ) invert_model = kwargs["invProp"] if "invMat" in kwargs: @@ -256,6 +266,7 @@ def get_face_inner_product_deriv( # NOQA D102 "The invMat keyword argument has been deprecated, please use invert_matrix. " "This will be removed in discretize 1.0.0", FutureWarning, + stacklevel=2, ) invert_matrix = kwargs["invMat"] if "doFast" in kwargs: @@ -263,6 +274,7 @@ def get_face_inner_product_deriv( # NOQA D102 "The doFast keyword argument has been deprecated, please use do_fast. " "This will be removed in discretize 1.0.0", FutureWarning, + stacklevel=2, ) do_fast = kwargs["doFast"] return self._getInnerProductDeriv( @@ -282,6 +294,7 @@ def get_edge_inner_product_deriv( # NOQA D102 "The invProp keyword argument has been deprecated, please use invert_model. " "This will be removed in discretize 1.0.0", FutureWarning, + stacklevel=2, ) invert_model = kwargs["invProp"] if "invMat" in kwargs: @@ -289,6 +302,7 @@ def get_edge_inner_product_deriv( # NOQA D102 "The invMat keyword argument has been deprecated, please use invert_matrix. " "This will be removed in discretize 1.0.0", FutureWarning, + stacklevel=2, ) invert_matrix = kwargs["invMat"] if "doFast" in kwargs: @@ -296,6 +310,7 @@ def get_edge_inner_product_deriv( # NOQA D102 "The doFast keyword argument has been deprecated, please use do_fast. " "This will be removed in discretize 1.0.0", FutureWarning, + stacklevel=2, ) do_fast = kwargs["doFast"] return self._getInnerProductDeriv( diff --git a/discretize/tree_mesh.py b/discretize/tree_mesh.py index ad95b93b3..7895be653 100644 --- a/discretize/tree_mesh.py +++ b/discretize/tree_mesh.py @@ -939,6 +939,7 @@ def get_interpolation_matrix( # NOQA D102 "The locType keyword argument has been deprecated, please use location_type. " "This will be removed in discretize 1.0.0", FutureWarning, + stacklevel=2, ) location_type = kwargs["locType"] if "zerosOutside" in kwargs: @@ -946,6 +947,7 @@ def get_interpolation_matrix( # NOQA D102 "The zerosOutside keyword argument has been deprecated, please use zeros_outside. " "This will be removed in discretize 1.0.0", FutureWarning, + stacklevel=2, ) zeros_outside = kwargs["zerosOutside"] locs = as_array_n_by_dim(locs, self.dim) diff --git a/discretize/utils/code_utils.py b/discretize/utils/code_utils.py index f5dad5194..c521683ac 100644 --- a/discretize/utils/code_utils.py +++ b/discretize/utils/code_utils.py @@ -145,7 +145,7 @@ def decorator(cls): cls._old__init__ = cls.__init__ def __init__(self, *args, **kwargs): - warnings.warn(message, warn) + warnings.warn(message, warn, stacklevel=2) self._old__init__(*args, **kwargs) cls.__init__ = __init__ @@ -181,7 +181,7 @@ def deprecate_module(old_name, new_name, removal_version=None, future_warn=False else: message += " It will be removed in a future version of discretize." message += " Please update your code accordingly." - warnings.warn(message, warn) + warnings.warn(message, warn, stacklevel=2) def deprecate_property(new_name, old_name, removal_version=None, future_warn=False): @@ -213,7 +213,7 @@ def get_dep(self): f"{class_name}.{old_name} has been deprecated, please use {class_name}.{new_name}." + tag ) - warnings.warn(message, warn) + warnings.warn(message, warn, stacklevel=2) return getattr(self, new_name) def set_dep(self, other): @@ -222,7 +222,7 @@ def set_dep(self, other): f"{class_name}.{old_name} has been deprecated, please use {class_name}.{new_name}." + tag ) - warnings.warn(message, warn) + warnings.warn(message, warn, stacklevel=2) setattr(self, new_name, other) doc = f""" @@ -265,6 +265,7 @@ def new_method(self, *args, **kwargs): f"{class_name}.{old_name} has been deprecated, please use {class_name}.{new_name}." + tag, warn, + stacklevel=2, ) return getattr(self, new_name)(*args, **kwargs) @@ -307,6 +308,7 @@ def dep_function(*args, **kwargs): warnings.warn( f"{old_name} has been deprecated, please use {new_name}." + tag, warn, + stacklevel=2, ) return new_function(*args, **kwargs) diff --git a/discretize/utils/codeutils.py b/discretize/utils/codeutils.py index 11b8cd8cb..9bee77f51 100644 --- a/discretize/utils/codeutils.py +++ b/discretize/utils/codeutils.py @@ -5,4 +5,5 @@ "Importing from discretize.codeutils is deprecated behavoir. Please import " "from discretize.utils. This module will be removed in version 1.0.0 of discretize.", FutureWarning, + stacklevel=1, ) diff --git a/discretize/utils/coordutils.py b/discretize/utils/coordutils.py index 7017d9ae8..535252ef0 100644 --- a/discretize/utils/coordutils.py +++ b/discretize/utils/coordutils.py @@ -5,4 +5,5 @@ "Importing from discretize.coordutils is deprecated behavoir. Please import " "from discretize.utils. This module will be removed in version 1.0.0 of discretize.", FutureWarning, + stacklevel=1, ) diff --git a/discretize/utils/curvilinear_utils.py b/discretize/utils/curvilinear_utils.py index 4b89f88c9..f7477e3e5 100644 --- a/discretize/utils/curvilinear_utils.py +++ b/discretize/utils/curvilinear_utils.py @@ -463,6 +463,7 @@ def face_info(xyz, A, B, C, D, average=True, normalize_normals=True, **kwargs): "The normalizeNormals keyword argument has been deprecated, please use normalize_normals. " "This will be removed in discretize 1.0.0", FutureWarning, + stacklevel=2, ) normalize_normals = kwargs["normalizeNormals"] if not isinstance(average, bool): diff --git a/discretize/utils/curvutils.py b/discretize/utils/curvutils.py index da672676d..86bcd5ab4 100644 --- a/discretize/utils/curvutils.py +++ b/discretize/utils/curvutils.py @@ -5,4 +5,5 @@ "Importing from discretize.curvutils is deprecated behavoir. Please import " "from discretize.utils. This module will be removed in version 1.0.0 of discretize.", FutureWarning, + stacklevel=1, ) diff --git a/discretize/utils/interputils.py b/discretize/utils/interputils.py index 3edf939ba..cfded432f 100644 --- a/discretize/utils/interputils.py +++ b/discretize/utils/interputils.py @@ -5,4 +5,5 @@ "Importing from discretize.interputils is deprecated behavoir. Please import " "from discretize.utils. This module will be removed in version 1.0.0 of discretize.", FutureWarning, + stacklevel=1, ) diff --git a/discretize/utils/matrix_utils.py b/discretize/utils/matrix_utils.py index cdd77bfde..095c6e98c 100644 --- a/discretize/utils/matrix_utils.py +++ b/discretize/utils/matrix_utils.py @@ -60,6 +60,7 @@ def mkvc(x, n_dims=1, **kwargs): "The numDims keyword argument has been deprecated, please use n_dims. " "This will be removed in discretize 1.0.0", FutureWarning, + stacklevel=2, ) n_dims = kwargs["numDims"] if type(x) == np.matrix: @@ -446,6 +447,7 @@ def make_boundary_bool(shape, bdir="xyz", **kwargs): "The `dir` keyword argument has been renamed to `bdir` to avoid shadowing the " "builtin variable `dir`. This will be removed in discretize 1.0.0", FutureWarning, + stacklevel=2, ) bdir = old_dir is_b = np.zeros(shape, dtype=bool, order="F") @@ -715,6 +717,7 @@ def inverse_3x3_block_diagonal( "The returnMatrix keyword argument has been deprecated, please use return_matrix. " "This will be removed in discretize 1.0.0", FutureWarning, + stacklevel=2, ) return_matrix = kwargs["returnMatrix"] @@ -867,6 +870,7 @@ def inverse_2x2_block_diagonal(a11, a12, a21, a22, return_matrix=True, **kwargs) "The returnMatrix keyword argument has been deprecated, please use return_matrix. " "This will be removed in discretize 1.0.0", FutureWarning, + stacklevel=2, ) return_matrix = kwargs["returnMatrix"] @@ -1392,6 +1396,7 @@ def inverse_property_tensor(mesh, tensor, return_matrix=False, **kwargs): "The returnMatrix keyword argument has been deprecated, please use return_matrix. " "This will be removed in discretize 1.0.0", FutureWarning, + stacklevel=2, ) return_matrix = kwargs["returnMatrix"] diff --git a/discretize/utils/matutils.py b/discretize/utils/matutils.py index f8cfa7d74..200d24dca 100644 --- a/discretize/utils/matutils.py +++ b/discretize/utils/matutils.py @@ -5,4 +5,5 @@ "Importing from discretize.matutils is deprecated behavoir. Please import " "from discretize.utils. This module will be removed in version 1.0.0 of discretize.", FutureWarning, + stacklevel=1, ) diff --git a/discretize/utils/mesh_utils.py b/discretize/utils/mesh_utils.py index ae49e99e7..8fab0d6ae 100644 --- a/discretize/utils/mesh_utils.py +++ b/discretize/utils/mesh_utils.py @@ -231,6 +231,7 @@ def closest_points_index(mesh, pts, grid_loc="CC", **kwargs): "The gridLoc keyword argument has been deprecated, please use grid_loc. " "This will be removed in discretize 1.0.0", FutureWarning, + stacklevel=2, ) grid_loc = kwargs["gridLoc"] warnings.warn( @@ -238,6 +239,7 @@ def closest_points_index(mesh, pts, grid_loc="CC", **kwargs): "a class object. Please access it as mesh.closest_points_index(). This will " "be removed in a future version of discretize", DeprecationWarning, + stacklevel=2, ) return mesh.closest_points_index(pts, grid_loc=grid_loc, discard=True) @@ -717,6 +719,7 @@ def refine_tree_xyz( "use the `TreeMesh.refine_points` functionality. It will be removed in a " "future version of discretize.", DeprecationWarning, + stacklevel=2, ) # Compute the outer limits of each octree level @@ -740,6 +743,7 @@ def refine_tree_xyz( "use the `TreeMesh.refine_surface` functionality. It will be removed in a " "future version of discretize.", DeprecationWarning, + stacklevel=2, ) # padding = np.zeros((len(octree_levels), mesh.dim)) # padding[:, -1] = np.maximum(octree_levels - 1, 0) @@ -861,6 +865,7 @@ def refine_tree_xyz( "use the `TreeMesh.refine_bounding_box` functionality. It will be removed in a " "future version of discretize.", DeprecationWarning, + stacklevel=2, ) # padding = np.zeros((len(octree_levels), mesh.dim)) # padding[:, -1] = np.maximum(octree_levels - 1, 0) diff --git a/discretize/utils/meshutils.py b/discretize/utils/meshutils.py index d4450e327..4fbd3bd12 100644 --- a/discretize/utils/meshutils.py +++ b/discretize/utils/meshutils.py @@ -5,4 +5,5 @@ "Importing from discretize.meshutils is deprecated behavoir. Please import " "from discretize.utils. This module will be removed in version 1.0.0 of discretize.", FutureWarning, + stacklevel=1, )