summaryrefslogtreecommitdiff
path: root/lidt/lidt.py
blob: ba5ca39f01fb0c27c55007629d56767d44bca6fa (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# LIDT
# Copyright (C) 2016  Karel Kočí
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import os
import sys
import math


class Lidt:
    def __init__(self, updatecall):
        self.updt = updatecall # Callback to GTK window for variable download

        # Root calculations
        self.smdia = 6 # Sample diameter
        self.acaredia = 5 # Active area diameter
        self.beamdia = 0.1 # Beam diameter

        # Procedure 1 calculations
        self.minnumpulse = 100 # Min number of pulses
        self.maxnumpulse = 5000 # Max number of pulses
        self.numsteps = 5 # Number of steps

        # Procedure 2 calculations
        self.numpulses = 18 # Number of pulses S
        self.numdesengstep = 5 # Number of desired energy steps

        self.calc()


    def set_smdia(self, val):
        "Set Sample Diameter"
        if val < 0:
            return False
        #print("houhou")
        self.smdia = val
        self.calc()
        return True


    def set_acaredia(self, val):
        "Set Active area diameter"
        if val < 0:
            return False
        self.acaredia = val
        self.calc()
        return True


    def set_beamdia(self, val):
        "Set Beam diameter"
        if val < 0:
            return False
        self.beamdia = val
        self.calc()
        return True


    def set_minnumpulse(self, val):
        "Set Min number of pulses"
        if val < 0:
            return False
        if self.maxnumpulse <= val:
            return False
        self.minnumpulse = val
        self.calc()
        return True


    def set_maxnumpulse(self, val):
        "Set Max number of pulses"
        if val < 0:
            return False
        if self.minnumpulse >= val:
            return False
        self.maxnumpulse = val
        self.calc()
        return True


    def set_numsteps(self, val):
        "Set Number of steps"
        if val < 0:
            return False
        self.numsteps = int(val)
        self.calc()
        return True


    def set_numpulses(self, val):
        "Set Number of pulses S"
        if val < 0:
            return False
        self.numpulses = val
        self.calc()
        return True


    def set_numdesengstep(self, val):
        "Set Number of desired energy steps"
        if val < 0:
            return False
        self.numdesengstep = val
        self.calc()
        return True


    def calc(self):
        ## Root
        # Active area
        self.actarea = math.pi * self.acaredia * self.acaredia / 4

        # Spot size
        self.spotzise = (math.pi * self.beamdia * self.beamdia / 4) * 0.9

        # Number of spots
        self.numspots = math.pi * self.acaredia * self.acaredia / \
                        (4 * self.actarea * self.spotzise)

        # Distance between test sites (square)
        self.disttestsitess = math.sqrt(self.actarea) / self.numspots

        # Distance between test sites (hex)
        self.disttestsitesshex = math.sqrt(2*self.actarea) /  \
            self.numspots * 5.1961524

        ## Procedure 1
        # Number of pulses per step
        # Lets normalize this to <0,1>
        arr = []
        for a in range(1, self.numsteps):
            # Using normalization to <0,1> for exact calculations
            # ea = log(e^0 + (a/steps * e^1))
            ea = math.log(1 + ((a/self.numsteps) * math.e))
            # Append real logarithmic step
            # ea =  (r - min) / (max - min)
            # r =  ea * (max - min) + min
            arr.append(str(
                (ea * (self.maxnumpulse - self.minnumpulse)) \
                        + self.minnumpulse
                ))
        self.numpulsperstep = ",".join(arr)
        # TODO round result numbers to most significant number

        # Number of sites for pulse step
        self.numsitespulsstep = 5 * (1 + math.log10(self.numspots))

        ## Procedure 2
        # Number of sites for single energy according to S
        self.numofsiteseng = 5 * (1 + math.log10(self.numpulses))

        # Number of energy steps available for sample
        self.numengavsample = self.numspots / self.numofsiteseng

        # Number of needed sites
        self.numofneededsites = self.numofsiteseng * self.numdesengstep

        # Number of needed sites - possibility
        self.numofneededsitesbool = not self.numofneededsites > self.numspots

        # Invoke Gtk form
        self.updt()