Tuesday, May 8, 2012

Repairing grub by booting from the Ubuntu live-CD

I just installed the new version of Ubuntu (12.04). The installation went fine but the bootloader installation at the end did not work. When I turn on the computer, the new version of the ubuntu does not show in the old bootloader (grub2) menu. What to do? #Boot the computer with the Ubuntu live cd, mount the / partition under /home/ubuntu/a and issue the following command : sudo mount --bind /dev/ /home/ubuntu/a/dev sudo mount --bind /proc/ /home/ubuntu/a/proc sudo mount --bind /sys/ /home/ubuntu/a/sys sudo chroot /home/ubuntu/a #Then let grub2 create /boot/grub/grub.cfg by autodetecting the present OS'es sudo update-grub Found linux image: /boot/vmlinuz-3.2.0-23-generic Found initrd image: /boot/initrd.img-3.2.0-23-generic Found memtest86+ image: /boot/memtest86+.bin Found Windows 7 (loader) on /dev/sda1 Found Ubuntu 10.10 (10.10) on /dev/sda6 done #Exit from the modified chroot exit #Run grub-install sudo grub-install --root-directory=/home/ubuntu/a /dev/sda You should get the message : Installation finished. No error reported.

Wednesday, April 25, 2012

Syntax highlighting in Blogger with SyntaxHighlighter

http://www.craftyfella.com/2010/01/syntax-highlighting-with-blogger-engine.html

Wednesday, March 21, 2012

Compiling source code of netcdf4 on linux

First obtain szip libraries (from the link at http://www.hdfgroup.org/HDF5/release/obtain5.html)
wget http://www.hdfgroup.org/ftp/lib-external/szip/2.1/src/szip-2.1.tar.gz
tar -xzvf szip-2.1.tar.gz
cd szip-2.1

./configure --prefix=/home/acizmeli/opt
make 
make test
make install

Then obtain the hd5 source code  (again from http://www.hdfgroup.org/HDF5/release/obtain5.html)
wget http://www.hdfgroup.org/ftp/lib-external/szip/2.1/src/szip-2.1.tar.gz
tar -xzvf hdf5-1.8.8.tar.gz 
cd hdf5-1.8.8
./configure --prefix=/home/acizmeli/opt  --with-szlib=/home/acizmeli/opt/
(make sure that ./configure has recognized the szip libraries)
make
(or for parallel compilation : ) make -j -16
make install

Then obtain the netcdf4 source :
wget http://www.unidata.ucar.edu/downloads/netcdf/ftp/netcdf-4.2.tar.gz
tar -xzvf netcdf-4.2.tar.gz
cd netcdf-4.2
CPPFLAGS=-I/home/acizmeli/opt/include/ LDFLAGS=-L/home/acizmeli/opt/lib ./configure --prefix=/home/acizmeli/opt/
make
make install

If there is a doxygen error, try adding --disable-doxygen

Sunday, March 11, 2012

Find nearest neighbours in a point cloud

From http://rwiki.sciviews.org/doku.php?id=tips:spatial-data:overlapping

library(spdep)
data(columbus)
#Extract coordinates from a data frame
coords <- columbus[,c("X", "Y")]
#For each point, determine the four closest points based on great circle distances:
knn.col <- knearneigh(as.matrix(coords), k=4, longlat=T)
knn.nb <- knn2nb(knn.col)
#What are the indices of the four nearest neighbours to point number 5?
knn.col$nn[5,]
#Equivalently:
knn.nb[[5]]
#Plot all points, then mark point number 5 by red, and its four nearest neighbours by blue:
plot(coords)
points(coords[5,], col="red", pch=19)
points(coords[knn.nb[[5]],], col="blue", pch=19)

Some beginner tricks with git

#################################################
Problem : error: Your local changes to the following files would be overwritten by merge: rfiles/BiOpticaR/Various/spacetime_ISIN.R
Please, commit your changes or stash them before you can merge.Aborting
#################################################
$ git pull
remote: Counting objects: 38, done.
remote: Compressing objects: 100% (19/19), done.
remote: Total 25 (delta 13), reused 1 (delta 0)
Unpacking objects: 100% (25/25), done.
From ssh://ekumen/home/acizmeli/GIT
   d63ba8f..cea6b9e  master     -> origin/master
Updating d63ba8f..cea6b9e
error: Your local changes to the following files would be overwritten by merge:
    rfiles/BiOpticaR/Various/spacetime_ISIN.R
Please, commit your changes or stash them before you can merge.
Aborting

Solution:
$ git reset --hard HEAD
HEAD is now at d63ba8f Moved all netcdf imagery functions in the fil......
$ git pull

#################################################
Problem :  Push rejected
! [rejected]        master -> master (non-fast forward)
error: failed to push some refs to.....
#################################################
Solution:
(From http://rip747.wordpress.com/2009/04/20/git-push-rejected-non-fast-forward/)

When trying to do a push to a repo, you might encounter the following error:
$ git push github master
To git@gitproxy:rip747/cfwheels.git
! [rejected]        master -> master (non-fast forward)
error: failed to push some refs to ‘git@gitproxy:rip747/cfwheels.git’
Don’t panic, this is extremely easy to fix. All you have to do is issue a pull and your branch will be fast-forward:
$ git pull github master
From git@gitproxy:rip747/cfwheels
* branch            master     -> FETCH_HEAD
Already uptodate!
Merge made by recursive.
Then retry your push and everything should be fine:
$ git push github master

#################################################
Problem : Automatic merge failed; fix conflicts and then commit the result.
#################################################
use :
git mergetool

Wednesday, March 7, 2012

Some time conversions in R

Form a "POSIXlt" object from a string :
tt = strptime("20100101","%Y%m%d", tz="GMT")

Compute the seconds since 1970 ((Internal storage format of the "POSIXlt" class)
as.double(tt)

Compute the days since 1970 (Internal storage format of the "Date class)
as.double(as.Date(tt))
or
unclass(as.Date(tt)) 

Convert an xts object into seconds since 1970
xx = xts(111, tt)
as.double(time(xx))

Convert an xts object into days since 1970
floor(as.double(time(xx))/60/60/24)

Construct a time object from different numeric components
ISOdatetime(year, month, day, hour, min, sec, tz = "")

Extract from a POSIXlt object the Year, month, day  etc information in numeric format :
class(a)
[1] "POSIXlt" "POSIXt"

a
[1] "2009-07-06 20:00:28"

c(a$year+1900, a$mon+1, a$mday, a$hour, a$min, a$sec)
[1] 2009    7    6   20    0   28

Convert a ESRI shapefile into GMT vector format

Use ogr2ogr to convert the shapefile into GMT vector format :

ogr2ogr -f "GMT" Hudson_bounds.gmt  Hudson_bounds.shp