Archive for 2014

Shared folder in linux

Posted October 23, 2014 By grigoris

Suppose that we want to create a folder in which multiple users will have full access (which means that they will be able to read, write, and execute).

  1. We create the folder (under ‘/’ in this example, although it can be anywhere else):

    sudo mkdir test

    which has the following permissions:

    drwxr-xr-x 2 root root 4096 Oct 23 13:07 test

  2. We make a new group of users (“testers”):

    sudo groupadd testers

    and then we add to this group all users we want to have access:

    sudo usermod -a -G testers testuser

    (id testuser will return the groups that the testuser belongs to)

  3. We change the permissions of the shared folder (this is more useful if we have copied or moved a folder with some contents already):

    sudo chgrp -R testers /test
    sudo chmod -R g+rwx /test

    so as every user in the groups “testers” can access the folder.
    However, when a user creates a file, it is assigned with the permissions set by the user and its primary group, e.g.

    -rw-rw-r-- 1 testuser testuser 0 Oct 23 14:21 tempfile

  4. In order to automatically assign the permissions of the group when creating files and folders in the shared folder, we assign the “s” option (for setting the group id – SGID):

    chmod -R g+s test

    For example:

    drwxrwsr-x 2 testuser testers 4096 Oct 23 14:34 newdir
    -rw-rw-r-- 1 testuser testers 0 Oct 23 14:35 newfile

    Now everyone in the “testers” groups can create, edit, delete, etc. the contents of this folder.

Useful articles:
[1] “How can I give write-access of a folder to all users in linux?”,, retrieved on Oct 23, 2014
[2] “Using SGID to Control Group Ownership of Directories”, Yale University Library Workstation Support / Yale University Library, retrieved Oct 23, 2014
[3] “Linux chmod command sticky bit example and implementations”,, retrieved Oct 23, 2014

the end …

Posted September 30, 2014 By grigoris

… and the start of a new chapter after the successful defense of the PhD on September 18th, 2014!

Relocation – moving to Prague, Chech Republic

Posted August 21, 2014 By grigoris

Since August 1, 2014, I have started working in the Stellar Physics Department of the Astronomical Institute of Academy of Sciences, in Czech Republic, with Michaela Kraus. I will contribute to the investigation of the mass-loss history of some massive beasts out there (Luminous Blue Variables, B[e] supergiants, yellow hypergiants)

Information on these new area and updates on the site will be performed after defending* the phd in September!

*when more free time will be available !

Ureka – one package to install them all!

Posted August 7, 2014 By grigoris

Among the simplest installation methods to install IRAF are SciSoft (for RedHat/Fedora based distributions) and Fernando Avila Castro iso files (for Ubuntu/Debian based distributions). However, both require root privileges. What can you do when you do not have these permissions?

Ureka [1] comes in rescue! It is easy to install (download and run the installer![2]) and it doesn’t need any root privileges, so you can install it under your home directory.

Moreover, it offers, along with a simple installation of IRAF, a full installation of Python, with many pre-installed modules useful to perform almost any astronomical reduction (e.g. PyRAF, Astropy, matplotlib, pandas, [more]).

By default Ureka (1.4.1) installs with a Python version (2.7.3), and it modifies your shell starting scripts (bashrc,tcshrc) to create the aliases to use. E.g. the added lines in a .bashrc file are:

ur_setup() {
    eval `/var/home/maravelias/.ureka/ur_setup -sh $*`
ur_forget() {
    eval `/var/home/maravelias/.ureka/ur_forget -sh $*`

and you can invoke Ureka by simple typing: ur_setup. Now, this means that in every shell that you start you will have to type over and over again the same command, which becomes at least frustrating. In order to avoid this, you can simply comment the alias line:

#ur_setup() {
eval `/var/home/maravelias/.ureka/ur_setup -sh $*`
ur_forget() {
    eval `/var/home/maravelias/.ureka/ur_forget -sh $*`

so Ureka starts with every shell now. This option allows Python to install any extra modules (through PyPI – pip install) to the Ureka path and not system’s Python path.

Ureka allows for multiple installations of difference versions or different variants so there is reasoning in using the alias – but still for many users it may not be necessary (in any case you just uncomment the lines and you get back to the normal use).

So, Ureka offers an easy and clean way to install IRAF and a powerfull Python installation at the same time, without any root permissions. The only drawback is that it needs a lot of space (~4-5 GB), but it does not seem dramatic nowadays. [As far as the sys-admins it is easier to provide you with more extra space rather than software installations/updates within their systems.]

[1] Ureka:
[2] Documentation 1.4:

Fast coordinate conversion with ds9

Posted July 22, 2014 By grigoris

Fast and easy conversion of a .reg file with image coordinates (x,y positions) to sky coordinates (RA,Dec;sexagesimal):

ds9 image.fits -regions load input_imageCoordinates.reg -regions system wcs -regions skyformat sexagesimal -regions save outout_skyCoordinates.reg -exit

with automatic exit of the program!

Thanks to Alexandros M. for providing some examples!

[1] ds9:
[2] ds9 command list:

Retrieve header key with gethead

Posted June 19, 2014 By grigoris

A quick note on gethead of WCSTools – as I have needed many times (but obviously not that many to remember it!).

Rather straightforward use: gethead HEADER_KEY image.fits
(as simple as possibly!)
If HEADER_KEY contains empty spaces then use double quotes, e.g. “HIERARCH TEL AIRM END”.

Reminder: you have to have installed already the WCSTools! (See the “Installing WCSTools” for this.)

[Ref: WCSTools – gethead: ]

Spectrophotometry with IRAF’s sbands

Posted June 16, 2014 By grigoris

After a long time I finally managed to understand how to use IRAF’s sbands, along with a standard star and a filter.

1. If you want to use a spectrum from the standard star library of IRAF, you have to convert it from a .dat file to an image file .fits – Spectra files located in …/iraf/iraf/noao/lib/onedstds/ – by using the rspectext.
2. Having created an image file* (of the 1D spectrum), sbands uses this image and a bandpass file to provide the results (fluxes, or magnitudes). The contents of the bandpass file is the bands for which we want to measure flux/mag: name of the band, central wavelength, width, filter transmission file (if available).

*[2014/06/25 update]
Caution: the spectrophotometric files contain 2 columns, the wavelength and the magnitude, which means that they are reversed when plotted – so they have to be transformed into fluxes (in wavelength units) to be used properly.

[originated from: spectrophotometry with sbands or something else at ]

Struggling with BibTeX ???

Posted June 3, 2014 By grigoris

Ok, it is time to try this promising thing called BibTeX [1,2,3], which allows you to use only one file with references* (suppose MyBibTeX.bib). Then, it easy to add references in any document just by simple adding the file and the citations. Although it seems rather straightforward hot to make the file its implementation is not.

So, first step is to add the file (or files separated with commas!) in you .tex document:
[or even multiple files and in various locations, e.g. \bibliography{/path/to/bib,bib2,MyBibTeX} – by the way I did not notice any difference if extension .bib is kept or omitted!]

The second step is to add the style which will be used to represent the references. This is done by adding:
\usepackage{natbib} – at the preamble of the document and
\bibliographystyle{plainnat} – after/before \bibliography{}
to have the normal author-year style representation [3].

Now, to get proper representation of the references we have to compile the .bib file. This may seem a little complex (but you get used to this easily!):

  • pdflatex afile.tex
  • bibtex MyBibTeX.aux
  • pdflatex afile.tex
  • pdflatex afile.tex

[pdflatex or latex – depending on what you are using; see [3] for details]

In case on the error: “Bibliography not compatible with author-year citations
check that all your BibTeX entries include a year [4].
It is also important when making changes to the \bibliographystyle to remove the .aux and .bbl files completely [4].

[1] (retrieved 3/6/2014)
[2] Wikipedia: (retrieved 3/6/2014)
[3] WikiBooks/LaTeX: (retrieved 3/6/2014)
[4] (retrieved 3/6/2014)

*EXAMPLE of references inside a MyBibTeX.bib:

    author    = "M. Up and G. Down",
    title     = "Handbook of Testing TeX",
    publisher = "OpenBooks",
    year      =  2222,
    address   = "Caprica",
    edition   = "567th"

Complex dictionaries in python

Posted March 21, 2014 By grigoris

How to make a dictionary of dictionaries with lists inside?
For example we have a number of stellar spectral types (spec) and for each one of them we have a series of spectral lines (line) and their equivalent widths (ew). By creating a rather complex dictionary we can then call the list of values for the equivalent width for any spectral type and line we want.

Let’s look at this step by step.

1. A simple dictionary, with spetral types (spec) as keys and corresponding spectral lines as values:
dic = {}
dic[spec] = line

Output (which includes all spectral types but only the last spectral line parsed, because it just overrides the value for each key):
{'B1': 'HeI/4026', 'B0.5': 'HeI/4026'}

2. In order to get all spectral lines we have to make a list of values for each key. For this we have to import defaultdict first:

from collections import defaultdict
dic = defaultdict(list)

defaultdict(, {'B1': ['CaIIK/3928', 'HeI/4009', 'HeI/4026'], 'B0.5': ['CaIIK/3928', 'HeI/4009', 'HeI/4026']})

3. Now, we want to add the value of ew for each line.

from collections import defaultdict
dic = defaultdict(defaultdict)
dic[spec][line] = ew

defaultdict(, {'B1': defaultdict(None, {'HeI/4009': 0.38, 'CaIIK/3928': 0.29, 'HeI/4026': 1.03}), 'B0.5': defaultdict(None, {'HeI/4009': 0.33, 'CaIIK/3928': 0.27, 'HeI/4026': 1.09})})

4. If we want to have not only a value but a list of values (per spectral line) we need to define a function within the defaultdict. If we just put defaultdict(defaultdict(list)) it will not work as the defaultdict(list) will return something that is not expected as input by the next level defaultdict. To overcome this we use a “lambda” (anonymous) function:

from collections import defaultdict
dic = defaultdict(lambda: defaultdict(list))

defaultdict( at 0x2508578>, {'B1': defaultdict(, {'HeI/4009': [0.38], 'CaIIK/3928': [0.29], 'HeI/4026': [1.03]}), 'B0.5': defaultdict(, {'HeI/4009': [0.33, 0.63], 'CaIIK/3928': [0.27, 0.13], 'HeI/4026': [1.09, 1.96]})})

We can easily call any spectral line per type by simply calling dic[specific_spec][specific_line], e.g. dic[‘B0.5’][‘CaIIK/3928’] will give us [0.27, 0.13].

Reading columns from a text file – fast and easy!

Posted February 5, 2014 By grigoris

Although the are many information on how to use the genfromtxt (from numpy) there is not a clear demonstration (that I found…) to show how to easily read a text file with columns of data (including strings – it is straightforward to read columns of numbers with loadtxt for example).

Suppose that we have the following text file (named ‘input.txt’):

#object	q1	q2
id-001	120.	2212.
id-002	145.	1222.
id-222	123.	1142.

Then we can just use:

g = genfromtxt('input.txt',dtype=None,names=True)

This will read all the file. dtype=None means that the command will decide what type of data is each element and name=True means that we can use the names from the first raw (header) to call each column, i.e.:

print g['object']
print g['q2']

will print:

['id-001' 'id-002' 'id-222']
[ 2212. 1222. 1142.]

That easy, that fast !