def makelogic(logic, startdate, enddate): #set up the logic for different dates date_logic='' if startdate: d,m,y=salttime.breakdate(startdate) y=str(y) m=string.zfill(m, 2) d=string.zfill(d, 2) date_logic += "UTStart > '%s-%s-%s 12:00:01'" % (y,m,d) if startdate and enddate: date_logic += " and " if enddate: edate=salttime.getnextdate(enddate) d,m,y=salttime.breakdate(str(edate)) y=str(y) m=string.zfill(m, 2) d=string.zfill(d, 2) date_logic += "UTStart < '%s-%s-%s 11:59:59'" % (y,m,d) if logic and date_logic: logic = '('+logic+')' + ' and ' + date_logic else: logic return logic
def dataquality(obsdate, sdb, instrume, clobber=True, logfile=None, verbose=True): """Run the data quality measurement for each instrument """ if instrume=='rss': instrumetable='FitsHeaderRss' elif instrume=='scam': instrumetable='FitsHeaderSalticam' #Look for any biases from the night sel_cmd='FileName' tab_cmd='FileData join FitsHeaderImage using (FileData_Id) join %s using (FileData_Id)' % instrumetable logic_cmd=makelogic("CCDTYPE='BIAS'", obsdate, getnextdate(obsdate)) record=saltmysql.select(sdb, sel_cmd, tab_cmd, logic_cmd) print record #Look for any flatfields from the night sel_cmd='FileName' tab_cmd='FileData join FitsHeaderImage using (FileData_Id) join %s using (FileData_Id)' % instrumetable logic_cmd=makelogic("CCDTYPE='FLAT'", obsdate, getnextdate(obsdate)) record=saltmysql.select(sdb, sel_cmd, tab_cmd, logic_cmd) print record #Look for any Cal_SPST stars sel_cmd='FileName' tab_cmd='FileData join ProposalCode using (ProposalCode_Id) join FitsHeaderImage using (FileData_Id) join %s using (FileData_Id)' % instrumetable logic_cmd=makelogic("CCDTYPE='OBJECT' and Proposal_Code='CAL_SPST'", obsdate, getnextdate(obsdate)) record=saltmysql.select(sdb, sel_cmd, tab_cmd, logic_cmd) print record #reduce each of the spectrophotometric standards if len(record): for infile in record: profile='/salt/data/%s/%s/%s/product/mbxgp%s' % (obsdate[0:4], obsdate[4:8], instrume, infile[0]) reducespst(profile, obsdate, clobber=clobber, logfile=logfile, verbose=verbose)
def saltslewstats(startdate, enddate, elshost, elsname, elsuser, elspass, sdbhost,sdbname,sdbuser, password, clobber,logfile,verbose): # set up proposers = [] propids = [] pids = [] with logging(logfile,debug) as log: #open the database els=saltmysql.connectdb(elshost, elsname, elsuser, elspass) sdb=saltmysql.connectdb(sdbhost,sdbname,sdbuser, password) #loop through each night and determine the statistics for the slew times #for each night obsdate=int(startdate) slew_list=[] while obsdate < int(enddate): night_id=saltmysql.getnightinfoid(sdb, obsdate) start,end=saltmysql.select(sdb,'EveningTwilightEnd,MorningTwilightStart','NightInfo', 'NightInfo_Id=%i' % night_id)[0] tslew, nslew=slewtime(els, start, end) if nslew>0: print obsdate, night_id, start, end, nslew, tslew/nslew slew_list.append([start, nslew, tslew]) obsdate=int(getnextdate(obsdate)) slew_arr=np.array(slew_list) days=np.zeros(len(slew_arr)) for i in range(len(slew_arr)): days[i]=(slew_arr[i,0]-slew_arr[0,0]).days coef=np.polyfit(days, slew_arr[:,2]/slew_arr[:,1], 2) ave_date=[] ave_values=[] ave_nslews=[] nstep=10 for i in np.arange(15,len(slew_arr), 2*nstep): ave_date.append(slew_arr[i,0]) i1=i-nstep i2=min(i+nstep, len(slew_arr)) #ave_values.append(np.median(slew_arr[i1:i2,2]/slew_arr[i1:i2,1])) ave_nslews.append(np.median(slew_arr[i1:i2,1])) ave_values.append(np.median(slew_arr[i1:i2,2])) print ave_date[-1], ave_values[-1], ave_nslews[-1] ave_values=np.array(ave_values) ave_nslews=np.array(ave_nslews) mean_slew=ave_nslews.mean() mean_slew=11 for i in range(len(ave_date)): #value is an attempt to correct for the average number of slews value=(ave_values[i]+30*(mean_slew-ave_nslews[i]))/mean_slew print ave_date[i], '%i %i %i' % (ave_values[i]/ave_nslews[i], ave_nslews[i], value) plt.figure() plt.plot(slew_arr[:,0], slew_arr[:,2]/slew_arr[:,1], ls='', marker='o') #plt.plot(slew_arr[:,0], slew_arr[:,1], ls='', marker='o') #plt.plot(slew_arr[:,0], slew_arr[:,2], ls='', marker='o') plt.plot(ave_date, ave_values/ave_nslews) #plt.plot(days, np.polyval(coef, days)) plt.ylabel('Slew Time(s)') plt.xlabel('Date') plt.show()