Commit 02fd9859 authored by karpov-sv's avatar karpov-sv
Browse files

Improve line wrapping in code examples. Still not perfect.

parent 52da0f00
......@@ -16,10 +16,13 @@ We have some simple convenience routines that may be used to quickly extract som
.. code-block:: python
# Get the center position, size and pixel scale for the image from WCS
center_ra,center_dec,center_sr = astrometry.get_frame_center(wcs=wcs, width=image.shape[1], height=image.shape[0])
center_ra,center_dec,center_sr = astrometry.get_frame_center(wcs=wcs,
width=image.shape[1], height=image.shape[0])
pixscale = astrometry.get_pixscale(wcs=wcs)
print('Frame center is %.2f %.2f radius %.2f deg, %.2f arcsec/pixel' % (center_ra, center_dec, center_sr, pixscale*3600))
print('Frame center is %.2f %.2f radius %.2f deg, %.2f arcsec/pixel' %
(center_ra, center_dec, center_sr, pixscale*3600))
Initial astrometric solution (blind solving)
--------------------------------------------
......@@ -62,9 +65,13 @@ Example of using the code for solving the astrometry if not set in the header:
pixscale_upp = 3
# We will use no more than 500 brightest objects with S/N>10 to solve
wcs = astrometry.blind_match_astrometrynet(obj[:500], center_ra=ra0, center_dec=dec0, radius=sr0, scale_lower=pixscale_low, scale_upper=pixscale_upp, sn=10)
wcs = astrometry.blind_match_astrometrynet(obj[:500], center_ra=ra0, center_dec=dec0,
radius=sr0, scale_lower=pixscale_low, scale_upper=pixscale_upp, sn=10)
# .. or the same using local solver with custom config
wcs = astrometry.blind_match_objects(obj[:500], center_ra=ra0, center_dec=dec0, radius=sr0, scale_lower=pixscale_low, scale_upper=pixscale_upp, sn=10, verbose=True, _exe='/home/karpov/astrometry/bin/solve-field', config='/home/karpov/astrometry/etc/astrometry-2mass.cfg')
wcs = astrometry.blind_match_objects(obj[:500], center_ra=ra0, center_dec=dec0, radius=sr0,
scale_lower=pixscale_low, scale_upper=pixscale_upp, sn=10, verbose=True,
_exe='/home/karpov/astrometry/bin/solve-field',
config='/home/karpov/astrometry/etc/astrometry-2mass.cfg')
if wcs is not None and wcs.is_celestial:
print('Blind solving succeeded!')
......@@ -92,11 +99,13 @@ Example:
.. code-block:: python
# Let's use SCAMP for astrometric refinement.
wcs = pipeline.refine_astrometry(obj, cat, 5*pixscale, wcs=wcs, method='scamp', cat_col_mag='rmag', verbose=True)
wcs = pipeline.refine_astrometry(obj, cat, 5*pixscale, wcs=wcs,
method='scamp', cat_col_mag='rmag', verbose=True)
if wcs is not None:
# Update WCS info in the header
astrometry.clear_wcs(header, remove_comments=True, remove_underscored=True, remove_history=True)
astrometry.clear_wcs(header, remove_comments=True,
remove_underscored=True, remove_history=True)
header.update(wcs.to_header(relax=True))
.. autofunction:: stdpipe.astrometry.refine_wcs_scamp
......
......@@ -19,13 +19,16 @@ The following example shows how to get a reference catalogue for a given image
wcs = WCS(header)
# Get the center position, size and pixel scale for the image from WCS
center_ra,center_dec,center_sr = astrometry.get_frame_center(wcs=wcs, width=image.shape[1], height=image.shape[0])
center_ra,center_dec,center_sr = astrometry.get_frame_center(wcs=wcs,
width=image.shape[1], height=image.shape[0])
pixscale = astrometry.get_pixscale(wcs=wcs)
print('Frame center is %.2f %.2f radius %.2f deg, %.2f arcsec/pixel' % (center_ra, center_dec, center_sr, pixscale*3600))
print('Frame center is %.2f %.2f radius %.2f deg, %.2f arcsec/pixel' %
(center_ra, center_dec, center_sr, pixscale*3600))
# Load Pan-STARRS stars for this region brighter than r=18.0 mag
cat = catalogs.get_cat_vizier(center_ra, center_dec, center_sr, 'ps1', filters={'rmag':'<18'})
cat = catalogs.get_cat_vizier(center_ra, center_dec, center_sr, 'ps1',
filters={'rmag':'<18'})
print(len(cat), 'catalogue stars')
.. autofunction:: stdpipe.catalogs.get_cat_vizier
......
......@@ -26,12 +26,14 @@ Below are some examples of object detection.
.. code-block:: python
# We will detect objects using SExtractor and get their measurements in apertures with 3 pixels radius
# We will detect objects using SExtractor and get their measurements
# in apertures with 3 pixels radius.
# We will also ignore anything closer than 10 pixels to image edge
obj = photometry.get_objects_sextractor(image, mask=mask, aper=3.0, gain=gain, edge=10)
print(len(obj), 'objects detected')
# Rough estimation of average FWHM of detected objects, taking into account only unflagged (e.g. not saturated) ones
# Rough estimation of average FWHM of detected objects, taking into account
# only unflagged (e.g. not saturated) ones
fwhm = np.median(obj['fwhm'][obj['flags'] == 0])
print('Average FWHM is %.1f pixels' % fwhm)
......@@ -40,7 +42,9 @@ Next example shows how to receive extra columns, as well as checkimages, from SE
.. code-block:: python
# Now we will also get segmentation map and a column with object numbers correspoding to this map
obj,segm = photometry.get_objects_sextractor(image, mask=mask, aper=3.0, gain=gain, edge=10, extra_params=['NUMBER'], checkimages=['SEGMENTATION'], verbose=True)
obj,segm = photometry.get_objects_sextractor(image, mask=mask,
aper=3.0, gain=gain, edge=10, extra_params=['NUMBER'],
checkimages=['SEGMENTATION'], verbose=True)
# We may now e.g. completely mask the footprints of objects having masked pixels
fmask = np.zeros_like(mask)
......@@ -56,12 +60,17 @@ Finally, using SExtractor star/galaxy separators - `CLASS_STAR` and `SPREAD_MODE
# Run SExtractor
# You should provide correct path to default.nnw file from SExtractor installation on your system!
obj = photometry.get_objects_sextractor(image, mask=mask, edge=10, wcs=wcs, aper=3.0, extra_params=['CLASS_STAR', 'NUMBER'], extra={'SEEING_FWHM':fwhm, 'STARNNW_NAME':'/Users/karpov/opt/miniconda3/envs/stdpipe//share/sextractor/default.nnw'}, psf='/tmp/psf.psf', verbose=True)
obj = photometry.get_objects_sextractor(image, mask=mask, edge=10, wcs=wcs,
aper=3.0, extra_params=['CLASS_STAR', 'NUMBER'],
extra={'SEEING_FWHM':fwhm, 'STARNNW_NAME':'/Users/karpov/opt/miniconda3/envs/stdpipe//share/sextractor/default.nnw'},
psf='/tmp/psf.psf', verbose=True)
for i,cand in enumerate(obj):
print('Candidate %d at x/y = %.1f %.1d and RA/Dec = %.4f %.4f' % (i, cand['x'], cand['y'], cand['ra'], cand['dec']))
print('Candidate %d at x/y = %.1f %.1d and RA/Dec = %.4f %.4f' %
(i, cand['x'], cand['y'], cand['ra'], cand['dec']))
print('SPREAD_MODEL = %.3f +/- %.3f, CLASS_STAR = %.2f' % (cand['spread_model'], cand['spreaderr_model'], cand['CLASS_STAR']))
print('SPREAD_MODEL = %.3f +/- %.3f, CLASS_STAR = %.2f' %
(cand['spread_model'], cand['spreaderr_model'], cand['CLASS_STAR']))
.. attention::
The most important problem with object detection using these routines is handling of blended objects, as the codes we are using can't properly deblend close groups, except for simplest cases.
......@@ -80,9 +89,11 @@ The photometric measurements returned by the routines above are sometimes not th
.. code-block:: python
# We will pass this FWHM to measurement function so that aperture and background radii will be relative to it.
# We will pass this FWHM to measurement function so that aperture and
# background radii will be relative to it.
# We will also reject all objects with measured S/N < 5
obj = photometry.measure_objects(obj, image, mask=mask, fwhm=fwhm, gain=gain, aper=1.0, bkgann=[5, 7], sn=5, verbose=True)
obj = photometry.measure_objects(obj, image, mask=mask, fwhm=fwhm, gain=gain,
aper=1.0, bkgann=[5, 7], sn=5, verbose=True)
print(len(obj), 'objects properly measured')
......
......@@ -40,14 +40,19 @@ The calibration routine performs an iterative weighted linear least square (or r
.. code-block:: python
# Photometric calibration using 2 arcsec matching radius, r magnitude, g-r color and second order spatial variations
m = pipeline.calibrate_photometry(obj, cat, sr=2/3600, cat_col_mag='rmag', cat_col_mag1='gmag', cat_col_mag2='rmag', max_intrinsic_rms=0.02, order=2, verbose=True)
# The code above automatically augments the object list with calibrated magnitudes, but we may also do it manually
# Photometric calibration using 2 arcsec matching radius, r magnitude,
# g-r color and second order spatial variations
m = pipeline.calibrate_photometry(obj, cat, sr=2/3600, cat_col_mag='rmag',
cat_col_mag1='gmag', cat_col_mag2='rmag',
max_intrinsic_rms=0.02, order=2, verbose=True)
# The code above automatically augments the object list with calibrated
# magnitudes, but we may also do it manually
obj['mag_calib'] = obj['mag'] + m['zero_fn'](obj['x'], obj['y'])
obj['mag_calib_err'] = np.hypot(obj['magerr'], m['zero_fn'](obj['x'], obj['y'], get_err=True))
# Now, if we happen to know object colors, we may also compute proper color-corrected magnitudes:
# Now, if we happen to know object colors, we may also compute
# proper color-corrected magnitudes:
obj['mag_calib_color'] = obj['mag_calib'] + obj['color']*m['color_term']
.. autofunction:: stdpipe.photometry.match
......
......@@ -13,10 +13,12 @@ Image subtraction requires template image that has to be astrometrically aligned
.. code-block:: python
# Get r band image from PanSTARRS with science image original resolution and orientation
tmpl = templates.get_hips_image('PanSTARRS/DR1/r', wcs=wcs, width=image.shape[1], height=image.shape[0], get_header=False, verbose=True)
tmpl = templates.get_hips_image('PanSTARRS/DR1/r', wcs=wcs,
width=image.shape[1], height=image.shape[0], get_header=False, verbose=True)
# Now mask some brighter stars in the template as we know they are saturated in Pan-STARRS
tmask = templates.mask_template(tmpl, cat, cat_col_mag='rmag', cat_saturation_mag=15, wcs=wcs, dilate=3, verbose=True)
tmask = templates.mask_template(tmpl, cat, cat_col_mag='rmag', cat_saturation_mag=15,
wcs=wcs, dilate=3, verbose=True)
# And now the same - using original Pan-STARRS images and masks
tmpl,tmask = templates.get_ps1_image_and_mask('r', wcs=wcs, width=, height=, verbose=True)
......@@ -60,14 +62,22 @@ Running image subtraction
.. code-block:: python
# Run the subtraction getting back all possible image planes, assuming the template to be noise-less, and estimating image noise model from its statistics. And also pre-flatting the images before subtraction to get rid of possible background inhomogeneities.
# Run the subtraction getting back all possible image planes, assuming the template
# to be noise-less, and estimating image noise model from its statistics.
# And also pre-flatting the images before subtraction to get rid
# of possible background inhomogeneities.
import photutils
bg = photutils.Background2D(image, 128, mask=mask, exclude_percentile=30).background
tbg = photutils.Background2D(tmpl, 128, mask=tmask, exclude_percentile=30).background
diff,conv,sdiff,ediff = subtraction.run_hotpants(image-bg, tmpl-tbg, mask=mask, template_mask=tmask, get_convolved=True, get_scaled=True, get_noise=True, image_fwhm=fwhm, template_fwhm=1.5, image_gain=gain, template_gain=1e6, err=True, verbose=True)
diff,conv,sdiff,ediff = subtraction.run_hotpants(image-bg, tmpl-tbg,
mask=mask, template_mask=tmask,
get_convolved=True, get_scaled=True, get_noise=True,
image_fwhm=fwhm, template_fwhm=1.5,
image_gain=gain, template_gain=1e6,
err=True, verbose=True)
# Now we have:
# - `diff` for the difference image
......
......@@ -50,7 +50,7 @@ def run_hotpants(image, template, mask=None, template_mask=None, err=None, templ
:param _tmpdir: If specified, all temporary files will be created in a dedicated directory (that will be deleted after running the executable) inside this path.
:param _exe: Full path to HOTPANTS executable. If not provided, the code tries to locate it automatically in your :envvar:`PATH`.
:param verbose: Whether to show verbose messages during the run of the function or not. May be either boolean, or a `print`-like function.
:returns:
:returns: The difference image and, optionally, other kinds of images as requested by the `get_*` options above
"""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment