Pages

mardi 17 juin 2014

Mac Port, Homebrew (and easy_install)

Mac Port:
Recently I tried to installed the HDF and netcdf software on Mac 10.9.2.
1) After installing the dependences HDF5-1.8 manually, I then tried to install the H5PY manually. But I got a problem which seems related to the utilisation of Clang (with gcc/cc compilers) and some long arguments of compilation.

2) I decide to use the Mac Port.

3) I installed the X-code command line (X-code already installed)

3) then installed Mac Port following the recommendation of port web site

4) several commands of Port are useful:
port search: give the list of softwares available for installation
port info software_full_name_in_mac_repertory: gives useful info about the software
port deps software_full_name_in_mac_repertory: gives the dependencies needed for this software
sudo port install software_full_name_in_mac_repertory: install the software
port contents software_full_name_in_mac_repertory: gives where the software is installed

Note:
-- Mac Port installs the softwares in /opt/local/bin , /opt/local/sbin which should be included in the PATH of bash file
-- Mac Port installs the Python softwares in /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages, which should be included in the PYTHONPATH of bash file
-- to check where the distribute package is, use the following python command
import site; site.getsitepackages()
5) the H5PY is installed with success by using Mac Port !!


--------------
easy_install:
It is a installation tool of for installing Python in linux and mac.  The path where the softwares can be installed must be defined in the file .pydistutils.cfg. 

For example, I used the following path:
[install]
install_lib = /Users/username/work/local/lib/python2.7/site-packages
#~/Library/Python/$py_version_short/site-packages

install_scripts = ~/work/local/bin


----
homebrew:
it is similar to Mac Port and it works well for installing and managing softwares on Mac OSX. This can be installed also easily once the X-code and X-code command line tool are installed. The default path of the installation is in /usr/local, which is different from Mac Port. 






mercredi 11 juin 2014

partition external disk on Mac

1) Open the Disk Utility
2) choose the disk that you want to make partition
   --- back up the data before doing any partition
   --- If there are several partitions existing in the disk, choose the whole disk, not a partition, if we want to have the tab Partition appearing in the window
   --- Choose Erase tab and OK
   --- choose Partition tab: decide how many partition you want to make, then for each one you give the partition name, partition size, the format, as well as the GUID (mac osx) or MRB(windows) in the Option. Choose Apply.
 3) then the disk should be partitioned according to your need.


   

mardi 22 avril 2014

use longtable in Latex

When I have a very long table which can occupy several pages, I need the package longtable for breaking the table and manage it.

When use this package, then we should not use the table package, ie., not to start by \begin{table}. The longtable should also replace the tabular. Then we can add caption and label in the following. We can start for example:
\begin{center}
\begin{longtable} {cccc}
\caption{Captions.}\\
\label{label name.}\\

If we want to adjust the table fontsize, we can:
 \begin{center}
\small{
\begin{longtable} {cccc}
\end{longtable}
}
\end{center}

If we want the same head line to appear in the table in the different pages, then we should for example define the head line of table in the first page:
FTLRS  &a &b  &   &MOBLAS-8 &a  &b \\  \hline
\endfirsthead

Then we need define the head line of table in the next pages:
FTLRS &a &b  & & MOBLAS-8 &a &b \\ \hline

\endhead

A complete example of using longtable is:
\documentclass{article}
\usepackage{longtable}
 \begin{document}

 \begin{center}
 \small{
   \begin{longtable} {ccccccc}
   \caption{Captions.} \\
   \label{label name} \\

  
   FTLRS &a &b  & &MOBLAS-8 & a &b \\ \hline   

   \endfirsthead

   FTLRS & a & b  &   & MOBLAS-8 & a & b \\ \hline   
   \endhead

   data1 & d1 &d2 &   &   data2 & d3 &d4 \\
   ....
   ...
   \end{longtable}
 }
\end{center}


 






Latex error: extra alignment tab has been changed to \cr

This is often caused by the inconsistency between the number of columns given in \begin{tabular}{ccc} and that given in the actual lines of the table.

If there is not inconsistency between them, then it is probably caused by the forgetting of \\ in the previous row.

mardi 4 février 2014

deal with very small value in python


sys.floatinfo(max=1.7976931348623157e+308, max_exp=1024, max_10_exp=308, min=2.2250738585072014e-308, min_exp=-1021, min_10_exp=-307, dig=15, mant_dig=53, epsilon=2.2204460492503131e-16, radix=2, rounds=1)

1+sys.float_info.epsilon  -----> 1.0000000000000002

1+sys.float_info.epsilon/10  -----> 1.0


To use and compute with very small values in python:

1) use the decimal module:
The defaut precision of decimal is 28, and we can change it. For example to define the Plank constant, 6.62606957e-34, we can do:
import decimal
decimal.getcontext().prec=46
h=decimal.Decimal('6.62606957e-34')
wavelength = np.arange(0.0001, 100)

frequency = c/wavelength
Iv = 5
tb = []
for v in frequency:
    temp_v = decimal.Decimal(str(v))
    temp_tb = h*temp_v/kb/(1+2*h*temp_v**3/Iv/c**2)
    #temp_tb_float = float(temp_tb)
    tb.extend([temp_tb])




Attention:
i) if use decimal, then we can not compute with another number which is defined in numpy.float64 for example. we have to convert them to the same format.
ii) the results of decimal is a string, and we can transfer to float directly.


2) use the C99 concept of nextafter to calculate the value appropriate epsilon. For Python, either use numpy or the Decimal class to calculate nextafter.



mardi 12 novembre 2013

awk: if a specific column contains a match


if a specific column of a file contains the matching string: it yes, print these lines:
set a = 200
awk  -v  col_value=$a   '{if ($5==col_value) print $0;}'   file

lundi 14 octobre 2013

use Uniq command

I wanted to remove the lines which contains certain repeated characters. For example, my file is:

0  name0 2011 station
1  name1 2012 station
2  name2 2012 station
3  name3 2013 station

what I want to have is:
0  name0 2011 station

2  name2 2012 station
3  name3 2013 station

I used the command uniq:
cat file | uniq -f 2 
This command ignores the first 2 fields in the file and only evaluate the remaining fields.

There are also other interesting options of uniq:
-w: This option restricts comparison to first specified ‘N’ characters only. For this example, use the following test2 input file.

-s:  This option skips comparison of first specified ‘N’ characters. For this example, use the following test3 input file.