Shallow Thoughts

Akkana's Musings on Open Source Computing, Science, and Nature.

Wed, 16 May 2012

Ring of Fire: 2012 annular eclipse

[Solar annular eclipse of January 15, 2010 in Jinan, Republic of China, by A013231 on Wikimedia Commons.] This Sunday, May 20th, the western half of the US will be treated to an annular solar eclipse.

Annular means that the moon is a bit farther away than usual, so it won't completely cover the sun even if you travel to the eclipse centerline. Why? Well, the moon's orbit around the earth isn't perfectly circular, so sometimes it's farther away, sometimes nearer. Remember all the hype two weeks ago about the "supermoon", where it was unusually close at full moon? The other side of that is that during this eclipse, at new moon, the moon is unusually far away, and therefore a little smaller, not quite big enough to cover the sun.

Since the sun will never be totally covered, make sure you have a safe solar filter for this one -- don't look with your naked eyes! You want a solar filter anyway, if you have any kind of telescope or even binoculars, because of next month's once-in-a-lifetime Venus transit (I'll write about that separately). But if you don't have a solar filter and absolutely can't get one in time, read on -- I'll have some suggestions later even for people without any sort of optical aid.

But first, the path of the eclipse. Here in the bay area, we're just a bit south of the southern limit of the annular path, which passes just south of the town of Redway, through Covelo, just south of Willows, then just misses Yuba City and Auburn. If you want to be closer to the centerline, go camping at Lassen National Park or Lake Shasta, or head to Reno or Tahoe If you're inclined to travel, NASA has a great interactive 2012 eclipse map you can use to check out possible locations.

Even back in the bay area, we still get a darn good dinner show. The partial eclipse starts at 5:17 pm PDT, with maximum eclipse at 6:33. The sun will be 18 degrees above the horizon at that point, and 89% eclipsed. Compare that with 97% for a site right on the centerline -- remember, since this is an annular eclipse, no place sees 100% coverage. The partial eclipse ends at 7:40 -- still well before sunset, which isn't until 8:11.

Photographers, if you want a shot of an annular eclipse as the sun sets, you'll need to head east, to Albuquerque, NM or Lubbock, TX. A little before sunset, the centerline also crosses near a lot of great vacation spots like Bryce, Zion and Canyon de Chelly.

[eclipse viewed through leaves] I mentioned that even without a solar filter, there are ways of watching the eclipse. The simplest is with a pinhole. You don't need to use an actual pin -- the size and shape of the hole isn't critical, as you can see in this image of the sun through the leaves of a tree during a 2005 eclipse in Malta. If you don't have a leafy tree handy, you can even lace your fingers together and look at the shadow of your hands. This eclipse will be very low in the sky, continuing through sunset, so you may need to project its shadow onto a wall rather than the ground.

If you have some time to prepare, take a piece of cardboard and punch a few holes through it. Try different sizes -- an actual pinhole, a BBQ skewer, a 3-hole punch, maybe even bigger holes up to the size of a penny. You might also try using aluminum foil -- you can get very clean circular holes that way, which might give a crisper image. Here's a good page on eclipse pinhole projection. What works best? I don't remember! It's been a very long time since the last eclipse here! Do the experiment! I know I will be.

[Solar projection with a Dobsonian] If you do have a telescope or binoculars but couldn't get a solar filter in time, don't despair. Instead of looking through the eyepiece, you can project the sun's image onto a white screen or even the ground or a wall. Use a cheap, low-power eyepiece -- any eyepiece you use for solar projection will get very hot, and you don't want to risk ruining a fancy one.

Point the telescope at the sun -- it's easy to tell when it's lined up by watching the shadow of the telescope -- and rotate the eyepiece so that it's aimed at your screen, which can be as simple as a sheet of paper. Be careful where that eyepiece is aimed -- make sure no one can walk through the path or put their hand in the way, and if you have a finderscope, make sure it's covered. This solar projection method works with binoculars too, but you'll want to mount them on a tripod so you don't have to hold them the whole time.

Of course, another great way to watch the eclipse is with your local astronomy club. I expect every club in the bay area -- and there are a lot of them -- will have telescopes out to share the eclipse with the public. So check with your local club -- San Jose Astronomical Association, Peninsula Astronomical Society, San Francisco Sidewalk Astronomers, San Francisco Amateur Astronomers, or any of the others on the AANC's list of Amateur Astronomy Clubs in Northern California or the SF Chronicle's list of astronomy clubs.

This eclipse should be pretty cool -- and a great chance to test out your solar equipment before next month's Venus transit.

When I went to put the event on my wall calendar last month, I discovered the calendar already had an entry for May 20: it's the start of Bear Awareness Week. So if you head up to Lassen or Shasta to watch the eclipse, be sure to be aware of the bears! (Also, maybe I should get a calendar that's a little more in tune with the sky.)

Tags: , ,
[ 20:12 May 16, 2012    More science/astro | permalink to this entry | comments ]

Sat, 12 May 2012

Downloading Adobe-protected books to a Nook using Linux

University of Chicago Press has a Carl Zimmer book, A Planet of Viruses, as their free monthly e-book.

I know Zimmer is a good writer. but the ebook, despite being free, is encumbered with Adobe's version of DRM, which unlocks via a Windows or Mac program. I use Linux, and wanted to read the book on a Nook. Was I out of luck?

Happily, the instruction page they sent when I signed up for the book helpfully included a section for Linux users. Hooray, U. Chicago! It said Adobe Digital Editions will run under Wine, the Windows emulator. I'd been meaning to try that anyway, and a Carl Zimmer book seemed like the perfect excuse.

And overall, it worked pretty well, with only a few snags. Here are the steps I had to follow:

Authorizing a book using Adobe Digital Editions in Linux on Wine

Install wine (on Ubuntu, I used apt-get install wine).

Download the Adobe Digital Editions setup.exe

Run: wine setup.exe (this should install ADE inside your .wine directory)

Copy the file, e.g. URLLink.acsm, into .wine/drive_c/My\ Documents/ Don't bother trying to open it with ADE -- the program won't open anything except PDF and epub. Curiously, the only ways to open the file from ADE are to drag the file onto the ADE window or to pass it as a commandline argument:
wine start .wine/drive_c/My\ Documents/URLLink.acsm

Now ADE should download your book and display it. You can read it there, if you want. But you won't want to -- it's not a good reading interface.

Authorizing a device with Adobe Digital Editions under Wine

Now how do you get it into your ebook reader? ADE running under Wine doesn't recognize devices such as ebook readers. so nothing will be copied automatically. But you can copy it manually.

In theory, the drive letter should stay mapped, so you should be able to use it for opening future books. Just remember to mount your device to the same location before running ADE under wine.

Tags: , ,
[ 10:03 May 12, 2012    More linux | permalink to this entry | comments ]

Sun, 06 May 2012

Playing an MP3 file from an Android app

I've mostly been enormously happy with my upgrade from my old Archos 5 to the Samsung Galaxy Player 5.0. The Galaxy does everything I always wanted the Archos to do, all those things the Archos should have done but couldn't because of its buggy and unsupported Android 1.6.

That is, I've been happy with everything except one thing: my birdsong app no longer worked.

I have a little HTML app based on my "tweet" python script which lets you choose from a list of birdsong MP3 files. (The actual MP3 files are ripped from the excellent 4-CD Stokes Field Guide to Western Bird Songs set.) The HTML app matches bird names as you type in characters. (If you're curious, an earlier test version is at tweet.html.)

On the Archos, I ran that under my WebClient Android app (I had to modify the HTML to add a keyboard, since in Android 1.6 the soft keyboard doesn't work in WebView text fields). I chose a bird, and WebView passed off the MP3 file to the Archos' built-in audio player. Worked great.

On the Samsung Galaxy, no such luck. Apparently Samsung's built-in media player can only play files it has indexed itself. If you try to use it to play an arbitrary file, say, "Song_Sparrow.mp3", it will say: unknown file type. No matter that the file ends in .mp3 ... and no matter that I've called intent.setDataAndType(Uri.parse(url), "audio/mpeg"); ... and no matter that the file is sitting on the SD cad and has in fact been indexed already by the media player. You didn't navigate to it via the media player's UI, so it refuses to play it.

I haven't been able to come up with an answer to how to make Samsung's media player more flexible, and I was just starting a search for alternate Android MP3 player apps, when I ran across Play mp3 in SD Card, using Android's MediaPlayer and Error creating MediaPlayer with Uri or file in assets which gave me the solution. Instead of using an intent and letting WebView call up a music application, you can use an Android MediaPlayer to play your file directly.

Here's what the code looks like, inside setWebViewClient() which is itself inside onCreate():

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                if (url.endsWith(".mp3")) {
                    MediaPlayer mediaPlayer = new MediaPlayer();
                    try {
                        mediaPlayer.setDataSource(getApplicationContext(), Uri.parse(url));
                        mediaPlayer.prepare();
                        mediaPlayer.start();
                    }
                    catch (IllegalArgumentException e) { showMessage("Illegal argument exception on " + url); }
                    catch (IllegalStateException e) { showMessage("Illegal State exception on " + url); }
                    catch (IOException e) { showMessage("I/O exception on " + url); }
                }
            }

showMessage() is my little wrapper that pops up an error message dialog. Of course, you can handle other types, not just files ending in .mp3.

And now I can take the Galaxy out on a birdwalk and use it to help me identify bird songs.

Tags: , , ,
[ 13:28 May 06, 2012    More programming | permalink to this entry | comments ]

Wed, 02 May 2012

Extremely strange seatbelt warning sticker

I bought a Miata yesterday! My new baby. It's a 2000, in a lovely color Mazda calls "twilight blue mica". (You can see Miata pictures here, if you're so inclined.)

I'd forgotten how much nicer sports cars are to drive. I retired my last X1/9 more than a year ago, and have been driving mushy street vehicles since then. The Miata surprises me every time I get into it with its immediacy -- throttle, brake, steering, everything happens now.

It does have some used-car glitches that I need to sort out (some of them maybe even severe), but in general it's a great car: in stock trim it handles a lot like the street-prepared X1/9, even on crappy Kumho tires. Of course, that could be new owner infatuation talking. Ask me again in a few months. :-)

[extremely strange seatbelt warning] But really what I wanted to write about was the extremely strange warning sticker that came plastered to the driver's side window. I didn't really look at the sticker until the second day after I drove the car home, and then did a double-take. It says:

While use of all seat belts reduce the chance of ejection, failure to install and use shoulder harnesses with lap belts can result in serious or fatal injuries in some crashes. Lap-only belts increase the chance of head and neck injury by allowing the upper torso to move unrestrained in a crash and increase the chance of spinal column and abdominal injuries by concentrating excessive force on the lower torso. Because children carry a disproportionate amount of body weight above the waist, they are more likely to sustain those injuries. Shoulder harnesses may be available that can be retrofitted in this vehicle. For more information call the Auto Safety Hotline at 1-800-424-9393.

If you look at the photo I took of the sticker, note the shoulder belt anchor at the right edge of the frame. It's a normal stock shoulder belt, just like you'll find in any car -- this is a 2000 model, for crying out loud, not a 1970.

A web search on the error message led me to Section 27314.5 of the California Vehicle Code, which states that

27314.5. (a) (1) Subject to paragraph (3), no dealer shall sell or offer for sale any used passenger vehicle of a model year of 1972 to 1990, inclusive, unless there is affixed to the window of the left front door or, if there is no window, to another suitable location so that it may be seen and read by a person standing outside the vehicle at that location, a notice, printed in 14-point type, which reads as follows:
... followed by the text on my sticker. It goes on:
(2) The notice shall remain affixed to the vehicle pursuant to paragraph (1) at all times that the vehicle is for sale.

So the dealer must have put this sticker on. But why? Reading on:

(3) The notice is not required to be affixed to any vehicle equipped with both a lap belt and a shoulder harness for the driver and one passenger in the front seat of the vehicle and for at least two passengers in the rear seat of the vehicle.

The dealer must not have read as far as paragraph (3).

I also found that, despite the fact that the DMV's website still links to the page I linked above, that statute was in the process of being repealed by CA Assembly Bill 2679. Except that if you click on "Read latest draft", apparently they changed their minds again in the latest version of AB 2679 and are now going to keep the warning in.

Maybe instead of leaving it unchanged or striking it, they should change it to make it clearer that it only applies to cars without shoulder harnesses installed ... if there are any such cars. Haven't shoulder harnesses been mandatory in US cars since the early 1970s? Wikipedia says they've been mandatory in the front seat since 1968 ... but the citation they give for that goes to a page that no longer exists, so that may be off by a few years.

In any case, anyone buying a car so old it doesn't have a shoulder harness and only "may" be able to have one retrofitted to it probably understands there may be some safety issues in a 40-year-old car, and doesn't need a warning sticker.

Tags: , , ,
[ 20:05 May 02, 2012    More misc | permalink to this entry | comments ]

Fri, 27 Apr 2012

Venus is at its brightest -- why? And how to calculate it

Venus has been a beautiful sight in the evening sky for months, but at the end of April it's reaching a brightness peak, magnitude -4.7.

By then, if you look at it in a telescope or even good binoculars, you'll see it has waned to a crescent. That's a bit non-obvious: when the moon is a crescent, it's a lot fainter than a full moon. So why is Venus brightest in its crescent phase?

It has to do with their orbits. The moon is always about the same distance away, about 385,000 km or 239,000 miles (I've owned cars with more miles than that!), though it varies a little, from 362,600 km at perigee to 405,400 km at apogee.

When we look at the full moon, not only are we seeing the whole Earth-facing surface illuminated, but the central part of that light is reflecting straight up off the moon's surface. When we look at a crescent moon, we're seeing light that's near the moon's sunrise or sunset point -- dimmer and more spread out than the concentrated light of noon -- and in addition we're seeing less of it.

Venus, in contrast, varies its distance from us immensely. We can't see Venus when it's "full", because it's on the other side of the sun from us and lost in the sun's glow. It'll next be there a year from now, in April of 2013. But if we could see it when it's full, Venus would be a distant 1.7 AU from us. An AU is an Astronomical Unit, the average distance of the earth from the sun or about 89 million miles, so Venus when it's full is about 170 million miles away. Its disk is a tiny 9.9 arcseconds (an arcsecond is 1/3600 of a degree) -- about the size of Mars this month.

In contrast, when we look at the crescent Venus around the end of this month, although we're only seeing about 28% of its surface illuminated, and that only with glancing twilight rays, it's much closer to us -- less than half an AU, or about 45 million miles -- and its disk extends a huge 37 arcseconds, bigger than Jupiter this month.

Of course, eventually, as Venus pulls between us and the sun, its crescent gets so slim that even its huge size can't compensate. So its peak brightness happens when those two curves cross, when the disk is somewhere around 27% illuminated, as happens at the end of this month and the beginning of May.

Exactly when? Good question. The RASC Handbook says Venus' "greatest illuminated extent" is on April 30, but PyEphem and XEphem say Venus is actually brighter from May 3-8 ... and when it emerges from the sun's glare and moves into the morning sky in June, it'll be slightly brighter still, peaking at magnitude -4.8 in the first week of July.)

Tracking Venus with PyEphem

When I started my Shallow Sky column this month, I saw the notice of Venus's maximum brightness and greatest illuminated extent in the RASC Handbook. But I wanted more details -- how much did its distance and size really change, when would the brightness peak again as it emerged from the sun's glare, when would it next be "full"?

PyEphem made it easy to calculate all this. Just create an ephem.Venus() object, calculate its values for any date of interest, then print out parameters like phase, mag, earth_distance and size. In just a few minutes of programming, I had a nice table of Venus data.

import ephem

venus = ephem.Venus()

print '%10s   %6s %6s %6s %6s' % ('date', '%', 'mag', 'dist', 'size')
def print_venus(when) :
    venus.compute(when)
    fmt = '%02d-%02d-%02d   %6.2f %6.2f %6.2f %6.2f'
    trip = when.triple()
    print fmt % (trip[0], trip[1], trip[2],
                 venus.phase, venus.mag, venus.earth_distance, venus.size)

# Loop from the beginning of 2012 through the middle of 2013:
d = ephem.date('2012')
end_date = ephem.date('2013/6/1')
while d < end_date :
    print_venus(d)
    # Add a week:
    d = ephem.date(d + ephem.hour * 24)

I've found PyEphem very handy for calculations like this -- and it's great to be able to double-check listings in other publications.

Tags: , ,
[ 13:44 Apr 27, 2012    More science/astro | permalink to this entry | comments ]

Tue, 24 Apr 2012

Firefox stopped accepting remote commands

When I upgraded to Firefox 11 a month or so ago, I got a surprise: I couldn't invoke firefox from other applications any more. Clicking on a link in an app such as xchat just gave me the Firefox Profile Manager dialog, instead of opening the link in the browser I was already running.

I couldn't find anything written about it, so I've been putting up with it, copying each link then switching to the desktop where Firefox is running and middleclick-pasting it into the browser. But this morning, I did a new round of searching, and finally found the answer, in bug 716110. and its duplicate, 716361.

Quoting from bug 716110::

[The developers] changed the -no-remote flag's behavior in a
surprising, backward incompatible way. Before, it just meant "start a
new instance." Now, it also means "don't listen for remote commands."
Apparently the change went in for Firefox 9, because of bug 650078.

Indeed, that was the problem. I have multiple Firefox profiles, so I use -no-remote -P profilename when I start Firefox, so each profile doesn't conflict with one that might already be running.

But with Firefox 9 or later, you can't do that. Instead, run your first, primary profile without -no-remote; then if you start up other profiles later, run them with -no-remote so they don't conflict with the first one. That works okay for my typical usage, fortunately: I have a main Firefox window I run all day, and only start up other profiles for short periods.

But since not everyone uses this model, fortunately, some upcoming Firefox version will fix the problem by adding a new runtime flag, -new-instance, to do what -no-remote used to do: start up a window for a new profile, rather than talking to the running Firefox. Here's the new --help text:
-no-remote Do not accept or send remote commands; implies -new-instance.\n
-new-instance Open new instance, not a new window in running instance.\n
The web Command Line Options page doesn't seem to have been updated yet, but perhaps it will when the Firefox with the fix is released.

Of course, it would have been much simpler if Firefox just honored the -P flag and used whatever profile it was given, as suggested by a commenter in bug 650078. But bsmedberg replies that the complexity of the code makes that difficult.

The new arguments look more sensible than the old -no-remote, though it's frustrating that it was so hard to find information about changes like this. All three bugs are filled with comments from people who, like me, lost a lot of time trying to figure out what broke and how to launch URLs remotely after the change. Thanks to Ryan for clarifying the issue and filing the bug to fix the problem, and to Jed, who added the new flag with his first Mozilla patch. Hooray for open source!

Tags: ,
[ 10:26 Apr 24, 2012    More tech/web | permalink to this entry | comments ]

Sat, 21 Apr 2012

Android WebView can't goBack from a page with iframes

I've been fighting a bug in Android's WebView class for ages: on some pages, clicking FeedViewer's back arrow (which calls WebView::goBack()) doesn't go back to the previous page. Instead, it jumps to some random position in the current page. If you repeat it, eventually, after five or so tries (depending on the page), eventually goBack() will finally work and you'll be back at the previous page.

It was especially frustrating in that it didn't happen everywhere -- only in pages from certain sites. I saw it all the time in pages from the Los Angeles Times and from Make Magazine, but only rarely on other sites.

But I finally tracked it down: it's because those pages include the HTML <iframe> tag. Apparently, if a WebView is on a page (at least if it's a local page) that contains N iframes, the first N calls to goBack will jump somewhere in the document -- probably the location of the associated iframe, though I haven't verified that -- and only on the N+1st call will the WebView actually go back to the previous page.

The oddest thing is, this doesn't seem to be reported anywhere. Android's bug tracker finds nothing for webview iframe goback, and web searching hasn't found a hint of it, even though I see this in Android versions from 1.6 through 2.3.5. How is it possible that other people haven't noticed this? I wonder if it only happens on local file:// URLs, and not many people use those.

In any case, I'm very happy to have found the answer at last. It was easy enough to modify FeedMe to omit iframes (and who wants iframes in simplified HTML anyway?), and it's great to have a Back button that works on any page.

Tags: ,
[ 19:56 Apr 21, 2012    More programming | permalink to this entry | comments ]

Wed, 18 Apr 2012

Mounting a Samsung Galaxy Player on Linux

My new toy: a Samsung Galaxy Player 5.0!

So far I love it. It's everything my old Archos 5 wanted to be when it grew up, except the Archos never grew up. It's the same size, a little lighter weight, reliable hardware (no random reboots), great battery life, fast GPS, modern Android 2.3, and the camera is even not too bad (though it certainly wouldn't tempt me away from my Canon).

For the record, Dave got a Galaxy Player 4.0, and it's very nifty too, and choosing between them was a tough choice -- the 4-inch is light and so easy to hold, and it uses replaceable batteries, while the 5-inch's screen is better for reading and maps.

USB-storage devices don't register

I love the Galaxy ... but there's one thing that bugs me about it. When I plug it in to Linux, dmesg reports two new storage devices, one for main storage and one for the SD card. Just like most Android devices, so far.

The difference is that these Samsung devices aren't fully there. They don't show up in /proc/partitions or in /dev/disk/by-uuid, dmesg doesn't show sizes for them, and, most important, they can't be mounted by UUID from an fstab entry, like

UUID=62B0-C667   /droidsd    vfat   user,noauto,exec,fmask=111,shortname=lower 0 0
That meant I couldn't mount it as myself -- I had to become root, figure out where it happened to show up this time (/dev/sdf or wherever, depending on what else might be plugged in), mount it, then do all my file transfers as root.

I found that if I mounted it explicitly using the device pathname -- mount /dev/sdf /mnt -- then subsequently the device shows up normally, even after I unmount it. So I could check dmesg to find the device name, mount it as root, unmount as root, then mount it again as myself using my fstab entry. What a pain!

A kernel expert I asked thought it looked like the Samsung is pretending to be a removable device, but only "plugging in" when the system actually tries to access it. Annoying. So how do you get Linux to "access" it?

Udev: still an exercise in frustration

The obvious solution is a udev rule. Some scrutiny of /lib/udev/rules.d/60-persistent-storage.rules found some rules that did this intriguing thing: IMPORT{program}="ata_id --export $tempnode".

Naturally, this mysterious ata_id is undocumented. It's hidden in /lib/udev/ata_id, and I found this tiny ata_id man page online since there's none available in Ubuntu. Running ata_id /dev/sdf seemed to do what I needed: it made the device show up in /proc/partitions and /dev/disk/by-uuid, and after that, I could mount it without being root.

I created a file named /etc/udev/rules.d/59-galaxy.rules, with the rule:

KERNEL=="sd[b-g]", SUBSYSTEMS=="usb", ATTRS{idVendor}=="04e8", SYMLINK+="galaxy-%k-%n", IMPORT{program}="ata_id --export $tempnode"

When I tested it with udevadm test /block/sdf, not only did the rule trigger correctly, but it actually ran ata_id and the device became visible -- even though udevadm test states clearly no programs will be run. How do I love udev -- let me count the ways.

But a reboot revealed that udev was not actually running the rule when I actually plugged the Galaxy in -- the devices did not become visible. Did I mention how much I love udev?

Much simpler: a shell alias

But one thing I'd noticed in all this: side by side with /dev/disk/by-uuid is a directory called /dev/disk/by-id. And the Samsung devices did show up there, with names like usb-Android_UMS_Composite_c197022a2b41c1ae-0:0.

Faced with the prospect of spending the rest of the day trying random udev rules, rebooting each time since that's the only way to test udev, I decided to cheat and find another way. I made a shell alias:

alias galaxy='sudo sh -c "for d in /dev/disk/by-id/usb-Android*; do /lib/udev/ata_id --export \$d; done"'

Typing galaxy will now cause the Samsung to register both devices; and from then on I can mount and unmount them without needing root, using my normal fstab entries.

Update: This works for the Nook's main storage, too -- just add x/dev/disk/by-id/usb-B_N_Ebook_Disk* to the list -- but it doesn't work reliably for the Nook's SD card. The SD card does show up in /dev/disk/by-id along with main storage; but running ata_id on it doesn't make its UUID appear. I may just change my fstab entry to refer to the /dev/disk/by-id device directly.

Tags: , ,
[ 12:43 Apr 18, 2012    More linux/kernel | permalink to this entry | comments ]

Syndicated on:
LinuxChix Live
Ubuntu Women
Women in Free Software
Graphics Planet
DevChix
Ubuntu California
Planet Openbox
Devchix
Planet LCA2009

Friends' Blogs:
Ups & Downs
DailyBBG
Long Live the Village Green
Dan Heller
Morris "Mojo" Jones
Jane Houston Jones

Other Blogs:
DevChix
Scott Adams
Dave Barry
BoingBoing (Cory Doctorow)
Young Female Scientist

Powered by PyBlosxom.