{"id":10795,"date":"2016-04-06T08:54:00","date_gmt":"2016-04-06T08:54:00","guid":{"rendered":"http:\/\/melotopia.net\/b\/?p=10795"},"modified":"2016-04-06T08:54:00","modified_gmt":"2016-04-06T08:54:00","slug":"%ea%b4%91%ec%84%ac%ec%9c%a0-%ea%b0%80%ea%b3%b5-%ed%9b%84-%eb%8d%b0%ec%9d%b4%ed%84%b0%eb%a5%bc-%ec%9e%90%eb%8f%99%ec%9c%bc%eb%a1%9c-%eb%b6%84%ec%84%9d%ed%95%98%eb%8a%94-%ed%94%84%eb%a1%9c%ea%b7%b8","status":"publish","type":"post","link":"http:\/\/melotopia.net\/b\/?p=10795","title":{"rendered":"\uad11\uc12c\uc720 \uac00\uacf5 \ud6c4 \ub370\uc774\ud130\ub97c \uc790\ub3d9\uc73c\ub85c \ubd84\uc11d\ud558\ub294 \ud504\ub85c\uadf8\ub7a8"},"content":{"rendered":"<div class=\"desc\">\n<div class=\"tt_article_useless_p_margin\">\n         #!\/usr\/bin\/env python<br \/>\n         <br \/>\n         # -*- coding: CP949 -*-<br \/>\n         <br \/>\n         #<br \/>\n         <br \/>\n         # generated by wxGlade 0.7.2 on Tue Apr 05 01:49:01 2016<br \/>\n         <br \/>\n         #<br \/>\n         <br \/>\n         # This is a converting program from thorlabs powermeter datafile taken from thorlab official data acquisition program to radius vs power after fiber taper process.<br \/>\n         <br \/>\n         # IF you want to use this program for your own purpose except learning python and programming, you have to ask me licence policy and copyright.<br \/>\n         <br \/>\n         # snowall@kaist.ac.kr \/ snowall@gmail.com \/ Keehwan Nam, Physics department, KAIST. 2016.<br \/>\n         <br \/>\n         #<br \/>\n         <br \/>\n         import wx<\/p>\n<p>         # begin wxGlade: dependencies<br \/>\n         <br \/>\n         import gettext<br \/>\n         <br \/>\n         # end wxGlade<\/p>\n<p>         # begin wxGlade: extracode<br \/>\n         <br \/>\n         # end wxGlade<br \/>\n         <br \/>\n         import numpy as np<br \/>\n         <br \/>\n         import os<br \/>\n         <br \/>\n         import re<br \/>\n         <br \/>\n         import sys<\/p>\n<p>         import struct<\/p>\n<p>         f= open(&#8216;sample.png&#8217;, &#8216;rb&#8217;)<\/p>\n<p>         w, h = struct.unpack(&#8216;>LL&#8217;, f.read()[16:24])<br \/>\n         <br \/>\n         displaysizeX = int(w)<br \/>\n         <br \/>\n         displaysizeY = int(h)<br \/>\n         <br \/>\n         f.close()<br \/>\n         <br \/>\n         reload(sys)<br \/>\n         <br \/>\n         sys.setdefaultencoding(&#8216;cp949&#8217;)<br \/>\n         <br \/>\n         #~ displaysizeX=1280<br \/>\n         <br \/>\n         #~ displaysizeY=1024<br \/>\n         <br \/>\n         x,y=0,0<br \/>\n         <br \/>\n         a=0<br \/>\n         <br \/>\n         b=0<br \/>\n         <br \/>\n         c=0<br \/>\n         <br \/>\n         sec=0<br \/>\n         <br \/>\n         minute=0<br \/>\n         <br \/>\n         hours=0<br \/>\n         <br \/>\n         msec=0<br \/>\n         <br \/>\n         class MyDialog(wx.Dialog):<br \/>\n         <br \/>\n         x00=0<br \/>\n         <br \/>\n         y00=0<br \/>\n         <br \/>\n         def __init__(self, parent, id, title):<br \/>\n         <br \/>\n         wx.Dialog.__init__(self, parent, id, title, size=(displaysizeX,displaysizeY))<br \/>\n         <br \/>\n         self.canvas = wx.StaticBitmap(self, -1, wx.Bitmap(&#8220;sample.png&#8221;, wx.BITMAP_TYPE_ANY))<br \/>\n         <br \/>\n         self.canvas.Bind(wx.EVT_LEFT_DOWN, self.positionnow)<\/p>\n<p>         def positionnow(self, event):<br \/>\n         <br \/>\n         self.x00=wx.MouseEvent.GetX(event)<br \/>\n         <br \/>\n         self.y00=wx.MouseEvent.GetY(event)<br \/>\n         <br \/>\n         print((wx.MouseEvent.GetX(event),wx.MouseEvent.GetY(event)))<\/p>\n<p>         def drawTick(self, pl):<br \/>\n         <br \/>\n         self.mydc = wx.MemoryDC()<br \/>\n         <br \/>\n         self.canvas2 = wx.Bitmap(&#8220;sample.png&#8221;, wx.BITMAP_TYPE_ANY)<br \/>\n         <br \/>\n         self.mydc.SelectObject(self.canvas2)<br \/>\n         <br \/>\n         self.mypen=wx.Pen(wx.Colour(255,0,0),5)<br \/>\n         <br \/>\n         self.mypen.SetWidth(1)<br \/>\n         <br \/>\n         self.mydc.SetPen(self.mypen)<br \/>\n         <br \/>\n         self.mydc.DrawLines(pl)<br \/>\n         <br \/>\n         self.mydc.SelectObject(wx.NullBitmap)<br \/>\n         <br \/>\n         self.canvas.SetBitmap(self.canvas2)<br \/>\n         <br \/>\n         self.mydc = None<br \/>\n         <br \/>\n         self.canvas = wx.StaticBitmap(self, -1, self.canvas2)<br \/>\n         <br \/>\n         return<\/p>\n<p>         def graphroutine(self, myf):<br \/>\n         <br \/>\n         self.convertedData=[]<br \/>\n         <br \/>\n         self.pointlist=[]<br \/>\n         <br \/>\n         src=open(myf, &#8220;r&#8221;)<br \/>\n         <br \/>\n         src.readline()<br \/>\n         <br \/>\n         d=src.readline()<br \/>\n         <br \/>\n         a=d.split(&#8221; &#8220;)<br \/>\n         <br \/>\n         self.mini=np.inf<br \/>\n         <br \/>\n         self.maxi=0.<br \/>\n         <br \/>\n         while True:<br \/>\n         <br \/>\n         d=src.readline()<br \/>\n         <br \/>\n         if d==&#8221;&#8221;:<br \/>\n         <br \/>\n         break<br \/>\n         <br \/>\n         a=d.split(&#8221; &#8220;)<br \/>\n         <br \/>\n         msec=float(((a[1]).split(&#8220;.&#8221;))[1])*0.001<br \/>\n         <br \/>\n         sec=float(a[2].split(&#8220;:&#8221;)[2].split(&#8220;\\t&#8221;)[0])<br \/>\n         <br \/>\n         minute=float((a[2]).split(&#8220;:&#8221;)[1])*60.<br \/>\n         <br \/>\n         hours=float((a[2]).split(&#8220;:&#8221;)[0])*3600.<br \/>\n         <br \/>\n         self.time=msec+sec+minute+hours<br \/>\n         <br \/>\n         self.convertedData+=[[self.time,float(a[2].split(&#8220;:&#8221;)[2].split(&#8220;\\t&#8221;)[1])]]<br \/>\n         <br \/>\n         if self.convertedData[-1][1]<self.mini:\n         <br \/>\n         self.mini=self.convertedData[-1][1]<br \/>\n         <br \/>\n         if self.convertedData[-1][1]>self.maxi:<br \/>\n         <br \/>\n         self.maxi=self.convertedData[-1][1]<br \/>\n         <br \/>\n         self.time0=self.convertedData[0][0]<br \/>\n         <br \/>\n         self.time1=self.convertedData[-1][0]<br \/>\n         <br \/>\n         self.timescale=displaysizeX\/(self.time1-self.time0)<br \/>\n         <br \/>\n         self.vertscale=displaysizeY\/(self.maxi-self.mini)<br \/>\n         <br \/>\n         for cd in self.convertedData:<br \/>\n         <br \/>\n         self.pointlist+=[[np.ceil((cd[0]-self.time0)*self.timescale),displaysizeY-np.ceil((cd[1]-self.mini)*self.vertscale)]]<br \/>\n         <br \/>\n         self.drawTick(self.pointlist)<br \/>\n         <br \/>\n         src.flush()<br \/>\n         <br \/>\n         src.close()<br \/>\n         <br \/>\n         return<\/p>\n<p>         def findV(self,no):<br \/>\n         <br \/>\n         logfile=open(&#8220;log.csv&#8221;,&#8221;r&#8221;)<br \/>\n         <br \/>\n         try:<br \/>\n         <br \/>\n         while True:<br \/>\n         <br \/>\n         d=logfile.readline()<br \/>\n         <br \/>\n         if d==&#8221;&#8221;:<br \/>\n         <br \/>\n         break<br \/>\n         <br \/>\n         a=d.split(&#8220;,&#8221;)<br \/>\n         <br \/>\n         if a[0]==str(no):<br \/>\n         <br \/>\n         logfile.close()<br \/>\n         <br \/>\n         return a<br \/>\n         <br \/>\n         except:<br \/>\n         <br \/>\n         logfile.close()<br \/>\n         <br \/>\n         return &#8220;0&#8221;<\/p>\n<p>         def inverse_ratio(self,logdata):<br \/>\n         <br \/>\n         return np.sqrt(((2.*float(logdata[15]))-float(logdata[14]))\/((2.*float(logdata[15]))+float(logdata[14])))<\/p>\n<p>         def converting(self,f):<br \/>\n         <br \/>\n         self.time0=(self.x00\/self.timescale)+self.time0<br \/>\n         <br \/>\n         tar=open(f[:-4]+&#8221;_processed.txt&#8221;, &#8220;w&#8221;)<br \/>\n         <br \/>\n         errorlist=open(&#8220;errorlist.txt&#8221;,&#8221;a&#8221;)<br \/>\n         <br \/>\n         plot=open(f[:-4]+&#8221;.gpl&#8221;, &#8220;w&#8221;)<br \/>\n         <br \/>\n         shotnumber=re.search(&#8220;\\d+&#8221;,f.split(&#8220;\\\\&#8221;)[-1]).group()<br \/>\n         <br \/>\n         expcondition=self.findV(shotnumber)<br \/>\n         <br \/>\n         shotlog=self.inverse_ratio(expcondition)<br \/>\n         <br \/>\n         try:<br \/>\n         <br \/>\n         for cd in self.convertedData:<br \/>\n         <br \/>\n         tar.writelines(str(cd[0])+&#8221;\\t&#8221;+str(cd[1])+&#8221;\\t&#8221;+str(float(expcondition[9])*np.power(shotlog,(cd[0]-self.time0)\/(float(expcondition[11])\/float(expcondition[15]))))+&#8221;\\t&#8221;+str(cd[1])+&#8221;\\n&#8221;)<br \/>\n         <br \/>\n         plot.writelines(&#8220;set logscale x\\nplot \\&#8221;&#8221;+(f.split(&#8220;\\\\&#8221;)[-1])[:-4]+&#8221;_processed.txt\\&#8221; using 3:4 w l &#8220;)<br \/>\n         <br \/>\n         except:<br \/>\n         <br \/>\n         errorlist.writelines(f+&#8221;\\n&#8221;)<br \/>\n         <br \/>\n         print &#8220;error&#8221;<br \/>\n         <br \/>\n         finally:<br \/>\n         <br \/>\n         tar.flush()<br \/>\n         <br \/>\n         tar.close()<br \/>\n         <br \/>\n         plot.flush()<br \/>\n         <br \/>\n         plot.close()<\/p>\n<p>         class MainPlotFrame(wx.Frame):<br \/>\n         <br \/>\n         def __init__(self, *args, **kwds):<br \/>\n         <br \/>\n         # begin wxGlade: MainPlotFrame.__init__<br \/>\n         <br \/>\n         kwds[&#8220;style&#8221;] = wx.DEFAULT_FRAME_STYLE<br \/>\n         <br \/>\n         wx.Frame.__init__(self, *args, **kwds)<br \/>\n         <br \/>\n         self.dig = wx.FileDialog(None, message=&#8221;Choose data files&#8221;, style = wx.FD_MULTIPLE)<br \/>\n         <br \/>\n         self.dia = MyDialog(self, -1, &#8216;Close after click!&#8217;)<br \/>\n         <br \/>\n         self.__set_properties()<br \/>\n         <br \/>\n         self.__do_layout()<br \/>\n         <br \/>\n         if self.dig.ShowModal() == wx.ID_OK:<br \/>\n         <br \/>\n         for fn in self.dig.GetPaths():<br \/>\n         <br \/>\n         self.dia.graphroutine(fn)<br \/>\n         <br \/>\n         self.dia.ShowModal()<br \/>\n         <br \/>\n         self.dia.converting(fn)<br \/>\n         <br \/>\n         self.Close()<br \/>\n         <br \/>\n         # end wxGlade<\/p>\n<p>         def __set_properties(self):<br \/>\n         <br \/>\n         # begin wxGlade: MainPlotFrame.__set_properties<br \/>\n         <br \/>\n         self.SetTitle((&#8220;frame_1&#8221;))<br \/>\n         <br \/>\n         self.SetSize((displaysizeX, displaysizeY))<br \/>\n         <br \/>\n         # end wxGlade<\/p>\n<p>         def __do_layout(self):<br \/>\n         <br \/>\n         # begin wxGlade: MainPlotFrame.__do_layout<br \/>\n         <br \/>\n         sizer_1 = wx.BoxSizer(wx.VERTICAL)<br \/>\n         <br \/>\n         self.SetSizer(sizer_1)<br \/>\n         <br \/>\n         self.Layout()<br \/>\n         <br \/>\n         # end wxGlade<\/p>\n<p>         # end of class MainPlotFrame<br \/>\n         <br \/>\n         if __name__ == &#8220;__main__&#8221;:<br \/>\n         <br \/>\n         app = wx.App(0)<br \/>\n         <br \/>\n         #~ wx.InitAllImageHandlers()<br \/>\n         <br \/>\n         frame_main = MainPlotFrame(None, -1, &#8220;&#8221;)<br \/>\n         <br \/>\n         frame_main.Show()<br \/>\n         <br \/>\n         app.MainLoop()<br \/>\n         <\/p>\n<p>\n\n<\/p>\n<div style=\"width:100%;margin-top:30px;clear:both;height:30px\">\n<div style=\"width:31px;float:left;\">\n<a href=\"\/toolbar\/popup\/abuseReport\/?entryId=3639\" onclick=\"window.open(this.href, 'tistoryThisBlogPopup', 'width=550, height=510, toolbar=no, menubar=no, status=no, scrollbars=no'); return false;\"><br \/>\n<img data-recalc-dims=\"1\" decoding=\"async\" alt=\"\uc2e0\uace0\" src=\"https:\/\/i0.wp.com\/t1.daumcdn.net\/tistory_admin\/static\/ico\/ico_spam_report.png\" style=\"border:0\"\/><br \/>\n<\/a>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>#!\/usr\/bin\/env python # -*- coding: CP949 -*- # # generated by wxGlade 0.7.2 on Tue Apr 05 01:49:01 2016 # # This is a converting program from thorlabs powermeter datafile taken from thorlab official data acquisition program to radius vs power after fiber taper process. # IF you want to use this program for your [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[12],"tags":[],"class_list":["post-10795","post","type-post","status-publish","format-standard","hentry","category-12"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8o6gA-2O7","jetpack-related-posts":[],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"http:\/\/melotopia.net\/b\/index.php?rest_route=\/wp\/v2\/posts\/10795","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/melotopia.net\/b\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/melotopia.net\/b\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/melotopia.net\/b\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/melotopia.net\/b\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10795"}],"version-history":[{"count":0,"href":"http:\/\/melotopia.net\/b\/index.php?rest_route=\/wp\/v2\/posts\/10795\/revisions"}],"wp:attachment":[{"href":"http:\/\/melotopia.net\/b\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10795"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/melotopia.net\/b\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10795"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/melotopia.net\/b\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10795"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}