Skip to content

Commit

Permalink
.diagram() is now a method of IPM instances. (#215)
Browse files Browse the repository at this point in the history
  • Loading branch information
JavadocMD authored Dec 18, 2024
1 parent f1eeddb commit f561751
Show file tree
Hide file tree
Showing 7 changed files with 208 additions and 316 deletions.
17 changes: 10 additions & 7 deletions USAGE.ipynb

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions epymorph/compartment_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import re
from abc import ABC, ABCMeta, abstractmethod
from dataclasses import dataclass, field
from pathlib import Path
from typing import (
Any,
Callable,
Expand All @@ -32,6 +33,7 @@
from epymorph.error import IpmValidationException
from epymorph.simulation import DEFAULT_STRATA, META_STRATA, gpm_strata
from epymorph.sympy_shim import simplify, simplify_sum, substitute, to_symbol
from epymorph.tools.ipm_diagram import render_diagram
from epymorph.util import (
acceptable_name,
are_instances,
Expand Down Expand Up @@ -409,6 +411,26 @@ def is_multistrata(self) -> bool:
def select(self) -> "QuantitySelector":
return QuantitySelector(self)

def diagram(
self,
*,
file: str | Path | None = None,
figsize: tuple[float, float] | None = None,
) -> None:
"""Render a diagram of this IPM, either by showing it with matplotlib (default)
or by saving it to `file` as a png image.
Parameters
----------
file : str | Path, optional
Provide a file path to save a png image of the diagram to this path.
If `file` is None, we will instead use matplotlib to show the diagram.
figsize : tuple[float, float], optional
The matplotlib figure size to use when displaying the diagram.
Only used if `file` is not provided.
"""
render_diagram(ipm=self, file=file, figsize=figsize)


def validate_compartment_model(model: BaseCompartmentModel) -> None:
name = model.__class__.__name__
Expand Down
245 changes: 0 additions & 245 deletions epymorph/draw.py

This file was deleted.

35 changes: 11 additions & 24 deletions epymorph/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@
from textwrap import dedent


class ExternalDependencyError(Exception):
"""Exception when a native program is required but not found."""

missing: list[str]
"""Which programs are missing?"""

def __init__(self, msg: str, missing: list[str]):
super().__init__(msg)
self.missing = missing


class GeographyError(Exception):
"""Exception working with geographic system representations."""

Expand All @@ -18,30 +29,6 @@ class DimensionError(Exception):
"""Raised when epymorph needed dimensional information that was not provided."""


class UnknownModel(Exception):
"""Exception for the inability to load a model as specified."""

model_type: str
name_or_path: str

def __init__(self, model_type: str, name_or_path: str):
super().__init__(f"Unable to load {model_type} model '{name_or_path}'")
self.model_type = model_type
self.name_or_path = name_or_path


class ModelRegistryException(Exception):
"""Exception during model library initialization."""


class ParseException(Exception):
"""Superclass for exceptions which happen while parsing a model."""


class MmParseException(ParseException):
"""Exception parsing a Movement Model."""


class ValidationException(Exception):
"""Superclass for exceptions which happen during simulation validation."""

Expand Down
3 changes: 0 additions & 3 deletions epymorph/kit.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
)
from epymorph.data_shape import Shapes, SimDimensions
from epymorph.data_type import CentroidDType, CentroidType, SimDType
from epymorph.draw import render, render_and_save
from epymorph.geography.custom import CustomScope
from epymorph.geography.us_census import (
BlockGroupScope,
Expand Down Expand Up @@ -54,8 +53,6 @@
"fork",
"BIRTH",
"DEATH",
"render", # TODO: refactor this to methods like the output tools?
"render_and_save",
# Single Strata RUME
"SingleStrataRume",
# Multistrata RUME
Expand Down
37 changes: 0 additions & 37 deletions epymorph/test/draw_test.py

This file was deleted.

Loading

0 comments on commit f561751

Please sign in to comment.