def Geodesic_script(): # setup the initial conditions geo = Geodesic() # assume initially a vertical launch from 5 degrees latitude radiusE = geo.oblateRadius(5) * 1000 # launch vehicle lv = LaunchVehicle() # standard atmosphere (1976) data atm = Atmosphere() [altList, tempList, pressureList, densityList, asoundList] = atm.stdAtm() Area = pow(lv.Rcross,2)*pi k = 9.81*pow(geo.a * 1000,2) # flight path angle (deg) fp = pi/2 # velocity magnitude /speed (m/s) vc = 0 # altitude above geodesic (m) alt = 0 nu = 0 # speed of sound (m/s) a = np.interp(alt,altList,asoundList) # atmospheric density (kg/m^3) rho = np.interp(alt,altList,densityList) r = radiusE + alt r2 = pow(r,2) g = k/r2 m = 2300000 T = 34020000 Isp = 400 theta = 0 Mach = vc/a D = 0.5 * lv.getCd(Mach) * Area * rho * pow(vc,2) params = (k, radiusE, altList, asoundList, densityList, Area, lv, Isp, T, theta) x0 = [r,m,nu,fp,vc] return x0, params
def fuelBurn(cruiseModel, weight, altitude, airSpeed): #(cruiseModel:CruiseModel) (weight:float<Pounds>) (altitude:float<Feet>) (airSpeed:float<Knots>) = #match cruiseModel with #CruiseModel(model) -> w = weight / 10000.0 a = altitude / 10000.0 s = airSpeed / 100.0 model = cruiseModel m = airSpeed/Atmosphere.speedOfSound(altitude) singles = model[0] + model[1]*a + model[2]*s + model[3]*w + model[4]*m squares = model[5]*w*w + model[6]*a*a + model[7]*s*s + model[8]*m*m pairs1 = model[9]*a*s + model[10]*a*w + model[11]*a*m pairs2 = model[12]*s*w + model[13]*s*m + model[14]*w*m sqrts1 = model[15]* math.sqrt(w) + model[16]* math.sqrt(a) + \ model[17]* math.sqrt(s) + model[18]* math.sqrt(m) triples = model[19]*a*s*w + model[20]*a*s*m + model[21]*a*w*m + model[22]*s*w*m linearCombination =singles+squares+pairs1+pairs2+sqrts1+triples result = math.exp(linearCombination) return result #result*1.0<FuelPounds/Hours>
def fuelBurn(cruiseModel, weight, altitude, airSpeed): #(cruiseModel:CruiseModel) (weight:float<Pounds>) (altitude:float<Feet>) (airSpeed:float<Knots>) = #match cruiseModel with #CruiseModel(model) -> w = weight / 10000.0 a = altitude / 10000.0 s = airSpeed / 100.0 model = cruiseModel m = airSpeed / Atmosphere.speedOfSound(altitude) singles = model[ 0] + model[1] * a + model[2] * s + model[3] * w + model[4] * m squares = model[5] * w * w + model[6] * a * a + model[7] * s * s + model[ 8] * m * m pairs1 = model[9] * a * s + model[10] * a * w + model[11] * a * m pairs2 = model[12] * s * w + model[13] * s * m + model[14] * w * m sqrts1 = model[15]* math.sqrt(w) + model[16]* math.sqrt(a) + \ model[17]* math.sqrt(s) + model[18]* math.sqrt(m) triples = model[19] * a * s * w + model[20] * a * s * m + model[ 21] * a * w * m + model[22] * s * w * m linearCombination = singles + squares + pairs1 + pairs2 + sqrts1 + triples result = math.exp(linearCombination) return result #result*1.0<FuelPounds/Hours>
def _setup_cb(handler, new_addr): global _sock_list if not new_addr: _err_msg(SSRPC_ERR.CONNECT_FAILED, "try connect to %s failed" % handler._to_server_id) return new_sock = _zmq_context.socket(zmq.DEALER) new_sock.connect(new_addr) _zmq_poll.register(new_sock, zmq.POLLIN) if not (_mode & MAIN_THREAD_SOCKET) and (not _socket_thread.is_alive()): _socket_thread.start() _sock_list[new_sock] = handler # print(handler) handler.set_zmq_socket(new_sock) handler.on_init_finish(True) print("create", "server" if handler.is_server else "client", "done ->", new_addr) if not handler.is_server: try: import Atmosphere Atmosphere.EventParasiteConnected() except Exception as e: print(e)
# Averaging Channels to improve signal to noise: if Parameters.getboolean('Averaging', 'average'): stride = Parameters.getint('Averaging','stride') badChans = json.loads(Parameters.get('Averaging','badChannels')) dnu = 2./tod.shape[2] nu = np.arange(tod.shape[2])*dnu + dnu/2. print(nu, dnu) tod, anu = Filters.AverageFreqs(tod, nu, stride, badChans) dataout['nu'] = anu # Next make atmospheric corrections if Parameters.getboolean('Atmosphere', 'remove'): stride = Parameters.getint('Atmosphere','stride') A = Atmosphere.SimpleRemoval(tod, el, stride) dataout['atmos']= A if Parameters.getboolean('Filters','median'): stride = Parameters.getint('Filters','stride') Filters.MedianFilter(tod, stride) # Fit for the Source in TOD if Parameters.getboolean('Fitting', 'fit'): print('FITTING JUPITER IN TOD') if Parameters.getboolean('Inputs', 'mergeDatafiles'): Pout, errors, crossings = FitSource.FitTOD(tod, ra, dec, obs, r0, d0, prefix, destripe=True) else: Pout, errors, crossings = FitSource.FitTOD(tod, ra, dec, obs, r0, d0, prefix, destripe=False)
Usage: wfs = WideFieldSHWFS(0, 16, 128, at, tel) SHWFSDemonstrator.eval_metascreen(wfs) """ all_dmaps = wfs.ImgSimulator.all_dmap() # Display process fig1 = plt.figure(1) plt.subplot(1, 2, 1) plt.imshow(wfs._get_metascreen(wfs.atmos.scrns[0])) for j in range(wfs.num_lenslet): for i in range(wfs.num_lenslet): plt.subplot(wfs.num_lenslet, 2 * wfs.num_lenslet, j * 2 * wfs.num_lenslet + i + 1 + wfs.num_lenslet) plt.axis('off') plt.imshow(all_dmaps[j, i][0]) plt.show() if __name__ == '__main__': tel = Telescope(2.5) at = Atmosphere() at.create_default_screen(0, 0.15) wfs = WideFieldSHWFS(0, 16, 128, at, tel) c_lenslet_pos = (0.2,0.5) dimg = wfs.ImgSimulator.dimg(c_lenslet_pos) SHWFSDemonstrator.display_dimg(dimg)
def go(source_ab=None, leff_ang=5000, R=5, fwhm_as=2, phase=0, t_s=1, Atel_cm2=100, n_pix=9, RN=5, eta=.2, coadds=1, sky_level=1.0): '''Calculates the signal to noise of a source with source_ab Args: source_ab: Source magnitude in AB leff_ang: Central wavelength in Angstrom R: Spectral resolution of an element fwhm_as: Extraction FWHM in as phase: Moon phase t_s: Exposure time in second Atel_cm2: Telescope area in cm2 n_pix: Number of pixels that participate RN: The read noise in electron eta: The efficiency of the instrument coadds: The number of coadds [1] Returns: {All Arg parameters and 'epp': Energy per photon in erg 'dlambda': The full with of the band 's_npp': The number of photons receive from the object 'sky_area': The area of extraction' 'k_npp': The number of sky photons received in the extraction area 'k_npp_pix': The number of sky photons received in a pixel 'k_npp_as2': The number of sky photons received per as2 'noise_obj': The noise from the object [e-] 'noise_sky': The noise from the sky [e-] 'noise_read': Total read noise 'noise': Total number of noise photons 'snr': The delivered signal to noise 'sky_level': Multiply sky level by this value ''' results = { 'AB': source_ab, 'leff': leff_ang, 'R': R, 'fwhm_as': fwhm_as, 'phase': phase, 't': t_s, 'Atel': Atel_cm2, 'n_pix': n_pix, 'RN': RN, 'eta': eta, 'coadds': coadds, 'sky_level': sky_level } hc = 1.98644521e-8 # erg angstrom epp = hc / leff_ang results['epp'] = epp dlambda = leff_ang / R results['dlambda'] = dlambda t_eff = t_s * coadds results['t_eff'] = t_eff s_flam = abmag_to_flambda(source_ab, leff_ang) # erg/s/cm2/ang s_npp = s_flam / epp * t_eff * Atel_cm2 * dlambda * eta results['s_npp'] = s_npp skyfun = AA.sky_function(phase) sky_area = np.pi * (fwhm_as / 2.0)**2 results['sky_area'] = sky_area k_flam = skyfun(leff_ang) # photon/s/cm2/ang/as2 k_npp = k_flam * t_eff * Atel_cm2 * dlambda * sky_area * eta * sky_level results['k_npp'] = k_npp results['k_npp_pix'] = k_npp / n_pix results['k_npp_pas2'] = k_npp / sky_area results['noise_obj'] = np.sqrt(s_npp) results['noise_sky'] = np.sqrt(k_npp) results['noise_read'] = np.sqrt(RN**2 * n_pix * coadds) results['noise'] = np.sqrt(results['noise_obj']**2 + results['noise_sky']**2 + results['noise_read']**2) results['snr'] = s_npp / results['noise'] results['rtel'] = np.sqrt(Atel_cm2 / np.pi) results['l0'] = leff_ang - dlambda / 2 results['l1'] = leff_ang + dlambda / 2 print(" Signal Noise") print( " Time Mag SNR Star Sky/as2 Star Sky Read R [cm] Waverange as2" ) print( "{t_eff:6.1f} {AB:6.2f} {snr:5.1f} {s_npp:7.1f} {k_npp_pas2:7.1f} {noise_obj:7.1f} {noise_sky:7.1f} {noise_read:7.1f} {rtel:7.1f} {l0:.0f}-{l1:.0f} {sky_area:4.1f}" .format(**results)) return results
def regulartorySpeedLimit(altitude): if altitude < 10000.0: return 250 else: return Atmosphere.speedOfSound(altitude)
def limitAirSpeed(maximumMachSpeed, weight, altitude, airSpeed): return min(airSpeed, regulartorySpeedLimit(altitude), Atmosphere.speedOfSound(altitude) * maximumMachSpeed)
def go( source_ab=None, leff_ang=5000, R=5, fwhm_as=2, phase=0, t_s=1, Atel_cm2=100, n_pix=9, RN=5, eta=.2, coadds=1, sky_level=1.0): '''Calculates the signal to noise of a source with source_ab Args: source_ab: Source magnitude in AB leff_ang: Central wavelength in Angstrom R: Spectral resolution of an element fwhm_as: Extraction FWHM in as phase: Moon phase t_s: Exposure time in second Atel_cm2: Telescope area in cm2 n_pix: Number of pixels that participate RN: The read noise in electron eta: The efficiency of the instrument coadds: The number of coadds [1] Returns: {All Arg parameters and 'epp': Energy per photon in erg 'dlambda': The full with of the band 's_npp': The number of photons receive from the object 'sky_area': The area of extraction' 'k_npp': The number of sky photons received in the extraction area 'k_npp_pix': The number of sky photons received in a pixel 'k_npp_as2': The number of sky photons received per as2 'noise_obj': The noise from the object [e-] 'noise_sky': The noise from the sky [e-] 'noise_read': Total read noise 'noise': Total number of noise photons 'snr': The delivered signal to noise 'sky_level': Multiply sky level by this value ''' results={'AB': source_ab, 'leff': leff_ang, 'R': R, 'fwhm_as': fwhm_as, 'phase': phase, 't': t_s, 'Atel': Atel_cm2, 'n_pix': n_pix, 'RN': RN, 'eta': eta, 'coadds': coadds, 'sky_level': sky_level} hc = 1.98644521e-8 # erg angstrom epp = hc/leff_ang results['epp'] = epp dlambda = leff_ang/R results['dlambda'] = dlambda t_eff = t_s * coadds results['t_eff'] = t_eff s_flam = abmag_to_flambda(source_ab, leff_ang) # erg/s/cm2/ang s_npp = s_flam/epp * t_eff * Atel_cm2 * dlambda * eta results['s_npp'] = s_npp skyfun = AA.sky_function(phase) sky_area = np.pi*(fwhm_as/2.0)**2 results['sky_area'] = sky_area k_flam = skyfun(leff_ang) # photon/s/cm2/ang/as2 k_npp = k_flam * t_eff * Atel_cm2 * dlambda * sky_area * eta * sky_level results['k_npp'] = k_npp results['k_npp_pix'] = k_npp/n_pix results['k_npp_pas2'] = k_npp/sky_area results['noise_obj'] = np.sqrt(s_npp) results['noise_sky'] = np.sqrt(k_npp) results['noise_read'] = np.sqrt(RN**2*n_pix*coadds) results['noise'] = np.sqrt(results['noise_obj']**2 + results['noise_sky']**2 + results['noise_read']**2) results['snr'] = s_npp/results['noise'] results['rtel'] = np.sqrt(Atel_cm2/np.pi) results['l0'] = leff_ang-dlambda/2 results['l1'] = leff_ang+dlambda/2 print(" Signal Noise") print(" Time Mag SNR Star Sky/as2 Star Sky Read R [cm] Waverange as2") print("{t_eff:6.1f} {AB:6.2f} {snr:5.1f} {s_npp:7.1f} {k_npp_pas2:7.1f} {noise_obj:7.1f} {noise_sky:7.1f} {noise_read:7.1f} {rtel:7.1f} {l0:.0f}-{l1:.0f} {sky_area:4.1f}".format(**results)) return results
def atm_transmission(self, airmass): return Atmosphere.atm_transmission(airmass, altitude=self.elevation)
for k in range(4): init_hgt_spd[k] = instruction[k][0][2] / ALT_SCALE # height init_hgt_spd[k + 7] = instruction[k][1] / SPD_SCALE # air-speed for k in range(4,7): init_hgt_spd[k] = instruction[n_ins + k - 7][0][2] / ALT_SCALE # height init_hgt_spd[k + 7] = instruction[n_ins + k - 7][1] / SPD_SCALE # air-speed args=(fullCoreFunctions, simulationParameters, airportEnvironment, airspace, costParameters, weather, flightState, flightParams, instruction) # this bounds should depend on the weight of plane, which needs to be calculated. weight = WeightModel.grossWeight(flightParams, flightState) max_altitude = AirSpeedLimiter.calculateMaximumAltitude(weight) max_speed = Atmosphere.speedOfSound(max_altitude) * flightParams.AircraftType.MaximumMachSpeed bnds = [(0.2, max_altitude / ALT_SCALE)] * min(n_ins,7) bnds.extend([(150.0/SPD_SCALE, max_speed / SPD_SCALE)]* min(n_ins, 7)) res2 = minimize(J, init_hgt_spd, args=args, tol = 0.05, method = 'SLSQP', bounds=bnds ) print "number of iters", res2['nit'] # construct the optimized instruction new_hgt_spd = bulk_hgt_spd(res2['x'], len(instruction)) instruction_opt = update_instr(new_hgt_spd, instruction) writeInstr(output_file, instruction_opt, raw_instr)
def __init__ ( self, modname, mapname, is_server=False, graphics_enabled=True ): """Initialize the world from the given map""" self.modname = modname self.mapname = mapname self.playerEnt = None self.isServer = is_server self.graphicsEnabled = graphics_enabled self.idCounter = 0 self.ninjasKilled = 0 self.piratesKilled = 0 self.treasuresTaken = 0 self.deathBlotches = [] path = Mod.MapPath( modname, mapname) hmap = path+"heightmap.bin" projectdesc = ProjectDesc ( modname, mapname ) self.projectDesc = projectdesc self.seaLevel = float(projectdesc.SeaLevel) self.solver = Physics.Solver() self.solver.setMinimumFramerate(10) #create materials self.materialMap = Materials.DefaultMaterialMap(self.solver) #setup atmosphere self.atmosphere = Atmosphere.Atmosphere(projectdesc) self._extractShadowMap() self.terrainMaterial = TerrainMaterial.TerrainMaterial( modname, mapname ) self.terrain = Terrain.TerrainPatch( None, self, Heightmap.fromFile(hmap), self.terrainMaterial, projectdesc.Spacing ) #if self.graphicsEnabled: # self.terrain.initGraphics() self.ocean = Ocean.Ocean(float(projectdesc.SeaLevel), projectdesc.WaterTexture, self.terrain.getextent() ) mx = self.terrain.getextent() / 2 mz = self.terrain.getextent() / 2 my = self.terrain.getWorldHeightValue( mx, mz ) + 2.0 #Set the world size (Newton will disable anything that's not #within the world box extent = float(self.terrain.getextent()) self.solver.setWorldSize( (-extent, -2000.0, -extent ), (extent, 2000.0, extent) ) #Create scene. This should load all the entities as well self.scene = SceneManager.SceneManager(self, modname, mapname) #set camera if not self.graphicsEnabled: self.playerEnt = None self.camera = None else: if self.playerEnt == None or Settings.RunPhysics == False: self.camera = Camera.Freecam() self.camera.position = vec3( mx, my, mz) self.camera.yaw = 0 self.camera.pitch = 0 else: self.camera = Camera.AttachableCamera( self.playerEnt ) self.frustrum_camera = self.camera.asFreecam() print "World loaded"