From: <jd...@us...> - 2007-10-20 17:57:39
|
Revision: 3971 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3971&view=rev Author: jdh2358 Date: 2007-10-20 10:57:36 -0700 (Sat, 20 Oct 2007) Log Message: ----------- added files workbook Added Paths: ----------- trunk/py4science/examples/skel/noisy_sine_skel.py trunk/py4science/workbook/fig/noisy_sine.eps trunk/py4science/workbook/fig/noisy_sine.png trunk/py4science/workbook/files_etc.tex Added: trunk/py4science/examples/skel/noisy_sine_skel.py =================================================================== --- trunk/py4science/examples/skel/noisy_sine_skel.py (rev 0) +++ trunk/py4science/examples/skel/noisy_sine_skel.py 2007-10-20 17:57:36 UTC (rev 3971) @@ -0,0 +1,22 @@ +from scipy import arange, sin, pi, randn, zeros +import pylab as p + +a = 2 # 2 volt amplitude +f = 10 # 10 Hz frequency +sigma = 0.5 # 0.5 volt standard deviation noise + +# create the t and v arrays; see the scipy commands arange, sin, and randn +t = XXX # an evenly sampled time array +v = XXX # a noisy sine wave + +# create a 2D array X and put t in the 1st column and v in the 2nd; +# see the numpy command zeros +X = XXX + +# save the output file as ASCII; see the pylab command save +XXX + +# plot the arrays t vs v and label the x-axis, y-axis and title save +# the output figure as noisy_sine.png. See the pylab commands plot, +# xlabel, ylabel, grid, show +XXX Added: trunk/py4science/workbook/fig/noisy_sine.eps =================================================================== --- trunk/py4science/workbook/fig/noisy_sine.eps (rev 0) +++ trunk/py4science/workbook/fig/noisy_sine.eps 2007-10-20 17:57:36 UTC (rev 3971) @@ -0,0 +1,954 @@ +%!PS-Adobe-3.0 EPSF-3.0 +%%Title: noisy_sine.eps +%%Creator: matplotlib version 0.90.1, http://matplotlib.sourceforge.net/ +%%CreationDate: Sat Oct 20 11:42:38 2007 +%%Orientation: portrait +%%BoundingBox: 18 180 594 612 +%%EndComments +%%BeginProlog +/mpldict 7 dict def +mpldict begin +/m { moveto } bind def +/l { lineto } bind def +/r { rlineto } bind def +/box { +m +1 index 0 r +0 exch r +neg 0 r +closepath +} bind def +/clipbox { +box +clip +newpath +} bind def +/ellipse { +newpath +matrix currentmatrix 7 1 roll +translate +scale +0 0 1 5 3 roll arc +setmatrix +closepath +} bind def +%!PS-Adobe-3.0 Resource-Font +%%Title: Bitstream Vera Sans +%%Copyright: Copyright (c) 2003 by Bitstream, Inc. All Rights Reserved. +%%Creator: Converted from TrueType by PPR +25 dict begin +/_d{bind def}bind def +/_m{moveto}_d +/_l{lineto}_d +/_cl{closepath eofill}_d +/_c{curveto}_d +/_sc{7 -1 roll{setcachedevice}{pop pop pop pop pop pop}ifelse}_d +/_e{exec}_d +/FontName /BitstreamVeraSans-Roman def +/PaintType 0 def +/FontMatrix[.001 0 0 .001 0 0]def +/FontBBox[-182 -235 1287 928]def +/FontType 3 def +/Encoding StandardEncoding def +/FontInfo 10 dict dup begin +/FamilyName (Bitstream Vera Sans) def +/FullName (Bitstream Vera Sans) def +/Notice (Copyright (c) 2003 by Bitstream, Inc. All Rights Reserved. Bitstream Vera is a trademark of Bitstream, Inc.) def +/Weight (Roman) def +/Version (Release 1.10) def +/ItalicAngle 0.0 def +/isFixedPitch false def +/UnderlinePosition -213 def +/UnderlineThickness 143 def +end readonly def +/CharStrings 25 dict dup begin +/space{318 0 0 0 0 0 _sc +}_d +/parenleft{390 0 86 -131 310 759 _sc +310 759 _m +266 683 234 609 213 536 _c +191 463 181 389 181 314 _c +181 238 191 164 213 91 _c +234 17 266 -56 310 -131 _c +232 -131 _l +183 -54 146 20 122 94 _c +98 168 86 241 86 314 _c +86 386 98 459 122 533 _c +146 607 182 682 232 759 _c +310 759 _l +_cl}_d +/parenright{390 0 80 -131 304 759 _sc +80 759 _m +158 759 _l +206 682 243 607 267 533 _c +291 459 304 386 304 314 _c +304 241 291 168 267 94 _c +243 20 206 -54 158 -131 _c +80 -131 _l +123 -56 155 17 177 91 _c +198 164 209 238 209 314 _c +209 389 198 463 177 536 _c +155 609 123 683 80 759 _c +_cl}_d +/hyphen{361 0 49 234 312 314 _sc +49 314 _m +312 314 _l +312 234 _l +49 234 _l +49 314 _l +_cl}_d +/period{318 0 107 0 210 124 _sc +107 124 _m +210 124 _l +210 0 _l +107 0 _l +107 124 _l +_cl}_d +/zero{636 0 66 -13 570 742 _sc +318 664 _m +267 664 229 639 203 589 _c +177 539 165 464 165 364 _c +165 264 177 189 203 139 _c +229 89 267 64 318 64 _c +369 64 407 89 433 139 _c +458 189 471 264 471 364 _c +471 464 458 539 433 589 _c +407 639 369 664 318 664 _c +318 742 _m +399 742 461 709 505 645 _c +548 580 570 486 570 364 _c +570 241 548 147 505 83 _c +461 19 399 -13 318 -13 _c +236 -13 173 19 130 83 _c +87 147 66 241 66 364 _c +66 486 87 580 130 645 _c +173 709 236 742 318 742 _c +_cl}_d +/one{636 0 110 0 544 729 _sc +124 83 _m +285 83 _l +285 639 _l +110 604 _l +110 694 _l +284 729 _l +383 729 _l +383 83 _l +544 83 _l +544 0 _l +124 0 _l +124 83 _l +_cl}_d +/two{{636 0 73 0 536 742 _sc +192 83 _m +536 83 _l +536 0 _l +73 0 _l +73 83 _l +110 121 161 173 226 239 _c +290 304 331 346 348 365 _c +380 400 402 430 414 455 _c +426 479 433 504 433 528 _c +433 566 419 598 392 622 _c +365 646 330 659 286 659 _c +255 659 222 653 188 643 _c +154 632 117 616 78 594 _c +78 694 _l +118 710 155 722 189 730 _c +223 738 255 742 284 742 _c +359 742 419 723 464 685 _c +509 647 532 597 532 534 _c +532 504 526 475 515 449 _c +504 422 484 390 454 354 _c +446 344 420 317 376 272 _c +332 227 271 164 192 83 _c +_cl}_e}_d +/three{{636 0 76 -13 556 742 _sc +406 393 _m +453 383 490 362 516 330 _c +542 298 556 258 556 212 _c +556 140 531 84 482 45 _c +432 6 362 -13 271 -13 _c +240 -13 208 -10 176 -4 _c +144 1 110 10 76 22 _c +76 117 _l +103 101 133 89 166 81 _c +198 73 232 69 268 69 _c +330 69 377 81 409 105 _c +441 129 458 165 458 212 _c +458 254 443 288 413 312 _c +383 336 341 349 287 349 _c +202 349 _l +202 430 _l +291 430 _l +339 430 376 439 402 459 _c +428 478 441 506 441 543 _c +441 580 427 609 401 629 _c +374 649 336 659 287 659 _c +260 659 231 656 200 650 _c +169 644 135 635 98 623 _c +98 711 _l +135 721 170 729 203 734 _c +235 739 266 742 296 742 _c +}_e{370 742 429 725 473 691 _c +517 657 539 611 539 553 _c +539 513 527 479 504 451 _c +481 423 448 403 406 393 _c +_cl}_e}_d +/four{636 0 49 0 580 729 _sc +378 643 _m +129 254 _l +378 254 _l +378 643 _l +352 729 _m +476 729 _l +476 254 _l +580 254 _l +580 172 _l +476 172 _l +476 0 _l +378 0 _l +378 172 _l +49 172 _l +49 267 _l +352 729 _l +_cl}_d +/five{{636 0 77 -13 549 729 _sc +108 729 _m +495 729 _l +495 646 _l +198 646 _l +198 467 _l +212 472 227 476 241 478 _c +255 480 270 482 284 482 _c +365 482 429 459 477 415 _c +525 370 549 310 549 234 _c +549 155 524 94 475 51 _c +426 8 357 -13 269 -13 _c +238 -13 207 -10 175 -6 _c +143 -1 111 6 77 17 _c +77 116 _l +106 100 136 88 168 80 _c +199 72 232 69 267 69 _c +323 69 368 83 401 113 _c +433 143 450 183 450 234 _c +450 284 433 324 401 354 _c +368 384 323 399 267 399 _c +241 399 214 396 188 390 _c +162 384 135 375 108 363 _c +108 729 _l +_cl}_e}_d +/A{684 0 8 0 676 729 _sc +342 632 _m +208 269 _l +476 269 _l +342 632 _l +286 729 _m +398 729 _l +676 0 _l +573 0 _l +507 187 _l +178 187 _l +112 0 _l +8 0 _l +286 729 _l +_cl}_d +/V{684 0 8 0 676 729 _sc +286 0 _m +8 729 _l +111 729 _l +342 115 _l +573 729 _l +676 729 _l +398 0 _l +286 0 _l +_cl}_d +/a{{613 0 60 -13 522 560 _sc +343 275 _m +270 275 220 266 192 250 _c +164 233 150 205 150 165 _c +150 133 160 107 181 89 _c +202 70 231 61 267 61 _c +317 61 357 78 387 114 _c +417 149 432 196 432 255 _c +432 275 _l +343 275 _l +522 312 _m +522 0 _l +432 0 _l +432 83 _l +411 49 385 25 355 10 _c +325 -5 287 -13 243 -13 _c +187 -13 142 2 109 33 _c +76 64 60 106 60 159 _c +60 220 80 266 122 298 _c +163 329 224 345 306 345 _c +432 345 _l +432 354 _l +432 395 418 427 391 450 _c +364 472 326 484 277 484 _c +245 484 215 480 185 472 _c +155 464 127 453 100 439 _c +100 522 _l +}_e{132 534 164 544 195 550 _c +226 556 256 560 286 560 _c +365 560 424 539 463 498 _c +502 457 522 395 522 312 _c +_cl}_e}_d +/e{{615 0 55 -13 562 560 _sc +562 296 _m +562 252 _l +149 252 _l +153 190 171 142 205 110 _c +238 78 284 62 344 62 _c +378 62 412 66 444 74 _c +476 82 509 95 541 113 _c +541 28 _l +509 14 476 3 442 -3 _c +408 -9 373 -13 339 -13 _c +251 -13 182 12 131 62 _c +80 112 55 181 55 268 _c +55 357 79 428 127 481 _c +175 533 241 560 323 560 _c +397 560 455 536 498 489 _c +540 441 562 377 562 296 _c +472 322 _m +471 371 457 410 431 440 _c +404 469 368 484 324 484 _c +274 484 234 469 204 441 _c +174 413 156 373 152 322 _c +472 322 _l +_cl}_e}_d +/i{278 0 94 0 184 760 _sc +94 547 _m +184 547 _l +184 0 _l +94 0 _l +94 547 _l +94 760 _m +184 760 _l +184 646 _l +94 646 _l +94 760 _l +_cl}_d +/l{278 0 94 0 184 760 _sc +94 760 _m +184 760 _l +184 0 _l +94 0 _l +94 760 _l +_cl}_d +/m{{974 0 91 0 889 560 _sc +520 442 _m +542 482 569 511 600 531 _c +631 550 668 560 711 560 _c +767 560 811 540 842 500 _c +873 460 889 403 889 330 _c +889 0 _l +799 0 _l +799 327 _l +799 379 789 418 771 444 _c +752 469 724 482 686 482 _c +639 482 602 466 575 435 _c +548 404 535 362 535 309 _c +535 0 _l +445 0 _l +445 327 _l +445 379 435 418 417 444 _c +398 469 369 482 331 482 _c +285 482 248 466 221 435 _c +194 404 181 362 181 309 _c +181 0 _l +91 0 _l +91 547 _l +181 547 _l +181 462 _l +201 495 226 520 255 536 _c +283 552 317 560 357 560 _c +397 560 430 550 458 530 _c +486 510 506 480 520 442 _c +}_e{_cl}_e}_d +/n{634 0 91 0 549 560 _sc +549 330 _m +549 0 _l +459 0 _l +459 327 _l +459 379 448 417 428 443 _c +408 469 378 482 338 482 _c +289 482 251 466 223 435 _c +195 404 181 362 181 309 _c +181 0 _l +91 0 _l +91 547 _l +181 547 _l +181 462 _l +202 494 227 519 257 535 _c +286 551 320 560 358 560 _c +420 560 468 540 500 501 _c +532 462 549 405 549 330 _c +_cl}_d +/o{612 0 55 -13 557 560 _sc +306 484 _m +258 484 220 465 192 427 _c +164 389 150 338 150 273 _c +150 207 163 156 191 118 _c +219 80 257 62 306 62 _c +354 62 392 80 420 118 _c +448 156 462 207 462 273 _c +462 337 448 389 420 427 _c +392 465 354 484 306 484 _c +306 560 _m +384 560 445 534 490 484 _c +534 433 557 363 557 273 _c +557 183 534 113 490 63 _c +445 12 384 -13 306 -13 _c +227 -13 165 12 121 63 _c +77 113 55 183 55 273 _c +55 363 77 433 121 484 _c +165 534 227 560 306 560 _c +_cl}_d +/s{{521 0 54 -13 472 560 _sc +443 531 _m +443 446 _l +417 458 391 468 364 475 _c +336 481 308 485 279 485 _c +234 485 200 478 178 464 _c +156 450 145 430 145 403 _c +145 382 153 366 169 354 _c +185 342 217 330 265 320 _c +296 313 _l +360 299 405 279 432 255 _c +458 230 472 195 472 151 _c +472 100 452 60 412 31 _c +372 1 316 -13 246 -13 _c +216 -13 186 -10 154 -5 _c +122 0 89 8 54 20 _c +54 113 _l +87 95 120 82 152 74 _c +184 65 216 61 248 61 _c +290 61 323 68 346 82 _c +368 96 380 117 380 144 _c +380 168 371 187 355 200 _c +339 213 303 226 247 238 _c +216 245 _l +160 257 119 275 95 299 _c +70 323 58 356 58 399 _c +58 450 76 490 112 518 _c +148 546 200 560 268 560 _c +}_e{301 560 332 557 362 552 _c +391 547 418 540 443 531 _c +_cl}_e}_d +/t{392 0 27 0 368 702 _sc +183 702 _m +183 547 _l +368 547 _l +368 477 _l +183 477 _l +183 180 _l +183 135 189 106 201 94 _c +213 81 238 75 276 75 _c +368 75 _l +368 0 _l +276 0 _l +206 0 158 13 132 39 _c +106 65 93 112 93 180 _c +93 477 _l +27 477 _l +27 547 _l +93 547 _l +93 702 _l +183 702 _l +_cl}_d +/v{592 0 30 0 562 547 _sc +30 547 _m +125 547 _l +296 88 _l +467 547 _l +562 547 _l +357 0 _l +235 0 _l +30 547 _l +_cl}_d +/w{818 0 42 0 776 547 _sc +42 547 _m +132 547 _l +244 120 _l +356 547 _l +462 547 _l +574 120 _l +686 547 _l +776 547 _l +633 0 _l +527 0 _l +409 448 _l +291 0 _l +185 0 _l +42 547 _l +_cl}_d +/y{592 0 30 -207 562 547 _sc +322 -50 _m +296 -114 271 -157 247 -177 _c +223 -197 191 -207 151 -207 _c +79 -207 _l +79 -132 _l +132 -132 _l +156 -132 175 -126 189 -114 _c +203 -102 218 -75 235 -31 _c +251 9 _l +30 547 _l +125 547 _l +296 119 _l +467 547 _l +562 547 _l +322 -50 _l +_cl}_d +end readonly def + +/BuildGlyph + {exch begin + CharStrings exch + 2 copy known not{pop /.notdef}if + true 3 1 roll get exec + end}_d + +/BuildChar { + 1 index /Encoding get exch get + 1 index /BuildGlyph get exec +}_d + +FontName currentdict end definefont pop +%%EOF +end +%%EndProlog +mpldict begin +18 180 translate +576 432 0 0 clipbox +1.000 setgray +1.000 setlinewidth +0 setlinejoin +2 setlinecap +[] 0 setdash +0 0 m +0 432 l +576 432 l +576 0 l +closepath +gsave +fill +grestore +stroke +0.000 setgray +72 43.2 m +72 388.8 l +518.4 388.8 l +518.4 43.2 l +closepath +gsave +1.000 setgray +fill +grestore +stroke +0.000 0.000 1.000 setrgbcolor +gsave +446.4 345.6 72 43.2 clipbox +72 192.08 m +76.464 314.444 l +80.928 238.206 l +85.392 145.963 l +89.856 52.5249 l +94.32 177.605 l +98.784 244.507 l +103.248 225.898 l +107.712 141.274 l +112.176 101.132 l +116.64 221.273 l +121.104 220.387 l +125.568 198.393 l +130.032 110.626 l +134.496 87.2167 l +138.96 172.301 l +143.424 288.57 l +147.888 223.822 l +152.352 109.895 l +156.816 99.5877 l +161.28 161.557 l +165.744 327.85 l +170.208 226.413 l +174.672 119.61 l +179.136 160.455 l +183.6 170.923 l +188.064 276.783 l +192.528 252.279 l +196.992 93.6217 l +201.456 102.264 l +205.92 231.631 l +210.384 344.07 l +214.848 237.692 l +219.312 118.454 l +223.776 88.4453 l +228.24 156.313 l +232.704 288.34 l +237.168 265.415 l +241.632 167.558 l +246.096 89.9739 l +250.56 176.91 l +255.024 291.251 l +259.488 263.848 l +263.952 152.691 l +268.416 113.887 l +272.88 209.028 l +277.344 335.703 l +281.808 269.446 l +286.272 94.2113 l +290.736 103.596 l +295.2 177.029 l +299.664 270.441 l +304.128 238.945 l +308.592 118.646 l +313.056 125.076 l +317.52 184.406 l +321.984 271.919 l +326.448 271.253 l +330.912 119.814 l +335.376 72.1308 l +339.84 129.271 l +344.304 273.684 l +348.768 291.815 l +353.232 113.503 l +357.696 77.032 l +362.16 204.519 l +366.624 272.078 l +371.088 226.513 l +375.552 141.138 l +380.016 95.2778 l +384.48 204.455 l +388.944 287.641 l +393.408 229.498 l +397.872 126.356 l +402.336 106.437 l +406.8 210.134 l +411.264 265.254 l +415.728 240.776 l +420.192 105.556 l +424.656 141.974 l +429.12 200.065 l +433.584 290.119 l +438.048 258.193 l +442.512 168.972 l +446.976 59.1563 l +451.44 194.952 l +455.904 311.614 l +460.368 199.751 l +464.832 132.967 l +469.296 76.716 l +473.76 232.12 l +478.224 278.764 l +482.688 217.446 l +487.152 148.717 l +491.616 86.2078 l +496.08 175.329 l +500.544 272.56 l +505.008 227.057 l +509.472 80.2823 l +513.936 93.877 l +stroke +grestore +0.000 setgray +/BitstreamVeraSans-Roman findfont +12.000 scalefont +setfont +63.25 30.122 m +0 0.172 rmoveto +(0.0) show +0.500 setlinewidth +0 setlinecap +[1 3] 0 setdash +gsave +446.4 345.6 72 43.2 clipbox +183.6 43.2 m +183.6 388.8 l +stroke +grestore +[] 0 setdash +/o { gsave +newpath +translate +-0.5 0 m +-0.5 4 l +closepath +stroke +grestore } bind def +183.6 43.2 o +/o { gsave +newpath +translate +-0.5 -4 m +-0.5 0 l +closepath +stroke +grestore } bind def +183.6 388.8 o +174.975 30.122 m +0 0.172 rmoveto +(0.5) show +[1 3] 0 setdash +gsave +446.4 345.6 72 43.2 clipbox +295.2 43.2 m +295.2 388.8 l +stroke +grestore +[] 0 setdash +/o { gsave +newpath +translate +-0.5 0 m +-0.5 4 l +closepath +stroke +grestore } bind def +295.2 43.2 o +/o { gsave +newpath +translate +-0.5 -4 m +-0.5 0 l +closepath +stroke +grestore } bind def +295.2 388.8 o +286.708 30.122 m +0 0.172 rmoveto +(1.0) show +[1 3] 0 setdash +gsave +446.4 345.6 72 43.2 clipbox +406.8 43.2 m +406.8 388.8 l +stroke +grestore +[] 0 setdash +/o { gsave +newpath +translate +-0.5 0 m +-0.5 4 l +closepath +stroke +grestore } bind def +406.8 43.2 o +/o { gsave +newpath +translate +-0.5 -4 m +-0.5 0 l +closepath +stroke +grestore } bind def +406.8 388.8 o +398.433 30.278 m +0 0.172 rmoveto +(1.5) show +509.689 30.122 m +0 0.172 rmoveto +(2.0) show +272.442 14.419 m +0 1.578 rmoveto +(time \(s\)) show +57.594 38.661 m +0 0.172 rmoveto +(-3) show +[1 3] 0 setdash +gsave +446.4 345.6 72 43.2 clipbox +72 92.5714 m +518.4 92.5714 l +stroke +grestore +[] 0 setdash +/o { gsave +newpath +translate +0 0.5 m +4 0.5 l +closepath +stroke +grestore } bind def +72 92.5714 o +/o { gsave +newpath +translate +-4 0.5 m +0 0.5 l +closepath +stroke +grestore } bind def +518.4 92.5714 o +57.828 88.118 m +(-2) show +[1 3] 0 setdash +gsave +446.4 345.6 72 43.2 clipbox +72 141.943 m +518.4 141.943 l +stroke +grestore +[] 0 setdash +/o { gsave +newpath +translate +0 0.5 m +4 0.5 l +closepath +stroke +grestore } bind def +72 141.943 o +/o { gsave +newpath +translate +-4 0.5 m +0 0.5 l +closepath +stroke +grestore } bind def +518.4 141.943 o +57.734 137.568 m +(-1) show +[1 3] 0 setdash +gsave +446.4 345.6 72 43.2 clipbox +72 191.314 m +518.4 191.314 l +stroke +grestore +[] 0 setdash +/o { gsave +newpath +translate +0 0.5 m +4 0.5 l +closepath +stroke +grestore } bind def +72 191.314 o +/o { gsave +newpath +translate +-4 0.5 m +0 0.5 l +closepath +stroke +grestore } bind def +518.4 191.314 o +61.953 186.775 m +0 0.172 rmoveto +(0) show +[1 3] 0 setdash +gsave +446.4 345.6 72 43.2 clipbox +72 240.686 m +518.4 240.686 l +stroke +grestore +[] 0 setdash +/o { gsave +newpath +translate +0 0.5 m +4 0.5 l +closepath +stroke +grestore } bind def +72 240.686 o +/o { gsave +newpath +translate +-4 0.5 m +0 0.5 l +closepath +stroke +grestore } bind def +518.4 240.686 o +62.781 236.311 m +(1) show +[1 3] 0 setdash +gsave +446.4 345.6 72 43.2 clipbox +72 290.057 m +518.4 290.057 l +stroke +grestore +[] 0 setdash +/o { gsave +newpath +translate +0 0.5 m +4 0.5 l +closepath +stroke +grestore } bind def +72 290.057 o +/o { gsave +newpath +translate +-4 0.5 m +0 0.5 l +closepath +stroke +grestore } bind def +518.4 290.057 o +62.438 285.604 m +(2) show +[1 3] 0 setdash +gsave +446.4 345.6 72 43.2 clipbox +72 339.429 m +518.4 339.429 l +stroke +grestore +[] 0 setdash +/o { gsave +newpath +translate +0 0.5 m +4 0.5 l +closepath +stroke +grestore } bind def +72 339.429 o +/o { gsave +newpath +translate +-4 0.5 m +0 0.5 l +closepath +stroke +grestore } bind def +518.4 339.429 o +62.25 334.89 m +0 0.172 rmoveto +(3) show +61.625 384.425 m +(4) show +52.594 191.453 m +gsave +90 rotate +0 1.578 rmoveto +(volts \(V\)) show +grestore +1.000 setlinewidth +2 setlinecap +72 43.2 m +518.4 43.2 l +518.4 388.8 l +72 388.8 l +72 43.2 l +stroke +/BitstreamVeraSans-Roman findfont +14.000 scalefont +setfont +232.848 395.712 m +0 2.906 rmoveto +(A noisy sine wave) show + +end +showpage Added: trunk/py4science/workbook/fig/noisy_sine.png =================================================================== (Binary files differ) Property changes on: trunk/py4science/workbook/fig/noisy_sine.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/py4science/workbook/files_etc.tex =================================================================== --- trunk/py4science/workbook/files_etc.tex (rev 0) +++ trunk/py4science/workbook/files_etc.tex 2007-10-20 17:57:36 UTC (rev 3971) @@ -0,0 +1,117 @@ +\section{Working with files, the web, arrays, etc\dots} +\label{sec:working_with_files} + +This section is a general overview to show how easy it is to load +and manipulate data on the file system and over the web using python's +built in data structures and numpy arrays. The goal is to exercise +basic programming skills like building filename or web addresses to +automate certain tasks like loading a series of data files or +downloading a bunch of related files off the web, as well as to +illustrate basic numpy and pylab skills. + +\subsection{Loading and saving ASCII data} +\label{sec:ascii_data} + +The simplest file format is a plain text ASCII file of numbers. +Although there are many better formats out there for saveing and +loading data, this format is extremely common because it has the +advantages of being human readable, and thus will survive the test of +time as the \textit{en vogue} programming languages, analysis +applications and data formats come and go, it is easy to parse, and it +is supported by almost all languages and applications. + +In this exercise we will create a data set of two arrays, the first +one regularly sampled time \textit{t} from 0..2 seconds with 20~ms +time step , and the second one an array \texttt{v} of sinusoidal +voltages corrupted by some noise. Let's assume the sine wave has +amplitude 2~V, frequency 10~Hz, and zero mean Gaussian distrubuted +white noise with standard deviation 0.5~V. Your task is to write two +scripts. + +The first script should create the vectors \texttt{t} and \texttt{v}, +plot the time series of \texttt{t} versus \texttt{v}, save them in a +two dimensional numpy array \texttt{X}, and then dump the array +\texttt{X} to a plain text ASCII file called +\texttt{'noisy_sine.dat'}. The file will look like (not identical +because of the noise) + +\begin{verbatim} +0.000000000000000000e+00 1.550947826934816025e-02 +2.000000000000000042e-02 2.493944587057004725e+00 +4.000000000000000083e-02 9.497694074551737975e-01 +5.999999999999999778e-02 -9.185779287524413750e-01 +8.000000000000000167e-02 -2.811127590689064704e+00 +... and so on +\end{verbatim} + +Here is the exercise skeleton of the script to create and plot the +data file + +\lstinputlisting[label=code:noisy_sine_skel,caption={IGNORED}]{skel/noise_sine_skel.py} + +and the graph will look something like Figure~\ref{fig:noisy_sine} + +\begin{center}% +\begin{figure} +\begin{centering}\includegraphics[width=4in]{fig/noise_sine}\par\end{centering} + + +\caption{\label{fig:noisy_sine}A 10~Hz sine wave corrupted by noise} +\end{figure} +\par\end{center} + +The second part of this exercise is to write a script which loads data +from the data file into an array \texttt{X}, extracts the columns into +arrays \texttt{t} and \texttt{v}, and computes the RMS +(root-mean-square) intensity of the signal using the \textt{load} +command. + + +\subsection{Loading and saving binary data} +\label{sec:binary_data} + +ASCII is bloated and slow for working with large arrays, and so binary +data should be used if performance is a consideration. To save the +array \texttt{X} in binary form, use the numpy \texttt{tostring} method + +\begin{lstlisting} +# open the file for writing binary and write the binary string +file('../data/binary_data.dat', 'wb').write(X.tostring()) +\end{lstlisting} + +\noindent This data can later be loaded into a numpy array using +\texttt{fromstring}. This method takes two arguments, a string and a +data type (note that numarray users can use \texttt{fromfile} which is +more efficient for importing data directly from a file). + +\lstinputlisting{code/load_binary_data.py} + +\noindent Note that although Numpy and numarray use different +typecode arguments (Numeric uses strings whereas numarray uses type +objects), the matplotlib.numpy compatibility layer provides symbols +which will work with either \rc{numpy} rc setting. + +\subsection{Processing several data files} +\label{sec:multiple_files} + +Since python is a programming language \textit{par excellence}, it is +easy to process data in batch. When I started the gradual transition +from a full time \matlab\ user to a full time python user, I began +processing my data in python and saving the results to data files for +plotting in \matlab. When that became too cumbersome, I decided to +write matplotlib so I could have all the functionality I needed in one +environment. Here is a brief example showing how to iterate over +several data files, named \fname{basename001.dat, basename002.dat, + basename003.dat, ... basename100.dat} and plot all of the traces to +the same axes. I'll assume for this example that each file is a 1D +ASCII array, which I can load with the \texttt{load} command. + +\begin{lstlisting} +hold(True) # set the hold state to be on +for i in range(1,101): #start at 1, end at 100 + fname = 'basename%03d.dat'%i # %03d pads the integers with zeros + x = load(fname) + plot(x) +\end{lstlisting} + + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |