From d4783015f56a358166d1883a21c75832b7f17869 2016-09-14 17:11:06 From: Juan C. Espinoza Date: 2016-09-14 17:11:06 Subject: [PATCH] Improve abs pattern views, templates and plots. git-svn-id: http://jro-dev.igp.gob.pe/svn/jro_hard/radarsys/trunk/webapp@203 aa17d016-51d5-4e8b-934c-7b2bbb1bbe71 --- diff --git a/apps/abs/static/images/loader.gif b/apps/abs/static/images/loader.gif new file mode 100644 index 0000000000000000000000000000000000000000..dcf8e4f948c088716076a398a83f21beb0a652df GIT binary patch literal 8468 zc$}Ttdsx%;+XwLP&PT>JHW;wM4lp(jV=VKrvfl&W?MrxMkh1Rxkqz*`NgyOBN|*yV zrGThl2ncA9ii)J7Scqt$M3|(OWMF8fR^&rvzn|6f*}k%i%j$VD{)FrDy4>r2-=F)w z_rikkdC!={kQmwnLBx_?Yya55t$Vt?Lv5c-`fMMVyg!|EbhP{WJzh<3?eOI2o$2n+ z@8!HV#@pOmdwz2N=l7=n{gAo2xAOeh(5-vRI*0aOo}AM-z%1{rJU4dlr-x}rM|-c| z6V~)L3{MukH#T%0EkkK1 zMtg7E6K)@9_++x6f9&_)e~13wkK}j8Qe@eS+Auw$QK<yLyB6doqd*rDGF*b{SRXF=+UmnQ z@fMUBIGrwoNSwlCKS<(Tl57!pRK}?xh+eH{)XH{5a%yP}k+o2j2gNs#xuda`q3~^m z-l?pw<*^T^R2S5e-Fqa(CH}P%1+@oKmv98NZW@lH$2TeC{aPoOKj`%;ncJGLQ4I<< zq$>!mBig$?!G5b0Yg>=Nj7vQ%>Ix4_D|udiRb?~@w{%WYCOZJ<=@&$ges%W^ZKdn? z=Hk!?L_}96#wBD%kxPzL_0XH2n**xCS zr&Ii>1a3SkfuyccPy(P3a^4$t_ybRX4=@3E&WTapj6Wy`KnE%UlmO7issNCJDggeV z5P&e|4@wLx0Z?3^Oh6%kngWFY3JtI?>l_8;0EzQ1c^9Pm zK`f1`%nJGDYN$CHuPs)0RjvpM(9r52@mpCuD_PRQtnsvZdF-p%4f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b}OO>x9e1*YhrL;^h^$+y?Sqh>@?!?{y81F;XE85 zGq?^1(a?hP6skc~r6+J$k!8|-F~{^nG46Ho78Lqc>pLZKJ%C8%`6xLGH`SRm-Uktj zAUqyV4e6xPirEBd-`f$|feP7V*aFjcQdb^@dtj>XW0{p&_+dVk6QU)q>-4D_&uo!X z@Vt&>I{pa`5Vrl)-h8n+7?@(OC^jg8$lA7<&3`!D+rK>pHGs`Z%$ba0Q -
- Error in Parameters - Error in Parameters - + Error ploting...
- {% endblock %} diff --git a/apps/abs/templates/abs_patterns.html b/apps/abs/templates/abs_patterns.html index 95d19bc..95b3736 100644 --- a/apps/abs/templates/abs_patterns.html +++ b/apps/abs/templates/abs_patterns.html @@ -42,7 +42,7 @@ {% endblock %} diff --git a/apps/abs/urls.py b/apps/abs/urls.py index 44df298..1160620 100644 --- a/apps/abs/urls.py +++ b/apps/abs/urls.py @@ -9,9 +9,8 @@ urlpatterns = ( #url(r'^(?P-?\d+)/import/$', views.dev_conf_import, name='url_import_abs_conf'), #url(r'^(?P-?\d+)/export/$', views.dev_conf_export, name='url_export_abs_conf'), url(r'^(?P-?\d+)/plot/$', views.plot_patterns, name='url_plot_abs_patterns'), - url(r'^(?P-?\d+)/plot/(?P-?\d+)/$', views.plot_pattern, name='url_plot_abs_pattern'), - url(r'^(?P-?\d+)/plot_up_beam/(?P-?\d+)/$', views.plot_uppattern, name='url_plot_up_beam'), - url(r'^(?P-?\d+)/plot_down_beam/(?P-?\d+)/$', views.plot_downpattern, name='url_plot_down_beam'), + url(r'^(?P-?\d+)/plot/(?P-?\d+)/$', views.plot_patterns, name='url_plot_abs_patterns'), + url(r'^(?P-?\d+)/plot/(?P-?\d+)/(?P[\w\-]+)/pattern.png$', views.plot_pattern, name='url_plot_beam'), url(r'^(?P-?\d+)/add_beam/$', views.add_beam, name='url_add_abs_beam'), url(r'^(?P-?\d+)/beam/(?P-?\d+)/delete/$', views.remove_beam, name='url_remove_abs_beam'), url(r'^(?P-?\d+)/beam/(?P-?\d+)/edit/$', views.edit_beam, name='url_edit_abs_beam'), diff --git a/apps/abs/utils/Graphics_Miscens.py b/apps/abs/utils/Graphics_Miscens.py index ae73466..f2c15c2 100644 --- a/apps/abs/utils/Graphics_Miscens.py +++ b/apps/abs/utils/Graphics_Miscens.py @@ -18,13 +18,15 @@ class ColorTable: self.table = table #set to path for data folder, file: col_koki.dat if filepath==None: - filepath= './data/' + filepath= './apps/abs/utils/data/' self.filepath = filepath def readTable(self): if self.table>0: if self.table==1: - f = open(os.path.join(self.filepath,'col_koki.dat'),'rb') + + f = open(os.path.join(self.filepath, './col_koki.dat') ,'rb') + #f = open('./col_koki.dat','rb') diff --git a/apps/abs/utils/Graphics_OverJro.py b/apps/abs/utils/Graphics_OverJro.py index 6012cd2..457147b 100644 --- a/apps/abs/utils/Graphics_OverJro.py +++ b/apps/abs/utils/Graphics_OverJro.py @@ -47,10 +47,11 @@ class AntPatternPlot: -------------------- Created by Freddy Galindo, ROJ, 06 October 2009. """ - self.figure = None - pass + + self.fig = matplotlib.pyplot.figure(figsize=(8,8), facecolor='white') + self.ax = self.fig.add_subplot(111) - def contPattern(self,iplot=0,gpath='',filename='',mesg='',amp=None ,x=None ,y=None ,getCut=None,title=''): + def contPattern(self,iplot=0,gpath='',filename='',mesg='',amp=None ,x=None ,y=None ,getCut=None,title='', save=True): """ contPattern plots a contour map of the antenna pattern. @@ -81,34 +82,34 @@ class AntPatternPlot: labels = range(5) for i in numpy.arange(5):labels[i] = str(numpy.int(tmp[i])) - if iplot==0: - xsize = 8.0 - if matplotlib.get_backend()=='QT4Agg':xsize = 6.0 - ysize = 8.0 - self.figure = matplotlib.pyplot.figure(num=2,figsize=(xsize,ysize)) - matplotlib.pyplot.clf() colors = ((0,0,1.),(0,170/255.,0),(127/255.,1.,0),(1.,109/255.,0),(128/255.,0,0)) - CS = matplotlib.pyplot.contour(x,y,amp.transpose(),levels,colors=colors) + CS = self.ax.contour(x,y,amp.transpose(),levels,colors=colors) fmt = {} - for l,s in zip(CS.levels,labels):fmt[l] = s - - matplotlib.pyplot.annotate('Ng',xy=(-0.05,1.04),xytext=(0.01,0.962),xycoords='axes fraction',arrowprops=dict(facecolor='black', width=1.,shrink=0.2),fontsize=15.) - matplotlib.pyplot.annotate(mesg,xy=(0,0),xytext=(0.01,0.01),xycoords='figure fraction') - matplotlib.pyplot.clabel(CS,CS.levels,inline=True,fmt=fmt,fontsize=10) - matplotlib.pyplot.xlim(xmin,xmax) - matplotlib.pyplot.ylim(ymin,ymax) - matplotlib.pyplot.title("Total Pattern" + title) - matplotlib.pyplot.xlabel("West to South") - matplotlib.pyplot.ylabel("West to North") - matplotlib.pyplot.grid(True) - print "SAVE_FIG" - print gpath - print filename - save_fig = os.path.join(gpath,filename) - matplotlib.pyplot.savefig(save_fig,format='png') - - def plotRaDec(self,gpath=None,filename=None,jd=2452640.5,ra_obs=None,xg=None,yg=None,x=None,y=None): + for l,s in zip(CS.levels,labels): + fmt[l] = s + + self.ax.annotate('Ng',xy=(-0.05,1.04),xytext=(0.01,0.962),xycoords='axes fraction',arrowprops=dict(facecolor='black', width=1.,shrink=0.2),fontsize=15.) + self.ax.annotate(mesg,xy=(0,0),xytext=(0.01,0.01),xycoords='figure fraction') + self.ax.clabel(CS,CS.levels,inline=True,fmt=fmt,fontsize=10) + self.ax.set_xlim(xmin,xmax) + self.ax.set_ylim(ymin,ymax) + self.ax.set_title("Total Pattern: " + title) + self.ax.set_xlabel("West to South") + self.ax.set_ylabel("West to North") + self.ax.grid(True) + + if save: + save_fig = os.path.join(gpath,filename) + self.fig.savefig(save_fig,format='png') + + + + def close(self): + + matplotlib.pyplot.close(self.fig) + + def plotRaDec(self,gpath=None,filename=None,jd=2452640.5,ra_obs=None,xg=None,yg=None,x=None,y=None, save=True): """ plotRaDec draws right ascension and declination lines on a JRO plane. This function must call after conPattern. @@ -131,9 +132,9 @@ class AntPatternPlot: """ # Finding RA of observatory for a specific date - if ra_obs==None:ra_obs = numpy.array([23.37060849]) - if xg==None:xg = numpy.array([0.62918474,-0.77725579,0.]) - if yg==None:yg = numpy.array([0.77700346,0.62898048,0.02547905]) + if ra_obs is None:ra_obs = numpy.array([23.37060849]) + if xg is None:xg = numpy.array([0.62918474,-0.77725579,0.]) + if yg is None:yg = numpy.array([0.77700346,0.62898048,0.02547905]) # Getting HA and DEC axes mindec = -28; maxdec = 4; incdec = 2. @@ -142,8 +143,8 @@ class AntPatternPlot: minha = -20; maxha = 20; incha = 2. nha = numpy.int((maxha - minha)/incha) + 1 - mcosx = numpy.zeros((nha,ndec)) - mcosy = numpy.zeros((nha,ndec)) + #mcosx = numpy.zeros((nha,ndec)) + #mcosy = numpy.zeros((nha,ndec)) ha_axes = numpy.reshape(numpy.arange(nha)*incha + minha,(nha,1)) ones_dec = numpy.reshape(numpy.zeros(ndec) + 1,(ndec,1)) @@ -188,14 +189,14 @@ class AntPatternPlot: idec0 = numpy.int((-14 - mindec)/incdec) colorgrid = (1.,109/255.,0) - matplotlib.pyplot.plot(mcosx.transpose(),mcosy.transpose(),color=colorgrid,linestyle='--') + self.ax.plot(mcosx.transpose(),mcosy.transpose(),color=colorgrid,linestyle='--') for idec in numpy.arange(ndec): if idec != idec0: valx = (mcosx[idec,iha0]<=xmax) & (mcosx[idec,iha0]>=xmin) valy = (mcosy[idec,iha0]<=ymax) & (mcosy[idec,iha0]>=ymin) if valx & valy: text = str(numpy.int(mindec + incdec*idec))+'$^o$' - matplotlib.pyplot.text(mcosx[idec,iha0],mcosy[idec,iha0],text) + self.ax.text(mcosx[idec,iha0],mcosy[idec,iha0],text) matplotlib.pyplot.plot(mcosx,mcosy,color=colorgrid,linestyle='--') for iha in numpy.arange(nha): @@ -204,13 +205,70 @@ class AntPatternPlot: valy = (mcosy[idec0,iha]<=ymax) & (mcosy[idec0,iha]>=ymin) if valx & valy: text = str(4*numpy.int(minha + incha*iha))+"'" - matplotlib.pyplot.text(mcosx[idec0,iha],mcosy[idec0,iha],text) + self.ax.text(mcosx[idec0,iha],mcosy[idec0,iha],text) + + if save: + save_fig = os.path.join(gpath,filename) + matplotlib.pyplot.savefig(save_fig,format='png') - matplotlib.pyplot.xlim(xmin,xmax) - matplotlib.pyplot.ylim(ymin,ymax) - save_fig = os.path.join(gpath,filename) - matplotlib.pyplot.savefig(save_fig,format='png') + def plotBField(self,gpath,filename,dcos,alpha, nlon, nlat, dcosxrange, dcosyrange, heights, alpha_i, save=True): + """ + plotBField draws the magnetic field in a directional cosines plot. + + Parameters + ---------- + dcos = An 4-dimensional array giving the directional cosines of the magnetic field + over the desired place. + alpha = An 3-dimensional array giving the angle of the magnetic field over the desi- + red place. + nlon = An integer to specify the number of elements per longitude. + nlat = An integer to specify the number of elements per latitude. + dcosxrange = A 2-element array giving the range of the directional cosines in the + "x" axis. + dcosyrange = A 2-element array giving the range of the directional cosines in the + "y" axis. + heights = An array giving the heights (km) where the magnetic field will be modeled By default the magnetic field will be computed at 100, 500 and 1000km. + alpha_i = Angle to interpolate the magnetic field. + Modification History + -------------------- + Converted to Python by Freddy R. Galindo, ROJ, 07 October 2009. + """ + + handles = [] + objects = [] + colors = ['k','m','c','b','g','r','y'] + marker = ['-+','-*','-D','-x','-s','->','-o','-^'] + + alpha_location = numpy.zeros((nlon,2,heights.size)) + + for ih in numpy.arange(heights.size): + alpha_location[:,0,ih] = dcos[:,0,ih,0] + for ilon in numpy.arange(nlon): + myx = (alpha[ilon,:,ih])[::-1] + myy = (dcos[ilon,:,ih,0])[::-1] + tck = scipy.interpolate.splrep(myx,myy,s=0) + mydcosx = scipy.interpolate.splev(alpha_i,tck,der=0) + + myx = (alpha[ilon,:,ih])[::-1] + myy = (dcos[ilon,:,ih,1])[::-1] + tck = scipy.interpolate.splrep(myx,myy,s=0) + mydcosy = scipy.interpolate.splev(alpha_i,tck,der=0) + alpha_location[ilon,:,ih] = numpy.array([mydcosx, mydcosy]) + + + ObjFig, = self.ax.plot(alpha_location[:,0,ih],alpha_location[:,1,ih], + marker[ih % 8],color=colors[numpy.int(ih/8)],ms=4.5,lw=0.5) + handles.append(ObjFig) + objects.append(numpy.str(heights[ih]) + ' km') + + self.ax.legend(handles,objects,loc="lower right", numpoints=1, handlelength=0.3, + handletextpad=0.02, borderpad=0.3, labelspacing=0.1) + + if save: + save_fig = os.path.join(gpath,filename) + matplotlib.pyplot.savefig(save_fig,format='png') + class BFieldPlot: diff --git a/apps/abs/utils/overJroShow.py b/apps/abs/utils/overJroShow.py index c3781d2..c2c5440 100644 --- a/apps/abs/utils/overJroShow.py +++ b/apps/abs/utils/overJroShow.py @@ -10,6 +10,7 @@ import numpy import numpy.fft import scipy.linalg import scipy.special +from StringIO import StringIO #import Numeric import Misc_Routines @@ -20,7 +21,7 @@ import Astro_Coords class JroPattern(): def __init__(self,pattern=0,path=None,filename=None,nptsx=101,nptsy=101,maxphi=5,fftopt=0, \ - getcut=0,dcosx=None,dcosy=None,eomwl=6,airwl=4): + getcut=0,dcosx=None,dcosy=None,eomwl=6,airwl=4, **kwargs): """ JroPattern class creates an object to represent the useful parameters for beam mode- lling of the Jicamarca VHF radar. @@ -60,16 +61,26 @@ class JroPattern(): # Getting antenna configuration. - setup = JroAntSetup.ReturnSetup(path=path,filename=filename,pattern=pattern) - - ues = setup["ues"] - phase = setup["phase"] - gaintx = setup["gaintx"] - gainrx = setup["gainrx"] - justrx = setup["justrx"] + if filename: + setup = JroAntSetup.ReturnSetup(path=path,filename=filename,pattern=pattern) + + ues = setup["ues"] + phase = setup["phase"] + gaintx = setup["gaintx"] + gainrx = setup["gainrx"] + justrx = setup["justrx"] + self.title = setup["title"] + else: + ues = kwargs["ues"] + phase = kwargs["phases"] + gaintx = kwargs["gain_tx"] + gainrx = kwargs["gain_rx"] + justrx = kwargs["just_rx"] + self.title = kwargs.get("title", "JRO Pattern") # Defining attributes for JroPattern class. # Antenna configuration + self.uestx = ues self.phasetx = phase self.gaintx = gaintx @@ -105,13 +116,13 @@ class JroPattern(): self.norpattern = None self.maxpattern = None - self.title = setup["title"] + self.getPattern() def getPattern(self): """ - getpattern method returns the modelled total antenna pattern and its mean position. + getpattern method returns the modeled total antenna pattern and its mean position. Return ------ @@ -342,12 +353,18 @@ class JroPattern(): yindex = iy*(self.getcut==0) + ix*(self.getcut==1) argx = ar[0,0]*self.dcosx[ix] - lr[0,0] - junkx = numpy.sin(0.5*self.kk*nr[0,0]*argx)/numpy.sin(0.5*self.kk*argx) - if argx == 0.0: junkx = nr[0,0] + if argx == 0.0: + junkx = nr[0,0] + else: + junkx = numpy.sin(0.5*self.kk*nr[0,0]*argx)/numpy.sin(0.5*self.kk*argx) + argy = ar[1,0]*self.dcosy[yindex] - lr[1,0] - junky = numpy.sin(0.5*self.kk*nr[1,0]*argy)/numpy.sin(0.5*self.kk*argy) - if argy == 0.0: junky = nr[1,0] + if argy == 0.0: + junky = nr[1,0] + else: + junky = numpy.sin(0.5*self.kk*nr[1,0]*argy)/numpy.sin(0.5*self.kk*argy) + dipole[ix,iy] = junkx*junky @@ -502,7 +519,7 @@ class BField(): x_ant = numpy.array([1,0,0]) y_ant = numpy.array([0,1,0]) z_ant = numpy.array([0,0,1]) - + if self.site==0: title_site = "Magnetic equator" coord_site = numpy.array([-76+52./60.,-11+57/60.,0.5]) @@ -530,8 +547,8 @@ class BField(): nfields = 1 grid_res = 0.5 - nlon = numpy.int(maglimits[2] - maglimits[0])/grid_res + 1 - nlat = numpy.int(maglimits[3] - maglimits[1])/grid_res + 1 + nlon = int(numpy.int(maglimits[2] - maglimits[0])/grid_res + 1) + nlat = int(numpy.int(maglimits[3] - maglimits[1])/grid_res + 1) location = numpy.zeros((nlon,nlat,2)) mlon = numpy.atleast_2d(numpy.arange(nlon)*grid_res + maglimits[0]) @@ -941,10 +958,10 @@ class overJroShow: # __tmpDir = 'overJro/tempReports' # __serverdocspath = '/Users/dsuarez/Pictures' # __tmpDir = 'overjro' - __serverdocspath = None - __tmpDir = None + __serverdocspath = '' + __tmpDir = '' - def __init__(self): + def __init__(self, title=''): self.year = None self.month = None self.dom = None @@ -971,12 +988,18 @@ class overJroShow: self.time_mag = None self.main_dec = None self.ObjC = None - self.ptitle = '' + self.ptitle = title self.path4plotname = None self.plotname0 = None self.plotname1 = None self.plotname2 = None self.scriptHeaders = 0 + self.glat = -11.95 + self.glon = -76.8667 + self.UT = 5 #timezone + + self.glat = -11.951481 + self.glon = -76.874383 # self.outputHead('Show Plot') # self.printBody() @@ -1180,8 +1203,6 @@ class overJroShow: # Defining plot filenames self.path4plotname = os.path.join(self.__serverdocspath,self.__tmpDir) - print "PATH4" - print os.path.join(self.__serverdocspath,self.__tmpDir) self.plotname0 = 'over_jro_0_%i.png'% (time.time()) #plot pattern & objects self.plotname1 = 'over_jro_1_%i.png'% (time.time()) #plot antenna cuts self.plotname2 = 'over_jro_2_%i.png'% (time.time()) #plot sky noise @@ -1204,7 +1225,71 @@ class overJroShow: self.xg = numpy.dot(self.MT3.transpose(),numpy.array([1,0,0])) self.yg = numpy.dot(self.MT3.transpose(),numpy.array([0,1,0])) - self.zg = numpy.dot(self.MT3.transpose(),numpy.array([0,0,1])) + self.zg = numpy.dot(self.MT3.transpose(),numpy.array([0,0,1])) + + def plotPattern2(self, date, phases, gain_tx, gain_rx, ues, just_rx): + # Plotting Antenna patterns. + + self.initParameters() + self.doy = datetime.datetime(date.year,date.month,date.day).timetuple().tm_yday + self.junkjd = TimeTools.Time(self.year,self.month,self.dom).change2julday() + self.junklst = TimeTools.Julian(self.junkjd).change2lst(longitude=self.glon) + self.ra_obs = self.junklst*Misc_Routines.CoFactors.h2d + + date = TimeTools.Time(date.year,date.month,date.day).change2strdate(mode=2) + + mesg = 'Over Jicamarca: ' + date[0] + + ObjAnt = JroPattern(pattern=0, + filename=None, + path=None, + nptsx=self.nptsx, + nptsy=self.nptsy, + #maxphi=self.maxphi, + fftopt=self.fftopt, + phases=numpy.array(phases), + gain_tx=numpy.array(gain_tx), + gain_rx=numpy.array(gain_rx), + ues=numpy.array(ues), + just_rx=just_rx + ) + + dum = Graphics_OverJro.AntPatternPlot() + + dum.contPattern(iplot=0, + gpath=self.path4plotname, + filename=self.plotname0, + mesg=mesg, + amp=ObjAnt.norpattern, + x=ObjAnt.dcosx, + y=ObjAnt.dcosy, + getCut=ObjAnt.getcut, + title=self.ptitle, + save=False) + + + dum.plotRaDec(gpath=self.path4plotname, + filename=self.plotname0, + jd=self.junkjd, + ra_obs=self.ra_obs, + xg=self.xg, + yg=self.yg, + x=ObjAnt.dcosx, + y=ObjAnt.dcosy, + save=False) + + ObjB = BField(self.year,self.doy,1,self.heights) + [dcos, alpha, nlon, nlat] = ObjB.getBField() + + dum.plotBField('', '',dcos,alpha,nlon,nlat, + self.dcosxrange, + self.dcosyrange, + ObjB.heights, + ObjB.alpha_i, + save=False) + + return dum.fig + def plotPattern(self): # Plotting Antenna patterns. @@ -1230,10 +1315,8 @@ class overJroShow: title += ObjAnt.title # Plotting Contour Map - print "Antes de la creacion" - self.path4plotname = '/home/fquino/workspace/radarsys/webapp/apps/abs/static/images' - print self.path4plotname - print self.plotname0 + + self.path4plotname = '/home/jespinoza/workspace/radarsys/trunk/webapp/apps/abs/static/images' dum = Graphics_OverJro.AntPatternPlot() dum.contPattern(iplot=ii, gpath=self.path4plotname, @@ -1246,8 +1329,6 @@ class overJroShow: title=title) # title=ObjAnt.title) # self.ptitle = ObjAnt.title - if ii==0: - self.figure = dum.figure if ii != (npatterns-1): title += '+' @@ -1267,7 +1348,14 @@ class overJroShow: self.ptitle = title - Graphics_OverJro.AntPatternPlot().plotRaDec(gpath=self.path4plotname,filename=self.plotname0,jd=self.junkjd, ra_obs=self.ra_obs, xg=self.xg, yg=self.yg, x=ObjAnt.dcosx, y=ObjAnt.dcosy) + Graphics_OverJro.AntPatternPlot().plotRaDec(gpath=self.path4plotname, + filename=self.plotname0, + jd=self.junkjd, + ra_obs=self.ra_obs, + xg=self.xg, + yg=self.yg, + x=ObjAnt.dcosx, + y=ObjAnt.dcosy) self.dcosx = ObjAnt.dcosx @@ -1616,8 +1704,7 @@ class overJroShow: self.plotSkyNoise() def getPlot(self): - print "GETPLot" - print os.path.join(self.__serverdocspath,self.__tmpDir,self.plotname0) + return os.path.join(self.__serverdocspath,self.__tmpDir,self.plotname0) @@ -1626,7 +1713,42 @@ if __name__ == '__main__': # Script overJroShow.py # This script only calls the init function of the class overJroShow() # All work is done by the init function - - newOverJro = overJroShow() - newOverJro.initParametersCGI() - newOverJro.execute() + + phases = numpy.array([[2.0,0.0,1.5,1.5,1.0,1.0,1.0,0.5], + [2.0,2.5,2.5,3.5,0.5,1.0,1.0,1.0], + [2.5,2.5,1.0,1.0,0.5,0.5,0.5,0.5], + [1.0,1.0,1.0,1.0,0.5,0.5,0.5,1.0], + [0.5,0.5,0.5,0.5,0.5,0.0,0.0,0.0], + [0.5,0.5,1.0,0.5,0.0,0.0,0.0,0.0], + [0.5,0.5,0.5,1.0,0.0,0.0,0.0,0.0], + [0.5,0.5,0.5,0.5,0.0,0.0,0.0,0.0]]) + + gain_tx = numpy.array([[0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0], + [0,0,0,0,1,1,1,1], + [0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0]]) + + gain_rx = numpy.array([[0,0,0,0,0,0,0,0], + [0,0,1,0,0,0,0,0], + [0,0,1,0,0,0,0,0], + [0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0]]) + + jro = overJroShow() + + fig = jro.plotPattern2(datetime.datetime.today(), + phases=phases, + gain_tx=gain_tx, + gain_rx=gain_rx, + ues=numpy.array([0.0,0.0,0.0,0.0]), + just_rx=0) + + fig.savefig('./pat.png') + diff --git a/apps/abs/views.py b/apps/abs/views.py index 95fac84..b8f80b8 100644 --- a/apps/abs/views.py +++ b/apps/abs/views.py @@ -315,55 +315,23 @@ def remove_beam(request, id_conf, id_beam): -def plot_patterns(request, id_conf): +def plot_patterns(request, id_conf, id_beam=None): - conf = get_object_or_404(ABSConfiguration, pk=id_conf) - beams_list = ast.literal_eval(conf.beams) - i = 1 - beams = [] - for b in beams_list: - beam = ABSBeam.objects.get(pk=beams_list['beam'+str(i)]) - beams.append(beam) - i=i+1 - - ###### SIDEBAR ###### kwargs = {} + conf = get_object_or_404(ABSConfiguration, pk=id_conf) + beams = ABSBeam.objects.filter(abs_conf=conf) + + if id_beam: + beam = get_object_or_404(ABSBeam, pk=id_beam) + kwargs['beam'] = beam + - kwargs['dev_conf'] = conf.device - kwargs['id_dev'] = conf.device - kwargs['id_conf'] = conf.id - kwargs['abs_beams'] = beams - kwargs['title'] = 'ABS Patterns' - kwargs['suptitle'] = conf.name - kwargs['no_sidebar'] = True - - return render(request, 'abs_patterns.html', kwargs) - - -def plot_pattern(request, id_conf, id_beam): - - conf = get_object_or_404(ABSConfiguration, pk=id_conf) - beam = get_object_or_404(ABSBeam, pk=id_beam) - - #Lista de Beams de la configuracion con su respectivo ID - beams_list = ast.literal_eval(conf.beams) - i = 1 - #Lista de Objetos ABSBeams en el 0rden de su respectiva configuracion - beams = [] - for b in beams_list: - beam = ABSBeam.objects.get(pk=beams_list['beam'+str(i)]) - beams.append(beam) - i=i+1 - - ###### SIDEBAR ###### - beam = get_object_or_404(ABSBeam, pk=id_beam) - kwargs = {} + ###### SIDEBAR ###### kwargs['dev_conf'] = conf.device kwargs['id_dev'] = conf.device kwargs['id_conf'] = conf.id kwargs['abs_beams'] = beams - kwargs['beam'] = beam kwargs['title'] = 'ABS Patterns' kwargs['suptitle'] = conf.name kwargs['no_sidebar'] = True @@ -371,112 +339,27 @@ def plot_pattern(request, id_conf, id_beam): return render(request, 'abs_patterns.html', kwargs) +def plot_pattern(request, id_conf, id_beam, antenna): + + if antenna=='down': + sleep(3) + + conf = get_object_or_404(ABSConfiguration, pk=id_conf) + beam = get_object_or_404(ABSBeam, pk=id_beam) -def plot_uppattern(request, id_conf, id_beam): - - from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas - - conf = get_object_or_404(ABSConfiguration, pk=id_conf) - beam = get_object_or_404(ABSBeam, pk=id_beam) - - exp_name = conf.experiment.name - - just_rx = 0 - - only_rx = json.loads(beam.only_rx) - if only_rx['up'] == True: - just_rx = 1 - - antenna = ast.literal_eval(beam.antenna) - objAntenna = json.dumps(antenna['antenna_up']) - antenna_up = ''.join(str(i) for i in objAntenna) - phase_tx = antenna_up.replace(' ','') - - tx = ast.literal_eval(beam.tx) - tx = json.dumps(tx['up']) - tx = ''.join(str(i) for i in tx) - gain_tx = tx.replace(' ','') - - rx = ast.literal_eval(beam.rx) - rx = json.dumps(rx['up']) - rx = ''.join(str(i) for i in rx) - gain_rx = rx.replace(' ','') - - ues = json.dumps(beam.get_up_ues) - ues = ''.join(str(i) for i in ues) - ues_tx = ues.replace(' ','') - - #sleep(1) - - overjro = OverJRO() - overjro.setParameters(settings.MEDIA_ROOT, exp_name, phase_tx, gain_tx, gain_rx, ues_tx, just_rx) - contentFile = overjro.setTextContent() - finalpath = overjro.saveFile(contentFile) - - currentdate = datetime.today() - newOverJro = overJroShow() - newOverJro.setInputParameters(settings.MEDIA_ROOT, currentdate, finalpath) - newOverJro.setupParameters() - newOverJro.execute() - path = newOverJro.getPlot() - path= "apps/abs/media/"+path - - - canvas=FigureCanvas(newOverJro.figure) - response=HttpResponse(content_type='image/png') - canvas.print_png(response) - return response - -def plot_downpattern(request, id_conf, id_beam): - - sleep(4) - from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas - - conf = get_object_or_404(ABSConfiguration, pk=id_conf) - beam = get_object_or_404(ABSBeam, pk=id_beam) - - exp_name = conf.experiment.name - - just_rx = 0 - - only_rx = json.loads(beam.only_rx) - if only_rx['down'] == True: - just_rx = 1 - - antenna = ast.literal_eval(beam.antenna) - objAntenna = json.dumps(antenna['antenna_down']) - antenna_down = ''.join(str(i) for i in objAntenna) - phase_tx = antenna_down.replace(' ','') - - tx = ast.literal_eval(beam.tx) - tx = json.dumps(tx['down']) - tx = ''.join(str(i) for i in tx) - gain_tx = tx.replace(' ','') - - rx = ast.literal_eval(beam.rx) - rx = json.dumps(rx['down']) - rx = ''.join(str(i) for i in rx) - gain_rx = rx.replace(' ','') - - ues = json.dumps(beam.get_down_ues) - ues = ''.join(str(i) for i in ues) - ues_tx = ues.replace(' ','') - - overjro = OverJRO() - overjro.setParameters(settings.MEDIA_ROOT, exp_name, phase_tx, gain_tx, gain_rx, ues_tx, just_rx) - contentFile = overjro.setTextContent() - finalpath = overjro.saveFile(contentFile) - - currentdate = datetime.today() - newOverJro = overJroShow() - newOverJro.setInputParameters(settings.MEDIA_ROOT, currentdate, finalpath) - newOverJro.setupParameters() - newOverJro.execute() - path = newOverJro.getPlot() - path= "apps/abs/media/"+path - - - canvas=FigureCanvas(newOverJro.figure) - response=HttpResponse(content_type='image/png') - canvas.print_png(response) + name = conf.experiment.name + + just_rx = 1 if json.loads(beam.only_rx)[antenna] else 0 + phases = json.loads(beam.antenna)['antenna_{}'.format(antenna)] + gain_tx = json.loads(beam.tx)[antenna] + gain_rx = json.loads(beam.rx)[antenna] + ues = json.loads(beam.ues)[antenna] + + newOverJro = overJroShow(name) + fig = newOverJro.plotPattern2(datetime.today(), phases, gain_tx, gain_rx, ues, just_rx) + + response=HttpResponse(content_type='image/png') + + fig.canvas.print_png(response) + return response