def fetchdata(where='', savedata=''): """Retrieves mysql data for RA and DEC. where is a string specifying which data from mysql to grab. ONLY include columns from table 'config'. do not include the word 'where' at the beginning or the semicolon at the end. all other common mysql syntax rules apply. savedata allows the user to have the data saved by inputting the file name. data is saved as an ASCII file. if left empty, no file will be saved returns three arrays, ra, dec, and specid""" #Create command to send to mysql if not where: cmd = command.generate('ra,decl,specid','config') else: cmd = command.generate('ra,decl,specid','config',where=where) #Send command to mysql, return data data = MySQLFunction.mysqlcommand(cmd) #Separate data into two arrays length = len(data) ra = numpy.asarray([data[x][0] for x in range(length)]) dec = numpy.asarray([data[x][1] for x in range(length)]) specid = numpy.asarray([data[x][2] for x in range(length)]) #Save data? if savedata!='': numpy.savetxt('%s' %savedata,(ra,dec,specid)) return(ra,dec,specid)
def fetchdata(where='',freqtype='topo',savedata=''): """Fetches data to produce the dynamic spectrum plot for hits. where is a string to include additional information to narrow the results. typically it will be used to specify a range of specids. each column name MUST be prefixed with the first letter of the table name and a period, like c.obstime. don't forget to include 'h.specid=c.specid if referencing config and hit. do not include the word 'where' at the beginning or the semicolon at the end. all other common mysql syntax rules apply. Ex: 'h.specid>1 and h.specid<=20 and c.beamnum!=8 and c.specid=h.specid'. freqtype is the frequency type for the y-axis, either 'binnum', 'topo', or 'bary'. returns three arrays: eventpower,frequency (in MHz),time (in seconds since first spectra in data set)""" import MySQLFunction, numpy, command # create full column name from freq_type if freqtype=='topo': freqtype = 'h.topocentric_freq' elif freqtype=='bary': freqtype = 'h.barycentric_freq' elif freqtype=='binnum': freqtype = 'h.binnum' # generate mysql command if ('c.specid=h.specid' or 'h.specid=c.specid') not in where: where = where + ' and c.specid=h.specid' cmd = command.generate('h.eventpower,%s,c.obstime'%freqtype,'hit h, config c',where=where) # send command to database and return results data = MySQLFunction.mysqlcommand(cmd) # separate data into individual arrays length = len(data) eventpower = numpy.asarray([data[x][0] for x in xrange(length)]) if freqtype != 'h.binnum': freq = numpy.asarray([data[x][1]/1000000 for x in xrange(length)]) elif freqtype=='h.binnum': freq=numpy.asarray([data[x][1] for x in xrange(length)]) time = numpy.array([data[x][2] for x in xrange(length)]) # create seconds array time = time-min(time) time = time*86400 # save data? if savedata!='': numpy.savetxt('%s' %savedata,(eventpower,freq,time)) return (eventpower,freq,time)
def fetchdata(where='',freqtype='binnum'): """Fetches data to produce the three panel dynamic spectrum plot. where is a string to include additional information to narrow the results. typically it will be used to specify a range of specids. each column name MUST be prefixed with the first letter of the table name and a period, like c.obstime. don't forget to include 's.specid=c.specid if referencing config and spec. do not include the word 'where' at the beginning or the semicolon at the end. all other common mysql syntax rules apply. Ex: 's.specid>1 and s.specid<=20 and c.beamnum!=8 and c.specid=s.specid'. don't include hit table. freqtype is the frequency type for the pcolormesh, either 'binnum' or 'topo'. output is xarr, a 1D array representing the x-axis, yarr, a 1D array representing the y-axis, and data, a 2D array of the data""" import MySQLFunction, struct, threeplot, pylab, numpy, command #Create command to send to database if ('c.specid=s.specid' or 's.specid=c.specid') not in where: where = where + ' and c.specid=s.specid' cmd = command.generate('s.coarsespec,c.obstime,c.IF1_rfFreq','spec s, config c', where=where) #Fetch data from mysql fromdb = MySQLFunction.mysqlcommand(cmd) #Create arrays from data length = len(fromdb) coarsespec = [fromdb[x][0] for x in xrange(length)] time = numpy.array([fromdb[x][1] for x in xrange(length)]) #Freq type? if freqtype=='topo': rfFreq = fromdb[0][2] RFLO = rfFreq - 50000000 yarr = numpy.linspace(RFLO, RFLO+200000000, 4096) yarr = yarr / 1000000 else: yarr = numpy.arange(1,4097,1) #Create seconds array time = time-min(time) xarr = time*86400 #Unpack data from blob data = [numpy.array(struct.unpack('i'*4096,coarsespec[x])) for x in xrange(length)] data = numpy.transpose(data) return (xarr,yarr,data)
def start(args, config, oj, contest_id): if args.show_a: print_statement(oj.get_statement_a(contest_id, 1)) url = urlparse(args.contest_url) problems = oj.get_problems(contest_id, 1) oj.download_testcases(problems[0]) with open("data/contest/problems.csv", mode="w") as f: for problem in problems: f.write(",".join(problem) + "\n") args.problem_char = "a" generate(args, config) if args.download: for problem in problems: oj.download_testcases(problem) return
def test_inputsize(urlnum): global oj global urls global config url = urls[urlnum] if not url.startswith("http"): url = "https://atcoder.jp/contests/" + url time.sleep(wait) generate(generate_args(url.split("/")[-1]), config) comp(comp_args(), config) ok = 1 testcase_num = 1 while 1: try: output = run(run_args(testcase_num, url.split("/")[-1]), config) except: break assert output == test_str + "\n" testcase_num += 1 testcase_num -= 1 assert testcase_num > 0
def generate_run_command(job, results_dir, params_file, scarab_args): scarab_launch_cmd = SystemConfig.python_bin + " " + \ SystemConfig.scarab_launch + \ " --scarab " + SystemConfig.scarab + \ " --frontend_pin_tool " + SystemConfig.frontend_pin_tool + \ " --pintool_args=\"" + SystemConfig.pintool_args + " " + job.pintool_args + "\"" \ " --scarab_args=\"" + SystemConfig.scarab_args + " " + scarab_args + "\"" \ " --params " + params_file + \ " --scarab_stdout " + results_dir + "/" + SystemConfig.scarab_stdout + \ " --scarab_stderr " + results_dir + "/" + SystemConfig.scarab_stderr + \ " --pin_stdout " + results_dir + "/" + SystemConfig.pin_stdout + \ " --pin_stderr " + results_dir + "/" + SystemConfig.pin_stderr + \ get_program_or_checkpoint_options(job) launch_out = results_dir + "/" + SystemConfig.scarab_launch_stdout launch_err = results_dir + "/" + SystemConfig.scarab_launch_stderr cmd = command.generate(SystemConfig.submission_system, scarab_launch_cmd, run_dir=results_dir, results_dir=results_dir, stdout=launch_out, stderr=launch_err) return cmd
def makeplot(eventpower,freq,time,errbar=[0], where='',freqtype='topo',vlim=(-1,-1),frac=0.9,saveplot=''): """Produces a 'confetti plot' of spectra dynamically. freqtype is the frequency type, either 'binnum', 'bary', or 'topo'. Input: where is a string to include additional information to narrow the results. typically it will be used to specify a range of specids. each column name MUST be prefixed with the first letter of the table name and a period, like c.obstime. don't forget to include 's.specid=c.specid if referencing config and spec. do not include the word 'where' at the beginning or the semicolon at the end. all other common mysql syntax rules apply. Ex: 's.specid>1 and s.specid<=20 and c.beamnum!=8 and c.specid=s.specid'. don't include hit table. vlim is a tuple of (vmin,vmax). Values are used in conjuction with norm to normalize luminance data. frac is the fraction of hits, sorted by eventpower, before which the size is 0.1 and after which the size is 1 saveplot='' allows you to save the plot by inputting its name as a string. if left blank, no plot is saved Output: Figure instance """ import pylab, numpy, MySQLFunction, command, jd2gd, math # initialize figure fig=pylab.figure(figsize=(12,7)) ax1 = fig.add_axes([0.1, 0.14, 0.85, 0.75]) #If no plot limits specified, if vlim==(-1,-1): vlim=(numpy.min(eventpower), numpy.max(eventpower)) # create array of point sizes sorted = numpy.sort(eventpower) index = math.floor(frac*len(eventpower)) cutoff = eventpower[index] size = [.1 if eventpower[x]<cutoff else 1 for x in xrange(len(eventpower))] # plot data if len(errbar)>1: size=20 pylab.errorbar(time,freq,xerr=errbar,fmt=None,ecolor='k', capsize=0.0) pylab.scatter(time,freq,s=size,c=eventpower,edgecolors='none',vmin=vlim[0],vmax=vlim[1]) # add grid pylab.grid(True,which='both') # add labels ax1.set_xlabel('Time (seconds)') ax1.set_title('Dynamic Spectra - Hits') if freqtype=='binnum': ax1.set_ylabel('Frequency channel') elif freqtype=='topo': ax1.set_ylabel('Topocentric Frequency (MHz)') elif freqtype=='bary': ax1.set_ylabel('Barycentric Frequency (MHz)') # gather additional info if where=='': cmd = command.generate('specid,obstime,AGC_Time,IF1_rfFreq','config') elif 'c.' not in where: where = where + ' and h.specid=c.specid' cmd = command.generate('h.specid,c.obstime,c.AGC_Time,c.IF1_rfFreq','hit h, config c',where=where) else: where = where + ' and h.specid=c.specid' cmd = command.generate('h.specid,c.obstime,c.AGC_Time,c.IF1_rfFreq','hit h, config c',where=where) data = MySQLFunction.mysqlcommand(cmd) # separate into arrays length = len(data) specid = [data[x][0] for x in xrange(length)] day = numpy.asarray([data[x][1] for x in xrange(length)]) # get specid and hit count uniq_IDs = set(specid) speccount = len(uniq_IDs) hitcount = len(eventpower) # determine start and end dates start = min(day) end = max(day) # calculate the min and max RF from the center freq # scale y axis accordinly rfctr=float(data[0][3]) rflo=rfctr-50e6 rfhi=rflo+200e6 rflo-=5e6 #Add offsets to get hits away from plot edges rfhi+=5e6 # guess whether data is given in Hz or MHz if numpy.log10(freq[0])<4: rflo/=1e6 rfhi/=1e6 # set axes limits v = [0,max(time),rflo,rfhi] pylab.axis(v) if min(freq)<rflo or max(freq)>rfhi: print "WARNING: There are hits outside freq limits" # create Gregorian date from obstime start = jd2gd.caldate(start) end = jd2gd.caldate(end) dates = ['January','February','March','April','May','June','July', 'August','September','October','November','December'] start = [str(start[x]) for x in range(len(start))] end = [str(end[x]) for x in range(len(end))] # insert zeros to make formatting nice if float(start[2])<10: start[2] = '0' + start[2] if float(start[3])<10: start[3] = '0' + start[3] if float(start[4])<10: start[4] = '0' + start[4] if float(start[5])<10: start[5] = '0' + start[5] if float(end[2])<10: end[2] = '0' + end[2] if float(end[3])<10: end[3] = '0' + end[3] if float(end[4])<10: end[4] = '0' + end[4] if float(end[5])<10: end[5] = '0' + end[5] # compile date strings date1 = start[0]+' '+dates[int(start[1])-1]+' '+start[2]+' '+start[3]+':'+start[4]+':'+start[5][:2] date2 = end[0]+' '+dates[int(end[1])-1]+' '+end[2]+' '+end[3]+':'+end[4]+':'+end[5][:2] # add text to figure pylab.figtext(0.4,.96,'Spectra Count: %s' %speccount) pylab.figtext(0.4,.935,'Hit Count: %s' %hitcount) pylab.figtext(0.61,.96,'Vmin,Vmax: %s %s' % (vlim[0], vlim[1])) pylab.figtext(0.61,.935,'ALFA RFctr: %4.1f' % (rfctr/1e6)) pylab.figtext(0.8,.96,'Max Power: %s' %max(eventpower)) pylab.figtext(0.8,.935,'Min Power: %s' %min(eventpower)) pylab.figtext(0.1,.96,'Start: %s' %date1) pylab.figtext(0.1,.935,'End: %s' %date2) # save plot? if saveplot != '': pylab.savefig('%s' %saveplot) return fig