""" import sys import matplotlib.pyplot as plt from matplotlib import cm from astropy.io import fits sys.path.insert(0, '../dark_current_model') import dark_models if not 'DARKS' in globals(): DARK0 = dark_models.get_dark_map('2013191') STAR = fits.open('obs890_adat41.fits')[1].data DARKS = {} DARKS[2014] = dark_models.degrade_ccd(DARK0, 0.5, inplace=False) for year in range(2015, 1999 + 25 + 1): print "Creating year {} image".format(year) DARKS[year] = dark_models.degrade_ccd(DARKS[year - 1], 1.0, inplace=False) # 237 == 1 # 279 == 100 # dt = 42 degC => 10*2 => 21 degC per decade STAR_IMG = STAR[400]['img_corr'] / 1.7 # e-/sec from a 1.7 sec readout STAR_MAG = 10.3 SL = slice(400, 440) def draw_star(year=2014, t_ccd=-16.0, mag=10.3, figure=1, savefig=False):
def make_darkmaps(case='nominal', initial='pristine'): """Make dark current maps by degrading the CCD using the best-fit model from fit_evol.py""" date0 = DateTime('1999-05-23T18:00:00') if initial == 'pristine': # Start from a synthetic pristine CCD. Probably no good reason to use this, # prefer starting from the pre-SSD-open dark cal on 1999223. dark = dark_models.pristine_ccd() darkcals = alldarkcals elif re.match('from|zero', initial): darkmap, year, doy = re.match(r'(\S+)(\d{4})(\d{3})', initial).groups() yeardoy = year + ':' + doy date0 = DateTime(yeardoy) darkcals = alldarkcals[alldarkcals['date'] > yeardoy] if darkmap == 'zero': dark = dark_models.zero_dark_ccd() else: ok = alldarkcals['date'] == yeardoy tccd = alldarkcals[ok]['tccd'][0] scalefac = dark_models.temp_scalefac(tccd) print 'Scaling dark cal', yeardoy, 'by', '%.2f' % scalefac hdus = pyfits.open(os.path.join('aca_dark_cal', year+doy, 'imd.fits')) dark = hdus[0].data.flatten() / scalefac warmpix = dict(year=[], n100=[], n200=[], n2000=[]) print 'Calculating for', case, 'case starting from', initial, 'CCD' # First evolve from date0 through last dark cal dates = [x['date'] for x in darkcals] + [str(yr) + ':182' for yr in range(2009, 2020)] datelast = date0 for datestr in dates: date = DateTime(datestr) datemx = date.mxDateTime print date.date # Evolve (degrade) the CCD dark map. 'dark' is for an effective T=-19 temperature. dyear = (datemx - datelast.mxDateTime).days / yeardays dark_models.degrade_ccd(dark, dyear) # Determine actual or predicted CCD temperature try: ok = darkcals['date'] == datestr tccd = darkcals[ok]['tccd'][0] except IndexError: if datemx.year > 2014: if case == 'nominal': tccd = -18 else: tccd = -15 else: tccd = -19 # Calculate dark map at actual temperature and possibly write out to file scalefac = dark_models.temp_scalefac(tccd) dark_tccd = dark * scalefac outdir = os.path.join(case, initial) if not os.path.exists(outdir): os.makedirs(outdir) outfile = os.path.join(outdir, '%04d%03d.fits' % (datemx.year, datemx.day_of_year)) if os.path.exists(outfile): os.unlink(outfile) hdu = pyfits.PrimaryHDU(np.float32(dark_tccd.reshape(1024,1024))) hdu.writeto(outfile) # Calculate the standard warm/hot pixel stats for prediction warmpix['year'].append(datemx.year + datemx.day_of_year / yeardays) warmpix['n100'].append(len(where(dark_tccd > 100)[0])) warmpix['n200'].append(len(where(dark_tccd > 200)[0])) warmpix['n2000'].append(len(where(dark_tccd > 2000)[0])) datelast = date ## out = open('warmpix_' + case + '.dat', 'w') ## for i, n100 in enumerate(warmpix['n100']): ## print >>out, warmpix['year'][i], warmpix['n100'][i], warmpix['n200'][i], warmpix['n2000'][i] ## out.close() return warmpix