|
2 | 2 | """
|
3 | 3 | import logging
|
4 | 4 |
|
5 |
| -from collections import OrderedDict |
6 |
| -from collections.abc import Callable |
| 5 | +from collections import defaultdict |
7 | 6 |
|
8 | 7 | from stdatamodels.properties import merge_tree
|
9 | 8 | from stdatamodels.jwst.datamodels import MultiExposureModel
|
@@ -31,7 +30,7 @@ def exp_to_source(inputs):
|
31 | 30 | instance contains slits belonging to the same source.
|
32 | 31 | The key is the ID of each source, i.e. ``source_id``.
|
33 | 32 | """
|
34 |
| - result = DefaultOrderedDict(MultiExposureModel) |
| 33 | + result = defaultdict(MultiExposureModel) |
35 | 34 |
|
36 | 35 | for exposure in inputs:
|
37 | 36 | log.info(f'Reorganizing data from exposure {exposure.meta.filename}')
|
@@ -111,47 +110,3 @@ def multislit_to_container(inputs):
|
111 | 110 | containers[id] = SourceModelContainer(containers[id])
|
112 | 111 |
|
113 | 112 | return containers
|
114 |
| - |
115 |
| - |
116 |
| -class DefaultOrderedDict(OrderedDict): |
117 |
| - # Source http://stackoverflow.com/a/6190500/562769 |
118 |
| - def __init__(self, default_factory=None, *a, **kw): |
119 |
| - if (default_factory is not None and |
120 |
| - not isinstance(default_factory, Callable)): |
121 |
| - raise TypeError('first argument must be callable') |
122 |
| - OrderedDict.__init__(self, *a, **kw) |
123 |
| - self.default_factory = default_factory |
124 |
| - |
125 |
| - def __getitem__(self, key): |
126 |
| - try: |
127 |
| - return OrderedDict.__getitem__(self, key) |
128 |
| - except KeyError: |
129 |
| - return self.__missing__(key) |
130 |
| - |
131 |
| - def __missing__(self, key): |
132 |
| - if self.default_factory is None: |
133 |
| - raise KeyError(key) |
134 |
| - self[key] = value = self.default_factory() |
135 |
| - return value |
136 |
| - |
137 |
| - def __reduce__(self): |
138 |
| - if self.default_factory is None: |
139 |
| - args = tuple() |
140 |
| - else: |
141 |
| - args = self.default_factory, |
142 |
| - return type(self), args, None, None, self.items() |
143 |
| - |
144 |
| - def copy(self): |
145 |
| - return self.__copy__() |
146 |
| - |
147 |
| - def __copy__(self): |
148 |
| - return type(self)(self.default_factory, self) |
149 |
| - |
150 |
| - def __deepcopy__(self, memo): |
151 |
| - import copy |
152 |
| - return type(self)(self.default_factory, |
153 |
| - copy.deepcopy(self.items())) |
154 |
| - |
155 |
| - def __repr__(self): |
156 |
| - return 'OrderedDefaultDict(%s, %s)' % (self.default_factory, |
157 |
| - OrderedDict.__repr__(self)) |
0 commit comments