Thursday, June 05, 2014

The (Forever) Language War

I generally find comparisons between programming languages to be a waste of time given they're largely based on personal preference over objective metrics, and even metric-based comparisons are often superficial or downright misleading (yeah, I'm talking about you Julia). Generally my view is use what best fits the application modulo your expertise, and the language doesn't really matter - it is an implementation choice.

That said, I've lately being feeling rather down about C++ which is the language I develop in most heavily. Sure, it has speed and expressive power but some of the most powerful features are semantically non-trivial and most galling of all, it really doesn't come with many standard "packages" in the way Java and Python do. OK, it comes with the STL, which I do like, but then you have to go to Boost, and then you look at how some of the Boost packages are coded and you wonder if it is even the same language. In a very large and complicated project I find the developer (or more technically, integration troubleshooter and debugger) role to have low productivity. It isn't as bad as perl but it is easy for "other" programmers to write code that is just overly complicated for the job. Oh great, someone has learnt about the Abstract Factory pattern, and has decided to use it everywhere: attempt to drill down through layers of unnecessary obfuscatory abstraction (that manages to be coupled to a million other things instead of decoupling the way abstraction should do) to find what some code is actually doing. Analyze, debug, code, compile ... ... ... and run again, all while you have a supposedly critical release deadline looming.

It is easy to forget the problem what C++ set out to fix, which I was reminded of when I starting reading "Learning OpenCV". Now OpenCV is a wonderfully powerful open source library in my opinion, based on mainly using it before now through its Python bindings. But reading how to use the C API was eye opening. What, I have to remember to delete those resources? Oh great, void* pointers and I have to remember what type to cast to/from. I could just imagine the fun bugs someone had to deal with. Suddenly C++ didn't seem so doddering.

While reading about Apple's new Swift language at Slate.com (Another new proprietary language to tie developers to Apple and in darkness bind them, how exciting for the Mac fan boys!) I came across a link to a discussion by David Green comparing his experience trying out both iOS and Android development tools. The comments are the article reveal the pattern that makes me dislike language comparisons: In a discussion of X and Y you must be biased toward X because you know more about it X so really X and Y are equally good. (There should be a name for this fallacy but I can't seem to find it). However the article itself is worth a look, because it compares the iOS+Xcode+Objective-C platform to Android+Eclipse+Java platform in terms of ease of development. I've always been somewhat curious about Xcode and Objective-C, but David Green's article is enough to stop me wasting my time. What the commentators on his article don't understand is that while you can do great stuff with Xcode and Objective-C it has placed extra hurdles in your way: the extra verbosity needed in the language, the extra time it'll take to hunt down solutions to non-trivial problems. That time might not matter to some developers, in particular to Apple-only developers, but it will to matter to someone and it certainly matters to me.

Friday, May 23, 2014

Plotting images with axis coordinates in Octave

It is remarkable that I've struggled to find any examples in the Octave documentation or other people's tutorials or examples on how to plot an image (or matrix) with axis coordinates that aren't the pixel or cell numbers.

function image_with_axes()
    clear all;
    more off;
   
    % These are our eventual axis coordinates.
    x = linspace(-10,10,100);
    y = x - 2;
   
    % Generate an Airy disk
    [xg,yg]=meshgrid(x,y);
    rad = sqrt( xg.^2 + yg.^2);
    airy = besselj(1,rad)./rad;
    airyintensity = abs(airy).^2;
   
    % The normal imagesc invocation. Note axis ratio.
    figure(1);
    imagesc(airyintensity)
    axis image
    %colorbar
   
    % Now invoke with axis vectors before the image/matrix
    figure(2);
    imagesc(x,y,airyintensity);
    axis image
    %colorbar
   
    % Demonstrate the coordinates a little more clearly
    % Coordinate axes are taken to be the center of the
    % image pixel.
    a=rand(4);
    x=[3:6];
    y=[-1:2];
    figure(3);
    imagesc(x,y,a);
   
    % What about non-linear axes. Not handled correctly like this.
    % This case is dealt with another time,
    figure(4);
    x2=sqrt(x)
    y2=x.^2
    imagesc(x2,y2,a);

endfunction

Tuesday, May 13, 2014

SN 2014J update

I've been exceptionally busy lately, and haven't had any time to follow up on what observations of SN 2014J have told us. A google search didn't show very much, so I ended up searching Arxiv.org for papers associated with SN 2014J returns the following list (search http://arxiv.org/find/all/1/all:+2014J/0/1/0/all/0/1):

1. arXiv:1405.1488 [pdf, other]
No X-rays from the very nearby Type Ia SN2014J: constraints on its environment
Comments: 9 pages, Submitted to ApJ
2. arXiv:1404.2639 [pdf, ps, other]
Diffuse Interstellar Bands vs. Known Atomic and Molecular Species in the Interstellar Medium of M82 toward SN 2014J
Daniel E. Welty (1), Adam M. Ritchey (2), Julie A. Dahlstrom (3), Donald G. York (1) ((1) Univ. of Chicago, (2) Univ. of Washington, (3) Carthage College)
Comments: 27 pages, 6 figures, submitted to ApJ (comments welcome)
3. arXiv:1403.7405 [pdf, ps, other]
Supernova 2014J at maximum light
Comments: 10 pages, 4 figures, submitted to Contrib. Astron. Obs. Skalnate Pleso
4. arXiv:1403.4250 [pdf, other]
Constraints on the Progenitor System of the Type Ia Supernova 2014J from Pre-Explosion Hubble Space Telescope Imaging
Comments: Submitted to ApJ, comments welcome
5. arXiv:1402.4806 [pdf, ps, other]
Expectations for the Hard X-ray Continuum and Gamma-ray Line Fluxes from the Type Ia supernova SN 2014J in M82
Comments: Accepted to the Astrophysical Journal (March 31, 2014), with one additional figure and further discussion of technique
6. arXiv:1402.2717 [pdf, ps, other]
Specific predictions for SN 2014J in the context of the Quark Nova Ia model
Rachid Ouyed (1), Nico Koning (1), Denis Leahy (1), Jan E. Staff (2) ((1) Department of Physics and Astronomy, University of Calgary, Calgary, Alberta, Canada, (2) Department of Physics and Astronomy, Macquarie University, Australia)
Comments: 3 pages
7. arXiv:1401.7968 [pdf, ps, other]
Estimating the First-Light Time of the Type Ia Supernova 2014J in M82
Comments: Accepted for publication in ApJ Letters
This is quite a varied set of papers. I quite like the Margutti et al paper, not just because it is on X-ray emission but because of the impressive figures.

Otherwise, the most interesting of the bunch is Zheng et al. Not only did they uncover some earlier but unrecognized observations of the supernova, but the managed to estimate the explosion time (*) at Jan 14.75 UT (2014), about a week before Fossey's UCL undergraduates first noticed it. Tsvetkov et al present UVBRI light and color curves and conclude that SN 2014J belongs the the "normal" [Quotation marks in the original] subset of Type 1a SNe. How this matches up with the unusual early-time powerl-law light curve Zheng discovered doesn't seem to be discussed in their article, and as the subject is out of my (former) expertise I don't have enough information to make an informed speculation.

(*) Technically the time that any light from the explosion would have passed Earth. At a distance of D~3.5 Megaparsecs the actual explosion occurred ~11 million years ago (i.e. well before our ancestors and the ancestors of chimpanzees split off from each other).


Friday, February 07, 2014

Supernova 2014J in M82: Some more pictures and how to spot it

The Type Ia supernova 2004J in M82 is near peak brightness, and should be easy to spot if you live in the northern hemisphere and have a small telescope or large binoculars. Brian Dodson has a good guide to finding it on the sky.

Here are two more images of M82 taken by Swift UVOT, the second taken some years before the SN and the first taken on January 22, the day after its initial discovery. [Images from NASA/GSFC media site, credit NASA/Swift/P. Brown, TAMU]. Note that the SN is circled in the first image. The large white blob surrounding a blue and white point is not the SN, but a bright foreground star.