mingrisch / compartmentmodels

Tracer-kinetic models for DCE MRI
BSD 3-Clause "New" or "Revised" License
5 stars 3 forks source link

getters and setters for time, curve, aif and so on #18

Open mingrisch opened 9 years ago

mingrisch commented 9 years ago

We would like to have simple attribute access on these curves, with the option of validation (all need to be proper numpy arrays, with the same length and so on)

this looks much like a case for a property:

In essence, we make these attributes semi-private, by prefixing an underscore With this, we can have both: easy attribute access, without breaking compatibliy to old code, like in the tests:

aif = model.aif
model.aif = newaif

and can perform validation (which is not done yet):

def get_aif(self):
    return self._aif
def set_aif(self, newaif):
    # t.b.d. check input validity
    self._aif = newaif

all by means of a simple

    aif = property(set_aif, get_aif)

or something along this line