# Sigma image

## Sigma image creation

• Number of photo-electrons:
```Ne = (Fgal+Fsky) × Ncomb  × G
```

Ncomb - number of images

Fgal [ADU] - flux of the galaxy

Fsky [ADU] - flux of the sky background

```σ2(Ne) = Ne + Ncomb × RON2
```

If there is a substantial dark current, then average value can be added in quadrature:

``` σ2(Ne) = Ne + Ncomb × RON2 + <DC> × Ncomb
```

<DC>[e] - dark current of the same exposure time as the images

```σ = σ(Ne) / (Ncomb  × G)
```

## SDSS sigma image

There is gain + rdnoise depending on camcol (for each filter) in the table (same link)!

To get sigma image go from Nmgy to DN: sky-subtracted image as well as calibrated in nanomaggies/pixel

```img = mrdfits(framename,0,hdr)
nrowc = (size(img,/dim))[1]
sky = mrdfits(framename,2)
```

Sky image must be of the same size as the frame image, in units of counts

```simg= interpolate(sky.allsky, sky.xinterp, sky.yinterp, /grid)
```

a calibration image the same size as the frame image, in units of nanomaggies per count

```calib = mrdfits(framename,1)
cimg= calib#replicate(1.,nrowc)
```

Original image in DN

```dn = img/cimg + simg
```

Corresponding sigma image

```dn_err= sqrt(dn/gain+darkVariance) ; in counts
```

To get those errors into nanomaggies, you simply apply back the calibration:

```img_err = dn_err*cimg
```

## Spitzer S4G sigma image

Ex. dwarf galaxy DDO 053: SKYDRKZB = 0.035142 and FLUXCONV = 0.1088

```imcopy ddo053_v7.phot.1 ddo53.phot.1
```

! SIGMA IMAGE must not have ZEROS, which we will solve by replacing 0 -> -1 in the WEIGHT image.

```imarith ddo053_v7.phot.1_wt.fits + 0. test
imexpr expr='(a = b) ? c : a' a='test.fits' b='0' c='-1' output='ddo53.phot.1_wt.fits'
imarith ddo53.phot.1.fits + 0.035142 ddo53.phot.1_sky.fits
imarith ddo53.phot.1_sky.fits / 909.9265 ddo53.phot.1_tmp.fits // 1./0.1088 *30*3.3 = 909.9265
imarith ddo53.phot.1_wt.fits / 10 ddo53_W.fits
imarith ddo53.phot.1_tmp.fits * ddo53_W.fits ddo53_Ne.fits
imarith ddo53_W.fits * 213.16 ddo53_ron.fits // 14.6*14.6 = ron^2 iz Salo2014_S4G
imarith ddo53_Ne.fits + ddo53_ron.fits ddo53_sigma2.fits
stsdas
toolbox
imgtools
imcalc ddo53_sigma2.fits ddo53_sigma.fits "sqrt(im1)" nullval="0"
imarith ddo53_sigma.fits * 0.0011 ddo53_sigma_tmp.fits
imarith ddo53_sigma_tmp.fits / ddo53_W.fits ddo53_sigma_est.fits
imarith ddo53_sigma_est.fits * 0.9 ddo53_sigma_decom.fits
imexpr expr='(a = b) ? c : a' a='ddo53_sigma_decom.fits' b='0' c='0.00266506'
output='ddo53_sigma_final.fits'
```

// This last number c is iterstat ddo53_sigma_decom.fits (it's last average value). Simply replace zeros in the sigma image by some resonable values, doesn't matter since galfit won't see those given the bad pixel mask...