def test_compute_flat_scale_NUV_array(self):
     band = 'NUV'
     ts=[869777733.995,901049156.995]
     scales=[0.986709143129,0.994262914909]
     out = gt.compute_flat_scale(ts,band,verbose=0)
     self.assertEqual(len(ts),len(out))
     self.assertAlmostEqual(out[0],scales[0])
     self.assertAlmostEqual(out[0],scales[0])
 def test_compute_flat_scale_FUV_array(self):
     band = 'FUV'
     ts=[869777733.995,901049156.995]
     scales=[0.991157347104,0.999816178202]
     out = gt.compute_flat_scale(ts,band,verbose=0)
     self.assertEqual(len(ts),len(out))
     self.assertAlmostEqual(out[0],scales[0])
     self.assertAlmostEqual(out[0],scales[0])
Beispiel #3
0
def hashresponse(band,events,verbose=0):
    """Given detector xi, eta, return the response at each position."""
    # Hash out the response correction
    if verbose:
        mc.print_inline("Applying the response correction.")
    flat, _ = cal.flat(band)
    events['col'], events['row'] = xieta2colrow(
                                            events['xi'], events['eta'], band)
    events['flat'] = flat[np.array(events['col'], dtype='int16'),
                          np.array(events['row'], dtype='int16')]
    events['scale'] = gxt.compute_flat_scale(events['t'], band)
    # TODO: Separately do the binlinearly interpolated response
    events['response'] = (events['flat']*events['scale'])
    return events
Beispiel #4
0
def rrhr(band,skypos,tranges,skyrange,width=False,height=False,stepsz=1.,
		 verbose=0,calpath='../cal/',tscale=1000.,response=True,hdu=False,
		 retries=20):
	"""Generate a high resolution relative response (rrhr) map."""
	imsz = gxt.deg2pix(skypos,skyrange)
	# TODO the if width / height

	flat = get_fits_data(flat_filename(band,calpath),verbose=verbose)
	flatinfo = get_fits_header(flat_filename(band,calpath))
	npixx,npixy 	= flat.shape
	fltsz 		= flat.shape
	pixsz = flatinfo['CDELT2']
	detsize = 1.25

	# Rotate the flat into the correct orientation to start.
	flat   = np.flipud(np.rot90(flat))

	# NOTE: This upsample interpolation is done _last_ in the canonical
	#	pipeline as part of the poissonbg.c routine.
	# 	The interpolation function is "congrid" in the same file.
	# TODO: Should this be first order interpolation? (i.e. bilinear)
	hrflat = scipy.ndimage.interpolation.zoom(flat,4.,order=0,prefilter=False)
	img = np.zeros(hrflat.shape)[
				hrflat.shape[0]/2.-imsz[0]/2.:hrflat.shape[0]/2.+imsz[0]/2.,
				hrflat.shape[1]/2.-imsz[1]/2.:hrflat.shape[1]/2+imsz[1]/2.]

	for trange in tranges:
		t0,t1=trange
		entries = gQuery.getArray(gQuery.aspect(t0,t1),retries=retries)
		n = len(entries)

		asptime = np.float64(np.array(entries)[:,2])/tscale
		aspra   = np.float32(np.array(entries)[:,3])
		aspdec  = np.float32(np.array(entries)[:,4])
		asptwist= np.float32(np.array(entries)[:,5])
		aspflags= np.float32(np.array(entries)[:,6])
		asptwist= np.float32(np.array(entries)[:,9])
		aspra0  = np.zeros(n)+skypos[0]
		aspdec0 = np.zeros(n)+skypos[1]

		xi_vec, eta_vec = gnomonic.gnomfwd_simple(
							aspra,aspdec,aspra0,aspdec0,-asptwist,1.0/36000.,0.)

		col = 4.*( ((( xi_vec/36000.)/(detsize/2.)*(detsize/(fltsz[0]*pixsz)) + 1.)/2. * fltsz[0]) - (fltsz[0]/2.) )
		row = 4.*( (((eta_vec/36000.)/(detsize/2.)*(detsize/(fltsz[1]*pixsz)) + 1.)/2. * fltsz[1]) - (fltsz[1]/2.) )

		vectors = rotvec(np.array([col,row]),-asptwist)

		for i in range(n):
			if verbose>1:
				print_inline('Stamping '+str(asptime[i]))
				# FIXME: Clean this mess up a little just for clarity.
	        	img += scipy.ndimage.interpolation.shift(scipy.ndimage.interpolation.rotate(hrflat,-asptwist[i],reshape=False,order=0,prefilter=False),[vectors[1,i],vectors[0,i]],order=0,prefilter=False)[hrflat.shape[0]/2.-imsz[0]/2.:hrflat.shape[0]/2.+imsz[0]/2.,hrflat.shape[1]/2.-imsz[1]/2.:hrflat.shape[1]/2+imsz[1]/2.]*dbt.compute_exptime(band,[asptime[i],asptime[i]+1],verbose=verbose,retries=retries)*gxt.compute_flat_scale(asptime[i]+0.5,band,verbose=0)

	return img
 def test_compute_flat_scale_NUV(self):
     band = 'NUV'
     ts=[869777733.995,901049156.995]
     scales=[0.986709143129,0.994262914909]
     for t,scl in zip(ts,scales):
         self.assertAlmostEqual(gt.compute_flat_scale(t,band,verbose=0),scl)
 def test_compute_flat_scale_FUV(self):
     band = 'FUV'
     ts=[869777733.995,901049156.995]
     scales=[0.991157347104,0.999816178202]
     for t,scl in zip(ts,scales):
         self.assertAlmostEqual(gt.compute_flat_scale(t,band,verbose=0),scl)