Saturday, February 22, 2014

pyAstroStack: First alpha release!

First I have to say that this project was a lot bigger than I thought. Even on the limited functionality it has now there was a lot more work I was prepared to. And all that work was surprisingly mostly user interface and saving the temporary files. I'll write a bigger post on all the problems I ran into and let this post be the announcement of the first released version of pyAstroStack.

No, I really haven't come up with a better name...

PyAstroStack 0.1


PyAstroStack is an open source stacking software for astronomical images taken with DSLR. This first version includes basic functionality such as subtracting and dividing images, debayering, registering and stacking. Supported image formats are limited to Canon EOS 1100D CR2 and similar. Don't expect anything spectacular. I'm not very experienced programmer.

Here's an example image what pyAstroStack can do. This is a median stack of about 30 exposures.

Image stacked with pyAstroStack. Full size in http://www.flickr.com/photos/96700120@N06/12621177443/

Features

  • Command line user interface
  • CFA to RGB conversion on OpenCL which makes it quite fast
    • Bilinear
    • LaRoche-Prescott
    • Variable Number of Gradients
  • Registering
    • SExtractor and method from http://adsabs.harvard.edu/abs/1986AJ.....91.1244G
  • Aligning
    • Affine transformations by ImageMagick
  • Stacking
    • Mean value
    • Median value

Supported cameras

  • Canon EOS 1100D
  • Everything else from Canon that has Bayer filter RGGB

Usage

  • Command line only. You really need to read the manual to use this. The software could really be user friendlier.
  • There might be a GUI in the future

Installation

Download and extract source package. See INSTALL.txt.

Help needed!

I have only access to one camera. Also my data isn't too good, I'm aware of that. That of course limits my test runs. What I would really appreciate is some raw photo sets that allows me to run tests on different features. 
  • Set of some light frames and proper flat frames. I'm bad at taking flats whenever I even bother to take them. This has made it quite difficult to implement flat frame calibrations properly.
  • Single example images from different cameras. This is just to make sure my program recognizes them and is able to debayer them properly. These images don't even have to be astronomical. Just something with recognizable colors.
If you would like to help, please contact via Google+

Wednesday, February 19, 2014

Moon for scale: Part 2

I did some comparison of apparent sizes of deep sky objects and the Moon (http://mikkolaine.blogspot.fi/2014/01/size-of-deep-sky-objects-compared-to.html) and that seems to be the most visited page on my blog so time for another one. These were actually made the same time with Andromeda and Orion Nebula, but for some reason I didn't include them in that post.

Flame Nebula and Horsehead Nebula

Names for these nebulae are quite describing. Flame nebula is easily visible and Horsehead a bit fainter. That red color is mostly filtered by digital cameras. With a modded camera that has the filter removed all the red details would be a lot brighter. Most people have seen photos of the Horshead nebula, but here's the size illustrated:

Bigger version: http://www.flickr.com/photos/96700120@N06/12630499714/

Jupiter

It's not a deep sky object, but interesting whatsoever. With naked eye Jupiter seems just like a star, but even a small telescope or binocular can show that it's not. Here's a composite picture comparing Jupiter and the Moon.

Bigger version: http://www.flickr.com/photos/96700120@N06/12630057315/

That's about it...

I don't think I have any more interesting photos to show. There hasn't been too many nights this winter to shoot any astrophotos... Too bad.

Sunday, January 19, 2014

Size of deep sky objects compared to the Moon

I wrote about this on some previous post, but I felt I'd have to get back to this. Most people, including me few years ago, don't realize how big all the galaxies and nebulae are in the sky. Most common example I've seen is the Andromeda galaxy.

Even if you could see it with naked eye (I've understood it's possible), it won't be more than a tiny smudge. But you won't need much of a camera to capture a lot more of it. Then you're starting to realize.

Here's a comparison of the Andromeda galaxy and the Moon. I took some photos of the Moon with a 200 mm lens, the same I use to photograph Andromeda. I then measured the size of the Moon and resampled a bigger photo (effective focal length 2400mm) to match that size. Resized Moon was then pasted next to Andromeda.

Wikipedia says the apparent size of Andromeda is 190' by 60'. 190 arc minutes is about 3.2 ° so a lot bigger than I measured from that photo. This is the amount I was able to catch on camera. (NOTE: I had mistakenly measured the size to 4.0 °. Now this is fixed.) Moon was on perigee when I took this so it should be about 30 arc minutes or 0.5 °

Here's another. Great Orion Nebula M42 with the Moon placed next to it. M42 is actually visible without any equipment almost everywhere. It's the Orion's Sword, three stars below Orion's Belt. From this photo you can see there's a bit more than three of them. The one on left is the top one on the sky.


Now just imagine if you could see all those galaxies and nebulae with your naked eye.

Tuesday, January 7, 2014

Orion, M42 and Horsehead Nebula

I still don't know much of the capabilities of my astrophotography set. As I've written before, I'm doing this on quite a tight budget. Partially my reason for this is that I see no point on buying expensive equipment that either I have no idea how to use (better cameras and lenses), or that does all the work on my behalf (goto-mounts). Of course you can get better photos that way, but where's the challenge? My plan is to learn things while doing this and getting better equipment when I definitely know what I need. Last thing I bought is a better lens: Canon EF 200mm f/2.8L II USM. After some testing this looks like a good buy.

Difference in my Andromeda photos were quite dramatic. 200/2.8L collects so much more light than my old EF 75-300mm f/4-5.6 III. Of course I started wondering how much better photos do I get from all the other objects I've already tried with my old lens. First thing that came to mind was Orion and M42. An awesome constellation for an amateur astrophotographer because there are so many different objects, some easy to see, some more and more difficult to even catch on camera.


Horsehead Nebula

One of the most fascinating objects to me is the Horsehead Nebula (Barnard 33) and I tried to photograph it as soon as I could. My first try was with the 75-300mm lens, and it was a disappointment.

Area of the Horsehead Nebula taken with EF 75-300mm f/4-5.6 III, at 2013-01-17
As you can see, no Horsehead even with a good imagination. Flame Nebula (which I was totally unaware of before this) can be seen somehow if you stretch the image to it's limits.

The next ones are taken later that year with a better lens.

Single shot of the Horsehead Nebula taken with EF 200mm f/2.8L II USM, at 2013-11-30
Here the Flame Nebula can be seen without extensive stretching and even the colors are about right. It's a single photo I took in November just before sky was filled with clouds. No further testing was possible. I didn't see the Horsehead back then but know that I know exactly where it should be, and if I use enough imagination, I think I can see it. Nothing spectacular though.

Single shot of the Horsehead Nebula taken with EF 200mm f/2.8L II USM, at 2013-12-30
This one's been taken December 30th 2013. After couple of months sky was clear for several hours. Clouds came around 11pm, but there was plenty of time to shoot Orion from balcony, even after clearing the problems. I lost the colors while stretching the photo, but Horsehead is can now be seen without imagination. I had about 20 of these and the stack made with IRIS looks like this:

Flame Nebula and Horsehead Nebula taken with EF 200mm f/2.8L II USM, at 2013-12-30. 20x30s exposure stacked with IRIS, postprocessing with Darktable.
Horsehead is easily visible. Mission accomplished.

The Flame Nebula took me by a surprise. For some reason I wasn't aware of that before I saw it in the photo. While stretching the colors on this photo I decided I'll learn how to shoot proper flat fields. The background is so difficult to fix in postprocessing. It even shows in this cropped image.

Orion

I've concentrated too much on too small objects. Images of larger scale can be nice too and one can more easily use longer exposures. Too bad I don't have a good camera lens for that. Only the one that came with the camera. I set it to 55 mm and tried to fit as much Orion as possible on screen. 

First I took a long exposure. I don't have a cable release and my camera supports exposures only up to 30s. There's Bulb-setting so I pressed the trigger for a while. From image exif I read it was 95 seconds. I processed the image on Darktable and here's the result:

Single 95 second shot of Orion

I also took series of photos, 10x30 seconds, and stacked them with IRIS. Total exposure is more than 3 times of the one above, but I think I still like the single shot more. I'll better prepare my camera control set before the next clear sky.

Stacked 10x30 second exposures of Orion

Great Orion Nebula M42

I also took more shots of the Orion Nebula M42. I've photographed this a lot in the past, but of course my skills get better and sometimes my equipment too. This time I tried stacking with Regim instead of IRIS.

Stacked 30x30 second exposures of M42
Level of visible details looks better than any of my photos before. Colors on the other hand are a bit wrong. I think what's green there should be blue. I'll have to try IRIS for the stacking as well.

Update:

Looks like Regim used the wrong Bayer matrix for my raw photos. When I manually set the correct one, the colors look the way they should look.


...more or less. I'd still like some blue there. Even the single shots show some blue, so it's kind of strange the stack doesn't.

And one more:

The same again, but now with IRIS. Finally I got the blue color I missed.


Mikko's Nonexistent Comet and Identical Ghost Nebulae

Lately several of my astrophotos have had some sort of lens flares or other reflections. I've figured that they're from street lights or yard lights. After all I do most of my observations and photographs on my backyard. Usually these flares appear on the edge of photo so I won't have to worry about them. Couple of times they have surprised me though.

Mikko's Nonexistent Comet


I was taking a panorama of Cassiopeia. That panorama didn't work (not enough overlapping), but there was this "comet" on one of the images. I immediately checked the other images as well and realized what this was. There's a star in a very convenient place to make the flare look like comet's tail. The next image had the same flare but the star had moved away from it.

Identical Ghost Nebulae

I was testing whether I could photograph the Horsehead Nebula. I had the EQ-mount surprisingly well set. I could take 30 second exposures with 200mm, where I usually have to settle to 20 sec or less. Flare nebula was easily visible on camera screen so I started to take series of photos. Then I noticed this:


First of all, there shouldn't be anything like that on sky, at least on Orion. But now there's two identical! I was taking the photos on my balcony and there were some lights from neighbors that might find their way to my camera even though I had quite a long hood on the lens. I put some cardboard to block all light I could think of, but still the flares remained.

I zoomed and looked the image thoroughly and I saw a third one. Then I got it. Those flares weren't from lights around me but from the stars. The next image (click it larger if the small one doesn't show) explains it quite well. There are three flares and three bright stars. Moreover, the positions of the flares are exact π rotation of star positions.


The flares were caused by UV-filter I had on the lens. I read somewhere that the filter does not affect anyhow on stellar photography so I've kept it on the lens to cover it. Looks like I have to remove it from now on. Without it there were no flares.

Tuesday, November 5, 2013

pyAstroStack: Getting prepared for first release

...where getting prepared means a LOT of work. By number of code lines maybe even more than there already is.

Things I'm working on, one by one:

Project file

I want the stacking process to be possible to continue on a later time starting from any point. I also want to make possible for example do the stacking couple times on different settings (perhaps to test which method works the best).

I'm implementing this via project file. It holds all the necessary information about source photos and what's done with them. Program reads the project file and it can tell user what's already done and what might be the next step. It also knows location to uncalibrated cfa-images, calibrated images, demosaiced images, registered images etc... so user can do any step again if wanted.

The project file approach is also required by my user interface.

User Interface

Eventually I'd like to have a graphical user interface (most likely PyQt) but for now only command line. I'm starting to like IRIS and its command window so that's what I had originally in mind. I got deviated a bit...

Here's how it's going to work:

AstroStack <operation> <project> <arguments>

Some examples (ones I have already implemented)

AstroStack init Andromeda
- Initialize a new project by the name of Andromeda

AstroStack adddir Andromeda light /media/.../Andromeda/
- Add all files of proper type from specified directory to project as light pictures. Actually this isn't fully implemented. It works now without the "light" argument but it asks what the type is.

AstroStack addfile Andromeda light /media/.../Andromeda/IMG_6234.CR2
- Add one file to project. Otherwise same as before. This probably should be made to understand wildcards.

AstroStack stack Andromeda flat
- Stack the flat images in the project file. This creates a file called masterflat.fits in working directory and will save the information about masterflat in the project file. I'll change all the file names to be project specific so there can be several simultaneous projects that don't interfere each other.

AstroStack demosaic Andromeda
AstroStack register Andromeda
- These are in the code but haven't been tested. Probably won't work yet.

I hope this shows the idea how the program is going to work. I'm also thinking of GUI implementation all the time and I'm trying to write everything compatible for it so no rewrite should be necessary then.

Check and rewrite everything for UI compability

I didn't really think how the UI is going to work when I first wrote this. Everything is classes and objects so it should be trivial to get everything working on UI instead of test script. Mostly the changes have been about where method gets it's arguments. Incorporating project files also requires changes so there won't be several places to update information.

Decide on image format

First I used FITS via astropy.fits, but I ran into some problems with it. I changed image format to TIFF via Pillow.Image but I've ran into even more problems... FITS might still be the better choice. AstroPy also has one advantage to Pillow: It's designed for exactly this use. I understood it supports automatically slicing large arrays into small ones which is handy for calculating medians.

Problems with TIFF
  • Pillow indexes arrays differently than SExtractor does with FITS. This requires coordination system changes in registering
  • Saving intermediate files with better precision than the final. Pillow doesn't like my numpy.float32's and such.
  • Saving RGB images. For some reason all RGB's I tried to save were only mess.
Problems with FITS
  • Creating them. I learned the right switches for Rawtran, but the problem is the program itself. I dislike the idea of having a dependency people have to compile themselves. I'll try to change this to DCRaw only or DCRaw + ImageMagick combo
  • Final result should be other than FITS for easier postprocessing. TIFF suits fine, but that means Pillow would remain as a dependency
ImageMagick is being used for affine transformations and I'm not sure if it can do that to FITS files. Better try soon before deciding. Otherwise I'm choosing FITS.

Change IDE

Does concern the program a bit. Eclipse was massive and sluggish and I constantly had problems with either PyDev or eGit (or whatever the Git plugin was called). I ranted about this on IRC and got suggested PyCharm. The free version seems extremely nice, fast and git works out-of-the-box. First things I did after changing to PyCharm was to fix all the PEP8 problems the program suggested. Agreed, the code is much readable now.

I'm also trying 2-panel setup. I've been switching between to files so much that this could be useful.

Better demosaic and median stacking

I want these to be ready before releasing version 0.1. Demosaic is now bilinear and the way it lost all the colours on my test images suggests it doesn't work too well. I found something called LaRoche-Prescott demosaicing algorithm and I decided to give it a go.

Stacking works now only by mean value, which is fast and easy to implement. Eventually I want to have sigma medians and such but for the first release I want at least median stacking.

Memory usage

While running tests, I ran out of RAM. And I have 16 GB of it. So that's a problem. Seems like Pythons garbage collecting isn't that efficient without programmers help. I managed to make stacking work on about 5 GB (with 30 light images) but I still think that's too much. Have to make that lower.

That's about it...

A lot to do as I said. Where I'm now?


This can already be done, so core modules seems to work. It's everything around it that needs work.

BTW, I've been using Andromeda galaxy as my test images and hence all the images so far processed have been about Andromeda. I decided to give names of celestial objects to different versions of pyAstroStack. Version 0.1 will be Andromeda. That's already a name of a branch in BitBucket.


Tuesday, October 22, 2013

pyAstroStack: Calibration works, affine transformations by ImageMagick

Actually all that worked already before the previous post. I had to do couple of changes to the calibration functions because now images are monochrome and before RGB, but otherwise everything was in order.

I had some problems on master dark being white, but I found out that to be because the program was reusing old temporary dark#.tiff files. Master bias was subtracted once every time I ran the program causing values of uint16 go below zero. I now changed the program to use float32 during the process and output int16 only when everything is ready. Also temporary files are now manually removed before every new test run.

I noticed ImageMagick can do affine transformations based on matching pairs. Just what I need! It's a lot faster than Scikit-Image, which I won't be needing anymore so one less dependency to worry about. I could probably do a lot more with ImageMagick as well so I have to look into that some more. This project isn't about coding everything by myself. It's about getting astronomical image stacking done on open source software. Hence, ImageMagick is fine.

Next I think I should make some kind of a project file which holds information about temporary files and which can be removed and which reused.

So here's the first result of full calibration process.


That's of course not what my code outputs. Postprocessing has been done with Darktable. Bigger version again on Flickr: http://www.flickr.com/photos/96700120@N06/10427590704/

I addition to project file I'll start working on interpolating calibrated raw images into RGB.

Btw, the whole process takes now 7 min 30 s. That's for 30 bias, 10 dark, 7 flat and 30 light frames. That's quite good, I think.