Feeds:
Posts
Comments

Posts Tagged ‘linux’

Debian 8 (Jessie)

Recently I bought a Lenovo T430 on eBay. The main reason I didn’t like T440 or T540 was it’s absolutely horrible touchpad ! After buying the Lenovo T430 with Windows 7, the most trivial step was to install a Linux on it. For that, I have experienced Debian, Kubuntu, Fedora, and Centos for two weeks on VirtualBox on my old laptop (T530). Since I was using Debian from Debian Sarge (3)  till Debian Wheezy (7), it was not a surprise to me that I converged to Debian.

Debian made a fantastic job and in the live environment, it had no problem with lan, wireless, or sound. I had a familiar package manager, synaptic, and instantly after installation activated some multimedia and backports for non-free libs.

Debian Jessie Desktop

Debian Jessie Desktop

Debian automatically configured the F-keys so all of them work out of the box. The only thing I had to change was the behaviour of the touchpad, so I can tap on the touchpad and the system recognise that as a click.

I installed KDE 4 as my default desktop environment and all of the familiar packages like emacs, kstars, digikam, gimp, etc.

Numeric libraries like ATLAS, LAPACK, BLAS, FFTW, CFITSIO, openmpi, etc can be easily installed either via synaptic or simply running the following as root:

#apt-get install fftw

Compared to old days, Debian is now so user friendly that it does not require much experience to either install or configure it.

Science Packages

Debian also offers “science” packages like science-physics, science-mathematics, etc. Each science package is a group of many packages in that category. So installing one science package will install all of them. There are also -dev version for science packages.

Firefox on Debian

There is no particular advantage over Debian brand of Firefox called icedove and the Mozilla versin of Firefox. However I decided to install Firefox instead of icedove since I had Fedora17 on my previous laptop so I could move all my Firefox profile like bookmarks, saved passwords, etc directly to Debian, and it was fairly easy.

Advertisements

Read Full Post »

Python pip

pip is a very helpful command to install python package either with or without root password. You can install a fresh python binding in your home directory. To install pip, you can do one of the following depending if you use redhat/centos/fedora or Debian/ubuntu:

Debian:  #apt-get install python-pip

Fedora: # yum install python-pip     (on fedora 23, yum was replaced by dnf).

then, you can easily use yum to manage your python packages:

$pip install numpy –user      # –user indicates that you install it in your home directory

$pip install numpy –upgrade   # to upgrade an installed package

$pip uninstall numpy

$pip show numpy    # This will show the installed version and directory of a package


Name: numpy
Version: 1.8.2
Location: /usr/lib/python2.7/dist-packages
Requires:

$pip list       # it will print a list of installed packages with their versions.
$pip list –outdated      # check each package with the latest available version and remark the outdated ones.
the following reviews everything and reports about problems:

# pip-review

What can be installed with pip?

There are several thousand packages that can be installed via pip. I do NOT recommend to click on this link (the page is very big). The easiest way to check if a particular package exists in pip is the following command:

$ pip search numpy

Read Full Post »

Once again, I have the challenge of installing Linux on  a Macbookpro laptop. The one that I had the first time was a Macbookpro 4,1. Since I like Debian more than  others, I installed Lenny which was testing at that time.  The first kernel was 2.6.26 and it is now 3.2.0. In the meantime, it was upgraded to Squeeze, and then Wheezy. The newer the kernel, the better the system performance.

Now, I have a new Retina display Macbookpro 10,1. With no ethernet card, no optical drive, and NVIDIA graphics, it will be a lot of fun to install any Linux distribution on it, as expressed in thisthis, and this pages, for instance. Sure, it will improve with time but for the moment, perhaps nobody get it working properly.

Read Full Post »

This is the repository of the Debian testing, wheezy. It is still in the testing branch and will be stable by end of 2012. I have installed that recently. ################################################################################## deb ftp://ftp.debian.org/debian wheezy main contrib non-free deb-src ftp://ftp.debian.org/debian wheezy main contrib non-free deb http://ftp.debian.org/debian wheezy-proposed-updates main contrib non-free #deb http://security.debian.org/debian-security Wheezy/updates main deb http://security.debian.org/ wheezy/updates main contrib non-free deb http://www.debian-multimedia.org wheezy main non-free deb http://download.skype.com/linux/repos/debian/ stable non-free  ##################################################################################

The procedure:

Basically I have changed the source file (/etc/apt/sources.list), then run apt-get update, and then apt-get dist-upgrade.  It updated the list, and downloaded all the new packages. After that, the old packages were removed and started to install the new ones.

Problems: Since I have Debian on a MacBookPro, there are basically two issues that I had to solve manually. They are related to NVidia graphics card and Broadcom wireless card. I have installed them using the module-assistant as explained here. At some point during upgrade, it crashed complaining a dependency conflict (libgstreamer, if I remember correctly). I removed some packages using dpkg -r to solve the problem. Then, the upgrade was completed and I got a message about errors during the upgrade. It was basically Nvidia problem, as I expected. I following the instruction and run the module assistant.

That was it. Now, it runs Debian 7 (Wheezy), with an updated kernel (3.1). As far as I have experienced the system so far, it is rather stable.

Read Full Post »

Pymc: Bayesian fit for Python

Using a Bayesian fit is totally different from a  least-squared fit. Doing it is also more complicated.  In a chi-squared fit, we minimize a merit function. In a Bayesian fit, we have a set of priors, and a set of observations. To fit a model to those observations, we calculate a likelihood function. Unlike a least-squared problem, here basically each variable has a distribution. and we find the peak of distribution as the solution for unknown parameters. It is way better to read a review or something like this nice paper:

http://adsabs.harvard.edu/abs/1992ApJ…398..146G

Well, now that we know what is it, how can we do simplest things with that: i.e., fitting a straight line to some data points? Pymc made it easy. It is a python package which contains three different solvers for Bayesian statistics including a Markov chain Monte Carlo (MCMC) estimator.

You can not only use it to do simple fitting stuff like this, but also do more complicated things.  However, I try to show some simple examples of its usage and comparison to a traditional fit in a separate post. Basically I compare fitting a parabola using chi-square and Bayesian method.

save the following in a file (I call it test.py):

# A quadratic fit
#———————————————————–
import numpy, pymc

# create some test data
x = numpy.arange(100) * 0.3
f = 0.1 * x**2 – 2.6 * x – 1.5
numpy.random.seed(76523654)
noise = numpy.random.normal(size=100) * .1     # create some Gaussian noise
f = f + noise                                # add noise to the data

z = numpy.polyfit(x, f, 2)   # the traditional chi-square fit
print ‘The chi-square result: ‘,  z

#priors
sig = pymc.Uniform(‘sig’, 0.0, 100.0, value=1.)

a = pymc.Uniform(‘a’, -10.0, 10.0, value= 0.0)
b = pymc.Uniform(‘b’, -10.0, 10.0, value= 0.0)
c = pymc.Uniform(‘c’, -10.0, 10.0, value= 0.0)

#model
@pymc.deterministic(plot=False)
def mod_quadratic(x=x, a=a, b=b, c=c):
      return a*x**2 + b*x + c

#likelihood
y = pymc.Normal(‘y’, mu=mod_quadratic, tau=1.0/sig**2, value=f, observed=True)
#———————————————————–

Now, go to command line and run the following (or alternatively put them in a file):

import pymc, test              # load the model file
R = pymc.MCMC(test)    #  build the model
R.sample(10000)              # populate and run it
print ‘a   ‘, R.a.value        # print outputs
print ‘b    ‘, R.b.value
print ‘c    ‘, R.c.value
The output looks like this:

The chi-square result: [ 0.0999244  -2.59879643 -1.49278601]
Sampling: 100% [00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000] Iterations: 10000
a    0.0981867109293
b     -2.54514077442
c     -1.77016283024

The correct results are a=0.1, b=2.6, and c=1.5. Both methods gave satisfactory results. Indeed, if you increase number of iterations from 10000 to one million, the answer will be like this:

Sampling: 100% [000000000000000000000000000000000000000000000000000000000000000000000000000000000000000] Iterations: 1000000
a    0.0997945467529
b     -2.59731835923
c     -1.47308938314

As you see, the results are more accurate compared to the former case.

If you like to have more information, you can use the following command:

print ‘a   ‘, R.a.stats()

a    {‘95% HPD interval’: array([ 0.09956635,  0.10027448]), ‘n’: 1000000, ‘quantiles’: {2.5: 0.099545071298350371, 25: 0.099805050609863097, 50: 0.099919386231275664, 75: 0.10003496316945379, 97.5: 0.10025986774435611}, ‘standard deviation’: 0.0050467522199834905, ‘mc error’: 0.0003721035009025152, ‘mean’: 0.099548164235412406}

Recall that in  a Bayesian fit, each variable has a distribution. The following plot shows the data points as well as the two Bayesian fits.

To compare it with a least-square fit, I repeated the experiment with a sample data which has more noise. The resulting fits are compared in the following panel.

There are much more you can learn from the examples of Pymc. I hope in a future post, I can explain other types of fit, like a weighted-least-square fit or a bisector fit.

Read Full Post »

Reading IDL Save files in Python

For many idl users, switching to python is not easy. An important reason is that restoring idl save files was not possible.  However, it IS possible now ! and it is in fact as easy as you can imagine:

1) download and install the package

http://astrofrog.github.com/idlsave/

go into python and import it:

>>> import idlsave

well, all you need to read a save file is like this:

>>> a = idlsave.read(‘/data/scratch/time.sav’)

you get things like that in terminal:

————————————————–
Date: Mon…..
User: …..
Host: ….
————————————————–
Format: 10
Architecture: x86_64
Operating System: linux
IDL Version: 8.1
————————————————–
Successfully read 5 records of which:
– 2 are of type VARIABLE
– 1 are of type TIMESTAMP
– 1 are of type VERSION
————————————————–
Available variables:
– xx [<type ‘numpy.ndarray’>]
– yy [<type ‘numpy.ndarray’>]
————————————————–

now, you have these two variables (xx, yy) available as a.xx and a.yy.

Done.

Read Full Post »

Jhead: edit exif information

Sometimes you want to edit the exif information of your images, e.g., Jpeg files. How to do so in Linux command line? This is an important question if you have to do something for many files. For instance, you have to correct the date of a lot of images since your camera had a wrong date. Jhead is an interesting program that does the job properly. Some simple applications:

If the image has no exif information, you can create an exif header
$jhead -mkexif file.jpg

changing the exif date
$jhead -ds2009:07:05  file.jpg

change the file time to Exif time
$jhead -ft *.jpg

add a comment
$jhead -cl “It was a nice photos” file.jpg

Hopefully this makes life easier for Linux users.

Read Full Post »

Older Posts »