aboutsummaryrefslogtreecommitdiff
path: root/scripts/find-pairs
blob: d45309c612f8920c42a2a0c3252af321130af161 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Find pairs of observations from the same pattern
#
# Copyright © 2014-2020 Deutsches Elektronen-Synchrotron DESY,
#                       a research centre of the Helmholtz Association.
#
# Author:
#    2014-2017 Thomas White <taw@physics.org>
#

import re as regexp

fn1 = "test-0.5.0-satfix.stream"
fn2 = "test-curr.stream"

def find_405(f):
    lines = dict()
    fn = ""
    prog = regexp.compile("^\s+([\d-]+)\s+([\d-]+)\s+([\d-]+)\s+")
    while True:
        fline = f.readline()
        if not fline:
            break
        if fline.find("Image filename: ") != -1:
            fn = fline.split(': ')[1].rstrip("\r\n")
            continue
        match = prog.match(fline)
        if not match:
            continue
        h = int(match.group(1))
        k = int(match.group(2))
        l = int(match.group(3))
        if (h==0) and (k==0) and (l==6):
            lines[fn] = fline
        if (h==0) and (k==0) and (l==-6):
            lines[fn] = fline
    return lines

f = open(fn1, 'r')
flines = find_405(f)
print("{} measurements in {}".format(len(flines),fn1))

g = open(fn2, 'r')
glines = find_405(g)
print("{} measurements in {}".format(len(glines),fn2))

print("\nThe common measurements:\n")
for fn in flines.keys():
    if fn in glines:
        print(fn)
        print(flines[fn].rstrip("\r\n"))
        print(glines[fn])
        print()
        del flines[fn]
        del glines[fn]

print("\nThe measurements only in {}:\n".format(fn1))

for fn in flines.keys():
    print(fn)
    print(flines[fn].rstrip("\r\n"))
    print()

print("\nThe measurements only in {}:\n".format(fn2))

for fn in glines.keys():
    print(fn)
    print(glines[fn].rstrip("\r\n"))
    print("")