In trying to build a scientific Python package, I'm aiming to separate key functionality into different .py files for clarity. Specifically, it seems logical to me to split complicated numerical calculations for a model into one python file (say, "processing.py"),and plotting routines for their visualisation into another python file ("plotting.py").
For convenient and memory-efficient usage, the model class should be able to inherit all the plotting methods, making them easily accessible for the user, yet keeping the code easy to maintain and read by separating scientific numerical code from visualisation code.
I outline my vision for achieving this below, but am struggling with how to implement this in Python / if a better OOP style is available.
For example, in plotting.py:
class ItemPlotter(object):
def visualisation_routine1(self):
plt.plot(self.values) # where values are to be acquired from the class in processing.py somehow
and in processing.py:
class Item(object):
def __init__(self, flag):
if flag is True:
self.values = (1, 2, 3)
else:
self.values = (10, 5, 0)
from plotting.py import ItemPlotter
self.plots = ItemPlotter()
which results in the following command line usage:
from processing.py import Item
my_item = Item(flag=True)
# Plot results
my_item.plots.visualisation_routine1()
My actual code will be more complicated than this and potentially Item will have attributes that are large datasets, thus I expect that I need to avoid copying these for memory efficiency.
Is my vision possible, or even a Pythonic approach please? Any comments re. OOP or efficient ways to achieve this would be appreciated.
PS, I'm aiming for Py2.7 and Py3 compatibility.