def create_image(self): print(">> creating planet values") my_planet = planet.random_planet() print("++ planet", my_planet) print(">> creating scene") my_scene = planet.scene() print("++ scene", my_scene) print(">> generating name") name = planet.planet_to_hex(my_planet) print(">> creating planet image") planet.planet(my_planet, my_scene, name) print("++ planet", name, "created") return name + ".png"
def create_image(): print(">> creating planet values") my_planet = planet.hex_to_planet(secrets.token_hex(7)) print("++ planet", my_planet) print(">> creating scene") my_scene = ((1500, 500), 235, 0.2784557339318898) print("++ scene", my_scene) print(">> generating name") name = planet.planet_to_hex(my_planet) print(">> creating planet image") planet.planet(my_planet, my_scene, name) print("++ planet", name, "created") return name + ".png"
def editImageB(self, bmod, Tmod): import planet nedit = 0 p = planet.planet('functions') bdata = p.bRequest(self.header['b'][0], block=[1, 1]) if len(bdata) != np.size(self.data): print( 'b-values (%d) do not number the same as the image size (%d)' % (len(bdata), np.size(self.data))) return 0 if len(bmod) == 3: # assume center and radius print('Circle edit') pixel_modlist = [] for i in range(len(bdata)): if math.sqrt(bdata[i][0]**2 + bdata[i][1]**2) > 0.95: continue # this is off the disk (assumed circular...) elif math.sqrt((bdata[i][0] - bmod[0])**2 + (bdata[i][1] - bmod[1])**2) < bmod[2]: row = int(float(i) // float(len(self.data))) col = i - row * len(self.data) pixel_modlist.append([row, col]) nedit += 1 elif len(bmod) == 4: # assume square print('Square') else: # assume list print('list') if type(Tmod) == float: tmp = Tmod Tmod = [] for b in bmod: Tmod.append(tmp) for px in pixel_modlist: self.data[px[0], px[1]] = Tmod return nedit
def editImageB(self, bmod, Tmod): import planet nedit = 0 p = planet.planet('functions') bdata = p.bRequest(self.header['b'][0],block=[1,1]) if len(bdata) != np.size(self.data): print 'b-values (%d) do not number the same as the image size (%d)' % (len(bdata),np.size(self.data)) return 0 if len(bmod)==3: # assume center and radius print 'Circle edit' pixel_modlist = [] for i in range(len(bdata)): if math.sqrt( bdata[i][0]**2 + bdata[i][1]**2 ) > 0.95: continue # this is off the disk (assumed circular...) elif math.sqrt( (bdata[i][0] - bmod[0])**2 + (bdata[i][1] - bmod[1])**2) < bmod[2]: row = int(float(i) // float(len(self.data))) col = i - row*len(self.data) pixel_modlist.append([row,col]) nedit+=1 elif len(bmod)==4: # assume square print 'Square' else: # assume list print 'list' if type(Tmod) == float: tmp = Tmod Tmod = [] for b in bmod: Tmod.append(tmp) for px in pixel_modlist: self.data[px[0],px[1]] = Tmod return nedit
def initialize_planets(self): data_file_name = os.path.join("data","planets.txt") read_planet_database = primitives.import_datasheet(data_file_name) planet_database = {} for planet_name in read_planet_database: planet_instance = planet.planet(planet_name,self,read_planet_database[planet_name]) #creating the planet instance try: global_variables.distance_data except: global_variables.distance_data = planet_instance.calculate_all_distances() planet_database[planet_name] = planet_instance #checking that all projections exist random_planet_name = random.choice(planet_database.keys()) random_planet = planet_database[random_planet_name] random_planet.pickle_all_projection_calculations() return planet_database
def add_planet(self, smaj): ecc = abs(random.gauss(0.0, 0.01)) #orbital eccentricity PB = 0 if (0.5 * self.m < smaj <= self.fl): PB = 1 elif (self.fl < smaj <= self.fl + 1.2): PB = 2 elif (self.fl + 1.2 < smaj <= self.rpo): PB = 3 elif (self.rpo < smaj): PB = 4 p = planet(smaj, ecc, self.l, self.m, PB) self.p.append(p)
def get_model_spectrum(val, name, tweakmodule, tweakTmp, freqs, b, par_names, limits): '''Generate model spectrum''' update_tweak(tweakmodule,tweakTmp,par_names, val, limits) plan = planet.planet(name, plot=False) datFile = plan.run(freqs=freqs, b=b) spec = [] with open(datFile, 'r') as tmp: for line in tmp: if not line.startswith("#"): values=[float(x) for x in line.split()] if len(spec) == 0: spec = values else: spec = np.vstack((spec, values)) os.remove(datFile) return spec
def get_model_spectrum(val, name, tweakmodule, tweakTmp, freqs, b, par_names, limits): '''Generate model spectrum''' update_tweak(tweakmodule, tweakTmp, par_names, val, limits) plan = planet.planet(name, plot=False) datFile = plan.run(freqs=freqs, b=b) spec = [] with open(datFile, 'r') as tmp: for line in tmp: if not line.startswith("#"): values = [float(x) for x in line.split()] if len(spec) == 0: spec = values else: spec = np.vstack((spec, values)) os.remove(datFile) return spec
def planet_dynamics(horizon, step, make_plot=True): delta_in_sec = step * days_to_sec # define your planets here planets = [static_sun("1"), planet("2", R_sun, M_earth, D_earth_sun, 0.0, 0.0, 0.0, V_earth, 0.0)] x, y, z = [[]], [[]], [[]] set_up_positions(x, y, z, len(planets)) lines = [] if make_plot: set_up_plot(lines, x, y, z, planets) total_time = 0 # in years while total_time <= horizon: print("Time (in y): ", total_time, " --- Number of planets: ", len(planets)) for p in planets: p.report() append_positions(x, y, z, planets) if make_plot: update_plot(lines, x, y, z, planets, total_time) compute_accelerations(planets) for p in planets: p.update_velocity(delta_in_sec) p.update_position(delta_in_sec) # planets = check_for_colliding_planets(planets) total_time += step * days_to_years # in years if make_plot: plt.show() return x, y, z
def editImageLat(self, latmod, Tmod, limb=[0.0]): """This only works for negative latitudes to pole. Need to make northern,southern,straddle + bands. latmod is the planetographic latitude that marks the boundary (degrees) Tmod is/are the temperature values limb are the corresponding b-values""" import planet import atmosphere pyPlanetPath = os.getenv('PYPLANETPATH') if pyPlanetPath == None: print('No PYPLANETPATH environment variable') pyPlanetPath = './' atm = atmosphere.atmosphere('neptune', pyPlanetPath) atm.run() p = planet.planet('functions') bdata = p.bRequest(self.header['b'][0], block=[1, 1]) if len(bdata) != np.size(self.data): print( 'b-values (%d) do not number the same as the image size (%d)' % (len(bdata), np.size(self.data))) return 0 radii = [] for i in range(len(self.header['radii'])): if isinstance(self.header['radii'][i], self.scalar): radii.append(self.header['radii'][i]) rNorm = self.header['rNorm'][0] Req = np.max(radii) Rpol = np.min(radii) f = (Req - Rpol) / Req gtype = 'ellipse' tip = self.header['aspect'][0] tip *= math.pi / 180.0 rotate = self.header['aspect'][1] #rotate = -1.0*math.atan(math.tan(rotate*math.pi/180.0)*(1.0-f)**2) rotate *= math.pi / 180.0 lat_pg = latmod * math.pi / 180.0 lat_pcmod = math.atan(math.tan(lat_pg) * (1.0 - f)**2) pixel_modlist = [] nedit = 0 if isinstance(Tmod, self.scalar): Tmod = list(Tmod) if len(Tmod) != len(limb): print('limb is incorrectly specified') return 0 for i in range(len(bdata)): edge, bmod = raypath.__findEdge__(atm, bdata[i], rNorm, tip, rotate, gtype, printdot=False) if edge == None: continue pclat = math.asin( np.dot(edge, raypath.yHat) / np.linalg.norm(edge)) delta_lng = math.atan2(np.dot(edge, raypath.xHat), np.dot(edge, raypath.zHat)) if pclat > 0.0: break if pclat < lat_pcmod: row = int(float(i) // float(len(self.data))) col = i - row * len(self.data) pixel_modlist.append([row, col, i]) nedit += 1 breakb = 0.96 if len(Tmod) > 1: wherebb = np.where(np.array(limb) < breakb) Tfunc3 = interpolate.interp1d( limb[wherebb[0][0]:wherebb[0][-1] + 1], Tmod[wherebb[0][0]:wherebb[0][-1] + 1], kind=3, bounds_error=False, fill_value=0.0) Tfunc1 = interpolate.interp1d(limb, Tmod, kind=1) else: Tfunc3 = lambda x: Tmod[0] Tfunc1 = lambda x: Tmod[0] testPlotLimb = False if testPlotLimb: pltl = np.linspace(limb[0], limb[-1], 50) pltt = Tfunc3(pltl) plt.figure('limbFunction') plt.plot(pltl, pltt) pltt = Tfunc1(pltl) plt.plot(pltl, pltt) plt.plot(limb, Tmod, 'o') math.sqrt(-1.) for px in pixel_modlist: bval = math.sqrt(bdata[px[2]][0]**2 + bdata[px[2]][1]**2) if bval < limb[0]: bval = limb[0] elif bval > limb[-1]: bval = limb[-1] if bval < breakb: Tnew = Tfunc3(bval) else: Tnew = Tfunc1(bval) self.data[px[0], px[1]] = Tnew return nedit
ddd.append(float(d)) T.append(ddd) fp.close() return f,T oldFreqs = [8.46,14.94,22.46,43.34] newFreqs = [1.46,2.44,3.04,3.44,4.42,5.45,5.9,6.45,7.45,8.58,9.61,10.38,11.41,13.18,14.21,15.18,16.21,17.38,22.45,23.45,24.45,25.45] newFreqsLo = [ 1.46, 2.44, 3.04, 3.44, 4.42, 5.45, 5.9] newFreqsMi = [ 6.45, 7.45, 8.58, 9.61,10.38,11.41,13.18] newFreqsHi = [14.21,15.18,16.21,17.38,22.45,23.45,24.45,25.45] freqs = oldFreqs freqs=10. print 'Reading input file ',sys.argv[1] j = planet.planet('jupiter') gasFile = 1 cloudFile = 1 if len(sys.argv) > 2: cloudFile = 2 j.atm.readGas(sys.argv[gasFile]) j.atm.readCloud(sys.argv[cloudFile]) j.atm.tweakAtm() j.atm.computeProp() regrid.regrid(j.atm,regridType=j.atm.config.regridType,Pmin=j.atm.config.pmin,Pmax=j.atm.config.pmax) j.atm.nAtm=len(j.atm.gas[0]) b = [90.,0.0,0.2,0.4,0.6,0.7,0.8,0.9] j.run(freqs,b=b,outputType='batch') nfreq,nTB = splitFile()
import random import pygame as pygame from planet import Planet as planet screen = (500, 500) disp = pygame.display.set_mode(screen) disp.fill((0, 0, 0)) pygame.display.update() #initialie planets #planet format is as follows: [postion, inital velocity, mass] planets = [ planet([screen[0] // 2, screen[1] // 2], [0, 0], 1000), planet([screen[0] // 2 - 100, screen[1] // 2], [0, -3], 10), planet([screen[0] // 2 + 100, screen[1] // 2], [0, 3], 10), planet([screen[0] // 2 - 150, screen[1] // 2], [0, -2], 10), planet([screen[0] // 2 + 250, screen[1] // 2], [0, 2], 10), ] #sun = planet([screen[0] // 2, screen[1] // 2], [0, 0], 10) #earth = planet([screen[0] // 2 - 10, screen[1] // 2 + 100], [0, -1], 10) clock = pygame.time.Clock() #planets=[planet([random.randint(0,screen[0]), random.randint(0,screen[1])], [0,0], random.randint(1,100)) for i in range(20)] dt = 0 timeScale = 25 running = True #main loop while running: disp.fill((0, 0, 0))
size = (screenWidth, screenHeight) screen = pygame.display.set_mode(size) pygame.display.set_caption("Solar System") #set title #logo = pygame.image.load("solar.gif") #set logo of program #pygame.display.set_icon(logo) # Loop until the user clicks the close button. done = False # Used to manage how fast the screen updates clock = pygame.time.Clock() #initialize planets #mercury mercury = planet('Mercury') mercury.setColor(solarColorPalette.mercuryColor) mercury.setWidth(3) mercury.setRadius(50) mercury.setSpeed(4.5) mercury.setX(50) mercury.setY(250) #venus venus = planet('Venus') venus.setColor(solarColorPalette.venusColor) venus.setWidth(7) venus.setRadius(100) venus.setSpeed(4) venus.setX(100) venus.setY(250) #earth
size = (screenWidth, screenHeight) screen = pygame.display.set_mode(size) pygame.display.set_caption("Solar System") # set title # logo = pygame.image.load("solar.gif") #set logo of program # pygame.display.set_icon(logo) # Loop until the user clicks the close button. done = False # Used to manage how fast the screen updates clock = pygame.time.Clock() # initialize planets # mercury mercury = planet('Mercury') mercury.setColor(solarColorPalette.mercuryColor) mercury.setWidth(3) mercury.setRadius(50) mercury.setSpeed(4.5) mercury.setX(50) mercury.setY(250) # venus venus = planet('Venus') venus.setColor(solarColorPalette.venusColor) venus.setWidth(7) venus.setRadius(100) venus.setSpeed(4) venus.setX(100) venus.setY(250) # earth
class User(): username = "******" settings = { "turn": "1", "created": "Days and days ago", } user = { "username": "******", "economy": 9000, "planet_ID": ["1"], "fleet_ID": ["1"], } planets = {"1": planet("Nopeming")} fleets = { "1": { "ships": 100, }, } def __init__(self): self.load_objs() # The following functions will edit this field def load_objs(self): try: with open('settings.objs', 'rb') as file: self.settings = pickle.load(file) except: print("Unable to load, reverting to default") try: with open('user.objs', 'rb') as file: self.user = pickle.load(file) except: print("Unable to load, reverting to default") try: with open('planets.objs', 'rb') as file: self.planets = pickle.load(file) except: print("Unable to load, reverting to default") try: with open('fleet.objs', 'rb') as file: self.fleets = pickle.load(file) except: print("Unable to load, reverting to default") def save_objs(self): with open('settings.objs', 'wb') as handles: pickle.dump(self.settings, handles) with open('user.objs', 'wb') as handles: pickle.dump(self.user, handles) with open('fleet.objs', 'wb') as handles: pickle.dump(self.fleets, handles) with open('planets.objs', 'wb') as handles: pickle.dump(self.planets, handles) print("saved") def getUserPlanetsFromList(self, user, planets, pid=[]): planet_id = [x for x in user["planet_ID"]] plist = [] for i in planet_id: plist.append(planets[i]) return plist def getUserFleetsFromList(self, user, fleets, fid=[]): fleet_id = [x for x in user["fleet_ID"]] flist = [] for i in fleet_id: flist.append(fleets[i]) return flist
def editImageLat(self,latmod,Tmod,limb=[0.0]): """This only works for negative latitudes to pole. Need to make northern,southern,straddle + bands. latmod is the planetographic latitude that marks the boundary (degrees) Tmod is/are the temperature values limb are the corresponding b-values""" import planet import atmosphere pyPlanetPath = os.getenv('PYPLANETPATH') if pyPlanetPath == None: print 'No PYPLANETPATH environment variable' pyPlanetPath = './' atm = atmosphere.atmosphere('neptune',pyPlanetPath) atm.run() p = planet.planet('functions') bdata = p.bRequest(self.header['b'][0],block=[1,1]) if len(bdata) != np.size(self.data): print 'b-values (%d) do not number the same as the image size (%d)' % (len(bdata),np.size(self.data)) return 0 radii = [] for i in range(len(self.header['radii'])): if type(self.header['radii'][i])==float or type(self.header['radii'][i])==int: radii.append(self.header['radii'][i]) rNorm = self.header['rNorm'][0] Req = np.max(radii) Rpol = np.min(radii) f = (Req-Rpol)/Req gtype = 'ellipse' tip = self.header['aspect'][0] tip*=math.pi/180.0 rotate = self.header['aspect'][1] #rotate = -1.0*math.atan(math.tan(rotate*math.pi/180.0)*(1.0-f)**2) rotate*=math.pi/180.0 lat_pg = latmod*math.pi/180.0 lat_pcmod = math.atan(math.tan(lat_pg)*(1.0-f)**2) pixel_modlist = [] nedit = 0 if type(Tmod)==float or type(Tmod)==int: Tmod = list(Tmod) if len(Tmod) != len(limb): print 'limb is incorrectly specified' return 0 for i in range(len(bdata)): edge, bmod = raypath.__findEdge__(atm,bdata[i],rNorm,tip,rotate,gtype,printdot=False) if edge == None: continue pclat = math.asin( np.dot(edge,raypath.yHat)/np.linalg.norm(edge) ) delta_lng = math.atan2( np.dot(edge,raypath.xHat), np.dot(edge,raypath.zHat) ) if pclat > 0.0: break if pclat < lat_pcmod: row = int(float(i) // float(len(self.data))) col = i - row*len(self.data) pixel_modlist.append([row,col,i]) nedit+=1 breakb = 0.96 if len(Tmod) > 1: wherebb = np.where(np.array(limb) < breakb) Tfunc3 = interpolate.interp1d(limb[wherebb[0][0]:wherebb[0][-1]+1],Tmod[wherebb[0][0]:wherebb[0][-1]+1],kind=3,bounds_error=False,fill_value=0.0) Tfunc1 = interpolate.interp1d(limb,Tmod,kind=1) else: Tfunc3 = lambda x: Tmod[0] Tfunc1 = lambda x: Tmod[0] testPlotLimb = False if testPlotLimb: pltl = np.linspace(limb[0],limb[-1],50) pltt = Tfunc3(pltl) plt.figure('limbFunction') plt.plot(pltl,pltt) pltt = Tfunc1(pltl) plt.plot(pltl,pltt) plt.plot(limb,Tmod,'o') math.sqrt(-1.) for px in pixel_modlist: bval = math.sqrt( bdata[px[2]][0]**2 + bdata[px[2]][1]**2 ) if bval < limb[0]: bval = limb[0] elif bval > limb[-1]: bval = limb[-1] if bval < breakb: Tnew = Tfunc3(bval) else: Tnew = Tfunc1(bval) self.data[px[0],px[1]] = Tnew return nedit
import planet n = planet.planet('neptune') frq = 43.34 bstep = 0.01 sizeofblock = 15 #thisrun = [11] #thisrun = [1,2,3,4] thisrun = [12,13,14,15] for i in thisrun: n.run(freqs=frq,b=bstep,block=[i,sizeofblock])
oldFreqs = [8.46, 14.94, 22.46, 43.34] newFreqs = [ 1.46, 2.44, 3.04, 3.44, 4.42, 5.45, 5.9, 6.45, 7.45, 8.58, 9.61, 10.38, 11.41, 13.18, 14.21, 15.18, 16.21, 17.38, 22.45, 23.45, 24.45, 25.45 ] newFreqsLo = [1.46, 2.44, 3.04, 3.44, 4.42, 5.45, 5.9] newFreqsMi = [6.45, 7.45, 8.58, 9.61, 10.38, 11.41, 13.18] newFreqsHi = [14.21, 15.18, 16.21, 17.38, 22.45, 23.45, 24.45, 25.45] freqs = oldFreqs freqs = 10. print 'Reading input file ', sys.argv[1] j = planet.planet('jupiter') gasFile = 1 cloudFile = 1 if len(sys.argv) > 2: cloudFile = 2 j.atm.readGas(sys.argv[gasFile]) j.atm.readCloud(sys.argv[cloudFile]) j.atm.tweakAtm() j.atm.computeProp() regrid.regrid(j.atm, regridType=j.atm.config.regridType, Pmin=j.atm.config.pmin, Pmax=j.atm.config.pmax) j.atm.nAtm = len(j.atm.gas[0])
from planet import planet all_planets = { 'improbable': planet('improbable', 'shell', 'shell', 'Improbable Landing Pad', ['out'], ['in'], ['w'], ['e'], [], []), 'unlikely': planet('unlikely', 'shell', 'shell', 'Unlikely Landing Pad', ['se', 'out'], ['in', 'nw'], ['w'], ['e'], [], []), 'doubtful': planet('doubtful', 'shell', 'shell', 'Doubtful Landing Pad', ['sw'], ['ne'], ['w'], ['e'], [], []), 'dubious': planet('dubious', 'shell', 'shell', 'Doubtful Landing Pad', ['nw'], ['se'], ['w'], ['e'], [], []), 'implausible': planet('implausible', 'shell', 'shell', 'Unlikely Landing Pad', ['ne', 'out'], ['in', 'sw'], ['w'], ['e'], [], []), 'welch': planet('welch', 'default', 'shell', 'This is the hub of Welch;', [], [], ['e'], ['w'], ['sw'], ['ne']), 'bilk': planet('bilk', 'default', 'shell', '', ['w'], ['e'], ['e'], ['w'], ['sw'], ['ne']), 'herringbone': planet('herringbone', 'chevron', 'shell', 'Ice planet Herringbone', [], [], ['sw'], ['ne'], ['s'], ['n']), 'wreck': planet('wreck', 'total', 'shell', 'Wreck currently has the layout', [], [], ['n'], ['s'], ['e'], ['w']), 'demolish': planet('demolish', 'total', 'shell', '...', ['w'], ['e'], ['n'], ['s'], ['e'], ['w']), 'crash': planet('crash', 'total', 'shell', '...', ['sw'], ['ne'], ['sw'], ['ne'], [''], ['']), 'divide': planet('divide', 'gulf', 'shell', 'Divide is currently just another Magrathea-built rock', [], [], ['s', 'w'], ['e', 'n'], ['s', 's'], ['n', 'n']), # 'viand': planet('viand', 'darkness', 'darkness', '...', ['w'], ['e'], ['e', 'n'], ['s', 'w'], [], []), # 'vivid': planet('vivid', 'darkness', 'darkness', '...', ['n', 'n'], ['s', 's'], ['in', 'wear sunglasses', 'w'], ['e', 's', 'out'], [], []), 'disco ball': planet('disco ball', 'disco', 'darkness', '...', [], [], ['s', 'w'], ['e', 'n'], [], []), 'zaldrizes': planet('zaldrizes', 'dragon', 'darkness', '...', [], [], ['e'], ['w'], [], []), # 'anacreon': planet('anacreon', 'far star', 'far star', '...', ['w'], ['e'], ['e'], ['w'], [], []), # 'santanni': planet('santanni', 'far star', 'far star', '...', ['sw'], ['ne'], ['e'], ['w'], [], []), # 'smyrno': planet('smyrno', 'far star', 'far star', '...', [], [], ['e'], ['w'], [], []), # 'terminus': planet('terminus', 'far star', 'far star', '...', ['s'], ['n'], ['e'], ['w'], ['ne'], ['sw']), # 'helicon': planet('helicon', 'stars end', 'far star', '...', ['s'], ['n'], ['e'], ['w'], [], []), # 'cinna': planet('cinna', 'stars end', 'far star', '...', [], [], ['e'], ['w'], [], []),