def do_test_compare_to_peaks_file(self, filebase, angles, measurement_file=None, measurement_angle=None, expect_bad=0, expect_good=0): if measurement_angle is None: measurement_angle = angles if measurement_file is None: measurement_file = filebase #@type e Experiment instrument.inst = instrument.Instrument("../instruments/TOPAZ_detectors_2010.csv") instrument.inst.goniometer = goniometer.Goniometer() self.exp = Experiment(instrument.inst) e = self.exp e.inst.d_min = 0.5 e.inst.wl_min = 0.5 e.inst.wl_max = 4.0 e.crystal.read_ISAW_ubmatrix_file(filebase + ".mat", angles=angles) e.range_automatic = True e.range_limit_to_sphere = True e.initialize_reflections() #Position coverage object with 0 sample rotation poscov = instrument.PositionCoverage( measurement_angle, None, e.crystal.u_matrix) e.inst.positions.append(poscov) pos_param = ParamPositions( {id(poscov):True} ) self.pos_param = pos_param e.recalculate_reflections(pos_param) #Now compare! (numbad, numgood, out) = e.compare_to_peaks_file(measurement_file + ".peaks") # print out, "\n\nsvi%d were bad; %d were good" % (numbad, numgood) print "%s: %d were bad; %d were good" % (filebase, numbad, numgood) assert numbad==expect_bad, "%s: expected %d bad peaks, but got %d bad peaks.\n%s" % (filebase, expect_bad, numbad, out) assert numgood==expect_good, "%s: expected %d good peaks, but got %d god peaks.\n%s" % (filebase, expect_good, numgood, out)
def test_imaka(psf_grid_raw): time_start = time.time() if psf_grid_raw is None: psf_grid_raw = prepare_test() h4rg = instrument.Instrument((6000,6000), 4.0, 10., 4.) h4rg.scale = 0.1 sources = scene.Scene(stars_x, stars_y, stars_f) psfgrid = psf.PSF_grid(psf_grid_raw) print('Making Image: {0} sec'.format(time.time() - time_start)) obs = observation.Observation(h4rg, sources, psfgrid, 4, 3.0) print('Saving Image: {0} sec'.format(time.time() - time_start)) obs.save_to_fits('tmp.fits', clobber=True) # print 'Displaying Image' # py.clf() # py.imshow(obs.img, cmap='gist_heat') # # Zoom in # py.axis([2000, 3000, 2000, 3000]) # Print out some runtime information. time_end = time.time() run_time = time_end - time_start print('Total Time: {0} seconds'.format(run_time)) print('Time Per Star: {0} seconds'.format(run_time / Nstars)) return obs
def test_get_oa(): instrObj = instrument.Instrument('HIRES', None, None, None, None) instrObj.init() oa = instrObj.get_oa('2021-01-16', 1) assert oa == 'tridenour' oa = instrObj.get_oa('2021-01-17', 1) assert oa == 'None'
def setupInstruments(self): """ Initalises a dictionary containing all instrument objects (from imported instrument class file, which can be accessed using a parsed instrument code (first three letters in full caps). """ instrument_object_list = instrument.instrument_choices inst_dict = {} for n, inst in zip(range(0, len(instrument_object_list)), instrument_object_list): print(list(instrument_object_list.keys())[n]) inst_dict[n] = instrument.Instrument(list(instrument_object_list.keys())[n]) self.instruments = inst_dict
def load_clump(tree, group=None): for ins in tree.find("meta_instrument"): subs = {} attr_list = [] for subins in ins.find("instrument"): sub = instrument.Instrument(subins.attrs, group=None, hidden=1) small_attr_list = map( string.strip, string.split(subins.attrs['attributes'], ',')) for i in small_attr_list: if i not in attr_list: attr_list.append(i) #attr_list = attr_list + small_attr_list for attr in small_attr_list: if subs.has_key(attr): subs[attr].append(sub) else: subs[attr] = [sub] i = MetaInstrument(ins.attrs, attr_list, subs, group)
def test_setup(): """Setup a small test.""" #Create the space instrument.inst = instrument.Instrument("TOPAZ_geom_all_2011.csv") experiment.exp = experiment.Experiment(instrument.inst) experiment.exp.inst.make_qspace() experiment.exp.verbose = False experiment.exp.inst.verbose = False #Angles to search chi_list = [0] phi_list = np.arange(0, 180, 90) omega_list = [0] #Simulate some positions for chi in np.deg2rad(chi_list): for phi in np.deg2rad(phi_list): for omega in np.deg2rad(omega_list): instrument.inst.simulate_position([phi, chi, omega])
def get_endpoint(self, endpoint): """ Parse /instrument/channel into specific channel handlers. """ if not endpoint.startswith('/'): return try: _, name, channel = endpoint.split('/', 3) except ValueError: return if name not in INSTRUMENTS: INSTRUMENTS[name] = instrument.Instrument(name=name) #print "NICE connection to",name,channel,INSTRUMENTS[name],INSTRUMENTS[name].channel[channel] #print INSTRUMENTS[name].channel[channel].channel_state() # There is role reversal with publisher and subscriber for the control # channel: the instrument is acting as a single subscriber for all # the web clients who are publishing commands to control it. if channel == 'control': return lambda *args, **kw: Subscriber( INSTRUMENTS[name].channel[channel], *args, **kw) elif channel in INSTRUMENTS[name].channel: return lambda *args, **kw: Publisher( INSTRUMENTS[name].channel[channel], *args, **kw)
def test_reflections_vs_volume(self): #@type e Experiment #@type instr Instrument instrument.inst = instrument.Instrument("../instruments/TOPAZ_detectors_2010.csv") instr = instrument.inst instr.set_goniometer( goniometer.Goniometer() ) instr.make_qspace() self.exp = Experiment(instr) e = self.exp instr.d_min = 1.0 instr.wl_min = 0.5 instr.wl_max = 4.0 e.crystal.read_ISAW_ubmatrix_file("data/natrolite_1223_isaw.mat", angles=[0,0,0]) e.range_automatic = True e.range_limit_to_sphere = True e.initialize_reflections() #Calculate the volume coverage of the one poscov = instr.simulate_position([0,0,0], e.crystal.get_u_matrix()) #Make a parameter for it pos_param = ParamPositions( {id(poscov):True} ) self.pos_param = pos_param #CAlculate reflections and total volume e.recalculate_reflections(pos_param) e.calculate_coverage(pos_param, None)
def initpars(self, pcf, log): """ add docstring. """ log.writelog('MARK: ' + time.ctime() + ' : New Event Started ') # Read Planet Parameters From TepFile # ccampo 5/27/2011: # origtep is a tepfile with its original units (not converted) self.origtep = tc.tepfile(pcf.tepfile[0], conv=False) tep = tc.tepfile(pcf.tepfile[0]) self.tep = tep self.ra = tep.ra.val self.dec = tep.dec.val self.rstar = tep.rs.val self.rstarerr = tep.rs.uncert self.metalstar = tep.feh.val self.metalstarerr = tep.feh.uncert self.tstar = tep.ts.val self.tstarerr = tep.ts.uncert self.logg = tep.loggstar.val self.loggerr = tep.loggstar.uncert self.rplan = tep.rp.val self.rplanerr = tep.rp.uncert self.semimaj = tep.a.val self.semimajerr = tep.a.uncert self.incl = tep.i.val self.inclerr = tep.i.uncert self.ephtime = tep.ttrans.val self.ephtimeerr = tep.ttrans.uncert self.period = tep.period.val / 86400.0 # conv to days self.perioderr = tep.period.uncert / 86400.0 # ditto self.transdur = tep.transdur.val self.transdurerr = tep.transdur.uncert self.arat = (self.rplan / self.rstar)**2 self.araterr = 2 * (self.arat) * np.sqrt( (self.rplanerr / self.rplan)**2 + (self.rstarerr / self.rstar)**2) # position corrections: if pcf.ra[0] is not None: self.ra = s2d.sexa2dec(pcf.ra[0]) / 12.0 * np.pi if pcf.dec[0] is not None: self.dec = s2d.sexa2dec(pcf.dec[0]) / 180.0 * np.pi # Convert units to uJy/pix self.fluxunits = pcf.fluxunits[0] # Initialize control file parameters self.planetname = pcf.planetname if np.size(self.planetname) > 1: self.planetname = ' '.join(self.planetname) else: self.planetname = self.planetname[0] self.planet = pcf.planet[0] self.ecltype = pcf.ecltype[0] self.photchan = pcf.photchan[0] if self.photchan < 5: self.instrument = 'irac' elif self.photchan == 5: self.instrument = 'irs' else: self.instrument = 'mips' # Instrument contains the instrument parameters # FINDME: inherit Instrument instead of adding as a parameter ? self.inst = inst.Instrument(self.photchan) self.visit = pcf.visit[0] self.sscver = pcf.sscver[0] # Directories self.topdir = pcf.topdir[0] self.datadir = pcf.datadir[0] self.dpref = (self.topdir + '/' + self.datadir + '/' + self.sscver + '/r') # aors self.aorname = np.array(pcf.aorname, dtype=np.str_) # get aorname as string self.aortype = np.array(pcf.aortype) # Number of aors per event self.naor = np.size(self.aorname[np.where(self.aortype == 0)]) # Number of position and noddings self.npos = pcf.npos[0] self.nnod = pcf.nnod[0] # Run next steps: self.runp2 = pcf.runp2[0] self.runp3 = pcf.runp3[0] # Ancil files self.hordir = pcf.hordir[0] self.leapdir = pcf.leapdir[0] self.kuruczdir = pcf.kuruczdir[0] self.filtdir = pcf.filtdir[0] self.psfdir = pcf.psfdir[0] pmaskfile = pcf.pmaskfile[0] self.pmaskfile = [ self.dpref + str(aorname) + self.inst.caldir + pmaskfile for aorname in self.aorname[np.where(self.aortype == 0)] ] self.horvecfile = self.topdir + self.hordir + pcf.horfile[0] self.kuruczfile = self.topdir + self.kuruczdir + pcf.kuruczfile[0] filt = pcf.filtfile if self.photchan < 5: filt = re.sub('CHAN', str(self.photchan), filt[0]) elif self.photchan == 5: filt = filt[1] else: # self.photchan == 5: filt = filt[2] self.filtfile = self.topdir + self.filtdir + filt # Default PSF file: if self.photchan < 5 and pcf.psffile[0] == "default": self.psffile = (self.topdir + self.psfdir + 'IRAC PSF/' + 'IRAC.%i.PRF.5X.070312.fits' % self.photchan) # User specified PSF file: else: self.psffile = self.topdir + self.psfdir + pcf.psffile[0] # Bad pixels: # Chunk size self.szchunk = pcf.szchunk[0] # Sigma rejection threshold self.sigma = pcf.sigma # User rejected pixels self.userrej = pcf.userrej if self.userrej[0] is not None: self.userrej = self.userrej.reshape(np.size(self.userrej) / 2, 2) else: self.userrej = None # set event directory self.eventdir = os.getcwd() # Denoise: self.denoised = False # Has the data been denoised?
def initpars(self, pcf): """ add docstring. """ log.writelog('MARK: ' + time.ctime() + ' : New Event Started ') # Read Planet Parameters From TepFile # ccampo 5/27/2011: # origtep is a tepfile with it's original units (not converted) self.origtep = tc.tepfile(pcf.tepfile.value[0], conv=False) tep = tc.tepfile(pcf.tepfile.value[0]) self.tep = tep self.ra = tep.ra.val self.dec = tep.dec.val self.rstar = tep.rs.val self.rstarerr = tep.rs.uncert self.metalstar = tep.feh.val self.metalstarerr = tep.feh.uncert self.tstar = tep.ts.val self.tstarerr = tep.ts.uncert self.logg = tep.loggstar.val self.loggerr = tep.loggstar.uncert self.rplan = tep.rp.val self.rplanerr = tep.rp.uncert self.semimaj = tep.a.val self.semimajerr = tep.a.uncert self.incl = tep.i.val self.inclerr = tep.i.uncert self.ephtime = tep.ttrans.val self.ephtimeerr = tep.ttrans.uncert self.period = tep.period.val / 86400.0 # conv to days self.perioderr = tep.period.uncert / 86400.0 # ditto self.transdur = tep.transdur.val self.transdurerr = tep.transdur.uncert # original code - tep conversions """ self.tep = tc.tepfile(pcf.tepfile.value[0]) self.ra = s2d.sexa2dec(tep.ra.val) / 12.0 * np.pi self.dec = s2d.sexa2dec(tep.dec.val) / 180.0 * np.pi self.rstar = tep.rs.val * self.rsun self.rstarerr = tep.rs.uncert * self.rsun self.metalstar = tep.feh.val self.metalstarerr = tep.feh.uncert self.tstar = tep.ts.val self.tstarerr = tep.ts.uncert self.logg = tep.loggstar.val self.loggerr = tep.loggstar.uncert self.rplan = tep.rp.val * self.rjup self.rplanerr = tep.rp.uncert * self.rjup self.semimaj = tep.a.val * self.au self.semimajerr = tep.a.uncert * self.au self.incl = tep.i.val * np.pi / 180.0 self.inclerr = tep.i.uncert * np.pi / 180.0 self.ephtime = tep.ttrans.val self.ephtimeerr = tep.ttrans.uncert self.period = tep.period.val self.perioderr = tep.period.uncert self.transdur = tep.transdur.val * 86400.0 self.transdurerr = tep.transdur.uncert * 86400.0 """ self.arat = (self.rplan / self.rstar)**2 self.araterr = 2 * (self.arat) * np.sqrt( (self.rplanerr / self.rplan)**2 + (self.rstarerr / self.rstar)**2) # position corrections: if pcf.ra.get(0) != None: self.ra = s2d.sexa2dec(pcf.ra.value[0]) / 12.0 * np.pi if pcf.dec.get(0) != None: self.dec = s2d.sexa2dec(pcf.dec.value[0]) / 180.0 * np.pi # Convert units to uJy/pix self.fluxunits = pcf.fluxunits.get(0) #FINDME: are we using converted?? #self.converted = pcf.getvalue(False) # are units uJy/pix ? # Initialize control file parameters self.planetname = pcf.planetname.getarr() if np.size(self.planetname) > 1: self.planetname = '-'.join(self.planetname) else: self.planetname = self.planetname[0] self.planet = pcf.planet.get(0) self.ecltype = pcf.ecltype.get(0) self.photchan = pcf.photchan.get(0) if self.photchan < 5: self.instrument = 'irac' elif self.photchan == 5: self.instrument = 'irs' else: self.instrument = 'mips' # Instrument contains the instrument parameters # FINDME: inherit Instrument instead of adding as a parameter ? self.inst = inst.Instrument(self.photchan) self.visit = pcf.visit.get(0) self.sscver = pcf.sscver.get(0) # FINDME: fix obsdate # FINDME2: hey, we are not using lcfile! self.lcfile = (self.planetname + '_' + self.ecltype + '_OBSDATE_Spitzer_' + self.inst.name + '_' + '%.1f_microns.fits' % (self.inst.spitzwavl * 1e6)) # Directories self.topdir = pcf.topdir.get(0) self.datadir = pcf.datadir.get(0) self.dpref = (self.topdir + '/' + self.datadir + '/' + self.sscver + '/r') # aors self.aorname = pcf.aorname.value # get aorname as string self.aortype = pcf.aortype.getarr() # Number of aors per event self.naor = np.size(self.aorname[np.where(self.aortype == 0)]) # Number of position and noddings self.npos = pcf.npos.get(0) self.nnod = pcf.nnod.get(0) # Variables added for calibration AORs # self.calnmcyc = pcf.getvalue('calnmcyc') # Ancil files self.hordir = pcf.hordir.get(0) self.kuruczdir = pcf.kuruczdir.get(0) self.filtdir = pcf.filtdir.get(0) self.psfdir = pcf.psfdir.get(0) self.leapdir = pcf.leapdir.get(0) self.pmaskfile = np.zeros(self.naor, '|S150') for i in np.arange(self.naor): self.pmaskfile[i] = (self.dpref + self.aorname[i] + self.inst.caldir + pcf.pmaskfile.get(0)) self.horvecfile = self.topdir + self.hordir + pcf.horfile.get(0) self.kuruczfile = self.topdir + self.kuruczdir + pcf.kuruczfile.get(0) filt = pcf.filtfile.getarr() if self.photchan < 5: filt = re.sub('CHAN', str(self.photchan), filt[0]) elif self.photchan == 5: filt = filt[1] else: # self.photchan == 5: filt = filt[2] self.filtfile = self.topdir + self.filtdir + filt # Default PSF file: if self.photchan < 5 and pcf.psffile.get(0) == "default": self.psffile = (self.topdir + self.psfdir + 'IRAC PSF/' + 'IRAC.%i.PRF.5X.070312.fits' % self.photchan) # User specified PSF file: else: self.psffile = pcf.psffile.get(0) # Bad pixels: # Chunk size self.szchunk = pcf.szchunk.get(0) # Sigma rejection threshold self.sigma = pcf.sigma.getarr() # User rejected pixels self.userrej = pcf.userrej.getarr() if self.userrej[0] != None: self.userrej = self.userrej.reshape(np.size(self.userrej) / 2, 2) else: self.userrej = None # set event directory self.eventdir = os.getcwd()
print(count) print(pygame.midi.get_device_info(device)) count += 1 o_port = pygame.midi.get_default_output_id() i_port = 3 print("default output_id :%s:" % o_port) print("using output_id :%s:" % TIMIDITYPORT) print("using input_id :%s:" % i_port) return (pygame.midi.Input(i_port, 1000), pygame.midi.Output(TIMIDITYPORT)) # open a specific midi device inp, midi_out = setup_midi() instrument = instrument.Instrument(midi_out) midi_out.set_instrument(0) midi_out.set_instrument(0, 1) midi_out.note_on(72, 127) midi_out.note_off(72, 127) print("sleeping...") time.sleep(5) if inp.poll(): #[[[144, 79, 75, 0], 4340]] midi_data = inp.read(1000) print(midi_data) data = False
def guessp1size(poetpcf): """From and event pcf, guesses how much memory running p1 will take.""" # the size of a p1 object is roughly 4.047 (rounding to 4.1) times # the size of one of its four arrays (data, uncertainty, bdmask, # and brmask). To guess the size of an event generated in p1, we # need to find the size of one of these arrays which at the time # of this writing, follows the formula: # # arrsize = 80 + 16*dim + 8*#ofvals [bytes] (assuming 64 bit values) # # Changes to this formula in future versions should be # insignificant (unless 128 or higher bit values are # used). Additionally, running python and importing everything # uses about 116 MB (res) of RAM. I round this up to 200 MB for # safesies and because more memory will be used to make other # things. Hence the final equation I will use is: # # size = 4.1 * (arrsize / 1024**2) + 200 # get values from pcf pcf, = rd.read_pcf(poetpcf.rundir + '/' + poetpcf.eventname + '.pcf', "event", expand=False) npos = pcf.npos[0] nnod = pcf.nnod[0] aornames = np.array(pcf.aorname) aortypes = np.array(pcf.aortype) # find dimensions of array which are ny, nx, npos, maxnimpos instru = inst.Instrument(pcf.photchan[0]) naor = np.size(aornames[np.where(aortypes == 0)]) nexpid = np.empty(naor, np.long) for i, aorname in enumerate(aornames[:naor]): bcddir = '/'.join([ pcf.topdir[0], pcf.datadir[0], pcf.sscver[0], 'r' + str(aorname), instru.bcddir ]) files = sorted( [f for f in os.listdir(bcddir) if f.endswith(instru.bcdsuf)]) first, last = files[0], files[-1] fexpid = first.split('_')[-4] expid, dcenum = last.split('_')[-4:-2] nexpid[i] = int(expid) - int(fexpid) + 1 ndcenum = int(dcenum) + 1 header = fits.getheader(bcddir + '/' + first) # number of dimension is hard coded to be 4 in # pdataread.poet_dataread() and throughout the code dim = 4 if header['NAXIS'] >= 3: nz = header['NAXIS1'] ny = header['NAXIS2'] nx = header['NAXIS3'] else: nz = 1 ny = header['NAXIS1'] nx = header['NAXIS2'] # equations taken from p1event if instru.name == 'mips': maxnimpos = int((np.sum(nexpid) / nnod) * (((ndcenum - 1) / 7) + 1)) else: maxnimpos = int(np.sum(nexpid) * ndcenum * nz / nnod) # in bytes arrsize = 80 + 16 * dim + 8 * (nx * ny * npos * maxnimpos) # in MB return 4.1 * (arrsize / 1024**2) + 200
exp.verbose = True return (ga, aborted, converged) def print_pop(ga_engine, *args): return for x in ga_engine.getPopulation(): print "score %7.3f; coverage %7.3f, %s" % (x.score, x.coverage, x.genomeList) if __name__ == "__main__": #Inits instrument.inst = instrument.Instrument( "../instruments/TOPAZ_geom_all_2011.csv") instrument.inst.set_goniometer(goniometer.TopazInHouseGoniometer()) # Create a default position of 0,0,0 instrument.inst.positions = [ PositionCoverage([0.0, 0.0, 0.0], None, np.identity(3)), PositionCoverage([1.0, 0.0, 0.0], None, np.identity(3)) ] experiment.exp = experiment.Experiment(instrument.inst) exp = experiment.exp exp.initialize_reflections() exp.verbose = False # Go through a bunch of cases for use_multiprocessing in [True, False]: