Changeset 117
- Timestamp:
- 07/02/07 16:28:35 (1 year ago)
- Files:
-
- doc/CNS2007/poster_cns2007.py (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
doc/CNS2007/poster_cns2007.py
r116 r117 11 11 from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle 12 12 from reportlab.lib.enums import * 13 from reportlab.pdfbase.pdfmetrics import stringWidth 13 14 import PIL 14 15 import pysvn 15 16 import imp, os 17 import SilverCity 18 import sys 19 import StringIO 20 16 21 17 22 class Author(object): … … 34 39 setattr(style, attr_name, attr*x) 35 40 36 def getStyleSheet( scale_factor):41 def getStyleSheet(base_fontSize, title_fontSize=None): 37 42 styles = getSampleStyleSheet() 43 scale_factor = float(base_fontSize)/styles['BodyText'].fontSize 38 44 # Scale font sizes and related spacing 39 45 for style in styles.byName.values(): 40 46 scale_style(style, scale_factor) 41 styles['Title'].fontSize += 8 47 if title_fontSize is not None: 48 scale_factor = float(title_fontSize)/styles['Title'].fontSize 49 scale_style(styles['Title'], scale_factor) 42 50 43 51 author_style = ParagraphStyle('Authors', parent=styles['Heading3']) … … 49 57 styles.add(affiliation_style) 50 58 51 users_guide_style = ParagraphStyle('UsersGuide', parent=styles['BodyText'])52 scale_style(users_guide_style, 1.5/scale_factor)53 styles.add(users_guide_style)54 55 for style in "Heading1","Heading2","Heading3","Code":56 newstyle = ParagraphStyle('UsersGuide%s' % style, parent=styles[style])57 scale_style(newstyle, 1.5/scale_factor)58 styles.add(newstyle)59 60 59 styles['Title'].alignment = TA_CENTER 61 60 styles['BodyText'].alignment = TA_JUSTIFY 62 styles['UsersGuide'].alignment = TA_JUSTIFY63 61 64 62 print "Font sizes:" 65 for style in 'BodyText','Title', 'Heading1', 'Heading2', 'Heading3' , 'UsersGuide':63 for style in 'BodyText','Title', 'Heading1', 'Heading2', 'Heading3': 66 64 print style, styles[style].fontSize 67 ##styles['UsersGuideCode'].listAttrs()68 65 69 66 return styles … … 85 82 poster.drawInlineImage(logo, x, y, height=logo_height, width=logo_width) 86 83 87 def make_title( title,authors,institutions,logo_left,logo_right):84 def make_title(styles,title,authors,institutions,logo_left,logo_right): 88 85 """Returns the y position of the bottom of the title (including bottom margin).""" 89 global poster, margins, pageheight, pagewidth, styles,pagetop86 global poster, margins, pageheight, pagewidth, pagetop 90 87 title_frame = Frame(margins['left'], pageheight/2.0, pagewidth, 20*cm, 91 88 showBoundary=True) … … 120 117 return title_bottom 121 118 122 def make_abstract( text,x,y,width,height,_debug):119 def make_abstract(styles,text,x,y,width,height,_debug): 123 120 abstract_frame = Frame(x, y - height, width, height, 124 121 showBoundary=_debug) … … 133 130 # print abstract_frame._height 134 131 135 def make_users_guide( x,y,width,height,_debug=False):136 global poster , styles132 def make_users_guide(styles,x,y,width,height,_debug=False): 133 global poster 137 134 svn_client = pysvn.Client() 138 135 svn_client.checkout(svnpath, "pyNN") … … 141 138 import restxsl.transform 142 139 import re 140 141 #scale_factor = 3.6 142 #users_guide_style = ParagraphStyle('UsersGuide', parent=styles['BodyText']) 143 #scale_style(users_guide_style, 1.5/scale_factor) 144 #styles.add(users_guide_style) 145 146 #for style in "Heading1","Heading2","Heading3","Code": 147 # newstyle = ParagraphStyle('UsersGuide%s' % style, parent=styles[style]) 148 # scale_style(newstyle, 1.5/scale_factor) 149 # styles.add(newstyle) 150 #styles['UsersGuide'].alignment = TA_JUSTIFY 143 151 144 152 user_guide_frame = Frame(x, y - height, width, height, showBoundary=_debug) … … 156 164 #if _debug: print xmltext 157 165 #if _debug: print "-----------------------------" 158 paragraph_list = [Paragraph(section, styles[' UsersGuideHeading1'])]166 paragraph_list = [Paragraph(section, styles['Heading1'])] 159 167 for match in paragraph_template.finditer(xmltext): 160 168 groups = match.groupdict() 161 169 content = groups['content'] 162 style = "UsersGuide" 170 #style = "UsersGuide" 171 style = "BodyText" 163 172 if groups['style'] is not None: 164 style += groups['style'] 173 #style += groups['style'] 174 style = groups['style'] 165 175 #if _debug: print "###### " + style 166 176 #if _debug: print content … … 168 178 user_guide_frame.addFromList(paragraph_list, poster) 169 179 170 def make_apidocs( x,y,width,height,scale_factor=0.5,_debug=False):171 global poster , styles180 def make_apidocs(styles,x,y,width,height,_debug=False): 181 global poster 172 182 svn_client = pysvn.Client() 173 183 svn_client.checkout(svnpath, "pyNN") … … 181 191 ('Category','Heading1'),('Class','Heading2')]: 182 192 newstyle = ParagraphStyle(style_name, parent=styles[parent]) 183 scale_style(newstyle, scale_factor)184 193 styles.add(newstyle) 185 194 styles[style_name].alignment = TA_LEFT … … 193 202 styles['Class'].spaceAfter *= 0.3 194 203 styles['APIBody'].spaceBefore = 0 195 styles['APIBody'].fontSize += 1 196 styles['APIBody'].leading += 1 204 styles['Title'].alignment = TA_LEFT 197 205 print "APIBody ", styles['APIBody'].fontSize 198 ##print styles['FunctionDef'].listAttrs()199 206 200 207 apidoc = wikidoc.apidoc('reportlab_xml') 201 #print apidoc202 208 margin = 0.03 203 209 subcol_width = width*(1-margin)/2.0 204 210 205 211 206 paragraph_list = [Paragraph("API reference <font size=14>(version %s)</font>" % __version__, styles['UsersGuideHeading1'])] 212 paragraph_list = [Paragraph("API reference <font size=14>(version %s)</font>" % __version__, 213 styles['Title'])] 207 214 for match in paragraph_template.finditer(apidoc): 208 215 groups = match.groupdict() … … 230 237 poster.roundRect(x,y-height,width,f_height,1*cm) 231 238 239 def colourize(code): 240 generator = SilverCity.Python.PythonHTMLGenerator() 241 io = StringIO.StringIO() 242 io.getvalue() 243 generator.generate_html(io, code) 244 output = io.getvalue() 245 colours = {'operator': 'brown', # bold 246 'number': 'seagreen', 247 'default': 'green', 248 'identifier': 'black', 249 'string': 'olive', 250 'word': 'black', # bold 251 'tripledouble': 'olive', # italic 252 'character': 'olive', 253 'commentline': 'gray', 254 } 255 for cls, colour in colours.items(): 256 output = output.replace('<span class="p_%s">' % cls, '<font color="%s">' % colour) 257 output = output.replace('</span>','</font>') 258 return output 259 260 def make_example(styles,x,y,width,height,_debug=False): 261 """ Make a frame showing the VAbenchmarks.py script, together with figure.""" 262 global poster 263 styles['Title'].alignment = TA_LEFT 264 styles['Code'].leftIndent = 0 265 svn_client = pysvn.Client() 266 svn_client.checkout(svnpath, "pyNN") 267 f = open(os.path.join('pyNN','test','VAbenchmarks.py'),'r') 268 example_script = f.read() 269 f.close() 270 example_script = colourize(example_script) 271 272 pad = 0.5*cm 273 code_flowable = XPreformatted(example_script, styles['Code']) 274 f_width = stringWidth("m"*110, styles['Code'].fontName, styles['Code'].fontSize, 'UTF-8') + 2*pad 275 paragraph_list = [Paragraph("Example", styles['Title']), 276 code_flowable] 277 # Scale the font size to fill the space 278 def calc_height(): 279 f_height = 0 280 for p in paragraph_list: 281 f_height += p.wrap(f_width, pageheight)[1] + p.getSpaceAfter() + p.getSpaceBefore() 282 ##f_height = nlines*(styles['Code'].leading+styles['Code'].spaceAfter+styles['Code'].spaceBefore) 283 ##f_height += styles['Title'].leading + styles['Title'].spaceBefore + styles['Title'].spaceAfter 284 f_height += 2*pad 285 return f_height 286 scale_style(styles['Code'],5.0) 287 while calc_height() > height: 288 #print styles['Code'].fontSize 289 scale_style(styles['Code'], 0.99) 290 print styles['Code'].fontSize 291 example_frame = Frame(x, y-height, f_width, height, showBoundary=_debug, 292 leftPadding=pad, rightPadding=pad, bottomPadding=pad, 293 topPadding=pad) 294 example_frame.addFromList(paragraph_list, poster) 295 poster.roundRect(x,y-height,f_width,height,1*cm) 296 297 def make_example_figure(styles,filename,caption,x,y,width,_debug=False): 298 global poster 299 img = Image(filename, width=width, height=1e12, kind='proportional', lazy=0) 300 caption_paras = [Paragraph(p.strip(), styles['BodyText']) for p in caption.split("\n") if p.strip()] 301 print len(caption_paras) 302 pad = 0.5*cm 303 f_height = img.drawHeight + 2*pad 304 for p in caption_paras: 305 f_height += p.wrap(width,pageheight)[1] + p.getSpaceAfter() + p.getSpaceBefore() 306 figure_frame = Frame(x, y-f_height, 307 width + 2*pad, f_height, 308 showBoundary=_debug, 309 leftPadding=pad, rightPadding=pad, 310 bottomPadding=pad, topPadding=pad) 311 figure_frame.addFromList([img] + caption_paras, poster) 312 313 def huge_url(x,y,width): 314 global poster 315 poster.saveState() 316 poster.setFillColor(colors.beige) 317 poster.setStrokeColor(colors.beige) 318 font = "Helvetica-Bold" 319 url = "http://neuralensemble.org/PyNN" 320 font_size = 200 321 while stringWidth(url, font, font_size, 'UTF-8') > width: 322 font_size *= 0.9 323 poster.setFont(font, font_size) 324 poster.drawCentredString(x,y,"http://neuralensemble.org/PyNN") 325 poster.restoreState() 326 232 327 # ============================================================================== 233 328 234 329 if __name__ == "__main__": 235 330 svnpath = "https://neuralensemble.kip.uni-heidelberg.de/svn/PyNN/branches/0.3" 236 DEBUG = False331 DEBUG = True 237 332 238 333 TITLE = "PyNN: Towards a universal neural simulator API in Python" … … 255 350 community, and promises leaps in simulation complexity and maintainability to any neural simulator 256 351 that adopts it. PyNN [<a href="http://neuralensemble.org/PyNN">http://neuralensemble.org/PyNN</a>] strives to provide a uniform application programming 257 interface (API) across neural simulators. Presently NEURON, NEST a re PCSIMsupported, and support for352 interface (API) across neural simulators. Presently NEURON, NEST and PCSIM are supported, and support for 258 353 other simulators, NeuroML output and neuromorphic VLSI hardware is under development. 259 354 … … 276 371 This work is supported by the European Union through the FACETS project (contract number FP6- 277 372 2004-IST-FETPI-15879).""" 373 374 CAPTIONS = { 375 'VAbenchmark_CUBA_exc.png': """<b>Results of running the CUBA benchmark script</b> (see Box: 'Example'), written in PyNN, with three different simulators (from left to right: NEURON, NEST, PCSIM). 376 377 The <b><i>top row</i></b> shows the membrane potential traces for two of the excitatory neurons in the network. 378 The <b><i>second row</i></b> shows the raster plots for the first 320 excitatory neurons in the network (total network size 3200 excitatory and 800 inhibitory neurons). Each dot represents one spike. Each row is a different cell. 379 The <b><i>third row</i></b> shows histograms of interspike intervals (ISIs) for the excitatory and inhibitory sub-populations. 380 The <b><i>bottom row</i></b> shows histograms of the coefficient of variation (CV) of the ISI. 381 382 For NEST and NEURON, the same sequence of random numbers was used to generate the network connectivity (using a PyNN <font face="Courier">NumpyRNG</font> object. For PCSIM, the random numbers were generated within the simulator (represented in PyNN with a <font face="Courier">NativeRNG</font> object). 383 384 Even when using exactly the same connectivity pattern, the membrane potential trajectories diverge after about the first 100 ms, although the pattern of mean activity across the network is well preserved between simulators. 385 386 With a different random connectivity (but with the same connection probability), there is no similarity in detailed activity patterns, but the statistical behaviour of the network in terms of spike train variability is the same. 387 """ 388 } 389 390 391 278 392 main_font = 'Helvetica' 279 393 margins = {'left':2*cm, 'right':2*cm, 'top':2*cm, 'bottom':2*cm} 280 394 colsep = 2*cm 281 395 titlesep = 2*cm 282 scale_factor = 3.6 283 styles = getStyleSheet(scale_factor) 396 397 ##base_fontSize = 36 398 ##styles = getStyleSheet(36, 8) 284 399 285 400 poster = Canvas("poster_cns2007.pdf", … … 295 410 pagetop = poster._pagesize[1] - margins['top'] 296 411 pageright = poster._pagesize[0] - margins['right'] 297 title_bottom = make_title(TITLE, AUTHORS, INSTITUTIONS, "pynn_tree2.png", "facetslogoweb.gif") 412 413 title_bottom = make_title(getStyleSheet(36, 72), TITLE, AUTHORS, INSTITUTIONS, "pynn_tree2.png", "facetslogoweb.gif") 298 414 # logos 299 415 institution_logos = ['facetslogoweb.gif','logo-cnrs.jpg','bccn-logo.jpg','kip_logo.gif'] 300 416 ncol = 3 301 417 colwidth = (pagewidth - (ncol-1)*colsep)/float(ncol) 302 make_abstract(ABSTRACT, margins['left'], title_bottom, colwidth, pageheight, DEBUG) 303 make_users_guide(margins['left']+colwidth+colsep, title_bottom, colwidth, pageheight, DEBUG) 418 colheight = title_bottom - margins['bottom'] 419 huge_url(poster._pagesize[0]/2.0, title_bottom/2.0, pagewidth) 420 make_abstract(getStyleSheet(36, 72),ABSTRACT, margins['left'], title_bottom, colwidth, colheight, DEBUG) 421 #make_users_guide(getStyleSheet(15),margins['left']+colwidth+colsep, title_bottom, colwidth, colheight, DEBUG) 422 make_example(getStyleSheet(10.5,36),margins['left']+colwidth+colsep, title_bottom, colwidth, colheight, DEBUG) 423 make_example_figure(getStyleSheet(20, 72), "VAbenchmark_CUBA_exc.png", 424 CAPTIONS["VAbenchmark_CUBA_exc.png"], 425 margins['left']+colwidth+colsep, title_bottom, colwidth, DEBUG) 304 426 apiwidth = 0.25*pagewidth 305 make_apidocs( margins['left']+pagewidth-apiwidth, title_bottom, apiwidth,306 title_bottom-margins['bottom'], 0.8/scale_factor, DEBUG)427 make_apidocs(getStyleSheet(9,36),margins['left']+pagewidth-apiwidth, title_bottom, apiwidth, 428 colheight, DEBUG) 307 429 308 430 poster.save()

