2014年5月13日星期二

Lensing shear


Weak lensing enables the direct study of mass in the universe. Lensing, weak or strong, provides a more direct probe of mass than other methods which rely on astrophysical assumptions (e.g. hydrostatic equilibrium in a galaxy cluster) or proxies (e.g. the galaxy distribution), and can potentially access a more redshift- independent sample of structures than can methods which depend on emitted light with its r2 falloff. But strong lensing can be applied only to the centers of very dense mass concentrations. Weak lensing, in contrast, can be applied to the vast majority of the universe. It provides a direct probe of most areas of already-known mass concentrations, and a way to discover and study new mass concentrations which could potentially be dark. With sources covering a broad redshift range, it also has the potential to probe structure along the line of sight.

Weak gravitational lensing can be described as a linear transformation between unlensed coordinates (xu, yu; with the origin at the center of the distant light source) and the lensed coordinates in which we observe galax- ies (xl, yl; with the origin at the center of the observed image), 
Note that any symmetric 2×2 matrix can be written in the form 
Wrong? From: http://mwhite.berkeley.edu/Lensing/SantaFe04.pdf
How to understand the three parameters (r1, r2, k)?
   For the meaning of r and k, you can understand in this way. Keep the r1 in the equation, and if r1>0, the observed x will be enlarged by a factor of r1 with y shrunk by a factor of r1. Thus the observed shape of the source will looks like be elongated in x axis. For the other two parameters, you can think in the same way.

a positive (negative) γ1 results in an image being stretched along the x (y) axis direction 


   The convergence κ represents an isotropic magnification, and the shear γ represents a stretching in the direction φ. They are both related to physical properties of the lens as linear combinations of derivatives of the deflection angle. However, κ can be interpreted very simply as the projected mass density Σ divided by the critical density Σcrit, while γ has no such straight- forward interpretation. In fact, γ is nonlocal: its value at a given position on the sky depends on the mass distribution everywhere, not simply at that position. 

The surface brightness is unchanged after lensing!
this is a consequence of the fact that the lens equation is a gradient map. Magnification changes only angular sizes and shapes on the sky. Thus a constant surface brightness sheet stays a constant brightness sheet when lensed 

%There are only two free parameters!
%The r = sqrt(r1**2+r2**2) is called the cosmic shear. In

Weak lensing dominate the lensing field!
The region with strong lensing is quite limited, however, the weak lensed region is several factors larger and can help us to determine the total mass of galaxies.

What is reduced shear? why?
In some cases, the size of  galaxies is not available, so we cannot detect the size changes to determine the convergence parameter.
   The convergence κ de- scribes a change in apparent size for lensed objects: areas of the sky for which κ is positive have apparent changes in area (at fixed surface brightness) that make lensed images appear larger and brighter than if they were unlensed, and a modified galaxy density.
   In these cases, we use reduced shear, g1 = γ1/(1 κ) and g2 = γ2/(1 κ) to include the influence of k to the parameter of r. If sources with intrinsically circular isophotes (contours of equal brightness) could be identified, the observed sources (post-lensing) would have elliptical isophotes that we can characterize by their minor-to-major axis ratio b/a and the orientation of the major axis φ. For |g| < 1, these directly yield a value of the reduced shear


What is the challenge?
    It is hard to make the shear measurement even we have utilized statistic methods. I list some problems in the work.

   Variable PSFs: For a summary of some common methods of PSF estimation and interpolation, see Kitching et al. (2013)

   Realistic galaxy morphologies: 20% galaxies can be perfectly fit by simple galaxy models. nearly half can be fit by them, but with additional substructure clearly evident. 30% are true “irregulars” that cannot be fit by simple models at all.
   Combination of multiple exposures
 
  


Reference:

Gravitational lensing: an astrophysical tool 

THE THIRD GRAVITATIONAL LENSING ACCURACY TESTING (GREAT3) CHALLENGE HANDBOOK 

2014年5月12日星期一

【relation】mass-metallicity relation for galaxies

From Erb's PPT (http://www2.astro.psu.edu/~caryl/a597/Bin_metallicity.pdf)


The simple interpretation for the mass- dependence is a metal loss via galactic winds, where galaxies with shallow potential well have more efficient outflows.

The scatter observed in the MZ relation is correlated with other physical properties. These correlations provide clues to the origin of the MZ relation. 
Deeper targeted surveys have extended the mass-metallicity relation to red- shifts of 1 (Savaglio et al. 2005), 2 (Erb et al. 2006), and 3 (Maiolino et al. 2008), and show that for a given stellar mass, galaxies have lower metallicities at increasing redshifts. [Christensen et al. 2014. He use the relation to obtain the mass of DLA galaxies using the DLA metallicity and DLA galaxy impact parameters.]

Zahid et al. 2014 defined the "turnover mass" in the mass-Z relation, and found that the "turnover mass" revolves with redshift from local to z~1.6.

I list some paper about the relation and will give a simple review for this relations sometime.
     CHEMICAL EVOLUTION OF THE ISM IN NEARBY GALAXIES

4.2. The Metallicity-Luminosity Relationship
The Universal Relation of Galactic Chemical Evolution: The Origin of the Mass-Metallicity Relation (Zahid 2014)

The MZ relation was first observed in a small sample of nearby galaxies by Lequeux et al. (1979). They showed that galaxy metallicity increases with stellar mass. Sub- sequently, Tremonti et al. (2004) measure the MZ rela- tion of 50, 000 star-forming galaxies in the local Uni- verse. They find a tight MZ relation (0.1 dex scatter) extending over three orders of magnitude in stellar mass. 

2014年5月10日星期六

【image】Bad Pixel Mask using DS9 Region Files

The basic idea to create the mask image is simple. Firstly, you need to define the bad pixels with ds9 region like box and polygon (one can only use these two type regions only usually). Usually,  there is two main steps to realize the idea.
(1) convert the ds9 region to a uniform format. Both the box and polygon regions can be treated as polygons.
an example of an image mask. The green outline is the polygon drawn into SAOimage DS9. [FROM the website of galfit]


(2) solve the PIP (point in polygon) problems (http://en.wikipedia.org/wiki/Point_in_polygon) and mask all the points in the polygon. I attached one useful python script to get rid of the PIP problem.
  If you want to make two loops in python to find all the inside points, you may find the speed is too low! Please avoid to use 'For' in python. The fast way is to use the exist program in numpymatplotlib.nxutils.points_inside_pol as following:

import numpy as np
from matplotlib.nxutils import points_inside_poly

nx, ny = 10, 10
poly_verts = [(1,1), (5,1), (5,9),(3,2),(1,1)]

# Create vertex coordinates for each grid cell...
# (<0,0> is at the top left of the grid in this system)
x, y = np.meshgrid(np.arange(nx), np.arange(ny))
x, y = x.flatten(), y.flatten()

points = np.vstack((x,y)).T

grid = points_inside_poly(points, poly_verts)
grid = grid.reshape((ny,nx))

print grid
[From: http://stackoverflow.com/questions/3654289/scipy-create-2d-polygon-mask]

(3) save your masked array !

=======================================================================

Python script to decide whether the point is inside the polygon.


def point_in_poly(x,y,poly):
    '''
    Decide whether the point is inside the polygon.
    '''
    n = len(poly)
    inside = False

    p1x,p1y = poly[0]
    for i in range(n+1):
        p2x,p2y = poly[i % n]
        if y > min(p1y,p2y):
            if y <= max(p1y,p2y):
                if x <= max(p1x,p2x):
                    if p1y != p2y:
                        xints = (y-p1y)*(p2x-p1x)/(p2y-p1y)+p1x
                    if p1x == p2x or x <= xints:
                        inside = not inside
        p1x,p1y = p2x,p2y

    return inside    


=======================================================================

Two example to realize the idea:

(1) A copy from here ( http://www.cfht.hawaii.edu/~chyan/wircam/badpix/badpix.html)
The program "wircampolyregion" and other IDL programs are attached in the end of the website.

(2) Another way and program is mentioned in GALFIT (http://users.obs.carnegiescience.edu/peng/work/galfit/MASKING.html).

=======================================================================

5. IDL Source Code

; NAME:
;       MASKREGION
; PURPOSE:
;       Produce a new bad pixel mask based on an exist one and ds9 region file 
;
; CALLING SEQUENCE:
;       MASKREGION, BADPIX = badpix, REGION = ds9.reg, NEWBADPIX= newbadpix
;
; INPUTS:
;       BADPIX    -  string scalar, the name of the original bad pixel mask.
;       REGION    -  DS9 region file, only polygon and box allowed.
;       NEWBADPIX -  string scalar, the new bad pixel mask.
;
;
; REVISION HISTORY:
;       initial version   Chi-hung Yan   March 2007
;-



PRO RDWIRCAMCUBE, file, im
    im=fltarr(2048,2048,4)
    for i=0,3 do begin
        im[*,*,i]=mrdfits(file,i+1)
    endfor
END


PRO MASKPOLYREGION, im, ext, x, y
    ind=polyfillv(x,y,2048,2048)
    tim=im[*,*,ext-1]
    tim[ind]=!values.f_nan
    im[*,*,ext-1]=tim[*,*]
END

PRO WRWIRCAMCUBE, im, fits, new
    main_hd=headfits(fits,exten=0)
    mwrfits, 3,new , main_hd, /create
    for i=1,4 do begin
        hdr = headfits(fits, exten=i)
        mwrfits,im[*,*,i-1],new,hdr
    endfor
END


PRO MASKREGION, badpix=badpix, region=region, newbadpix=newbadpix
    file=region
    fits=badpix    
        
    ; Read image        
    rdwircamcube,fits,im
        
        
    spawn,"wircampolyregion "+file+" /tmp/region.txt"
    readcol,"/tmp/region.txt",id,ext,x,y
    n=0
    
    xx=fltarr(1)
     yy=fltarr(1)
    for i=0,n_elements(x)-1 do begin
        if i eq 0 then begin
            temp=id[i]
        endif else begin
            temp=id[i-1]
        endelse
        
        if i eq 0 then begin
            xx=x[i]
            yy=y[i]
        endif else if id[i] eq temp then begin
            xx=[xx,x[i]]
            yy=[yy,y[i]]
        endif else begin
            maskpolyregion,im,ext[i-1],xx,yy
            xx=x[i]
            yy=y[i]
            n=n+1
        endelse
        
    end
    spawn,'rm -rf /tmp/region.txt'
    wrwircamcube, im, fits, newbadpix
    
END

6. Perl Script


#! /usr/bin/perl 
#----------------------------------------------------------------------------
#                             wircampolyregion
#----------------------------------------------------------------------------
# Contents: This script parse the ds9 region file into better format.  The out
#                out file can be easily used for IDL program.
#----------------------------------------------------------------------------
# Part of:     WIRcam C pipeline                               
# From:        ASIAA                    
# Author:      Chi-hung Yan(chyan@asiaa.sinica.edu.tw)                       
#----------------------------------------------------------------------------

use warnings;
use strict;

# Define global variable
our $SCRIPT_NAME = 'wircampolyregion';

sub trim {
   my $string=$_;
   for ($string) {
       s/^\s+//;
       s/\s+$//;
    }
   return $string;
}

# This finction is used to return program usage.
sub usage(){

print<<EOF
 USAGE: $SCRIPT_NAME <ds9.reg> <output.txt>


 EXAMPLES:
  $SCRIPT_NAME ds9.reg output.txt

EOF
}

if(@ARGV == 0 || @ARGV != 2){
   usage();
   exit 0;
}

my $file = $ARGV[0];
my $i=0;
my $j=0;
my $ext;
my $reg=0;

open(OUT,">$ARGV[1]");
open(FILE,$file);
while(<FILE>){
    if (/^# tile/){
        my @chip=split(" ",$_);
        $ext = $chip[2];
    }
    if (/^polygon/){
        $reg=$reg+1;
        my @word=split(/[\(\)]/,$_);
        my @coord=split(",",$word[1]);
        my $n=@coord/2;
        for ($i=0;$i<$n;$i++){
            printf(OUT "%d %d %7.2f %7.2f\n",$reg,$ext,$coord[2*$i],$coord[2*$i+1]);
        }    
    }
    if (/^box/){
        $reg=$reg+1;
        my @word=split(/[\(\)]/,$_);
        my @para=split(",",$word[1]);
        printf("$word[1]\n");
         printf(OUT "%d %d %7.2f %7.2f\n",$reg,$ext,$para[0]-$para[2]/2,$para[1]-$para[3]/2);
         printf(OUT "%d %d %7.2f %7.2f\n",$reg,$ext,$para[0]+$para[2]/2,$para[1]-$para[3]/2);
         printf(OUT "%d %d %7.2f %7.2f\n",$reg,$ext,$para[0]+$para[2]/2,$para[1]+$para[3]/2);
         printf(OUT "%d %d %7.2f %7.2f\n",$reg,$ext,$para[0]-$para[2]/2,$para[1]+$para[3]/2);
    }    


}

close(OUT);

2014年5月7日星期三

【HST, IRAC】make good photometry for IRAC image with HST high resolution image

This note keeps some tips of my work, so it may be hard for you to understand the details. You can give me emails to if you have difficult to make iraf photometry for faint objects.

How to make photometry?

   .... add soon



Be careful!

*) In galfit parameter file,
    Using a convolution box size larger than the image to make sure all the flux of bright objects in included.
    Resampling the psf to make sure the PSF fine-sampling factor is an integer value.
    The ellipticity is defined different in Sextractor which is "#ELLIPTICITY = 1-B_IMAGE/A_IMAGE".

How to improve the photometry?

Some steps for check
*) clip a large region for HST and IRAC images to check whether there is extended bright objects nearby.
*) for some objects, you can fake an object close to the target, and galfit them in the mean time. If  there is some bias about the magnitude, you should check your route.

Some improvement for galfit
*) Include all objects with HST magnitude brighter than 1 sigma IRAC detection limiting. 
*) Delete objects that are not detected in IRAC, and combine objects that are too close to be separated in IRAC image. Delete objects which are too close to the 
*) make sersic model for object larger than 1 IRAC pixel and estimate the position angle (the position angle are not define as the same in Sextractor and galfit, image1).
*) fixed all the positions, but release the position for quite bright or sersic model. fixed the ELLIPTICITY in sersic model.
*) release the postion of all object in the last run.
*) after complete the fit for ch1, then apply the same parameters for ch2. 


still not resoloved!!
*) The shift between IRAC and HST images, also between ch1 and ch2 IRAC images.
*) if the number of free parameters is larger than ??
*) which psf should be used?  one lose the information for the larger radius, the other is not so accurate.
*) galfit magnitude vs aperture photometry magnitude?
*) how to define whether one object is detected?
    the chi^2 improvement ?

Image1. Position angle



How to describe the results?

  Undetected
       too faint
       bright contaminated
  detected
       no other contamination
       bright galaxy nearby. give a flag to such candidates.
       faint galaxy in that cannot separated with the target.