elif tname == 'Deflection Error':
tname = 'Deflection'
if tname in traces:
- continue
- msg = None
- if (traces[tname].info != image):
- ik = set(image.keys())
- ok = set(traces[tname].info.keys())
- if ik != ok:
- mmsg = 'extra keys: %s, missing keys %s' % (ik-ok, ok-ik)
- else:
- mmsg = []
- for key in image.keys():
- if image[key] != traces[tname].info[key]:
- mmsg.append(
- '%s (%s != %s)'
- % (key, image[key], traces[tname].info[key]))
- mmsg = ', '.join(mmsg)
- msg = 'info difference: %s' % mmsg
- elif not (traces[tname] == d).all():
- msg = 'data difference'
- if msg != None:
- raise NotImplementedError(
- 'Missmatched duplicate traces for %s: %s'
- % (tname, msg))
+ #d.tofile('%s-2.dat' % tname, sep='\n')
+ tname = self._replace_name(tname, d, traces, info)
+ if tname == None:
+ continue # Don't replace anything
+ else:
+ #d.tofile('%s.dat' % tname, sep='\n')
+ pass
traces[tname] = d
return traces
block = self._scale_block(block)
return block
+ def _replace_name(self, trace_name, trace, traces, info):
+ """Determine if a duplicate trace name should replace an earlier trace.
+
+ Return the target trace name if it should be replaced by the
+ new trace, or `None` if the new trace should be dropped.
+ """
+ #msg = []
+ #target = traces[trace_name]
+ #
+ ## Compare the info dictionaries for each trace
+ #ik = set(trace.info.keys())
+ #ok = set(traces[trace_name].info.keys())
+ #if ik != ok: # Ensure we have the same set of keys for both traces
+ # msg.append('extra keys: %s, missing keys %s' % (ik-ok, ok-ik))
+ #else:
+ # # List keys we *require* to change between traces
+ # variable_keys = ['Data offset', 'X data type'] # TODO: What is X data type?
+ # for key in trace.info.keys():
+ # if key in variable_keys:
+ # if target.info[key] == trace.info[key]:
+ # msg.append('constant %s (%s == %s)'
+ # % (key, target.info[key], trace.info[key]))
+ # else:
+ # if target.info[key] != trace.info[key]:
+ # msg.append('variable %s (%s != %s)'
+ # % (key, target.info[key], trace.info[key]))
+ # Compare the data
+ #if not (traces[trace_name] == trace).all():
+ # msg.append('data difference')
+ #if len(msg) > 0:
+ # raise NotImplementedError(
+ # 'Missmatched duplicate traces for %s: %s'
+ # % (trace_name, ', '.join(msg)))
+ import sys
+ for name,t in traces.items():
+ if (t == trace).all():
+ print >> sys.stderr, 'replace %s with %s-2' % (name, trace_name)
+ return name # Replace this identical dataset.
+ print >> sys.stderr, 'store %s-2 as Other' % (trace_name)
+ return 'Other'
+ # return None
+
def _translate_block_info(self, info, z_piezo_info, deflection_info, name):
version = info['Force file list']['Version']
ret = {