From 61a78fb16b031f839d5395047ff7c3171b70db5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Thu, 18 Aug 2016 21:14:27 +0200 Subject: Initial commit --- lidt/__init__.py | 95 +++++ lidt/form.glade | 1026 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ lidt/lidt.py | 174 +++++++++ lidt/plotout.py | 121 +++++++ 4 files changed, 1416 insertions(+) create mode 100644 lidt/__init__.py create mode 100644 lidt/form.glade create mode 100644 lidt/lidt.py create mode 100644 lidt/plotout.py (limited to 'lidt') diff --git a/lidt/__init__.py b/lidt/__init__.py new file mode 100644 index 0000000..5966a98 --- /dev/null +++ b/lidt/__init__.py @@ -0,0 +1,95 @@ +# 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 . + +import os +import sys + +import gi +gi.require_version('Gtk', '3.0') +from gi.repository import Gtk + +#from . import lidt +import lidt +#from . import plotout +import plotout + +L = None +builder = None + +label_list = [ + "actarea", + "spotzise", + "numspots", + "disttestsitess", + "disttestsitesshex", + "numpulsperstep", + "numsitespulsstep", + "numofsiteseng", + "numengavsample", + "numofneededsites", + "numofneededsitesbool" + ] + +def updategtk(): + if builder is None: + return + #print("render") + for edt in label_list: + #print(edt) + edtobj = builder.get_object(edt) + edtobj.set_text(str(eval("L." + edt))) + +class Handler: + def __init__(self, lidt): + self.lidt = lidt + + def onDeleteWindow(self, *args): + Gtk.main_quit(*args) + + def onRootChange(self, editable): + #print("signal " + Gtk.Buildable.get_name(editable)) + try: + eval("self.lidt.set_" + Gtk.Buildable.get_name(editable) + "(float(editable.get_text()))") + self.lidt.calc() + except ValueError: + print("Invalid input!") + + def render_click(widg, _): + plotout.grid_render(window, L.disttestsitess, L.beamdia) + + +def main(): + global L + L = lidt.Lidt(updategtk) + + glade_file = os.path.join(os.path.dirname(__file__), "form.glade") + + global builder + builder = Gtk.Builder() + builder.add_from_file(glade_file) + builder.connect_signals(Handler(L)) + + updategtk() + + global window + window = builder.get_object("window") + window.show_all() + + Gtk.main() + + +if __name__ == "__main__": + main() diff --git a/lidt/form.glade b/lidt/form.glade new file mode 100644 index 0000000..0faa5e7 --- /dev/null +++ b/lidt/form.glade @@ -0,0 +1,1026 @@ + + + + + + False + LIDT + + + + True + False + vertical + + + True + False + + + True + False + Sample diameter: + right + 19 + + + False + True + 0 + + + + + True + True + 6 + number + + + + True + True + 1 + + + + + True + False + [cm] + 6 + + + False + True + 2 + + + + + False + True + 0 + + + + + True + False + + + True + False + Active area diameter: + right + 19 + + + False + True + 0 + + + + + True + True + 5 + number + + + + True + True + 1 + + + + + True + False + [cm] + 6 + + + False + True + 2 + + + + + False + True + 1 + + + + + True + False + + + True + False + Beam diameter: + right + 19 + + + False + True + 0 + + + + + True + True + 0.1 + number + + + + True + True + 1 + + + + + True + False + [cm] + 6 + + + False + True + 2 + + + + + False + True + 2 + + + + + True + False + + + False + True + 3 + + + + + True + False + + + True + False + vertical + + + True + False + + + True + False + Active area: + + + False + True + 0 + + + + + True + False + 0 + right + True + + + False + True + 5 + 1 + + + + + True + False + [cm^2] + + + False + True + 2 + + + + + True + True + 0 + + + + + True + False + + + True + False + Spot size: + + + False + True + 0 + + + + + True + False + 0 + right + True + + + False + True + 5 + 1 + + + + + True + False + [mm^2] + + + False + True + 2 + + + + + True + True + 1 + + + + + True + False + + + True + False + Number of spots: + + + False + True + 0 + + + + + True + False + 0 + right + True + + + False + True + 5 + 1 + + + + + True + False + [-] + + + False + True + 2 + + + + + True + True + 2 + + + + + True + True + 0 + + + + + True + False + vertical + + + True + False + + + True + False + Distance between test sites (square): + + + False + True + 0 + + + + + True + False + 0 + right + True + + + False + True + 5 + 1 + + + + + True + False + [cm] + + + False + True + 2 + + + + + True + True + 0 + + + + + True + False + + + True + False + Distance between test sites (hex): + + + False + True + 0 + + + + + True + False + 0 + right + True + + + False + True + 5 + 1 + + + + + True + False + [cm] + + + False + True + 2 + + + + + True + True + 1 + + + + + True + False + + + + False + True + 2 + + + + + True + True + 1 + + + + + False + True + 4 + + + + + True + True + + + True + False + vertical + + + True + False + + + True + False + Min number of pulses: + right + 20 + + + False + True + 0 + + + + + True + True + 100 + number + + + + True + True + 1 + + + + + True + False + [cm] + 6 + + + False + True + 2 + + + + + False + True + 0 + + + + + True + False + + + True + False + Max number of pulses: + right + 20 + + + False + True + 0 + + + + + True + True + 5000 + number + + + + True + True + 1 + + + + + True + False + [cm] + 6 + + + False + True + 2 + + + + + False + True + 1 + + + + + True + False + + + True + False + Number of steps: + right + 20 + + + False + True + 0 + + + + + True + True + 5 + number + + + + True + True + 1 + + + + + True + False + [cm] + 6 + + + False + True + 2 + + + + + False + True + 2 + + + + + True + False + + + True + False + Number of pulses per. step: + + + False + True + 0 + + + + + True + False + NaN + True + + + False + True + 2 + 1 + + + + + False + True + 3 + + + + + True + False + + + True + False + Number of sites for pulse step: + + + False + True + 0 + + + + + True + False + NaN + True + + + False + True + 1 + + + + + False + True + 4 + + + + + True + False + + + True + False + Placeholder: + + + False + True + 0 + + + + + True + False + + + False + True + 1 + + + + + False + True + 5 + + + + + + + True + False + Procedure 1 + + + False + + + + + True + False + vertical + + + True + False + + + True + False + Number of pulses S: + + + False + True + 0 + + + + + True + True + 18 + number + + + + True + True + 1 + + + + + False + True + 0 + + + + + True + False + + + True + False + Number of sites for single energy acording to S (=5*int(1 + log S)): + + + False + True + 0 + + + + + True + False + NaN + + + False + True + 1 + + + + + False + True + 1 + + + + + True + False + + + True + False + Number of energy steps available for sample: + + + False + True + 0 + + + + + True + False + NaN + True + + + False + True + 1 + + + + + False + True + 2 + + + + + True + False + + + True + False + Number of desired energy steps: + + + False + True + 0 + + + + + True + True + 5 + number + + + + True + True + 1 + + + + + False + True + 3 + + + + + True + False + + + True + False + Number of needed sites: + + + False + True + 0 + + + + + True + False + NaN + True + + + False + True + 2 + 1 + + + + + True + False + Possible + + + False + True + 4 + 2 + + + + + False + True + 4 + + + + + 1 + + + + + True + False + Procedure 2 + + + 1 + False + + + + + True + False + vertical + + + Render + True + True + True + + + + False + True + 0 + + + + + + + + 2 + + + + + True + False + Grid + + + 2 + False + + + + + True + True + 7 + + + + + + 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 . + +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() diff --git a/lidt/plotout.py b/lidt/plotout.py new file mode 100644 index 0000000..cb3b838 --- /dev/null +++ b/lidt/plotout.py @@ -0,0 +1,121 @@ +# 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 . + +import math +import gi +gi.require_version('Gtk', '3.0') +from gi.repository import Gtk, Gdk + +grid = None +grid_bot = None +step = 50 +dia = 300 +selectx = None +selecty = None +grid_h = 1 + +def __grid_draw(wd, cr): + w = wd.get_allocated_width() + h = wd.get_allocated_height() + if w < h: + s = w + else: + s = h + cr.set_source_rgb(0, 0, 0) + h = s / 2 # half of the size of drawing area + global grid_h + grid_h = h + st = (h / dia) * step + + cr.rectangle(0, 0, s, s) + cr.fill() + + cr.move_to(0, h) + cr.arc(h, h, h, 0, 2 * math.pi) + cr.set_source_rgb(1, 1, 1) + cr.fill() + + cr.set_source_rgb(0, 0, 0) + i = 0 + while i < h: + cr.move_to(h + i, 0) + cr.line_to(h + i, s) + cr.move_to(h - i, 0) + cr.line_to(h - i, s) + cr.move_to(0, h + i) + cr.line_to(s, h + i) + cr.move_to(0, h - i) + cr.line_to(s, h - i) + i = i + st + cr.set_line_width(1) + cr.stroke() + + if selectx is not None: + slx = (h / dia) * selectx + sly = (h / dia) * selecty + cr.move_to(h +slx - 5, h + sly) + cr.arc(h + slx, h + sly, 5, 0, 2 * math.pi) + cr.set_source_rgb(0, 1, 0) + cr.fill() + +def __grid_button(widg, button): + global selectx + global selecty + selectx = (button.x - grid_h) * (dia / grid_h) + selecty = (button.y - grid_h) * (dia / grid_h) + selectx = round(selectx / step) * step + selecty = round(selecty / step) * step + grid_bot.set_text(str(selectx) + ':' + str(selecty)) + grid.queue_draw() + +def test(): + grid_render(None, 1, 1) + grid.connect("delete-event", Gtk.main_quit) + Gtk.main() + + +def grid_render(win, st, di): + global grid + if not grid is None: + grid.destroy() + global step + step = st + global dia + dia = di + global selectx + selectx = None + global selecty + selecty = None + grid = Gtk.Window() + grid.set_title("LIDT: Grid") + grid.set_attached_to(win) + grid.set_destroy_with_parent(True) + + box = Gtk.Box(orientation = Gtk.Orientation.VERTICAL) + grid.add(box) + + drawarea = Gtk.DrawingArea() + drawarea.set_size_request(512, 512) + drawarea.set_events(drawarea.get_events() | Gdk.EventMask.BUTTON_PRESS_MASK) + drawarea.connect('draw', __grid_draw) + drawarea.connect('button-press-event', __grid_button) + box.pack_start(drawarea, True, True, 0) + + global grid_bot + grid_bot = Gtk.Label('') + box.pack_start(grid_bot, False, False, 0) + + grid.show_all() -- cgit v1.2.3