def _planetdotang( a, b, theta, r_dot_adj=0.23, dot_color="#C8C5E2", r_dot_size=0.6, rot_x=0.0, rot_y=0.0, dot_op=1.0, dot_str_op=1.0 ): if theta < 180: r_dot_adj = r_dot_adj * -1.0 r_dot = _rellipse(a, b, theta) r_trans = svg.rotate(theta, rot_x, rot_y) # print(r_dot) ret_dot = svg.Fig( svg.Dots( [(r_dot, 0)], svg.make_symbol( "dot_{}_{}".format(theta, dot_color), fill=dot_color, fill_opacity=dot_op, stroke="black", stroke_width="0.15pt", stroke_opacity=dot_str_op, ), r_dot_size, r_dot_size, ), trans=r_trans, ) # print(theta) # print(r_dot*cos(radians(theta)), r_dot*sin(radians(theta))) return ret_dot
def _orbitdot( a, b, theta, r_dot_adj=0.1, color="#C8C5E2", r_dot_size=0.6, rot_x=0.0, rot_y=0.0, dot_op=1.0, dot_str_op=1.0 ): if theta > 180: r_dot_adj = r_dot_adj * -1.0 r_dot = _rellipse(a, b, theta) # +r_dot_adj*sin(theta) r_trans = svg.rotate(theta, rot_x, rot_y) # print(r_dot) ret_dot = svg.Fig( svg.Dots( [(r_dot, 0)], svg.make_symbol( "dot_{}_{}".format(theta, color), fill=color, fill_opacity=dot_op, stroke="black", stroke_width="0.15pt", stroke_opacity=dot_str_op, ), r_dot_size, r_dot_size, ), trans=r_trans, ) # print(defs) return ret_dot
def _planetdot(name, rpos, dot_color="#C8C5E2", r_dot_size=0.6, dot_op=1.0, dot_str_op=1.0): r_x = rpos[0] r_y = rpos[1] cname = dot_color.replace("#", "") ret_dot = svg.Fig(svg.Dots([(r_x, r_y)], svg.make_symbol("dot_{}_{}".format(name, cname), fill=dot_color, fill_opacity=dot_op, stroke="black", stroke_width="0.15pt", stroke_opacity=dot_str_op), r_dot_size, r_dot_size)) return ret_dot
def draw_dot_field(self): self.dot_field_data = np.array( [[x,y] for x in range(-self.dx/2, self.dx/2+1) for y in range(-self.dy/2, self.dy/2+1)], dtype=np.float32) #grid drawing is really slow #re-enable when it is not redrawn every time self.set_color('grid') #for (x,y) in self.dot_field_data: # self.scene.addEllipse(x, y, 0.001, 0.001, self.pen, self.brush) r = 0.05 rpx = "%spx" % (r) dots = svgfig.Dots(self.dot_field_data, svgfig.make_symbol("dot_field", stroke=None, fill=self.color, r=r*self.q)).SVG(trans=self.trans) self.set_color('axes') res = [dots] res += self._line(-self.dx/2,0,self.dx/2,0, r) res += self._line(0,-self.dy/2, 0, self.dy/2, r) return res
def draw_dot_field(self): self.dot_field_data = np.array( [[x,y] for x in range(-self.dx/2, self.dx/2+1) for y in range(-self.dy/2, self.dy/2+1)], dtype=np.float32) #grid drawing is really slow #re-enable when it is not redrawn every time self.set_color('grid') #for (x,y) in self.dot_field_data: # self.scene.addEllipse(x, y, 0.001, 0.001, self.pen, self.brush) r = 0.05 rpx = "%spx" % (r) dots = svgfig.Dots(self.dot_field_data, svgfig.make_symbol("dot_field", stroke=None, fill=self.color, r=r*self.q)).SVG(trans=self.trans) self.set_color('axes') res = [dots] res += self._line(-self.dx/2,0,self.dx/2,0, r) res += self._line(0,-self.dy/2, 0, self.dy/2, r) print res return res
def ex1(): angle_axis = svgfig.LineAxis(5, 0, 5, 2*pi, 0, 2*pi, stroke='white', text_attr={'fill':'white'}) angle_axis.text_start = -2.5 angle_axis.text_angle = 180. angle_axis.ticks = [x*2*pi/8 for x in range(8)] angle_axis.labels = lambda x: "%g" % (x*180/pi) angle_axis.miniticks = [x*2*pi/8/9 for x in range(8*9)] radial_axis = svgfig.XAxis(0, 5, aty=pi/2, stroke='white', text_attr={'fill':'white'}) radial_axis.text_start = 5 radial_axis.text_angle = 90. radial_axis.ticks = range(5) points = [(max(0.5, random.gauss(2.5, 1)), random.uniform(-pi, pi), max(0.1, random.gauss(0.3, 0.1))) for i in range(10)] xerr = svgfig.XErrorBars(points, stroke='white') yerr = svgfig.YErrorBars(points, stroke='white') dots = svgfig.Dots(points, svgfig.make_symbol("name", stroke="white", fill="red", stroke_width="0.25pt")) xml = svgfig.Fig(svgfig.Fig(angle_axis, radial_axis, xerr, yerr, dots, trans="x*cos(y), x*sin(y)")).SVG(svgfig.window(-6, 6, -6, 6)).standalone_xml() return QtCore.QByteArray(xml)
def mpoplot(userdates, master_scale=15, demo=False): """ ... explain what this does... """ outdir = '../sample_data/output' # if demo: # shutil.rmtree(outdir) # os.makedirs(outdir) # else: # if not os.path.exists(outdir): # os.makedirs(outdir) # else: # print('\n Uh-oh! The directory {} already exists.'.format( # outdir)) # if yesno(' Do you want to replace it?'): # shutil.rmtree(outdir) # os.makedirs(outdir) # else: # return # Clear and load the kernels that this program requires. spice.kclear() spice.furnsh('epys.mk') # A graphic will be created for each 'date' in 'dates': for date in userdates: et = spice.str2et(date) datestr = (spice.et2utc(et, 'ISOC', 0)) # -- Outer frame ------------------------------------------------- dist_scl = 250.0 elts = getorbelts(date) arg_peri = elts[4] # Opacity of degree frame and Venus graphic frame_op = 0.5 # # Process JD time into calendar time strings # datestr = spice.et2utc(et, 'ISOC', 0) date = '{} {}'.format(datestr.split('T')[0], datestr.split('T')[1]) edate, etime = date.split() eyear = "{}".format(edate.split('-')[0]) emonth = "{0:02d}".format(int(edate.split('-')[1])) eday = "{0:02d}".format(int(edate.split('-')[2])) epoch = "{}/{}/{}".format(eday, emonth, eyear) ep_name = "{}{}{}".format(eyear, emonth, eday) frame = _outerframe(epoch, frmSize=master_scale, frm_op=frame_op, mpoargp=arg_peri) # -- Mercury Planet -------------------------------------------------- # tru_ano = 90 # look_from = 270 # x1 = "{}%".format((100*math.sin(math.radians((tru_ano+90)/2.)))) # x2 = "{}%".format(100-(100*sin(radians((tru_ano+90)/2.)))) angs = range(0, 360, 1) plt.plot(angs, ["{}".format((100 * math.sin(math.radians(x / 2)))) for x in angs], 'yo-') plt.plot(angs, ["{}".format(100 - (100 * math.sin(math.radians(x / 2)))) for x in angs], 'ro-') # plt.show() stop1 = "#C8C5E2" # stop2 = "#373163" defs = svg.SVG("defs", svg.SVG("linearGradient", svg.SVG("stop", stop_color=stop1, stop_opacity=1, offset="45%"), svg.SVG("stop", stop_color=stop1, stop_opacity=1, offset="55%"), x1="0%", y1="0%", x2="100%", y2="0%", spreadMethod="pad", id="mercGrad") ) # defs = svg.SVG('defs', # svg.SVG('radialGradient', # svg.SVG('stop', # stop_color=stop1, # stop_opacity=1, # offset='38%'), # svg.SVG('stop', # stop_color=stop2, # stop_opacity=1, # offset='40%'), # cx='50%', cy='50%', # fx='230%', fy='50%', # r='300%', # spreadMethod='pad', # id='mercGrad') # ) merc_rad = 2439.99 # km merc_rad_scl = merc_rad / dist_scl merc_ball = svg.Ellipse(0, 0, 0, merc_rad_scl, merc_rad_scl, fill="url(#mercGrad)", stroke_width="0.15pt") # -- MPO Orbit -- mpo_orb_ecc = 0.163229 mpo_orb_sma = 3394.0 # km mpo_orb_sma_scl = mpo_orb_sma / dist_scl mpo_orb_smi_scl = mpo_orb_sma_scl * math.sqrt(1 - mpo_orb_ecc ** 2) # Make things cleaner a = mpo_orb_sma_scl b = mpo_orb_smi_scl mpo_orb = svg.Ellipse(-math.sqrt(a ** 2 - b ** 2), 0, 0, a, b, fill="none", stroke_width="0.25pt") # apof = 8 mpo_orb_apses = svg.Line(-_rellipse(a, b, 180) - 5, 0, _rellipse(a, b, 0) + 10, 0, stroke_width="0.15pt", stroke_dasharray="2, 2") dot_angs = range(0, 360, 20) dots = [_orbitdot(a, b, x, color="black") for x in dot_angs] mpo_orb_dots = svg.Fig() for dot in dots: mpo_orb_dots.d.append(dot) mpo_orb_trans = svg.rotate(arg_peri, 0, 0) mpo_orb_plot = svg.Fig(mpo_orb, mpo_orb_apses, mpo_orb_dots, trans=mpo_orb_trans) # -- Direction arrow ------------------------------------------------- dirarend = svg.make_marker("dirarrowend", "arrow_end", fill_opacity=0.2) dirarend.attr["markerWidth"] = 7.5 x1, y1 = master_scale + 1, 0.4, x2, y2 = master_scale + 1, 1 dirarwstrt = svg.Line(x1, y1, x2, y2, stroke_width=".4pt", stroke_opacity=0.2, arrow_end=dirarend) dirarw = svg.Fig(dirarwstrt, trans="x*cos(y), x*sin(y)") # -- Apsis view ------------------------------------------------------ apvx, apvy = master_scale + 3, -master_scale - 3 apsisviewball = svg.Ellipse(apvx, apvy, 0, merc_rad_scl * 0.25, merc_rad_scl * 0.25, fill="url(#mercGrad)", stroke_width="0.15pt") apsisviewlats = svg.Fig() for x in range(-9, 10, 3): hscl = math.sin(math.radians(x * 10)) wscl = math.cos(math.radians(x * 10)) x1 = apvx - (merc_rad_scl * 0.25 * wscl) y1 = apvy + (merc_rad_scl * 0.25 * hscl) x2 = apvx + (merc_rad_scl * 0.25 * wscl) y2 = apvy + (merc_rad_scl * 0.25 * hscl) apsisviewlats.d.append(svg.Line(x1, y1, x2, y2, stroke_width=".2pt", stroke_opacity=0.4)) apvarend = svg.make_marker("apvarrowend", "arrow_end", fill_opacity=0.6) apvarend.attr["markerWidth"] = 3.0 apvarend.attr["markerHeight"] = 3.0 x1, y1 = apvx, apvy - 3 x2, y2 = apvx, apvy + 3 apsisvieworbit = svg.Line(x1, y1, x2, y2, stroke_width=".4pt", stroke_opacity=0.6, arrow_end=apvarend) xd = apvx yd = apvy + (merc_rad_scl * 0.25 * math.sin(math.radians(arg_peri))) apsisviewdot = svg.Fig(svg.Dots([(xd, yd)], svg.make_symbol("apsisdot", fill="black", fill_opacity=0.6 ), 0.6, 0.6 ) ) apsisview = svg.Fig(apsisviewball, apsisviewlats, apsisvieworbit, apsisviewdot) # -- Build final figure ---------------------------------------------- wa = master_scale * 1.5 svgout = svg.Fig(frame, merc_ball, mpo_orb_plot, dirarw, apsisview ).SVG(svg.window(-wa, wa, -wa, wa)) svgout.prepend(defs) argp = int(arg_peri) svgout.save(os.path.join(outdir, "mpo_orbit_plot_{}_{}.svg".format(ep_name, argp) ) )
def _sun(id="Sun", posx=0, posy=0, size=1.5, fill="yellow", stroke="orange", stroke_width="0.1pt"): return svg.Dots([(0, 0)], svg.make_symbol(id, stroke=stroke, fill=fill, stroke_width=stroke_width), size, size)