Friday, 3 October 2014

test ipython.parallel

from IPython import parallel
c = parallel.Client(packer='pickle')
c.block = True
print(c.ids)

dview = c.direct_view()
dview.block = True
print(dview)

dview.execute('import numpy as np')

###using execute
dview.execute('a=np.random.randint(0,5,size=(1,2))')
print("a:\n{}".format(dview.gather('a')))

###using run
f=open('iptest.py','w')
f.write('import numpy as np\nb=np.zeros(shape=(1,4),dtype=np.int32)')
f.close()
dview.run('iptest.py')
print("b:\n{}".format(dview.gather('b')))
print type(dview.gather('b')[0,0])

###using dictionary
dview['c']=np.ones(shape=(2,3),dtype=np.int8)
print("a:\n{}".format(dview.gather('c')))
print type(dview.gather('c')[0,0])

---------------output------------------
[0, 1, 2]
<DirectView all>
a:
[[4 0]
 [4 1]
 [3 2]]
b:
[[0 0 0 0]
 [0 0 0 0]
 [0 0 0 0]]
<type 'numpy.int32'>
a:
[[1 1 1]
 [1 1 1]
 [1 1 1]
 [1 1 1]
 [1 1 1]
 [1 1 1]]
<type 'numpy.int8'>




Wednesday, 23 July 2014

To resize images

I used ffmpeg to scale the width to 480 pixels.

------------------------resize.bat------------------------
mkdir out
FOR %%A IN (*.jpg) DO (
    c:\tools\ffmpeg\bin\ffmpeg -i "%%A" -vf "scale=-1:480" "out/%%A.jpg"
)

Wednesday, 7 May 2014

Setting up a single node IPython Notebook

Install IPython

  After installing IPython by sudo apt-get install ipython-notebook, we can follow the instruction here to setup a public notebook. The steps are below:

note: this works for my old desktop
$ sudo apt-get install python-pip
$ sudo pip install ipython[all] --upgrade

1. create a certificate
openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem

2. generate a hashed password in IPython environment
In [1]: from IPython.lib import passwd
In [2]: passwd()
Enter password:
Verify password:
Out[2]: 'sha1:xxx:yyy'

3. create a notebook profile
ipython profile create wasit

4. edit /home/ubuntu/.ipython/profile_wasit/ipython_notebook_config.py by the following code:
c = get_config()
c.IPKernelApp.pylab = 'inline'
c.NotebookApp.certfile = u'/home/ubuntu/.ipython/profile_wasit/mycert.pem'
c.NotebookApp.ip = '*'
c.NotebookApp.open_browser = False
c.NotebookApp.password = u'sha1:xxx:yyy'
c.NotebookApp.port = 8888
c.NotebookApp.enable_mathjax = True

5. then we can start the notebook by going to particular directory and run the script
$ipython notebook --profile=wasit
or
$ipthon notebook --certfile=mycert.pem

However, the session will be terminate and we no longer run the job. In order to redirect the terminal output and keep the job run after terminating ssh, we should put the command in the 5th step in somescript.sh and run this
$ nohup ./somescript.sh </dev/null & 

Monday, 16 December 2013

Mount shared folder to Ubuntu in VirtualBox


We cannot use the /media/sf_Dropbox as a mount point because of permission. Create new folder as <~/Dropbox> and mount shared folder for VirtualBox by

>>sudo mount -t vboxsf <Dropbox> <~/Dropbox>

The mount above performs by root so normal user cannot write on the folder. We can define user and group of normal user by specify uid and gid as shown below

>>sudo mount -t vboxsf -o rw,uid=1000,gid=1000  <Dropbox> <~/Dropbox>

And you can unmount by

>>sudo umount -a -t vboxsf

Tuesday, 3 December 2013

Install Qt on Ubuntu 64 bit

I just got Lenovo L330 with Windows 8. I got a secured boot lock problem that made installing Ubuntu along with Windows 8. The secure boot lock must be disabled, for more detail please go to here.

Well, this note is about preparing Qt framework in Ubuntu 64 bit. I downloaded Qt online installer for Linux 64bit. It took about 30 minutes and installed with a warning message "This should not happen". I really don't know what does the message means. The installation finished and it looks OK.


3/12/13 10:40pm
Then I'm installing the g++ compiler by 
>>sudo apt-get install build-essential

Next the cmake, I found cmake in Synaptic Package Manager, installing  with 3 clicks. I also need OpenCV 2.3, another 3 clicks. The size of all OpenCV packages is quite large, so please be patient, it took me  20 minutes.

We just finished installed all package required for the project.

Thursday, 24 October 2013

Storyline test!

Storyline test!
To compare, three different techniques (our method, [tanahashi] and [Munroe]) for drawing storyline chart.

Ref
[Tanahashi] Tanahashi, Y. & Ma, K.-L. Design Considerations for Optimizing Storyline Visualizations Visualization and Computer Graphics, IEEE Transactions on, 2012, 18, 2679 -2688

[Munroe] R. Munroe. Xkcd #657: Movie narrative charts. http://xkcd.com/657, December 2009.

Marker

Marker to label the class of pixels, by Wasit Limprasert
Source files: marker.cpp, CMakeLists.txt, number.png 
Requirement: OpenCV2.4.5, Cmake2.8
Description: Marker load an original image and let user label classes of pixels. The marked image is then saved into bitmap file. There are 10 classes to be selected by pressing key number 0-9. "-" and "=" are used for deleting and saving, respectively.