def main(): if len(sys.argv) != 2: print("Please choose a single .mod1 file") return data = get_file(sys.argv[1]) if data is None: return None viewer.viewer(data) print("Finished")
def main(): global led_status listener = SampleListener() controller = Leap.Controller() controller.add_listener(listener) controller.set_policy(Leap.Controller.POLICY_BACKGROUND_FRAMES) controller.set_policy(controller.POLICY_IMAGES) controller.enable_gesture(Leap.Gesture.TYPE_SWIPE) #Controller.set_policy v = viewer.viewer() v.setDaemon(True) v.start() while True: pass #frame=controller.frame() pointable = frame.pointables.frontmost direction = pointable.direction length = pointable.length width = pointable.width stabilizedPosition = pointable.stabilized_tip_position position = pointable.tip_position speed = pointable.tip_velocity touchDistance = pointable.touch_distance zone = pointable.touch_zone print "Press Enter to Quit" try: sys.stdin.readline() except KeyboardInterpt: pass finally: controller.remove_listener(listener)
def _init_viewer(self, user, viewlvl): """Initializes the viewer and puts the viewer object into viewerlist. If the viewer doesn't have a relationship with the stream one is created. If the viewer relationship is different than what is in the database it is updated. Since this is called for each iteration of the viewerlist population the rewards counter is increased in this function as well. Parameters: user = Username of the viewer viewlvl = The permission level of the viewer """ if user == self.stream_name: #if the viewer is the streamer set to a streamer relationship streamReltn = 'streamer' else: streamReltn = viewlvl if user in self.viewerlist: #if the viewer is already in the list make sure the relationships line up #No rewards for stream if self._max_tick != 0: #Updates the viewer's reward tick count as well as reward points if #they meet the threshhold if ((self.viewerlist[user].reward_ticks + 1) == self._max_tick): self.viewerlist[user].reward_ticks = 0 self.viewerlist[user].reward_points += self._reward_rate else: self.viewerlist[user].reward_ticks += 1 #update viewer level if it has changed if streamReltn != self.viewerlist[user].view_lvl: self.viewerlist[user].view_lvl = streamReltn self.stream_db.update_person_stream_reltn(self.viewerlist[user].person_id, self.stream_id, streamReltn) else: personID = self.stream_db.get_person_id(user) print('Caputred person_id = ' + str(personID)) if personID < 0: #error in query print('ERROR GETTING PERSON_ID') personID = 0 elif personID == 0: print('Add personID') personID = self.stream_db.add_person(user, self.stream_id, streamReltn) if personID < 0: print('Error adding person') personID = 0 else:# personID > 0: self.stream_db.update_person_stream_reltn(personID, self.stream_id, streamReltn) self.viewerlist[user] = viewer.viewer(personID, user, streamReltn) #get number of reward points for user in stream self.viewerlist[user].reward_points = self.stream_db.get_person_stream_rewards(self.stream_id, personID)
def parse(value, full=True): # URL value = urlize_html.urlize_html(value) if full: # Youtube, NicoNico value = viewer.viewer(value) # Commons value = commons.parse_commons_html(value) # Calls value = calls.parse_id_calls_html(value) return mark_safe(value)
def make_plots(dirname, fnames): # get the highest-level directory, assume it is the target source ID obj = os.path.split(dirname)[-1] for fn in fnames: # each band gets listed... if 'band0' not in fn or '.sav' not in fn: continue # templates: # coadd_cleanband0in_clean_music_20130815_jk000.sav # 130820_ob1_band0i_clean_music_20130815_map.sav obs = "_".join(fn.split("_")[:2]) #obs = fn[:11] print "Working on file ",os.path.join(dirname,obs) data = load_data(os.path.join(dirname,obs)) headers = {k: load_header(data[k].mapstruct) for k in data} sm,us = convolve_and_match(data,obj,headers=headers,writefits=True,savepath=dirname) vmin = -1000 #max([sm[2].min(),-1000]) vmax = max([sm[2].max(),5000]) print obj, obs, vmin, vmax prefix = os.path.join(dirname,obj+obs) pl.clf() viewer(data, vmin=vmin, vmax=vmax, cb=True) pl.suptitle(obj) pl.savefig(prefix+"_quicklook.png",bbox_inches='tight') pl.clf() dictviewer(sm, vmin=vmin, vmax=vmax, cb=True) pl.suptitle(obj) pl.savefig(prefix+"_quicklook_smooth.png",bbox_inches='tight') pl.clf() dictviewer(us, vmin=vmin, vmax=vmax, cb=True) pl.suptitle(obj) pl.savefig(prefix+"_quicklook_unsharp.png",bbox_inches='tight')
def main(): loader = loadFile() loader.mainloop() foto = Image.open(loader.get_path()) foto = foto.convert('L') rows = foto.size[1] cols = foto.size[0] data = foto.getdata() newPic = Image.new('L',foto.size) newPic.putdata(data) newPic.save('normal.png') newPic.close() foto.close() create_file(data, 'pic.bin') create_file([], 'res.bin') # [[0, -1, 0], [-1, 5, -1], [0, -1, 0]] sharpen = [[2, 1, 2], [1, 7, 1], [2, 1, 2]] # [[0,-2,0],[-2, 9, -2], [0, -2, 0]] oversharpen = [[2, 0, 2], [0, 11, 0], [2, 0, 2]] create_file(to_list(sharpen), 'kernel.bin') create_file([], 'res.bin') # sharpening os.system("nasm -f elf64 conv.asm -o conv.o") os.system("ld conv.o -o conv") os.system("./conv "+str(rows)+" "+str(cols)) os.rename(r'res.bin', r'sharpening.bin') toPic('sharpening.bin', rows, cols) # oversharpening create_file(to_list(oversharpen), 'kernel.bin') create_file([], 'res.bin') os.system("./conv "+str(rows)+" "+str(cols)) os.rename(r'res.bin', r'oversharpening.bin') toPic('oversharpening.bin', rows, cols) myview = viewer(rows,cols) myview.mainloop()
from viewer import viewer from utils import bytes_to_rgb, bgr_weights from stream import stream_client, unpack import numpy as np host = 'localhost' port = 5556 if len(sys.argv) > 1: host = sys.argv[1] if len(sys.argv) > 2: port = sys.argv[2] client = stream_client(host=host, port=port) view = viewer() i, t1, t = 0, 0, 0 t0 = time.time() print('Stream from: ', client.addr) while True: msg = client.receive() if msg: data = unpack(msg) if data['type'] == 'bgr': frame = bytes_to_rgb(data['data'], data['size']) #frame = np.uint8(np.dot(frame, bgr_weights)) elif data['type'] == 'grayscale': frame = np.frombuffer(data['data'],
def selfcal(vis, spwn=6, doplots=True, INTERACTIVE=False, reclean=True, field='W51 Ku', outdir_template="spw%i_selfcal_iter/", statsbox='170,50,229,97', ant1list=['ea14','ea05'], ant2list=['ea16','ea07'], avgchannel_wide='128', avgchannel_narrow='8', cleanboxes=cleanboxes, refant='ea27', solint='30s', niter=2, multiscale=[0,5,10,15,25,50], imsize=512, ): """ Docstring incomplete """ spw = int(spwn) outdir = outdir_template % spwn try: os.mkdir(outdir) except OSError: pass # you're supposed to pass in avg_data as input avg_data = vis mytb.open(vis+"/ANTENNA") antnames = mytb.getcol("NAME") # (1) Clean a single SPW *interactively*, boxing the brightest regions and not # cleaning very deeply (maybe 100 iterations). Keep this model in the header # -- it's what you'll use for the first round of self-calibration. if reclean: imagename="average_spw%i_shallowclean_masked" % spwn for suffix in clean_output_suffixes: os.system("rm -rf "+imagename+suffix) clean(vis=avg_data, field=field, imagename=imagename, mode='mfs', psfmode='hogbom',multiscale=multiscale, weighting='briggs', robust=0.0, niter=100, imsize=imsize, mask=cleanboxes, nterms=2, usescratch=True) viewer(imagename+".image.tt0", outfile=outdir+imagename+".image.tt0.png", outformat='png', gui=False) exportfits(imagename=imagename+".image.tt0", fitsimage=imagename+".fits", overwrite=True) imrms = [imstat(imagename+".image.tt0",box=statsbox)['rms']] for calnum in xrange(niter): # for Ku D W51 Ku spw 2 if reclean: first_image = 'spw%i_ku_d_firstim_selfcal%i' % (spwn,calnum) for suffix in clean_output_suffixes: os.system("rm -rf "+first_image+suffix) clean(vis=avg_data,imagename=first_image,field=field, mode='mfs', psfmode='hogbom',multiscale=multiscale, weighting='briggs', robust=0.0, niter=100, imsize=imsize, mask=cleanboxes, nterms=2, usescratch=True) exportfits(imagename=first_image+".image.tt0", fitsimage=first_image+".fits", overwrite=True) viewer(first_image+".image.tt0", outfile=outdir+first_image+".image.tt0.png", outformat='png', gui=False) caltable = 'selfcal%i_%s_spw%i.pcal' % (calnum,field.replace(" ",""),spwn) if reclean: os.system('rm -rf '+caltable) gaincal(vis=avg_data, field='', caltable=caltable, spw='', # gaintype = 'T' could reduce failed fit errors by averaging pols... gaintype='G', # 'G' from http://casaguides.nrao.edu/index.php?title=EVLA_Advanced_Topics_3C391 solint=solint, refant=refant, calmode='p', combine='scan', minblperant=4) if reclean: applycal(vis=avg_data, gaintable=caltable, interp='linear', flagbackup=True) # was False when flagmanager was used if reclean: selfcal_image = 'spw%i_ku_d_selfcal%i' % (spwn,calnum) for suffix in clean_output_suffixes: os.system("rm -rf "+selfcal_image+suffix) clean(vis=avg_data,imagename=selfcal_image,field=field, mode='mfs', psfmode='hogbom',multiscale=multiscale, weighting='briggs', robust=0.5, niter=1000, imsize=imsize, nterms=2, mask=cleanboxes, usescratch=True) exportfits(imagename=selfcal_image+".image.tt0", fitsimage=selfcal_image+".fits", overwrite=True) imrms.append(imstat(selfcal_image+".image.tt0",box=statsbox)['rms']) viewer(selfcal_image+".image.tt0", outfile=outdir+selfcal_image+".image.tt0.png", outformat='png', gui=False) print "FINISHED ITERATION %i" % calnum print "FINISHED ITERATING!!! YAY!" # final phase + gain cal: # http://casaguides.nrao.edu/index.php?title=Calibrating_a_VLA_5_GHz_continuum_survey#One_Last_Iteration:_Amplitude_.26_Phase_Self_Calibration aptable = 'selfcal_ap_%s_spw%i.gcal' % (field.replace(" ",""),spwn) gaincal(vis=avg_data, field='', caltable=aptable, gaintable=caltable, spw='', solint='inf', refant=refant, calmode='ap', combine='', minblperant=4) plotcal(caltable=aptable, xaxis='phase', yaxis='amp', plotrange=[-50,50,0.5,1.5], showgui=INTERACTIVE, figfile='' if INTERACTIVE else outdir+'selfcal%i_spw%i_ampvsphase_final.png' % (calnum,spwn), iteration='spw' if INTERACTIVE else '')#, subplot = 221) applycal(vis=avg_data, gaintable=[aptable,caltable], interp='linear', flagbackup=True) # was False when flagmanager was used selfcal_image = 'spw%i_ku_d_selfcal%i_final' % (spwn,calnum) for suffix in clean_output_suffixes: os.system("rm -rf "+selfcal_image+suffix) clean(vis=avg_data,imagename=selfcal_image,field=field, mode='mfs', mask=cleanboxes, weighting='briggs', robust=0.5, niter=10000, imsize=imsize, nterms=2, usescratch=True) exportfits(imagename=selfcal_image+".image.tt0", fitsimage=selfcal_image+".fits", overwrite=True) plotms(vis=avg_data, spw='0', xaxis='baseline', yaxis='amp', avgtime='1e8', ydatacolumn='corrected-model', avgscan=T, coloraxis='baseline', iteraxis='', xselfscale=T, yselfscale=T, title='Residual vs. Baseline after CSCLEAN iter %i' % calnum, plotfile=outdir+'post_selfcal%i_spw%i_residVSbaseline.png' % (calnum,spwn), field=field, overwrite=True, ) plotms(vis=avg_data, spw='0', xaxis='time', yaxis='amp', avgtime='5s', ydatacolumn='corrected-model', coloraxis='baseline', iteraxis='', xselfscale=T, yselfscale=T, title='Residual vs. Time after CSCLEAN iter %i' % (calnum), plotfile=outdir+'post_selfcal%i_spw%i_residVStime.png' % (calnum,spwn), field=field, overwrite=True, ) plotms(vis=avg_data, spw='0', xaxis='uvdist', yaxis='amp', avgtime='1e8', ydatacolumn='corrected-model', avgscan=T, coloraxis='baseline', iteraxis='', xselfscale=T, yselfscale=T, title='Residual vs. UVDIST after CSCLEAN iter %i' % (calnum) , plotfile=outdir+'post_selfcal%i_spw%i_residVSuvdist.png' % (calnum,spwn), field=field, overwrite=True, ) selfcal_image = 'spw%i_ku_d_selfcal%i_final_multiscale' % (spwn,calnum) for suffix in clean_output_suffixes: os.system("rm -rf "+selfcal_image+suffix) clean(vis=avg_data,imagename=selfcal_image,field=field, mode='mfs', imagermode='csclean',# mask=cleanboxes, multiscale=multiscale, psfmode='hogbom', nterms=2, weighting='briggs', robust=0.5, niter=10000, imsize=imsize, usescratch=True) exportfits(imagename=selfcal_image+".image.tt0", fitsimage=selfcal_image+".fits", overwrite=True) plotms(vis=avg_data, spw='0', xaxis='baseline', yaxis='amp', avgtime='1e8', ydatacolumn='corrected-model', avgscan=T, coloraxis='baseline', iteraxis='', xselfscale=T, yselfscale=T, title='Residual vs. Baseline after multiscale CLEAN iter %i' % (calnum), plotfile=outdir+'post_selfcal%i_spw%i_residVSbaseline_multiscale.png' % (calnum,spwn), field=field, overwrite=True, ) plotms(vis=avg_data, spw='0', xaxis='time', yaxis='amp', avgtime='5s', ydatacolumn='corrected-model', coloraxis='baseline', iteraxis='', xselfscale=T, yselfscale=T, title='Residual vs. Time after multiscale CLEAN iter %i' % (calnum), plotfile=outdir+'post_selfcal%i_spw%i_residVStime_multiscale.png' % (calnum,spwn), field=field, overwrite=True, ) plotms(vis=avg_data, spw='0', xaxis='uvdist', yaxis='amp', avgtime='1e8', ydatacolumn='corrected-model', avgscan=T, coloraxis='baseline', iteraxis='', xselfscale=T, yselfscale=T, title='Residual vs. UVDIST after multiscale CLEAN iter %i' % (calnum), plotfile=outdir+'post_selfcal%i_spw%i_residVSuvdist_multiscale.png' % (calnum,spwn), field=field, overwrite=True, ) return imrms
def __init__(self): # Current coords self.z = 0; self.imagesLoaded = 300 # In pyqt widgets must be stacked vertically or horizontally. To achive # to achive the desired layout they are stored in larger containers ### Create viewport self.viewport = viewer("/home/alex/Documents/Uni/Project/data/HV01/HV01-B1_800nm_sweep006.tiff", self.imagesLoaded); ### Basic saturaton controls # Create widgits self.saturationControl = QVBoxLayout(); self.xControl = sliderControl("x", self.viewport.layers - 1); self.alphaControl = sliderControl("Saturaton", 100); self.betaControl = sliderControl("Brightness", 100); # Connect widgits self.xControl.slider.valueChanged.connect(lambda: self.updateCoords(self.xControl.value)); self.alphaControl.slider.valueChanged.connect(lambda: self.updateSaturation(self.alphaControl.value, self.betaControl.value)); self.betaControl.slider.valueChanged.connect(lambda: self.updateSaturation(self.alphaControl.value, self.betaControl.value)); # Create layout self.saturationControl.addLayout(self.xControl.layout); self.saturationControl.addLayout(self.alphaControl.layout); self.saturationControl.addLayout(self.betaControl.layout); ### Circular saturaton controls # Create widgets self.circularSaturationControl = QVBoxLayout(); self.xScaleControl = sliderControl("xScale", 100); self.yScaleControl = sliderControl("yScale", 100); self.circularAlphaControl = sliderControl("Circular Saturaton", 100); self.circularBetaControl = sliderControl("Circular Brightness", 100); # Connect widgits self.xScaleControl.slider.valueChanged.connect(lambda: self.updateCircularSaturation(self.circularAlphaControl.value, self.circularBetaControl.value, self.xScaleControl.value, self.yScaleControl.value)); self.yScaleControl.slider.valueChanged.connect(lambda: self.updateCircularSaturation(self.circularAlphaControl.value, self.circularBetaControl.value, self.xScaleControl.value, self.yScaleControl.value)); self.circularAlphaControl.slider.valueChanged.connect(lambda: self.updateCircularSaturation(self.circularAlphaControl.value, self.circularBetaControl.value, self.xScaleControl.value, self.yScaleControl.value)); self.circularBetaControl.slider.valueChanged.connect(lambda: self.updateCircularSaturation(self.circularAlphaControl.value, self.circularBetaControl.value, self.xScaleControl.value, self.yScaleControl.value)); # Create layout self.circularSaturationControl.addLayout(self.xScaleControl.layout); self.circularSaturationControl.addLayout(self.yScaleControl.layout); self.circularSaturationControl.addLayout(self.circularAlphaControl.layout); self.circularSaturationControl.addLayout(self.circularBetaControl.layout); ### Connect saturation and circular saturation layouts self.allSaturations = QHBoxLayout(); self.allSaturations.addLayout(self.saturationControl); self.allSaturations.addLayout(self.circularSaturationControl); ### Noise filtering controls (for opencv's fastNlMeansDenoising) # Create widgets self.noiseHVal = labeledEdit("h value"); self.noiseTemplateWindowSize = labeledEdit("Template window size") self.noiseSearchWindowSize = labeledEdit("Search window size"); self.denoiseButton = QPushButton("denoise"); # Connect widgets self.denoiseButton.clicked.connect(lambda: self.updateFilter(self.noiseHVal.getVal(), self.noiseTemplateWindowSize.getVal(), self.noiseSearchWindowSize.getVal())); # Create layout self.noiseControls = QVBoxLayout(); self.noiseControls.addLayout(self.noiseHVal.layout); self.noiseControls.addLayout(self.noiseTemplateWindowSize.layout); self.noiseControls.addLayout(self.noiseSearchWindowSize.layout); self.noiseControls.addWidget(self.denoiseButton); ### Connect noise filter to saturatoin layout self.filterPanel = QVBoxLayout(); self.filterPanel.addLayout(self.allSaturations); self.filterPanel.addLayout(self.noiseControls); ### Allow files to be loaded # Create widgets self.loadPath = QLineEdit(); self.loadButton = QPushButton("load"); self.loadLabel = QLabel("Images filepath"); # Connect widgets self.loadButton.clicked.connect(lambda: self.load(self.loadPath.text(), self.imagesLoaded)) # Create layout self.loadLayout = QHBoxLayout(); self.loadLayout.addWidget(self.loadLabel); self.loadLayout.addWidget(self.loadPath); self.loadLayout.addWidget(self.loadButton); ### Allow cleaned files to be saved # Create widgets self.savePathSelect = labeledEdit("Save path"); self.saveButton = QPushButton("Save"); self.startPoint = labeledEdit("Start"); self.endPoint = labeledEdit("End"); # Connect widgets self.saveButton.clicked.connect(lambda: self.saveImages(self.savePathSelect.getText(), self.startPoint.getVal(), self.endPoint.getVal())) # Create layout self.saveControlLayout = QHBoxLayout(); self.saveControlLayout.addLayout(self.startPoint.layout); self.saveControlLayout.addLayout(self.endPoint.layout); self.saveControlLayout.addWidget(self.saveButton); self.saveLayout = QVBoxLayout(); self.saveLayout.addLayout(self.savePathSelect.layout); self.saveLayout.addLayout(self.saveControlLayout); ### Display image self.image = QLabel("loop"); self.pixmap = QPixmap('Flamboyant_Potato.jpg'); self.image.setPixmap(self.pixmap); ### Connect image to control layouts self.imgControl = QHBoxLayout(); self.imgControl.addWidget(self.image); self.imgControl.addLayout(self.filterPanel); # Full interface layout self.layout = QVBoxLayout(); self.layout.addLayout(self.loadLayout); self.layout.addLayout(self.imgControl); self.layout.addLayout(self.saveLayout);
args = parser.parse_args() # Load input file pcd_list = np.array(ut.loadPoints(args.input, [0,1,2])) # Compute the number of iterations to do given the slice size to_process = len(pcd_list) slice_size = args.slice iterations = to_process/slice_size if (iterations == 0 or to_process%slice_size == 0): iterations += 1 # Initialize the iteration variable i = 0 # Get the matplotlib object that shows the point cloud plt = viewer(pcd_list, get=True) # Compute the fitting polynoms and plot them for i in range(iterations): begin = i*slice_size if (i+1)*slice_size < to_process: end = (i+1)*slice_size else: end = to_process points_slice = pcd_list[begin:end] xp = np.linspace(points_slice[0,0], points_slice[end-begin-1,0], 100) pl = np.poly1d(np.polyfit(points_slice[:,0], points_slice[:,1], args.degree)) plt.plot(xp, pl(xp), 'r-', linewidth=3.0) plt.show()
soc.connect(("localhost",5555)) soc.send("addlogger:root.moje,") time.sleep(0.1) soc.send("port:6868,") time.sleep(0.1) soc.send("level:0,endaddlogger") try: while True: time.sleep(0.1) d = soc.recv(32) if (d == ""): print "Connection Closed" break except KeyboardInterrupt: print "Ctrl + C pressed" soc.close() if __name__ == '__main__': app = QtGui.QApplication(sys.argv) #w = logger.superLogger() w = viewer.viewer() w.show() app.exec_() pass
def buildThread(): v = viewer.viewer() v.setDaemon(True) v.start()
parser = argparse.ArgumentParser() parser.add_argument("input", help='input file that contains the point cloud', type=str) parser.add_argument("output", help='path to the output file', type=str) parser.add_argument("--slice", "-s", help='slice size (default: 15000)', type=int, default=15000) args = parser.parse_args() # Load input file pcd_list = ut.loadPoints(args.input, [2,3,4]) # Compute the number of iterations to do given the slice size to_process = len(pcd_list) slice_size = args.slice iterations = to_process/slice_size if (iterations == 0 or to_process%slice_size == 0): iterations += 1 largest_clusters = [] i = 0 for i in range(iterations): begin = i*slice_size if (i+1)*slice_size < to_process: end = (i+1)*slice_size else: end = to_process # Get the largest clusters largest_clusters += noise_removal(pcd_list[begin:end], ratio=0.1) largest_clusters = np.array(largest_clusters) ut.savePoints(largest_clusters, args.output, [0,1,2]) viewer(largest_clusters, c=largest_clusters[:,2], s=2)
def compute_background(img): colors = np.ndarray((img.shape[0], img.shape[1]), dtype=np.uint32) colors[:, :] = np.uint32(img[:, :, 0]) << 16 colors[:, :] += np.uint32(img[:, :, 1]) << 8 colors[:, :] += np.uint32(img[:, :, 2]) << 0 (values, counts) = np.unique(colors, return_counts=True) pix = values[np.argmax(counts)] bg = np.array([(pix >> 16) & 0xFF, (pix >> 8) & 0xFF, (pix >> 0) & 0xFF], dtype=np.uint8) return bg slides = [] viewer = viewer(interactive=1) SDL_Init(SDL_INIT_EVERYTHING) window = SDL_CreateWindow("Futhark Presents!", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_SHOWN) def reWindow(window): window_surface = SDL_GetWindowSurface(window) frame_py = np.ndarray(shape=(height, width), dtype=np.int32, order='C') surface = SDL_CreateRGBSurfaceFrom(frame_py.ctypes.data, width, height, 32, width * 4, 0xFF0000, 0xFF00, 0xFF, 0x00000000) return (window_surface, frame_py, surface)
def selfcal(vis, spwn=6, doplots=True, INTERACTIVE=False, reclean=True, field='W51 Ku', outdir_template="spw%i_selfcal_iter/", statsbox='170,50,229,97', ant1list=['ea14','ea05'], ant2list=['ea16','ea07'], avgchannel_wide='128', avgchannel_narrow='8', cleanboxes=cleanboxes, refant='ea27', solint='30s', niter=2, multiscale=[0,5,10,15,25,50], imsize=512, robust=0.0 ): """ Docstring incomplete """ spw = int(spwn) outdir = outdir_template % spwn try: os.mkdir(outdir) except OSError: pass # you're supposed to pass in avg_data as input avg_data = vis mytb.open(vis+"/ANTENNA") antnames = mytb.getcol("NAME") # plot each antenna's ampl vs time for flagging purposes for ant2 in ant2list: for ant in ant1list: plotms(vis=vis, spw=str(spwn), xaxis='time', yaxis='amp', avgchannel=avgchannel_wide, avgscan=F, coloraxis='baseline', iteraxis='', xselfscale=T, yselfscale=T, antenna=ant+"&"+ant2, title='Amp vs Time before averaging for spw %i ant %s-%s' % (spwn,ant,ant2), plotfile=outdir+'ampvstime_spw%i_ant%s-%s.png' % (spwn,ant,ant2), field=field, overwrite=True, ) plotms(vis=vis, spw=str(spwn), xaxis='freq', yaxis='phase', avgtime='1e8', avgscan=T, coloraxis='corr', iteraxis='baseline', xselfscale=T, yselfscale=T, antenna=ant+"&"+ant2, title='Phase vs Freq with time averaging for spw %i ant %s-%s' % (spwn,ant,ant2), plotfile=outdir+'phasevsfreq_spw%i_ant%s-%s.png' % (spwn,ant,ant2), field=field, overwrite=True, ) plotms(vis=vis, spw=str(spwn), xaxis='amp', yaxis='phase', avgtime='1e8', avgscan=T, coloraxis='corr', iteraxis='baseline', xselfscale=T, yselfscale=T, antenna=ant+"&"+ant2, title='Phase vs Amp with time averaging for spw %i ant %s-%s' % (spwn,ant,ant2), plotfile=outdir+'phasevsamp_spw%i_ant%s-%s.png' % (spwn,ant,ant2), field=field, overwrite=True, ) # imagename = "noaverage_spw%i" % spwn # os.system("rm -rf "+imagename+".image") # os.system("rm -rf "+imagename+".model") # os.system("rm -rf "+imagename+".flux") # os.system("rm -rf "+imagename+".psf") # os.system("rm -rf "+imagename+".residual") # clean(vis=vis, field=field, imagename=imagename, mode='mfs', # weighting='briggs', robust=robust, niter=500, imsize=512) # viewer(imagename+".image", # outfile=outdir+imagename+".image.png", # outformat='png', # gui=False) # exportfits(imagename=imagename+".image", fitsimage=imagename+".fits", overwrite=True) #width = 10 # for TW Hydra # width = 4 # for NGC 3256 # (0) Using your split-off, calibrated data, plot the "model" in this MS using # plotms. It should be unit-valued for all data. If not, run delmod to get # rid of any model that might still be lurking in the header, and/or clearcal # to set to 1 any MODEL data. plotms(vis=avg_data, spw='0', xaxis='time', yaxis='amp', avgchannel=avgchannel_wide, xdatacolumn='model', ydatacolumn='model', avgscan=F, coloraxis='baseline', iteraxis='', xselfscale=T, yselfscale=T, title='Model Amp vs Time after split for spw %i. Should be all 1s' % spwn, plotfile=outdir+'ampvstime_model_shouldbe1.png', field=field, overwrite=True,) delmod(vis=avg_data) plotms(vis=avg_data, spw='0', xaxis='phase', yaxis='amp', avgchannel=avgchannel_wide, xdatacolumn='data', ydatacolumn='data', avgscan=F, coloraxis='baseline', iteraxis='', xselfscale=T, yselfscale=T, title='Corrected Phase vs Amp after split', plotfile=outdir+'ampvsphase_corrected_avg_spw%i.png' % spwn, field=field, overwrite=True,) # (0.5) Run clean non-interactively with some set number of iterations, and be # sure to keep the image around for comparison later. Run delmod to get rid of # the model it saved to the MS header. #if reclean: # imagename="average_spw%i_shallowclean" % spwn # for suffix in clean_output_suffixes: # os.system("rm -rf "+imagename+suffix) # clean(vis=avg_data, field=field, imagename=imagename, mode='mfs', # weighting='briggs', robust=robust, niter=100, imsize=512) # viewer(imagename+".image", # outfile=outdir+imagename+".image.png", # outformat='png', # gui=False) # exportfits(imagename=imagename+".image", fitsimage=imagename+".fits", overwrite=True) # delmod(avg_data,scr=True) # (1) Clean a single SPW *interactively*, boxing the brightest regions and not # cleaning very deeply (maybe 100 iterations). Keep this model in the header # -- it's what you'll use for the first round of self-calibration. if reclean: imagename="average_spw%i_shallowclean_masked" % spwn for suffix in clean_output_suffixes: os.system("rm -rf "+imagename+suffix) clean(vis=avg_data, field=field, imagename=imagename, mode='mfs', psfmode='hogbom',multiscale=multiscale, weighting='briggs', robust=robust, niter=100, imsize=imsize, mask=cleanboxes, nterms=2, usescratch=True) viewer(imagename+".image.tt0", outfile=outdir+imagename+".image.tt0.png", outformat='png', gui=False) exportfits(imagename=imagename+".image.tt0", fitsimage=imagename+".fits", overwrite=True) imrms = [imstat(imagename+".image.tt0",box=statsbox)['rms']] # FAILS!!!! #plotms(vis=avg_data, spw='0', xaxis='time', yaxis='amp', # avgchannel='128', xdatacolumn='model', ydatacolumn='model', avgscan=F, # coloraxis='baseline', iteraxis='', xselfscale=T, yselfscale=T, # title='Model Amp vs Time after shallow clean for spw %i.' % spwn, # plotfile=outdir+'ampvstime_model_shallowclean_spw%i.png' % spwn, field=field, # overwrite=True,) for calnum in xrange(niter): # for Ku D W51 Ku spw 2 if reclean: first_image = 'spw%i_C_C_firstim_selfcal%i' % (spwn,calnum) for suffix in clean_output_suffixes: os.system("rm -rf "+first_image+suffix) clean(vis=avg_data,imagename=first_image,field=field, mode='mfs', psfmode='hogbom',multiscale=multiscale, weighting='briggs', robust=robust, niter=100, imsize=imsize, mask=cleanboxes, nterms=2, usescratch=True) exportfits(imagename=first_image+".image.tt0", fitsimage=first_image+".fits", overwrite=True) viewer(first_image+".image.tt0", outfile=outdir+first_image+".image.tt0.png", outformat='png', gui=False) # this fails? #plotms(vis=avg_data, spw='0', xaxis='time', yaxis='amp', # avgchannel='128', xdatacolumn='model', ydatacolumn='model', avgscan=F, # coloraxis='baseline', iteraxis='', xselfscale=T, yselfscale=T, # title='Model Amp vs Time after shallow clean for spw %i iter %i.' % (spwn,calnum), # plotfile=outdir+'ampvstime_model_shallowclean_spw%i_iter%i.png' % (spwn,calnum), field=field, # overwrite=True,) # DONE avg/split ing caltable = 'selfcal%i_%s_spw%i.gcal' % (calnum,field.replace(" ",""),spwn) if reclean: os.system('rm -rf '+caltable) gaincal(vis=avg_data, field='', caltable=caltable, spw='', # gaintype = 'T' could reduce failed fit errors by averaging pols... gaintype='G', # 'G' from http://casaguides.nrao.edu/index.php?title=EVLA_Advanced_Topics_3C391 solint=solint, refant=refant, calmode='p', combine='scan', minblperant=4) # # Watch out for failed solutions noted in the terminal during this # solution. If you see a large fraction (really more than 1 or 2) of # your antennas failing to converge in many time intervals then you # may need to lengthen the solution interval. # # =%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=% # INSPECT THE CALIBRATION # =%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=% # # After you have run the gaincal, you want to inspect the # solution. Use PLOTCAL to look at the solution (here broken into # panels by SPW with individual antennas mapped to colors). Look at # the overall magnitude of the correction to get an idea of how # important the selfcal is and at how quickly it changes with time to # get an idea of how stable the instrument and atmosphere were. # if doplots: for ant2 in ant2list: for ant in ant1list: # (4) Have a look at the gain solutions by antenna. Which antennas # have the largest phase corrections? Before applying the # calibration, use plotms to display the corrected phase vs. amp # for these antennas, to compare with *after* the correction is # applied. plotcal(caltable=caltable, xaxis='time', yaxis='phase', showgui=False, antenna=ant+'&'+ant2, figfile=outdir+'selfcal%i_spw%i_phasevstime_ant%s-%s.png' % (calnum,spwn,ant,ant2), iteration='')#, subplot = 221) #plotcal(caltable=caltable, xaxis='amp', yaxis='phase', # showgui=False, # antenna=ant, # figfile=outdir+'selfcal%i_spw%i_phasevsamp_ant%s.png' % (calnum,spwn,ant), # iteration='')#, subplot = 221) if calnum == 0: datacol='data' else: datacol='corrected' plotms(vis=avg_data, xaxis='time', yaxis='phase', xdatacolumn=datacol, ydatacolumn=datacol, avgtime='15s', avgchannel=avgchannel_narrow, coloraxis='corr', antenna=ant+'&'+ant2, overwrite=True, title='Iteration %i for spw %i and ant %s-%s. datacol=%s' % (calnum,spwn,ant,ant2,datacol), plotfile=outdir+'selfcal%i_spw%i_ant%s-%s_phasetime.png' % (calnum,spwn,ant,ant2),) plotms(vis=avg_data, xaxis='time', yaxis='amp', xdatacolumn=datacol, ydatacolumn=datacol, avgtime='15s', avgchannel=avgchannel_narrow, coloraxis='corr', antenna=ant+'&'+ant2, overwrite=True, title='Iteration %i for spw %i and ant %s-%s. datacol=%s' % (calnum,spwn,ant,ant2,datacol), plotfile=outdir+'selfcal%i_spw%i_ant%s-%s_amptime.png' % (calnum,spwn,ant,ant2),) plotms(vis=avg_data, xaxis='phase', yaxis='amp', xdatacolumn=datacol, ydatacolumn=datacol, avgtime='60s', avgchannel=avgchannel_narrow, coloraxis='corr', antenna=ant+'&'+ant2, overwrite=True, title='Iteration %i for spw %i and ant %s-%s. datacol=%s' % (calnum,spwn,ant,ant2,datacol), plotfile=outdir+'selfcal%i_spw%i_ant%s-%s_phaseamp.png' % (calnum,spwn,ant,ant2),) plotcal(caltable=caltable, xaxis='time', yaxis='phase', plotrange=[0,0,-180,180], showgui=INTERACTIVE, figfile='' if INTERACTIVE else outdir+'selfcal%i_spw%i_phasevstime.png' % (calnum,spwn), iteration='spw' if INTERACTIVE else '')#, subplot = 221) plotcal(caltable=caltable, xaxis='antenna', yaxis='phase', showgui=INTERACTIVE, figfile=outdir+'selfcal%i_spw%i_phasevsantenna.png' % (calnum,spwn), iteration='') plotcal(caltable=caltable, xaxis='time', yaxis='amp', plotrange=[0,0,0.5,1.5], showgui=INTERACTIVE, figfile='' if INTERACTIVE else outdir+'selfcal%i_spw%i_ampvstime.png' % (calnum,spwn), iteration='spw' if INTERACTIVE else '')#, subplot = 221) #plotcal(caltable=caltable, # xaxis='phase', yaxis='amp', # plotrange=[-50,50,0.5,1.5], # showgui=INTERACTIVE, # figfile='' if INTERACTIVE else outdir+'selfcal%i_spw%i_ampvsphase.png' % (calnum,spwn), # iteration='spw' if INTERACTIVE else '')#, subplot = 221) # THERE WILL BE WEIRD "LUSTRE" ERRORS GENERATED BY THE FILE SYSTEM. DO # NOT FREAK OUT. These are just a feature of our fast file # system. Plotcal will still work. # It can be useful useful to plot the X-Y solutions (i.e., differences # between polarizations) as an indicator of the noise in the # solutions. plotcal(caltable=caltable, xaxis='time', yaxis='phase', plotrange=[0,0,-25, 25], poln = '/', showgui=INTERACTIVE, iteration='spw,antenna' if INTERACTIVE else '', figfile='' if INTERACTIVE else outdir+'selfcal%i_spw%i_poldiff.png' % (calnum,spwn), subplot = 221 if INTERACTIVE else 111) plotms(vis=avg_data, xaxis='uvdist', yaxis='amp', xdatacolumn='corrected', ydatacolumn='corrected', avgtime='1e8s', avgchannel=avgchannel_narrow, coloraxis='baseline', overwrite=True, title='Iteration %i for spw %i' % (calnum,spw), plotfile='' if INTERACTIVE else outdir+'selfcal%i_spw%i_uvdistamp.png' % (calnum,spwn), ) #plotms(vis=avg_data, # xaxis='phase', # yaxis='amp', # xdatacolumn='corrected', # ydatacolumn='corrected', # avgtime='60s', # avgchannel=avgchannel_narrow, # coloraxis='corr', # overwrite=True, # title='Iteration %i for spw %i' % (calnum,spw), # plotfile='' if INTERACTIVE else outdir+'selfcal%i_spw%i_phaseamp.png' % (calnum,spwn), # ) plotms(vis=avg_data, xaxis='time', yaxis='amp', xdatacolumn='corrected', ydatacolumn='corrected', avgtime='10s', avgchannel=avgchannel_narrow, coloraxis='baseline', overwrite=True, title='Iteration %i for spw %i' % (calnum,spw), plotfile='' if INTERACTIVE else outdir+'selfcal%i_spw%i_amptime.png' % (calnum,spwn), ) # The rms noise is about 4 to 8 deg, depending on antenna, but the # phase changes are considerably larger. This indicates that the # application of this solution will improve the image. # =%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=% # APPLY THE CALIBRATION # =%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=% # # If you are satisfied with your solution, you can now apply it to the # data to generate a new corrected data column, which you can then # image. Be sure to save the previous flags before you do so because # applycal will flag data without good solutions. The commented # command after the applycal will roll back to the saved solution in # case you get in trouble. # # flagmanager(vis=avg_data, # mode='save', # versionname='before_selfcal_apply') # 2013-03-04 19:53:37 SEVERE agentflagger:: (file /opt/casa/stable-2013-02/gcwrap/tools/flagging/agentflagger_cmpt.cc, line 37) Exception Reported: Invalid Table operation: ArrayColumn::setShape; shape cannot be changed for row 0 column FLAG # *** Error *** Invalid Table operation: ArrayColumn::setShape; shape cannot be changed for row 0 column FLAG if reclean: applycal(vis=avg_data, gaintable=caltable, interp='linear', flagbackup=True) # was False when flagmanager was used # (6) Plot corrected phase vs. amp for the antennas you picked out in (4), # to check that in fact the corrections have been applied as expected. for ant2 in ant2list: for ant in ant1list: plotms(vis=avg_data, xaxis='time', yaxis='phase', xdatacolumn='corrected', ydatacolumn='corrected', avgtime='15s', avgchannel=avgchannel_narrow, coloraxis='corr', antenna=ant+'&'+ant2, overwrite=True, title='Iteration %i for spw %i and ant %s-%s' % (calnum,spwn,ant,ant2), plotfile=outdir+'selfcal%i_spw%i_ant%s-%s_phasetime_applied.png' % (calnum,spwn,ant,ant2),) plotms(vis=avg_data, xaxis='time', yaxis='amp', xdatacolumn='corrected', ydatacolumn='corrected', avgtime='60s', avgchannel=avgchannel_narrow, coloraxis='corr', antenna=ant+'&'+ant2, overwrite=True, title='Iteration %i for spw %i and ant %s-%s' % (calnum,spwn,ant,ant2), plotfile=outdir+'selfcal%i_spw%i_ant%s-%s_amptime_applied.png' % (calnum,spwn,ant,ant2),) plotms(vis=avg_data, xaxis='phase', yaxis='amp', xdatacolumn='corrected', ydatacolumn='corrected', avgtime='60s', avgchannel=avgchannel_narrow, coloraxis='corr', antenna=ant+'&'+ant2, overwrite=True, title='Iteration %i for spw %i and ant %s-%s' % (calnum,spwn,ant,ant2), plotfile=outdir+'selfcal%i_spw%i_ant%s-%s_phaseamp_applied.png' % (calnum,spwn,ant,ant2),) plotms(vis=vis, spw='0', xaxis='freq', yaxis='phase', avgtime='1e8', avgscan=T, coloraxis='corr', iteraxis='baseline', xselfscale=T, yselfscale=T, antenna=ant+'&'+ant2, title='Phase vs Freq with time averaging for spw %i ant %s-%s iter %i' % (spwn,ant,ant2,calnum), plotfile=outdir+'phasevsfreq_spw%i_ant%s-%s_selfcal%i.png' % (spwn,ant,ant2,calnum), field=field, overwrite=True, ) # Use this command to roll back to the previous flags in the event of # an unfortunate applycal. #flagmanager(vis=avg_data, # mode='restore', # versionname='before_selfcal_apply') if reclean: selfcal_image = 'spw%i_C_C_selfcal%i' % (spwn,calnum) for suffix in clean_output_suffixes: os.system("rm -rf "+selfcal_image+suffix) clean(vis=avg_data,imagename=selfcal_image,field=field, mode='mfs', psfmode='hogbom',multiscale=multiscale, weighting='briggs', robust=robust, niter=1000, imsize=imsize, nterms=2, mask=cleanboxes, usescratch=True) exportfits(imagename=selfcal_image+".image.tt0", fitsimage=selfcal_image+".fits", overwrite=True) plotms(vis=avg_data, spw='0', xaxis='baseline', yaxis='amp', avgtime='1e8', ydatacolumn='corrected-model', avgscan=T, coloraxis='baseline', iteraxis='', xselfscale=T, yselfscale=T, title='Residual vs. Baseline after CSCLEAN iter %i' % calnum, plotfile=outdir+'post_selfcal%i_spw%i_residVSbaseline.png' % (calnum,spwn), field=field, overwrite=True, ) plotms(vis=avg_data, spw='0', xaxis='time', yaxis='amp', avgtime='5s', ydatacolumn='corrected-model', coloraxis='baseline', iteraxis='', xselfscale=T, yselfscale=T, title='Residual vs. Time after CSCLEAN iter %i' % (calnum), plotfile=outdir+'post_selfcal%i_spw%i_residVStime.png' % (calnum,spwn), field=field, overwrite=True, ) plotms(vis=avg_data, spw='0', xaxis='uvdist', yaxis='amp', avgtime='1e8', ydatacolumn='corrected-model', avgscan=T, coloraxis='baseline', iteraxis='', xselfscale=T, yselfscale=T, title='Residual vs. UVDIST after CSCLEAN iter %i' % (calnum) , plotfile=outdir+'post_selfcal%i_spw%i_residVSuvdist.png' % (calnum,spwn), field=field, overwrite=True, ) imrms.append(imstat(selfcal_image+".image.tt0",box=statsbox)['rms']) viewer(selfcal_image+".image.tt0", outfile=outdir+selfcal_image+".image.tt0.png", outformat='png', gui=False) print "FINISHED ITERATION %i" % calnum print "FINISHED ITERATING!!! YAY!" # final phase + gain cal: # http://casaguides.nrao.edu/index.php?title=Calibrating_a_VLA_5_GHz_continuum_survey#One_Last_Iteration:_Amplitude_.26_Phase_Self_Calibration aptable = 'selfcal_ap_%s_spw%i.gcal' % (field.replace(" ",""),spwn) gaincal(vis=avg_data, field='', caltable=aptable, gaintable=caltable, spw='', solint='inf', refant=refant, calmode='ap', combine='', minblperant=4) plotcal(caltable=aptable, xaxis='phase', yaxis='amp', plotrange=[-50,50,0.5,1.5], showgui=INTERACTIVE, figfile='' if INTERACTIVE else outdir+'selfcal%i_spw%i_ampvsphase_final.png' % (calnum,spwn), iteration='spw' if INTERACTIVE else '')#, subplot = 221) applycal(vis=avg_data, gaintable=[aptable,caltable], interp='linear', flagbackup=True) # was False when flagmanager was used selfcal_image = 'spw%i_C_C_selfcal%i_final' % (spwn,calnum) for suffix in clean_output_suffixes: os.system("rm -rf "+selfcal_image+suffix) clean(vis=avg_data,imagename=selfcal_image,field=field, mode='mfs', mask=cleanboxes, weighting='briggs', robust=robust, niter=10000, imsize=imsize, nterms=2, usescratch=True) exportfits(imagename=selfcal_image+".image.tt0", fitsimage=selfcal_image+".fits", overwrite=True) plotms(vis=avg_data, spw='0', xaxis='baseline', yaxis='amp', avgtime='1e8', ydatacolumn='corrected-model', avgscan=T, coloraxis='baseline', iteraxis='', xselfscale=T, yselfscale=T, title='Residual vs. Baseline after CSCLEAN iter %i' % calnum, plotfile=outdir+'post_selfcal%i_spw%i_residVSbaseline.png' % (calnum,spwn), field=field, overwrite=True, ) plotms(vis=avg_data, spw='0', xaxis='time', yaxis='amp', avgtime='5s', ydatacolumn='corrected-model', coloraxis='baseline', iteraxis='', xselfscale=T, yselfscale=T, title='Residual vs. Time after CSCLEAN iter %i' % (calnum), plotfile=outdir+'post_selfcal%i_spw%i_residVStime.png' % (calnum,spwn), field=field, overwrite=True, ) plotms(vis=avg_data, spw='0', xaxis='uvdist', yaxis='amp', avgtime='1e8', ydatacolumn='corrected-model', avgscan=T, coloraxis='baseline', iteraxis='', xselfscale=T, yselfscale=T, title='Residual vs. UVDIST after CSCLEAN iter %i' % (calnum) , plotfile=outdir+'post_selfcal%i_spw%i_residVSuvdist.png' % (calnum,spwn), field=field, overwrite=True, ) selfcal_image = 'spw%i_C_C_selfcal%i_final_multiscale' % (spwn,calnum) for suffix in clean_output_suffixes: os.system("rm -rf "+selfcal_image+suffix) clean(vis=avg_data,imagename=selfcal_image,field=field, mode='mfs', imagermode='csclean',# mask=cleanboxes, multiscale=multiscale, psfmode='hogbom', nterms=2, weighting='briggs', robust=robust, niter=10000, imsize=imsize, usescratch=True) exportfits(imagename=selfcal_image+".image.tt0", fitsimage=selfcal_image+".fits", overwrite=True) plotms(vis=avg_data, spw='0', xaxis='baseline', yaxis='amp', avgtime='1e8', ydatacolumn='corrected-model', avgscan=T, coloraxis='baseline', iteraxis='', xselfscale=T, yselfscale=T, title='Residual vs. Baseline after multiscale CLEAN iter %i' % (calnum), plotfile=outdir+'post_selfcal%i_spw%i_residVSbaseline_multiscale.png' % (calnum,spwn), field=field, overwrite=True, ) plotms(vis=avg_data, spw='0', xaxis='time', yaxis='amp', avgtime='5s', ydatacolumn='corrected-model', coloraxis='baseline', iteraxis='', xselfscale=T, yselfscale=T, title='Residual vs. Time after multiscale CLEAN iter %i' % (calnum), plotfile=outdir+'post_selfcal%i_spw%i_residVStime_multiscale.png' % (calnum,spwn), field=field, overwrite=True, ) plotms(vis=avg_data, spw='0', xaxis='uvdist', yaxis='amp', avgtime='1e8', ydatacolumn='corrected-model', avgscan=T, coloraxis='baseline', iteraxis='', xselfscale=T, yselfscale=T, title='Residual vs. UVDIST after multiscale CLEAN iter %i' % (calnum), plotfile=outdir+'post_selfcal%i_spw%i_residVSuvdist_multiscale.png' % (calnum,spwn), field=field, overwrite=True, ) return imrms
parser.add_argument("--eps", help='epsilon value for DBSCAN (default: 0.00005)', type=float, default=0.00005) args = parser.parse_args() method = args.meth if method == "kmeans": sys.stderr.write("Clustering with K-Means method...\n") options = {'init':'random', 'n_clusters':args.n, 'n_jobs':-1, 'n_init':10} elif method == "affinity": sys.stderr.write("Clustering with Affinity Propagation method...\n") options = {'preference':-50} elif method == "dbscan": sys.stderr.write("Clustering with DBScan method...\n") options = {'eps':args.eps} elif method == "ward": sys.stderr.write("Clustering with Ward method...\n") options = {'n_clusters':args.n} elif method == "meanshift": sys.stderr.write("Clustering with Mean Shift method...\n") options = {'bandwidth':bandwidth, 'bin_seeding':True} else: sys.stderr.write("Error: Unsupported clustering method.\n") exit(0) # Load file pcd_list = ut.loadPoints(args.file, [2,3,4]) # Cluster the points clusters = cluster(pcd_list, method, options) # Show the clusters viewer(clusters, draw_elevation=False, c=clusters[:,2])
# Load input file pcd_list = np.array(ut.loadPoints(args.input, [0, 1, 2])) # Compute the number of iterations to do given the slice size to_process = len(pcd_list) slice_size = args.slice iterations = to_process / slice_size if (iterations == 0 or to_process % slice_size == 0): iterations += 1 # Initialize the iteration variable i = 0 # Get the matplotlib object that shows the point cloud plt = viewer(pcd_list, get=True) # Compute the fitting polynoms and plot them for i in range(iterations): begin = i * slice_size if (i + 1) * slice_size < to_process: end = (i + 1) * slice_size else: end = to_process points_slice = pcd_list[begin:end] xp = np.linspace(points_slice[0, 0], points_slice[end - begin - 1, 0], 100) pl = np.poly1d( np.polyfit(points_slice[:, 0], points_slice[:, 1], args.degree)) plt.plot(xp, pl(xp), 'r-', linewidth=3.0) plt.show()
sys.stderr.write("Clustering with K-Means method...\n") options = { 'init': 'random', 'n_clusters': args.n, 'n_jobs': -1, 'n_init': 10 } elif method == "affinity": sys.stderr.write("Clustering with Affinity Propagation method...\n") options = {'preference': -50} elif method == "dbscan": sys.stderr.write("Clustering with DBScan method...\n") options = {'eps': args.eps} elif method == "ward": sys.stderr.write("Clustering with Ward method...\n") options = {'n_clusters': args.n} elif method == "meanshift": sys.stderr.write("Clustering with Mean Shift method...\n") options = {'bandwidth': bandwidth, 'bin_seeding': True} else: sys.stderr.write("Error: Unsupported clustering method.\n") exit(0) # Load file pcd_list = ut.loadPoints(args.file, [2, 3, 4]) # Cluster the points clusters = cluster(pcd_list, method, options) # Show the clusters viewer(clusters, draw_elevation=False, c=clusters[:, 2])