Commit 276c2fb983900c79abad78a84802dc949fcffd3f
1 parent
29d88dfd
Add csbkgmodel.__getstate__ and __setstate__ methods
Showing
1 changed file
with
34 additions
and
0 deletions
cscripts/csbkgmodel.py
| ... | ... | @@ -47,6 +47,40 @@ class csbkgmodel(ctools.csobservation): |
| 47 | 47 | # Return |
| 48 | 48 | return |
| 49 | 49 | |
| 50 | + # State methods por pickling | |
| 51 | + def __getstate__(self): | |
| 52 | + """ | |
| 53 | + Extend ctools.csobservation getstate method to include some members | |
| 54 | + | |
| 55 | + Returns | |
| 56 | + ------- | |
| 57 | + state : dict | |
| 58 | + Pickled instance | |
| 59 | + """ | |
| 60 | + # Set pickled dictionary | |
| 61 | + state = {'base' : ctools.csobservation.__getstate__(self), | |
| 62 | + 'models' : self._models, | |
| 63 | + 'instrument' : self._instrument} | |
| 64 | + | |
| 65 | + # Return pickled dictionary | |
| 66 | + return state | |
| 67 | + | |
| 68 | + def __setstate__(self, state): | |
| 69 | + """ | |
| 70 | + Extend ctools.csobservation setstate method to include some members | |
| 71 | + | |
| 72 | + Parameters | |
| 73 | + ---------- | |
| 74 | + state : dict | |
| 75 | + Pickled instance | |
| 76 | + """ | |
| 77 | + ctools.csobservation.__setstate__(self, state['base']) | |
| 78 | + self._models = state['models'] | |
| 79 | + self._instrument = state['instrument'] | |
| 80 | + | |
| 81 | + # Return | |
| 82 | + return | |
| 83 | + | |
| 50 | 84 | |
| 51 | 85 | # Private methods |
| 52 | 86 | def _get_parameters(self): | ... | ... |