This simple script can be used to reduce (simulated) VIS data.
The script was initially written for reducing a single CCD data. However, since the version 0.5 the script tries to guess if the input is a single quadrant then reduce correctly.
The script performs the following data reduction steps:
1 Bias correction
2 CTI correction
3 Flat fielding (only if an input file is provided)
To Run:
python reduceVISdata.py -i VISCCD.fits -b superBiasVIS.fits -f SuperFlatField.fits
requires: | PyFITS |
---|---|
requires: | NumPy |
requires: | CDM03 (FORTRAN code, f2py -c -m cdm03 cdm03.f90) |
author: | Sami-Matias Niemi |
contact: | smn2@mssl.ucl.ac.uk |
version: | 0.5 |
Todo
Simple class to reduce VIS data.
Applies a CTI correction in electrons using CDM03 CTI model. Converts the data to electrons using the gain value given in self.values. The number of forward reads is defined by self.values[‘order’] parameter.
Bristow & Alexov (2003) algorithm further developed for HST data processing by Massey, Rhodes et al.
There is probably an excess of .copy() calls here, but I had some problems when calling the Fortran code so I added them for now.
Take into account pixel-to-pixel non-uniformity through multiplicative flat fielding.
Simply subtracts self.bias from the input data.
Write out FITS files using PyFITS.
This simple script can be used to study the number of bias frames required to meet the VIS calibration requirements.
The following requirements related to the bias calibration has been taken from GDPRD.
R-GDP-CAL-052: The contribution of the residuals of VIS bias subtraction to the error on the determination of each ellipticity component of the local PSF shall not exceed 3x10-5 (one sigma).
R-GDP-CAL-062: The contribution of the residuals of VIS bias subtraction to the relative error sigma(R2)/R2 on the determination of the local PSF R2 shall not exceed 1x10-4 (one sigma).
requires: | PyFITS |
---|---|
requires: | NumPy |
requires: | matplotlib |
requires: | VISsim-Python |
version: | 0.95 |
author: | Sami-Matias Niemi |
contact: | smn2@mssl.ucl.ac.uk |
Add readout noise to the input data. The readout noise is the median of the number of frames.
Parameters: |
|
---|---|
Returns: | data + read out noise |
Return type: | ndarray [same as input data] |
Calculate ellipticity and size for PSFs of different scaling when there is a residual bias offset.
Parameters: | sigma (float) – 1sigma radius of the Gaussian weighting function for shape measurements |
---|
Calculate ellipticity and size for PSFs of different scaling when there is a residual bias slope.
Parameters: | sigma (float) – 1sigma radius of the Gaussian weighting function for shape measurements |
---|
Generates a simple plot showing the errors in the ellipticity components.
Generates a simple plot showing the ellipticity components.
Creates a simple plot to combine and show the results for errors (delta).
Parameters: |
|
---|
Creates a simple plot to combine and show the results.
Parameters: |
|
---|
A simple function to test the area of pixels needed (defined by size) to derive the pixel offset to the level of required number of electrons given the readout noise and the gain of the system.
Parameters: |
|
---|---|
Returns: | none |
Derive the PSF ellipticities for a given number of random surfaces with random PSF positions and a given number of biases median combined and compare to the nominal PSF ellipticity.
This function can be used to derive the error (delta) in determining ellipticity and size given a reference PSF.
Choices that need to be made and effect the results:
- bias surface that is assumed (amplitude, complexity, etc.)
- whether the order of the polynomial surface to be fitted is known or not
- size of the Gaussian weighting function when calculating the ellipticity components
There are also other choices such as the number of PSFs and scaling and the random numbers generated for the surface that also affect the results, however, to a lesser degree.
Generates a set of plots that can be used to inspect the simulation.
Derive the PSF ellipticities for a given number of random surfaces with random PSF positions and a given number of biases median combined.
This function is to derive the the actual values so that the knowledge (variance) can be studied.
Choices that need to be made and effect the results:
- bias surface that is assumed (amplitude, complexity, etc.)
- whether the order of the polynomial surface to be fitted is known or not
- size of the Gaussian weighting function when calculating the ellipticity components
There are also other choices such as the number of PSFs and scaling and the random numbers generated for the surface that also affect the results, however, to a lesser degree.
Generates a set of plots that can be used to inspect the simulation.
This simple script can be used to study the number of flat fields required to meet the VIS calibration requirements.
The following requirements related to the flat field calibration has been taken from GDPRD.
R-GDP-CAL-054: The contribution of the residuals of VIS flat-field correction to the error on the determination of each ellipticity component of the local PSF shall not exceed 3x10-5 (one sigma).
R-GDP-CAL-064: The contribution of the residuals of VIS flat-field correction to the relative error on the determination of the local PSF R2 shall not exceed 1x10-4 (one sigma).
Note
The amount of cosmic rays in the simulated input images might be too low, because the exposure was set to 10 seconds and cosmic rays were calculated based on this. However, in reality the readout takes about 80 seconds. Thus, the last row is effected by cosmic a lot more than by assuming a single 10 second exposure.
requires: | PyFITS |
---|---|
requires: | NumPy |
requires: | SciPy |
requires: | matplotlib |
requires: | VISsim-Python |
version: | 0.97 |
author: | Sami-Matias Niemi |
contact: | s.niemi@ucl.ac.uk |
Calculate ellipticity and size for PSFs of different scaling when there is a residual pixel-to-pixel variations.
Generate a median combined flat field residual from given input files.
Randomly draws a given number (kw combine) of files from the file list identified using the files kw. Median combine all files before the lamp profile given by lampfile kw is being divided out. This will produce a derived flat field. This flat can be compared against the reference that was used to produce the initial data to derive a residual flat that describes the error in the flat field that was derived.
Parameters: |
|
---|
Warning
Remember to use an appropriate lamp and reference files so that the error in the derived flat field can be correctly calculated.
Returns: | residual flat field (difference between the generated flat and the reference) |
---|---|
Return type: | ndarray |
Creates a simple plot to combine and show the results.
Parameters: |
|
---|---|
Returns: | None |
Derive the PSF ellipticities for a given number of random surfaces with random PSF positions and a given number of flat fields median combined.
This function is to derive the the actual values so that the knowledge (variance) can be studied.
Calculate ellipticity and size variance and error in case of no pixel-to-pixel flat field correction.
This simple script can be used to study the error in the non-linearity correction that can be tolerated given the requirements.
The following requirements related to the non-linearity have been taken from GDPRD.
R-GDP-CAL-058: The contribution of the residuals of the non-linearity correction on the error on the determination of each ellipticity component of the local PSF shall not exceed 3x10**-5 (one sigma).
R-GDP-CAL-068: The contribution of the residuals of the non-linearity correction on the error on the relative error sigma(R**2)/R**2 on the determination of the local PSF R**2 shall not exceed 1x10**-4 (one sigma).
requires: | PyFITS |
---|---|
requires: | NumPy |
requires: | SciPy |
requires: | matplotlib |
requires: | VISsim-Python |
version: | 0.97 |
author: | Sami-Matias Niemi |
contact: | s.niemi@ucl.ac.uk |
Creates a simple plot to combine and show the results.
Parameters: |
|
---|---|
Returns: | None |
Function to study the error in the non-linearity correction on the knowledge of the PSF ellipticity and size.
The error has been assumed to follow a sinusoidal curve with random phase and a given number of angular frequencies (defined by the multiplier). The amplitudes being studied, i.e. the size of the maximum deviation, can be spaced either linearly or logarithmically.
Parameters: |
|
---|---|
Returns: | reference value and results dictionaries |
Return type: | list |
This script can be used to test the CTI correction algorithm performance.
requires: | NumPy |
---|---|
requires: | PyFITS |
requires: | matplotlib |
version: | 0.3 |
author: | Sami-Matias Niemi |
contact: | s.niemi@ucl.ac.uk |
Add CTI trails to a FITS file or input data.
Parameters: |
|
---|---|
Returns: |
Plot the CTI correction algorithm results.
Parameters: | results – CTI test results |
---|---|
Returns: | None |
Plot the CTI correction algorithm results.
Returns: | None |
---|
Calculates PSF properties such as ellipticity and size from data without CTI and from CTI data.
Parameters: |
|
---|---|
Returns: | ellipticity and size |
Return type: | dict |
Calculates PSF properties such as ellipticity and size from data w/ and w/o CTI.
Parameters: |
|
---|---|
Returns: | ellipticity and size |
Return type: | dict |
Test the impact of CTI in case of no noise and no correction.
Parameters: |
|
---|---|
Returns: |
This simple script can be used to study the error in the cosmic ray rejection that can be tolerated given the requirements.
The following requirements related to the cosmic rays have been taken from CalCD-B.
Note that the analysis is for a single star. Thus, if we consider a single exposure we can relax the requirements given that there will be on average about 1850 stars in each field that are usable for PSF modelling. Furthermore it shuold be noted that the presence of cosmic rays will always increase the size. Because of this one cannot combine the contribution from cosmic rays with other effects by adding each individual contribution in quadrature. It is more appropriate to add the impact of cosmic rays to the size of the PSF linearly given the preferred direction.
requires: | PyFITS |
---|---|
requires: | NumPy |
requires: | SciPy |
requires: | matplotlib |
requires: | VISsim-Python |
version: | 0.4 |
author: | Sami-Matias Niemi |
contact: | s.niemi@ucl.ac.uk |
Creates a simple plot to combine and show the results.
Parameters: |
|
---|---|
Returns: | None |
This is for a single PSF.
Parameters: |
|
---|---|
Returns: |
Parameters: |
|
---|---|
Returns: |
This scripts can be used to study the impact of ghost images on the weak lensing measurements.
requires: | PyFITS |
---|---|
requires: | NumPy (1.7.0 or newer for numpy.pad) |
requires: | SciPy |
requires: | matplotlib |
requires: | VISsim-Python |
version: | 0.2 |
author: | Sami-Matias Niemi |
contact: | s.niemi@ucl.ac.uk |
Calculates PSF size and ellipticity when including another PSF scaled to a given level (requirement = 5e-5)
Parameters: |
|
---|---|
Returns: | results |
Return type: | dict |
Calculates PSF size and ellipticity when including an out-of-focus doughnut of a given contrast level. The dougnut pixel values are all scaled to a given scaling value (requirement 5e-5).
Parameters: |
|
---|---|
Returns: | results |
Return type: | dict |
Parameters: |
|
---|---|
Returns: |
Draws a doughnut shape with a given inner and outer radius.
Parameters: |
|
---|---|
Returns: | image, xcentre, ycentre |
Return type: | list |
Derive area loss in case of object detection i.e. the SNR drops below the requirement. Assumes that a ghost covers the covering number of pixels and that the peak pixel of a point source contains fpeak fraction of the total counts. An offset between the V-band and VIS band is applied as VIS = V + offset.
Parameters: |
|
---|---|
Returns: | None |
Shape measurement bias as a result of ghosts.
Most PSF stars are bright while most weak lensing galaxies are faint, thus the PSF model needs to be transferable to an appropriate object luminosity (and colour, position, etc.). This simple script can be used to study the error in the model transfer due to non-linearity that can be tolerated given the requirements.
The following requirements related to the model transfer have been taken from CalCD-B.
requires: | PyFITS |
---|---|
requires: | NumPy |
requires: | SciPy |
requires: | matplotlib |
requires: | VISsim-Python |
version: | 0.2 |
author: | Sami-Matias Niemi |
contact: | s.niemi@ucl.ac.uk |
Creates a simple plot to combine and show the results.
Parameters: |
|
---|---|
Returns: | None |
Function to study the error in the non-linearity correction on the knowledge of the PSF ellipticity and size.
The error has been assumed to follow a sinusoidal curve with random phase and a given number of angular frequencies (defined by the multiplier). The amplitudes being studied, i.e. the size of the maximum deviation, can be spaced either linearly or logarithmically.
Parameters: |
|
---|---|
Returns: | reference value and results dictionaries |
Return type: | list |
This script can be used to derive statistics of background pixels.
Use dilation to define the background. Not working too well...
Kernel Density Estimation with Scipy
Kernel Density Estimation with Scikit-learn
Multivariate Kernel Density Estimation with Statsmodels
Univariate Kernel Density Estimation with Statsmodels
Load data, exclude pre- and over scan regions, and subtract the bias level found from the header.
Mask objects using sigma clipping around the median.
Will also plot the data and the mask.
Returns: | masked numpy array |
---|
Plots the entropy in the data. No really suitable as the input data not in a useful format.
Plot statistics of the background pixels. Assumes that the input contains only the background pixel values as a 1D array.
Returns: | None |
---|
Perform Gaussian filtering, sigma clipping and binary opening to define a mask for the background pixels.
This scripts can be used to study the impact of background subtraction errors on the shape measurements.
requires: | NumPy |
---|---|
requires: | SciPy |
requires: | matplotlib |
requires: | VISsim-Python |
version: | 0.1 |
author: | Sami-Matias Niemi |
contact: | s.niemi@ucl.ac.uk |
A simple function to test the area of pixels needed (defined by size) to derive the pixel value to the level of required number of electrons given the readout noise and the gain of the system.
Parameters: |
|
---|---|
Returns: | none |