#def contrib_1toall(con): # return con.workspace.Fs_by_body[1]/con.workspace.net_Fs # scalar measure of relative variability of net force over entire orbit # (surrogate for eccentricity in multi-body system) #@prep('variability_force') #def variability_force(con): # return np.std(con.workspace.net_Fs) # ------------------------------------------------- # Attach measures to a context and select which to be hooked up # to auto-updated plots as game2 is refreshed game2.calc_context = calc_context_forces(game2, 'con2') con2 = game2.calc_context variability_force = fovea.make_measure('variability_force', 'math.sqrt(np.std(net_Fs))') con2.declare('PyDSTool.Toolbox.phaseplane', 'pp') arc = fovea.make_measure('arclength', 'pp.arclength(sim.pts)') contrib_1to2 = fovea.make_measure('contrib_1to2', 'Fs_by_body[1]/Fs_by_body[2]') contrib_1toall = fovea.make_measure('contrib_1toall', 'Fs_by_body[1]/net_Fs') w2 = con2.workspace con2.attach((arc, contrib_1to2, contrib_1toall, variability_force))
game1 = GUIrocket(body_setup1, "Scenario 1: Game 1", axisbgcol='white') # ! W1b Initial conditions # Hit planet 3 game1.set((-51.6, 0.7)) # ! W2a Constraints # NONE # ! W2b Goals / targets # ! W3 Create exploratory tool & calculation context objects game1.calc_context = calc_context_forces(game1, 'con1') con1 = game1.calc_context w1 = con1.workspace variability_force = fovea.make_measure('variability_force', 'math.sqrt(np.std(net_Fs))') con1.attach(variability_force) game1.go() # User interaction to draw line print "Pause here to draw line with 'l' then make it an Event" plt.show() ##def line_to_event(): ## ltarget = game1.selected_object ## ## #ltarget = gx.line_GUI(game1, pp.Point2D(0.31, 0.8), ## # pp.Point2D(0.36, 0.74), subplot='11') ## ltarget.make_event_def('target1', -1)
tracker.show() plt.show() # initialize go(30, 10, do_tracker=False) # call tracker every loop to show all sim_stub tracked objects # (= tracker_plotter objects) #fig = plt.figure(1) #ax = plt.gca() fig, ax = plt.subplots() max_dist = fovea.make_measure('maxdist', 'max(sim.pts["x"])') max_height = fovea.make_measure('maxheight', 'max(sim.pts["y"])') cc.attach((max_dist, max_height)) tracker(cc, 2, ('angle', 'maxdist', 'ko'), clear_on_refresh=False) tracker(cc, 2, ('angle', 'maxheight', 'ro'), clear_on_refresh=False) def make_iter_angle(): for angle in np.linspace(5, 85, 10): yield angle iter_angle = make_iter_angle()
#def contrib_1toall(con): # return con.workspace.Fs_by_body[1]/con.workspace.net_Fs # scalar measure of relative variability of net force over entire orbit # (surrogate for eccentricity in multi-body system) #@prep('variability_force') #def variability_force(con): # return np.std(con.workspace.net_Fs) # ------------------------------------------------- # Attach measures to a context and select which to be hooked up # to auto-updated plots as game2 is refreshed game2.calc_context = calc_context_forces(game2, 'con2') con2 = game2.calc_context variability_force = fovea.make_measure('variability_force', 'math.sqrt(np.std(net_Fs))') con2.declare('PyDSTool.Toolbox.phaseplane', 'pp') arc = fovea.make_measure('arclength', 'pp.arclength(sim.pts)') contrib_1to2 = fovea.make_measure('contrib_1to2', 'Fs_by_body[1]/Fs_by_body[2]') contrib_1toall = fovea.make_measure('contrib_1toall', 'Fs_by_body[1]/net_Fs') w2 = con2.workspace con2.attach((arc, contrib_1to2, contrib_1toall, variability_force)) # Don't need to update order #con2._update_order = ['', '']
pt2=pp.Point2D((ltarget.x2, ltarget.y2)), speed_inter=Interval('speed', float, (1,2)), bearing_inter=Interval('bearing', float, (-15,45)), loc_event_name='exit_ev_target1') ) #l = array((target.pars.pt1, target.pars.pt2)) #game1.ax.plot(l.T[0], l.T[1], 'k-', lw=3) #plt.draw() # ! W3 Create exploratory tool & calculation context objects game1.calc_context = calc_context_forces(game1, 'con1') con1 = game1.calc_context w1 = con1.workspace variability_force = fovea.make_measure('variability_force', 'math.sqrt(np.std(net_Fs))') con1.attach(variability_force) game1.go() test_model = intModelInterface(game1.model) print("Success? %s"%(str(target(test_model)))) print("Variability of net force felt along trajectory = %.3f" % con1.variability_force()) print(" (smaller is better)") # alternative (deprecated) method, shown for reference ecc1 = eccentricity_vs_n(game1, 1) peri1 = pericenter_vs_n(game1, 1, ecc1) print("Eccentricity = %.3f" % ecc1) dom_thresh = 0.6