From 02d95cfacca599dd902090d15bc1be8e88fc3c85 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Fri, 4 Jun 2010 13:24:35 -0400 Subject: [PATCH] Split out curve renaming to PicoForceDriver._replace_name I still haven't gotten things working for the 0x07200000 data, but I'm beginning to doubt the example file. Things appear to work on the 0x06 data. --- hooke/driver/picoforce.py | 71 +++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 22 deletions(-) diff --git a/hooke/driver/picoforce.py b/hooke/driver/picoforce.py index 9978751..a465c2e 100644 --- a/hooke/driver/picoforce.py +++ b/hooke/driver/picoforce.py @@ -232,28 +232,13 @@ class PicoForceDriver (Driver): 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 @@ -274,6 +259,48 @@ class PicoForceDriver (Driver): 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 = { -- 2.26.2