summaryrefslogtreecommitdiff
path: root/lidt/lidt.py
diff options
context:
space:
mode:
Diffstat (limited to 'lidt/lidt.py')
-rw-r--r--lidt/lidt.py174
1 files changed, 174 insertions, 0 deletions
diff --git a/lidt/lidt.py b/lidt/lidt.py
new file mode 100644
index 0000000..ba5ca39
--- /dev/null
+++ b/lidt/lidt.py
@@ -0,0 +1,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()