Skip to content

Commit

Permalink
kmtnets update; implemented default distortion parameters (currently …
Browse files Browse the repository at this point in the history
…kmtnets only); better support for mosaic cameras
  • Loading branch information
mommermi committed Feb 24, 2017
1 parent 687bbed commit 8d84d31
Show file tree
Hide file tree
Showing 6 changed files with 172 additions and 58 deletions.
26 changes: 15 additions & 11 deletions diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,8 @@ def add_registration(data, extraction_data):
'_astrometry.png'
imgdat = fits.open(dat['fits_filename'],
ignore_missing_end=True)[0].data
imgdat = imresize(imgdat,
min(1., 1000./numpy.max(imgdat.shape)),
interp='nearest')
resize_factor = min(1., 1000./numpy.max(imgdat.shape))
imgdat = imresize(imgdat, resize_factor, interp='nearest')
header = fits.open(dat['fits_filename'],
ignore_missing_end=True)[0].header
median = numpy.median(imgdat[int(imgdat.shape[1]*0.25):
Expand Down Expand Up @@ -354,8 +353,10 @@ def add_registration(data, extraction_data):
c[0] < header[obsparam['extent'][0]]
and
c[1] < header[obsparam['extent'][1]])]
plt.scatter([c[0] for c in img_coo], [c[1] for c in img_coo],
s=20, marker='o', edgecolors='red', facecolor='none')
plt.scatter([c[0]*resize_factor for c in img_coo],
[c[1]*resize_factor for c in img_coo],
s=5, marker='o', edgecolors='red', linewidth=0.1,
facecolor='none')

plt.savefig(framefilename, format='png', bbox_inches='tight',
pad_inches=0, dpi=200)
Expand Down Expand Up @@ -633,9 +634,8 @@ def add_calibration(data):
fits_filename = dat['filename'][:dat['filename'].find('.ldac')] + \
'.fits'
imgdat = fits.open(fits_filename, ignore_missing_end=True)[0].data
imgdat = imresize(imgdat,
min(1., 1000./numpy.max(imgdat.shape)),
interp='nearest')
resize_factor = min(1., 1000./numpy.max(imgdat.shape))
imgdat = imresize(imgdat, resize_factor, interp='nearest')
header = fits.open(fits_filename, ignore_missing_end=True)[0].header
median = numpy.median(imgdat[int(imgdat.shape[1]*0.25):
int(imgdat.shape[1]*0.75),
Expand Down Expand Up @@ -668,10 +668,14 @@ def add_calibration(data):
world_coo = [[dat['match'][0][3][idx], dat['match'][0][4][idx]] \
for idx in dat['zp_usedstars']]
img_coo = w.wcs_world2pix(world_coo, True )
plt.scatter([c[0] for c in img_coo], [c[1] for c in img_coo],
s=40, marker='o', edgecolors='red', facecolor='none')
print(img_coo)
plt.scatter([c[0]*resize_factor for c in img_coo],
[c[1]*resize_factor for c in img_coo],
s=10, marker='o', edgecolors='red', linewidth=0.1,
facecolor='none')
for i in range(len(dat['zp_usedstars'])):
plt.annotate(str(i+1), xy=(img_coo[i][0]+30, img_coo[i][1]),
plt.annotate(str(i+1), xy=((img_coo[i][0]*resize_factor)+15,
img_coo[i][1]*resize_factor),
color='red', horizontalalignment='left',
verticalalignment='center')

Expand Down
18 changes: 17 additions & 1 deletion pp_distill.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,10 +412,26 @@ def distill(catalogs, man_targetname, offset, fixed_targets_file, posfile,
# sort objects by catalog idx
for cat_idx, cat in enumerate(catalogs):

objects_thiscat = [obj for obj in objects if obj['cat_idx']==cat_idx]
# check for each target if it is within the image boundaries
min_ra = numpy.min(cat['ra.deg'])
max_ra = numpy.max(cat['ra.deg'])
min_dec = numpy.min(cat['dec.deg'])
max_dec = numpy.max(cat['dec.deg'])
objects_thiscat = []
for obj in objects:
if obj['cat_idx'] != cat_idx:
continue
if (obj['ra.deg'] > max_ra or obj['ra.deg'] < min_ra or
obj['dec.deg'] > max_dec or obj['dec.deg'] < min_dec):
continue
objects_thiscat.append(obj)

if len(objects_thiscat) == 0:
continue

# create a new catalog
target_cat = catalog('targetlist:_'+cat.catalogname)

target_cat.add_fields(['ident', 'ra.deg', 'dec.deg'],
[[obj['ident'] for obj in objects_thiscat],
[obj['ra.deg'] for obj in objects_thiscat],
Expand Down
18 changes: 15 additions & 3 deletions pp_prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,7 @@ def prepare(filenames, obsparam, header_update, flipx=False,
if key not in obsparam.values():
header.remove(key)
elif 'PV' in key and '_' in key:
if key not in obsparam.values():
header.remove(key)
header.remove(key)
elif key in ['CTYPE1', 'CRPIX1', 'CRVAL1', 'CROTA1',
'CROTA2', 'CFINT1', 'CTYPE2', 'CRPIX2',
'CRVAL2', 'CFINT2', 'LTM1_1', 'LTM2_2',
Expand All @@ -229,7 +228,6 @@ def prepare(filenames, obsparam, header_update, flipx=False,
'AP_2_0', 'BP_ORDER', 'BP_0_0', 'BP_0_1',
'BP_0_2', 'BP_1_0', 'BP_1_1', 'BP_2_0', 'CDELT1',
'CDELT2', 'CRDELT1', 'CRDELT2']:
# used by LOWELL31, LOWELL90
if key not in obsparam.values():
header.remove(key)

Expand Down Expand Up @@ -374,6 +372,20 @@ def prepare(filenames, obsparam, header_update, flipx=False,
header['CRPIX2'] = (int(old_div(
float(header[obsparam['extent'][1]]), 2)),
'PP: fake Coordinate reference pixel')

# plugin default distortion parameters, if available
if 'distort' in obsparam and 'functionof' in obsparam['distort']:
try:
pv_dict = obsparam['distort'][header[obsparam['distort']
['functionof']]]
for pv_key, pv_val in pv_dict.items():
header[pv_key] = pv_val
except KeyError:
logging.error(('No distortion coefficients available for %s '
'%s') % (obsparam['distort']['functionof'],
header[obsparam['distort']
['functionof']]))

header['CD1_1'] = (xnorm * numpy.cos(this_rotate/180.*numpy.pi) *
obsparam['secpix'][0]*binning[0]/3600.,
'PP: fake Coordinate matrix')
Expand Down
58 changes: 25 additions & 33 deletions pp_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ def register(filenames, telescope, sex_snr, source_minarea, aprad,
if mancat is not None:
obsparam['astrometry_catalogs'] = [mancat]

# use each catalog twice
obsparam['astrometry_catalogs'] = [catcat for cat in
obsparam['astrometry_catalogs']
for catcat in [cat]*
_pp_conf.n_registration_repetitions ]
# # use each catalog twice
# obsparam['astrometry_catalogs'] = [catcat for cat in
# obsparam['astrometry_catalogs']
# for catcat in [cat]*
# _pp_conf.n_registration_repetitions ]

n_success_last_iteration = None

Expand Down Expand Up @@ -141,16 +141,8 @@ def register(filenames, telescope, sex_snr, source_minarea, aprad,
ra, dec, rad = toolbox.skycenter(ldac_catalogs)
logging.info('FoV center (%.7f/%+.7f) and radius (%.2f deg) derived' %
(ra, dec, rad))

del(ldac_catalogs)

ra = float(hdulist[0].header['CRVAL1'])
dec = float(hdulist[0].header['CRVAL2'])
rad = max([float(hdulist[0].header[obsparam['extent'][0]])*
float(hdulist[0].header['SECPIXX'])/3600.,
float(hdulist[0].header[obsparam['extent'][1]])*
float(hdulist[0].header['SECPIXY'])/3600.])

checkrefcat = catalog(refcat, display=False)
n_sources = checkrefcat.download_catalog(ra, dec, rad, 100,
save_catalog=False)
Expand Down Expand Up @@ -261,26 +253,26 @@ def register(filenames, telescope, sex_snr, source_minarea, aprad,
print('###\n###############################' + \
'#######################\n')

# registration succeeded for all images
if len(badfits) == 0:
break
# same number of good fits as for the last iteration
# break out!
elif len(goodfits) == n_success_last_iteration:
break
# registration failed for most (or all) images
else:
logging.info(' > match failed for %d/%d images' % \
(len(badfits), len(filenames)))

### if registration failed, try again with the same catalog
# and no extraction!
# this will make use of the .head files and improves results
logging.critical('Not all images matched ' \
+ '- try again or different catalog, if available')
if display:
print('Not all images matched ' \
+ '- try again for different catalog, if available')
# # registration succeeded for all images
# if len(badfits) == 0:
# break
# # same number of good fits as for the last iteration
# # break out!
# elif len(goodfits) == n_success_last_iteration:
# break
# # registration failed for most (or all) images
# else:
# logging.info(' > match failed for %d/%d images' % \
# (len(badfits), len(filenames)))

# ### if registration failed, try again with the same catalog
# # and no extraction!
# # this will make use of the .head files and improves results
# logging.critical('Not all images matched ' \
# + '- try again or different catalog, if available')
# if display:
# print('Not all images matched ' \
# + '- try again for different catalog, if available')

n_success_last_iteration = len(goodfits)

Expand Down
12 changes: 6 additions & 6 deletions setup/kmtnets.scamp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ MATCH Y # Do pattern-matching (Y/N) ?
MATCH_NMAX 0 # Max.number of detections for MATCHing
# (0=auto)
PIXSCALE_MAXERR 1.1 # Max scale-factor uncertainty
POSANGLE_MAXERR 2.0 # Max position-angle uncertainty (deg)
POSITION_MAXERR 150.0 # Max positional uncertainty (arcmin)
POSANGLE_MAXERR 5.0 # Max position-angle uncertainty (deg)
POSITION_MAXERR 80.0 # Max positional uncertainty (arcmin)
MATCH_RESOL 0 # Matching resolution (arcsec); 0=auto
MATCH_FLIPPED N # Allow matching with flipped axes?
MOSAIC_TYPE UNCHANGED # UNCHANGED, SAME_CRVAL, SHARE_PROJAXIS,
Expand All @@ -56,13 +56,13 @@ FIXFOCALPLANE_NMIN 1 # Min number of dets for FIX_FOCALPLANE

#---------------------------- Cross-identification ----------------------------

CROSSID_RADIUS 5.0 # Cross-id initial radius (arcsec)
CROSSID_RADIUS 2.0 # Cross-id initial radius (arcsec)

#---------------------------- Astrometric solution ----------------------------

SOLVE_ASTROM Y # Compute astrometric solution (Y/N) ?
PROJECTION_TYPE TPV # SAME, TPV or TAN
ASTRINSTRU_KEY FILTER,QRUNID # FITS keyword(s) defining the astrom
ASTRINSTRU_KEY FILTER,CCD_NAME # FITS keyword(s) defining the astrom
STABILITY_TYPE INSTRUMENT # EXPOSURE, PRE-DISTORTED or INSTRUMENT
CENTROID_KEYS XWIN_IMAGE,YWIN_IMAGE # Cat. parameters for centroiding
CENTROIDERR_KEYS ERRAWIN_IMAGE,ERRBWIN_IMAGE,ERRTHETAWIN_IMAGE
Expand All @@ -76,7 +76,7 @@ ASTRACCURACY_TYPE SIGMA-ARCSEC # SIGMA-PIXEL, SIGMA-ARCSEC,
# or TURBULENCE-ARCSEC
ASTRACCURACY_KEY ASTRACCU # FITS keyword for ASTR_ACCURACY param.
ASTR_ACCURACY 0.01 # Astrom. uncertainty floor parameter
ASTRCLIP_NSIGMA 2 # Astrom. clipping threshold in sigmas
ASTRCLIP_NSIGMA 2 # Astrom. clipping threshold in sigmas
COMPUTE_PARALLAXES N # Compute trigonom. parallaxes (Y/N)?
COMPUTE_PROPERMOTIONS N # Compute proper motions (Y/N)?
CORRECT_COLOURSHIFTS N # Correct for colour shifts (Y/N)?
Expand Down Expand Up @@ -120,7 +120,7 @@ CHECKIMAGE_NAME check.fits # Check-image filename(s)

#------------------------------ Miscellaneous ---------------------------------

SN_THRESHOLDS 20.0,50.0 # S/N thresholds (in sigmas) for all and
SN_THRESHOLDS 30.0,50.0 # S/N thresholds (in sigmas) for all and
# high-SN sample
FWHM_THRESHOLDS 50.0,100.0 # FWHM thresholds (in pixels) for sources
ELLIPTICITY_MAX 0.5 # Max. source ellipticity
Expand Down
98 changes: 94 additions & 4 deletions setup/telescopes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1446,12 +1446,97 @@
'ra': 'CCD_RA', # telescope pointing, RA
'dec': 'CCD_DEC', # telescope pointin, Dec
'radec_separator': 'XXX', # RA/Dec hms separator, use 'XXX'
# # use full CCD mosaic
# use full CCD mosaic
# 'ra': 'RA', # telescope pointing, RA
# 'dec': 'DEC', # telescope pointin, Dec
# 'radec_separator': ':', # RA/Dec hms separator, use 'XXX'

# default distortion parameters per CCD
# using individual CCD centers for CRPIX1/2, CRVAL1/2
# using 1x1 binning
'distort': {'functionof': 'CCD_NAME',
'K': {'PV1_0': -0.000711762135419,
'PV1_1': 1.00171981124,
'PV1_2': -0.000228317298275,
'PV1_4': 0.0160316513101,
'PV1_5': -0.0113636730644,
'PV1_6': 0.00549290221274,
'PV1_7': -0.010384662223,
'PV1_8': 0.00081137447258,
'PV1_9': -0.0104005033165,
'PV1_10': 0.000396116525231,
'PV2_0': 0.00319659825814,
'PV2_1': 1.00057217492,
'PV2_2': 0.0116970617468,
'PV2_4': -0.0165165992945,
'PV2_5': 0.0108419617955,
'PV2_6': -0.00548712635243,
'PV2_7': -0.0103126090939,
'PV2_8': 0.000686169735533,
'PV2_9': -0.0103739930263,
'PV2_10': 0.000240139308823},
'M': {'PV1_0': 0.000460033317474,
'PV1_1': 1.00141889978,
'PV1_2': -0.000430380594516,
'PV1_4': -0.015400655054,
'PV1_5': -0.0115995667827,
'PV1_6': -0.00518535937805,
'PV1_7': -0.0101118044677,
'PV1_8': -3.19250493138e-05,
'PV1_9': -0.0106737708283,
'PV1_10': -0.000431356736006,
'PV2_0': 0.00198339122013,
'PV2_1': 0.999670425747,
'PV2_2': -0.011005193782,
'PV2_4': -0.0167779694087,
'PV2_5': -0.0106335253045,
'PV2_6': -0.00526313446543,
'PV2_7': -0.0101955642118,
'PV2_8': -0.000255088245494,
'PV2_9': -0.0094035107269,
'PV2_10': -0.000292075883415},
'T': {'PV1_0': -0.00127421419519,
'PV1_1': 1.00104160823,
'PV1_2': -0.000660886473555,
'PV1_4': 0.0158990914667,
'PV1_5': 0.01169760742,
'PV1_6': 0.00543678807381,
'PV1_7': -0.0103261215423,
'PV1_8': -0.000794914727406,
'PV1_9': -0.0103649052751,
'PV1_10': -0.000279241301327,
'PV2_0': -0.00392674586144,
'PV2_1': 0.999343102486,
'PV2_2': -0.0111411751205,
'PV2_4': 0.017084775899,
'PV2_5': 0.010790771213,
'PV2_6': 0.00566154555136,
'PV2_7': -0.0102149292801,
'PV2_8': -0.000623538149787,
'PV2_9': -0.0102808588946,
'PV2_10': -0.000162027267646},
'N': {'PV1_0': 0.000594262478073,
'PV1_1': 0.998957324393,
'PV1_2': 0.00141244617639,
'PV1_4': -0.015924297871,
'PV1_5': 0.0114088931271,
'PV1_6': -0.00544474906971,
'PV1_7': -0.010256940745,
'PV1_8': 0.000789499342505,
'PV1_9': -0.0101626175866,
'PV1_10': 0.000179932486564,
'PV2_0': -0.00166315601111,
'PV2_1': 0.997680853652,
'PV2_2': 0.0102233336556,
'PV2_4': 0.0166335481995,
'PV2_5': -0.0107970324189,
'PV2_6': 0.00556273542573,
'PV2_7': -0.0103304464752,
'PV2_8': 0.00070600868855,
'PV2_9': -0.0102590932248,
'PV2_10': 0.000205537467251}},


# if already in degrees
'date_keyword': 'DATE-OBS', # obs date/time
# keyword; use
Expand Down Expand Up @@ -1481,13 +1566,18 @@

# registration settings (Scamp)
'scamp-config-file': rootpath + '/setup/kmtnets.scamp',
'reg_max_mag' : 19,
'reg_max_mag' : 18,
'reg_search_radius' : 0.5, # deg
'source_tolerance': 'none',
'scamp': {'ASTRINSTRU_KEY': 'FILTER,CCD_NAME'},

# default catalog settings
'astrometry_catalogs': ['GAIA'],
'photometry_catalogs': ['SDSS-R9', 'APASS9', '2MASS']
'astrometry_catalogs': ['GAIA', 'GAIA'], # run registration twice
# due to large field distortions
'photometry_catalogs': ['SDSS-R9', 'APASS9', '2MASS'],

# list of header keywords that should not be removed
'dont_remove': 'CCD_NAME'
}


Expand Down

0 comments on commit 8d84d31

Please sign in to comment.