Friday, May 9, 2014

A Chart for Words and things

I wandered into a discussion on Google+ recently, regarding a particular format of word alternative charts.

It was basically a set of concentric annular segments. I originally suggested a macro in either GIMP or an office product. Rather than just recommend and run I thought I'd actually put my money here my mouth is and have a go at it. As it turns out, neither of those actually appealed to a quick and dirty solution late at night, so I went with generating an SVG image directly from python.

Those more familiar with using script-fu or the Libre-Office scripting tools could probably integrate this into one of those (and please feel free to us my code to do so) fairly quickly.

Here's a sample result, exported to png:


For a colourless, scalable version try this link. Blogger wont insert an svg as an inline image, but you can save it to your machine and convert it to whatever format you like.

You can get the source code here. It was thrown together very quickly, so it's far from perfect, but it should be commented well enough to make basic changes very straightforward. I've only tested it on my Ubuntu machine, but it should work on any python install, with the addition of the svgwrite package.

Edit: I created a libre office drawing with this as a background, and rotated text objects, for (reasonably) easy editing.  The odt file is in a shared google drive folder.

If anything is missing, inaccessible, or unclear, let me know. Preferably on Google+, but a message here is OK too!

# Concentric segment plot utility
# Created by John Tocher, 09/05/2014
#
# Built for generating a template for a particular type of word-chart
import svgwrite
import math
import os
from svgwrite import cm, mm
# Put your paths here
output_path="/home/john/Temp"
output_file_name = "my_output_file.svg"
# basic drawing settings
ring_colour = 'black'
line_thickness = 2
# How many times to divide each subring, can be the same or different
# This number describes how many sectors each sector will be divided into
# If they're not multipes if the ones inside them, the segment lines won't
# meet neatly, but it will still draw just fine!
annulus_segments = [ 6, 30 , 60 ]
# Ring radii
ring_radii = [ 20 , 40 , 60 ]
# Ring Colours
ring_colours = [ "red" , "green" , "blue" ]
# A Scale factor, not really necessary for svg, but can make testing simpler
global_scale_factor = 10
# Start of main program
# You shouldn't have to edit much below here if you just want variations on the original
base_radius = int(ring_radii[-1]) * global_scale_factor
annulus_count=0
annulus_radius=[]
# Origin
org_x=ring_radii[-1]*global_scale_factor
org_y=org_x
print "Scaled origin is {0},{1}".format(org_x,org_y)
print "Max Radii is {0}".format(ring_radii[-1])
outputfile=os.path.join(output_path,output_file_name)
dwg = svgwrite.Drawing(outputfile, profile='tiny')
outlines = dwg.add(dwg.g(id='outlines', stroke=ring_colour, stroke_width=line_thickness, fill='none'))
# First we'll draw and fill the circles
colour_count=-1
last_radius=0
for this_radius in reversed(ring_radii):
outlines.add(dwg.circle((org_x,org_y),this_radius*global_scale_factor, fill=ring_colours[colour_count] ))
colour_count-=1
annulus_count=0
last_radius=0
# Now we'll draw the segment dividing lines
for this_radius in ring_radii:
sectors_for_this_annulus = annulus_segments[annulus_count]
each_angle=2*math.pi/sectors_for_this_annulus
for sector_count in range(0 , sectors_for_this_annulus ):
this_angle = sector_count*each_angle
inner_x = last_radius * math.cos(this_angle) * global_scale_factor
inner_y = last_radius * math.sin(this_angle) * global_scale_factor
outer_x = this_radius * math.cos(this_angle) * global_scale_factor
outer_y = this_radius * math.sin(this_angle) * global_scale_factor
outlines.add(dwg.line( (org_x+inner_x,org_x+inner_y) , (org_x+outer_x,org_y+outer_y) ))
print "Annulus {0} Sector {1} angle {2} from ( {3},{4} ) to ( {5},{6} )".format(annulus_count, sector_count, this_angle, inner_x , inner_y, outer_x, outer_y)
annulus_count+=1
last_radius = this_radius
dwg.save()




Tuesday, November 13, 2012

Source material for eBooks

Executive Summary:

I purchased an eBook from which seems to contain a large number of typographical errors. I'm quite certain that the errors aren't from the author in question. Apart from the fact that . I'd like to get to the bottom of this by polling readers who've purchased the book from other vendors, or perhaps even in other media.

Details

The book is "The Diamond Age" by Neal Stephenson.
I purchased the eBook in ePub format from kobo books on the 4th Nov 2012.

I've purchased books from kobo in the past that have been OK. I've also purchased other eBooks by Neal Stephenson which have not had the same problem.

Some of the errors are repeated several times, and look like they could almost be speech to text errors, but tI don't imagine that being a terribly useful tool for a Science Firction title. They could also be some sort of OCR error, but again, I'm not sure about the consistency there, either.

How you can help

Check the errors below in your eBook/Book and let me know one way or another whether or not they are present! Let me know whether or not you want me to attribute your response(s) personally.

Thanks!

List of suspected errors so far:

The page numbers are as given on my eReader for the ePub version. I've tried to include complete sentences or at least a large enough quote to make it easy to search for.

1. Page 12 - "The logo of nis favorite meedfeed coalesced on the page." - "nis" instead of "his"
2. Page 19 - "Fiona Hackworth had been wandering through the Royal Ecological Conservatory bracketed by her parents, who hoped mat in this way they could keep mud and vegetable debris off her skirts." - "mat" instead of "that"
3. Page 24 - "MPS made consumer goods and ITL made real estate, which was, as everywhere me real money was." - Perhaps "me" instead of "the"
4. Page 25 - ""This tenuous grasp of American culture might have been owing to the fact mat his parents home-schooled him up to the age of fourteen. - "mat" instead of "that"
5. Page 25 - "the Finkle-McGraws belonged to a Methodist church, a Roman Catholic church, and a tiny synagogue mat met in a rented room in Sioux City." -  "mat" instead of "that"
6. Page 26 - "He earned some repute as a wrestler and cross-country runner, but never exploited it for sexual favors, which would have been easy enough in die promiscuous climate of the times." - "die" instead of "the"
7. Page 26 - "—reporters from the coasts kept showing up and announcing, with some bewilderment, mat there had been no looting." - "mat" instead of "that"
8. Page 26 - "Finkle-McGraw began to develop an opinion that was to shape his political views in later years, namely, mat while people were not genetically different, they were culturally as different as they could possibly be," - "mat" instead of "that"
9. Page 27 - "The held was an obscure one then, the clients tended to be large research institutions, and practical applications seemed far away." - "held" instead of (I suspect) "field"
10. Page 29 - "I am alluding to things well known to me, as they made my own childhood less man idyllic." - "man" instead of "than"
11,12,13. Page 29 - "My life was not without periods of excessive, unreasoning discipline, usally imaposed capriciosly by those responsible for laxity in the first place." - Spelling errors on 3 consecutive words.
14. Page 30 - "and just like mat, the man took some hard ucus out of his pocket and handed them over—and then actually thanked him as he backed away." - "mat" instead of "that"
15. Page 37 - "As mis territory belongs to a nation-state that recognizes the Common Economic Protocol, you are entitled to a hearing of any such charges within the judicial framework of the nation-state in question" - "mis" for "this"|

As it turns out, getting my annotations from the nook back onto the PC was a bit of a pain, but I'm sure this list will be enough to start with.









Wednesday, January 19, 2011

eReaders and eBooks. eEk.

This has been re-formatted slightly from an email I sent to a family member, as I'm probably going to be ordering two of whatever we decide on. I'm leaning strongly towards the Nook at the moment, but I'm prepared to have my mind changed. Keep in mind, this is written from, and mostly for, an Australian perspective.

Let me know if anything is unclear, or I've missed anything that's important to you.

Intro:

I originally narrowed my choices down to 3 models:
1. The Amazon Kindle 3: Probably the current market leader. ( Amazon link )
2. The Barnes and Noble "Nook". ( B&N link )
3. The Kobo reader ( Kobo link, A&R link )

They all have more or less identical reading areas, 6 inch / 15.2 cm diagonal , 600 x 800 pixel screen with 16 levels of gray. I've not considered any of the full-colour options, as I'd like to use this out-and about, or while away from time to time, so good battery life is important. There are other readers out there, but none of them looked compelling to me, feel free to suggest others if you think I've missed something great.

WiFi or WiFi+3G?

The first choice was whether to go WiFi only, or WiFi+3G. WiFi only means you need to have access to a WiFi network to buy/download new books from the online stores. 3G means the unit has a SIM card and phone module embedded, which allows you to purchase anywhere there is phone coverage. This sounds good, but I decided against it for a few reasons:
  • It makes the unit more expensive.
  • It is likely to reduce battery life.
  • You're usually limited to using the manufacturers eBook store over the 3G connection.
  • I doubt I'll ever be completely stuck for reading material and absolutely have to have a new book right now.
  • Many smart phones can be turned into a mobile WiFi hotspot anyway, so you connect to the internet via your phone, and your eReader connects to the phone's WiFi. (Update - this is trivial, but I find I don't do it all that often, I do most of my book management and purchasing at home)

Battery life:

These are manufacturers claims, I don't know how accurate they are, but if true, all are OK by me. I don't think I could be away from power for much more than a week, so they're all acceptable.

1 Kindle: Up to month.
2. Nook: 10 days.
3. Kobo: 2 weeks or 10,000 page turns.

Formats:

1 Kindle : azw (Amazon proprietary format), pdf, html, mp3 audio. Notably - no ePub
2. Nook: ePub, pdf, html, mp3 audio. Also does pdb.
3. Kobo: ePub, pdf. No html, no audio.

The Nook and Kobo are very similar. They both do ePub, and pdf as their main formats, and don't to azw, which is the Kindles default format. The kindle doesn't do ePub. There are tools around to to conversions and such, but this is based on out-of-te-box functionality.

Libraries here seem to be all using ePub, so if you plan to use walk-in services from libraries, the Kindle won't cut it.This is reasonably important in my opinion.

Storage:

Realistically, they all have enough internal storage to hold metric bucket-loads of books, it's mostly text, after all. However, I like the idea of removable storage, and if you do want to use it for music playback, it's some extra headroom.

1. Kindle: 4 GB internal, not expandable.
2. Nook: 2 GB Internal, microSD card slot, up to 16GB
3. Kobo: 1GB Internal, SDHC card slot, up to 32 GB

Phone Apps:

These are apps which, strangely enough, run on your phone, allowing you to read from your collection when you don't have your device. I kind of like this idea, and in I've already downloaded the Nook and Kobo Android versions and had a bit of a play with them, downloading and reading some free eBooks. Certainly handy, but not critical. They've all got good solutions here as far as I'm concerned. I've read entire books on my phone and even the old palm, so in a pinch, it's good to have.

1. Kindle:Android, Blackberry, iPad, iPhone, Mac, Windows, Windows Phone 7
2. Nook: Android, iPad, iPhone, PC
3. Kobo: Android, Blackberry, iPhone, Palm

Web Features:

The Kindle and Nook both have web browsers, the Kobo doesn't. You're never going to use one of these devices as a serious internet tablet device, but I like the idea of being able to get on the web in some fashion, plus I have some ideas for using it at home for interacting with my home automation setup and such.

Other features:

The Kindle is the only one of the three to do text-to-speech. Not a big deal for me personally, I'm a podcast junkie anyway, generally having at least one or two other audio capable devices nearby, but a nice feature I guess.

The Nook has the extra colour touchscreen for navigation. Cute, and good for recognising/browsing book covers, although I suspect it will have a small effect on battery life.

Cost:

1 Amazon Kindle. Amazon will ship here. Their web site say it should be US $155 shipped. There are also people based here re-selling. Approx $240 per unit in Sydney, I'm not sure why the big difference, the exchange rate it pretty good at the moment.
2. Nook: Not available locally. B&N don't ship to Australia. Purchasing on-line elsewhere, I can get two of them here for just approx $206 each.
3. Kobo: Nice in that you can buy them retail in Australia. Angus and Robertson have them for $179

eBook Stores:

I picked about 20-30 authors and titles, and checked Amazon, Barnes and Noble, the Kobo bookstore and Borders. Prices and availability vary a lot. Prices in the US stores are typically a lot cheaper than the Australian equivalents. Amazon and B&N had the best ranges and prices by my estimation, although there may be a bit of technical messing about to purchase directly from the US stores, but I've got that more-or-less sorted out. Both the Nook and Kobo do ePub (with DRM), but you could transfer titles from any store to either.

Other links:

--
John

Saturday, July 17, 2010

More than the sum of it's singles

Listened to a couple of whole albums on the 2 hour trip back from my parents' place tonight. Was listening to Live's "The distance to here" and thought to myself "There's scarcely even a sniff of filler on this disc". It an actual album that works end-to-end, in fact probably more so than as a bunch of individual tracks.

So do (m)any young-uns buys or listen to albums these days, or has the 99c track on iTunes destroyed this experience for future generations?

Here endeth the old-guy-back-in-my-day rant. Feel free to go all internet-music-critic if you must, but the particular album isn't really the point. Get off my lawn.

Monday, April 12, 2010

Little LEDs and Spaceships

I was recently asked by a friend about helping to dress up some models for table top gaming. Putting small electronic bits'n'bobs'n'batteries inside various objects is something I'm not unfamiliar with, but I hadn't attempted this particular operation before.


The models aren't truly tiny, so I could use 3mm diameter LEDs for the undercarriage lights, and 5 diameter mm ones for the engine lights.


Overall, it think it turned out not too badly, although I haven't yet had any feedback as to how he went in the painting/decorating section yet. If nothing else, he should definitely be in the running for the "most liberal use of hot melt glue" category.

I've put a few more detailed pics below for those that care to get up close and personal. The top two are a little blurry as I turned off the flash to better show the LED's, but was too lazy to set up the tripod. The detail shots are all sharper.











Not shown are the battery packs. I used a 6V battery a little thinner than a AAA and about a third the length (9.5 mm diameter by 15 mm). I used heat shrink hold on the leads to make it into a flying-lead version so as to connect to the mini terminal blocks, for a solder-less battery swap for the end user.

Sunday, March 7, 2010

Image Processing with Python

I needed to turn this:



into this:



Why? Well, my wife wanted to paste smiley faces onto some triangles, rectangles and other shapes. The set with the outline is great, but she wanted to put faces onto triangles, rectangle's and some other shapes too. (She's a teacher, the shapes were warring, harmnony day is approachng and, and ..... it's complicated, trust me). Anyway, the borders looked a little odd.

As there were 60 of them to do (15 expressions in 4 different colours), I started thinking I'd figure out how to do some python scripting from inside GIMP, but after half an hour of futzing about, I decided that was too messy, and just decided to process the images directly. This is pretty easy actually. One of python's included batteries is the "Image" library.

I decided to tackle it thusly; modify any pixels within a specified annulus to transparent. I originally intended to check that the pixel was black before modifying it, but I forgot, and in this case, it worked just fine anyway.

Here's the code I used:

# RemoveAnnulus_01.py
# Removes a dark circle from smiley faces
# Replaces black pixels in a specified annulus with transparency
# Doesn't do anti-aliasing

import os
import sys
import Image
import math

# Parameters to modify pixels in an annulus
xMid=53 # Centre position
yMid=53 # (origin)
rInner=45.0 # Inner radius
rOuter=54.0 # Outer radius
xMax=106 # (Image size)-1
yMax=106

inputFile=sys.argv[1] # Input image file
outputFile=sys.argv[2] # Output file, will be overwritten if it exists

thisImage = Image.open(inputFile)
pixelArray=thisImage.load() # Use load method for pixel addresing mode

try:
reportMessage="OK"
for thisX in range(0,xMax):
for thisY in range(0,yMax):
dX=float(xMid-thisX)
dY=float(yMid-thisY)
thisRad = math.sqrt((dX*dX + dY*dY))
if ( (thisRad>rInner ) and (thisRad
pixelArray[thisX,thisY]=(0,0,0,0)

except IOError:
reportMessage="Failed"

thisImage.save(outputFile, "PNG")

print "%s:Processing [%s] to [%s]" % ( reportMessage,inputFile,outputFile )


I've not shown the script for iterating through the 60 different files, but that's not really the point of this post. This code works with two command line arguments, the input file, and the destination file.

BTW, none of this is meant as a slight on the GIMP's scripting capabilities, I just have little experience with them, and decided to go with something more familiar.

Monday, March 1, 2010

A Cyberspace Independence Declaration

The "This Week in Google" podcast I just listened to mentioned the "Cyberspace Independence Declaration", written by John Perry Barlow. Leo read some excerpts and I thought a link to an audio version I enjoyed would be in order.

Link to MP3 audio, ~5 MB.

The reading is by Jan Ruback, and included as a bonus chapter at the end of his reading of Cory Doctorow's collectedion, Content. (Highly recommended, BTW) It's available a variety of audio formats on this internet archive page, the second bonus item after the numbered chapters. You can also play it directly from the embedded player on the page if you're so inclined (It's chapter 32 in the player).

The full text version is available, with a little background on the eff site. Here's the obligatory wikipedia article.