Skip to content

Commit

Permalink
Significant cleanup x 3.
Browse files Browse the repository at this point in the history
This commit is the next in a commit chain quietly resurrecting BETSE
for a modern audience and the modern Python ecosystem. Specifically,
this commit:

* Refactors the fundamentally broken
  `betse.util.math.mathinterp.interp2d_linear()` interpolator away from
  the recently removed `scipy.interpolate.interp2d()` function and
  towards the recently introduced
  `scipy.interpolate.RectBivariateSpline` interpolator.
* Resolved a variety of erroneous forward references in the core
  `betse.science.visual.visabc` submodule.

(*Flustered fasteners!*)
  • Loading branch information
leycec committed Sep 12, 2024
1 parent bb4773d commit 1a74e58
Show file tree
Hide file tree
Showing 3 changed files with 230 additions and 103 deletions.
70 changes: 38 additions & 32 deletions betse/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
#!/usr/bin/env python3
# --------------------( LICENSE )--------------------
# --------------------( LICENSE )--------------------
# Copyright 2014-2025 by Alexis Pietak & Cecil Curry.
# See "LICENSE" for further details.

'''
Application-specific exception hierarchy.
'''

# ....................{ IMPORTS }....................
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# ....................{ IMPORTS }....................
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# WARNING: To avoid race conditions during application startup, this module may
# import *ONLY* from modules guaranteed to exist at startup. This includes all
# standard Python and application modules but *NOT* third-party dependencies,
# which if unimportable will only be validated at some later time in startup.
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
from abc import ABCMeta

# ....................{ EXCEPTIONS }....................
# ....................{ EXCEPTIONS }....................
#FIXME: Define an __init__() method asserting that the passed exception message
#is non-None, which Python permits by default but which is functionally useless.
class BetseException(Exception, metaclass=ABCMeta):
Expand Down Expand Up @@ -46,7 +45,7 @@ class BetseMetaAppException(BetseException):

pass

# ....................{ EXCEPTIONS ~ call }....................
# ....................{ EXCEPTIONS ~ call }....................
class BetseCallableException(BetseException):
'''
General-purpose exception applicable to all **callables** (e.g., functions,
Expand Down Expand Up @@ -88,7 +87,7 @@ class BetseParamException(BetseCallableException):

pass

# ....................{ EXCEPTIONS ~ call : func }....................
# ....................{ EXCEPTIONS ~ call : func }....................
class BetseFunctionException(BetseCallableException):
'''
Function-specific exception.
Expand All @@ -107,7 +106,7 @@ class BetseFunctionUnimplementedException(
dependency or platform that have yet to be implemented).
'''

# ....................{ EXCEPTIONS ~ call : method }....................
# ....................{ EXCEPTIONS ~ call : method }....................
class BetseMethodException(BetseCallableException):
'''
Method-specific exception.
Expand All @@ -130,7 +129,7 @@ class BetseMethodUnimplementedException(
alternative for defining optional methods. Hence, this exception.
'''

# ..................{ INITIALIZERS }..................
# ..................{ INITIALIZERS }..................
def __init__(self) -> None:

# Avoid circular import dependencies.
Expand All @@ -140,7 +139,7 @@ def __init__(self) -> None:
super().__init__('Method {}() unimplemented.'.format(
callers.get_caller_basename()))

# ....................{ EXCEPTIONS ~ call : descriptor }....................
# ....................{ EXCEPTIONS ~ call : descriptor }....................
class BetseDescriptorException(BetseCallableException):
'''
Descriptor-specific exception.
Expand All @@ -154,8 +153,7 @@ class BetseExprAliasException(BetseDescriptorException):
'''
pass


# ....................{ EXCEPTIONS ~ cli }....................
# ....................{ EXCEPTIONS ~ cli }....................
class BetseCLIException(BetseException):
'''
General-purpose command-line interface (CLI) exception.
Expand All @@ -180,7 +178,7 @@ class BetseCLIArgParserException(BetseCLIArgException):

pass

# ....................{ EXCEPTIONS ~ lib }....................
# ....................{ EXCEPTIONS ~ lib }....................
class BetseLibException(BetseException):
'''
General-purpose exception applicable to third-party dependencies.
Expand Down Expand Up @@ -212,7 +210,7 @@ class BetseYamlException(BetseException):

pass

# ....................{ EXCEPTIONS ~ log }....................
# ....................{ EXCEPTIONS ~ log }....................
class BetseLogException(BetseException):
'''
Logging-specific exception.
Expand Down Expand Up @@ -247,7 +245,7 @@ class BetseLogRaceException(BetseLogException):

pass

# ....................{ EXCEPTIONS ~ math }....................
# ....................{ EXCEPTIONS ~ math }....................
class BetseMathException(BetseException):
'''
General-purpose exception applicable to all low-level math algorithms.
Expand All @@ -256,6 +254,14 @@ class BetseMathException(BetseException):
pass


class BetseMathInterpolationException(BetseMathException):
'''
Interpolation-specific math exception.
'''

pass


class BetseMathLineException(BetseMathException):
'''
Line- and line segment-specific math exception.
Expand All @@ -279,7 +285,7 @@ class BetseMathPolygonException(BetseMathException):

pass

# ....................{ EXCEPTIONS ~ module }....................
# ....................{ EXCEPTIONS ~ module }....................
class BetseModuleException(BetseException):
'''
Module-specific exception.
Expand All @@ -295,7 +301,7 @@ class BetsePackageException(BetseModuleException):

pass

# ....................{ EXCEPTIONS ~ os }....................
# ....................{ EXCEPTIONS ~ os }....................
class BetseOSException(BetseException):
'''
General-purpose low-level operating system (OS) exception.
Expand All @@ -311,7 +317,7 @@ class BetseShellEnvException(BetseOSException):

pass

# ....................{ EXCEPTIONS ~ os : proc }....................
# ....................{ EXCEPTIONS ~ os : proc }....................
class BetseProcessException(BetseOSException):
'''
General-purpose low-level process exception.
Expand All @@ -327,7 +333,7 @@ class BetseProcessNotFoundException(BetseProcessException):

pass

# ....................{ EXCEPTIONS ~ path }....................
# ....................{ EXCEPTIONS ~ path }....................
class BetsePathnameException(BetseException):
'''
Pathname-specific exception.
Expand Down Expand Up @@ -367,7 +373,7 @@ class BetseGitException(BetsePathException):

pass

# ....................{ EXCEPTIONS ~ path : file }....................
# ....................{ EXCEPTIONS ~ path : file }....................
class BetseFileException(BetsePathException):
'''
File-specific exception.
Expand All @@ -391,7 +397,7 @@ class BetseImageException(BetseFileException):

pass

# ....................{ EXCEPTIONS ~ py }....................
# ....................{ EXCEPTIONS ~ py }....................
class BetsePyException(BetseException):
'''
General-purpose low-level Python interpreter exception.
Expand Down Expand Up @@ -421,7 +427,7 @@ class BetsePyIdentifierException(BetsePyException):

pass

# ....................{ EXCEPTIONS ~ test }....................
# ....................{ EXCEPTIONS ~ test }....................
class BetseTestException(BetseException):
'''
General-purpose exception pertaining to this application's test suite.
Expand Down Expand Up @@ -453,7 +459,7 @@ class BetseTestParamException(BetseTestException):

pass

# ....................{ EXCEPTIONS ~ type }....................
# ....................{ EXCEPTIONS ~ type }....................
class BetseTypeException(BetseException):
'''
General-purpose exception applicable to all types (i.e., classes).
Expand Down Expand Up @@ -485,7 +491,7 @@ class BetseIntException(BetseTypeException):

pass

# ....................{ EXCEPTIONS ~ type : iter }....................
# ....................{ EXCEPTIONS ~ type : iter }....................
class BetseIterableException(BetseTypeException):
'''
Iterable-specific exception.
Expand All @@ -501,7 +507,7 @@ class BetseSequenceException(BetseIterableException):

pass

# ....................{ EXCEPTIONS ~ type : iter : map }....................
# ....................{ EXCEPTIONS ~ type : iter : map }....................
class BetseMappingException(BetseIterableException):
'''
Dictionary-specific exception.
Expand All @@ -525,7 +531,7 @@ class BetseMappingValueException(BetseMappingException):

pass

# ....................{ EXCEPTIONS ~ type : str }....................
# ....................{ EXCEPTIONS ~ type : str }....................
class BetseStrException(BetseTypeException):
'''
String-specific exception.
Expand All @@ -550,7 +556,7 @@ class BetseRegexException(BetseStrException):

pass

# ....................{ EXCEPTIONS ~ sci : sim }....................
# ....................{ EXCEPTIONS ~ sci : sim }....................
class BetseSimException(BetseException):
'''
General-purpose simulation exception.
Expand Down Expand Up @@ -598,7 +604,7 @@ class BetseSimVectorException(BetseSimException):

pass

# ....................{ EXCEPTIONS ~ sci : sim : unstable }....................
# ....................{ EXCEPTIONS ~ sci : sim : unstable }....................
class BetseSimUnstableException(BetseSimException):
'''
Simulation-specific exception indicating the current simulation to have
Expand All @@ -618,7 +624,7 @@ class BetseSimUnstableNaNException(BetseSimUnstableException):

pass

# ....................{ EXCEPTIONS ~ sci : visual }....................
# ....................{ EXCEPTIONS ~ sci : visual }....................
class BetseSimVisualException(BetseSimException):
'''
Simulation visualization-specific exception, applicable to both plots and
Expand All @@ -635,7 +641,7 @@ class BetseSimVisualLayerException(BetseSimVisualException):

pass

# ....................{ EXCEPTIONS ~ sci : pipe }....................
# ....................{ EXCEPTIONS ~ sci : pipe }....................
class BetseSimPipeException(BetseSimException):
'''
Simulation pipeline-specific exception.
Expand All @@ -661,7 +667,7 @@ class BetseSimPipeRunnerUnsatisfiedException(BetseSimPipeException):
string is neither capitalized *nor* punctuated.
'''

# ..................{ INITIALIZERS }..................
# ..................{ INITIALIZERS }..................
def __init__(self, result: str, reason: str) -> None:
'''
Initialize this exception.
Expand Down
20 changes: 10 additions & 10 deletions betse/science/visual/visabc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1252,13 +1252,13 @@ def _plot_stream(
zorder=ZORDER_STREAM,
)

# ..................{ PLOTTERS ~ cell }..................
# ..................{ PLOTTERS ~ cell }..................
#FIXME: Pretty intense, and obviously better refactored two distinct
#"LayerCellsABC" subclasses. This will probably prove pivotal to
#implementing deformations sanely.
#FIXME: After doing so, excise *ALL* of the methods below.

def _plot_cells_sans_ecm(self, *args, **kwargs) -> 'Collection':
def _plot_cells_sans_ecm(self, *args, **kwargs) -> PolyCollection:
'''
Plot and return an intracellular plot of all cells with colours
corresponding to the passed vector of arbitrary cell data (e.g.,
Expand All @@ -1285,8 +1285,8 @@ def _plot_cells_sans_ecm(self, *args, **kwargs) -> 'Collection':
method called by this method (e.g., `_plot_cell_mosaic()`).
Returns
--------
Collection
-------
PolyCollection
Plot produced by plotting the passed cell data.
'''

Expand All @@ -1298,7 +1298,7 @@ def _plot_cells_sans_ecm(self, *args, **kwargs) -> 'Collection':

def _update_cell_plot_sans_ecm(
self,
cell_plot: 'Collection',
cell_plot: PolyCollection,
cell_data: np.ndarray,
*args, **kwargs
) -> None:
Expand All @@ -1309,7 +1309,7 @@ def _update_cell_plot_sans_ecm(
Parameters
-----------
cell_plot : Collection
cell_plot : PolyCollection
Cell plot previously returned by either the
:meth:`_plot_cells_sans_ecm` *or*
:meth:`_revive_cell_plot_sans_ecm` method.
Expand Down Expand Up @@ -1342,10 +1342,10 @@ def _update_cell_plot_sans_ecm(

def _revive_cell_plots_sans_ecm(
self,
cell_plot: 'Collection',
cell_plot: PolyCollection,
cell_data: np.ndarray,
*args, **kwargs
) -> 'Collection':
) -> PolyCollection:
'''
Recreate the passed intracellular plot and return a similar plot of all
cells with colours corresponding to the passed vector of arbitrary cell
Expand Down Expand Up @@ -1373,7 +1373,7 @@ def _revive_cell_plots_sans_ecm(
Parameters
-----------
cell_plot : Collection
cell_plot : PolyCollection
Cell plot previously returned by either the
:meth:`_plot_cells_sans_ecm` *or*
:meth:`_revive_cell_plots_sans_ecm` method.
Expand All @@ -1385,7 +1385,7 @@ def _revive_cell_plots_sans_ecm(
Returns
--------
Collection
PolyCollection
Plot produced by replotting the passed cell data.
'''
assert types.is_sequence_nonstr(cell_data), (
Expand Down
Loading

0 comments on commit 1a74e58

Please sign in to comment.