Exemple #1
0
def make_darkhist(dateglob='20?????', plot=True, outroot=None, peak_norm=8.0, zodi_norm=False):
    if plot:
        plt.clf()

    darkfiles = glob('aca_dark_cal/{}'.format(dateglob))
    for darkdir in sorted(darkfiles):
        date = re.search(r'(\d+)', darkdir).group(1)
        if date not in cals_map:
            print '{} not in cals map'.format(date)
            continue

        cal = cals_map[date]
        print 'Processing', darkdir, date
        hdus = fits.open(os.path.join(darkdir, 'imd.fits'))
        dark = hdus[0].data.flatten()
        hdus.close()

        # Put in random gaussian noise to smooth things out at the low end
        dark += np.random.normal(0.0, 0.8, size=1024 ** 2)

        # Scale factor to adjust data to an effective temperature of t_ccd_ref.
        # For t_ccds warmer than t_ccd_ref this scale factor is < 1, i.e. the
        # observed dark current is made smaller to match what it would be at the
        # lower reference temperature.
        scale = 1.0 / dark_models.temp_scalefac(cal['temp'])
        dark *= scale

        if peak_norm is not None:
            peak = get_peak(dark)
            dark += peak_norm - peak

        if zodi_norm:
            dark -= cal['zodib']

        print (' t_ccd={:.2f} scale={:.2f} peak={:.2f} zodib={:.2f}'
               .format(cal['temp'], scale, peak, cal['zodib']))

        y, xb = np.histogram(dark, darkbins.bins)
        x = (xb[1:] + xb[:-1]) / 2
        if plot:
            plt.loglog(x, y)
            plt.draw()
            plt.show()

        if outroot:
            out = open('{}/{}.dat'.format(outroot, date), 'w')
            for i in range(len(x)):
                print >>out, x[i], y[i], 1 + y[i] * 0.1
            out.close()
Exemple #2
0
def draw_star(year=2014, t_ccd=-16.0, mag=10.3, figure=1, savefig=False):
    year = int(year)

    plt.close(figure)
    plt.figure(figure, figsize=(6, 6))

    img = dark_models.temp_scalefac(t_ccd) * DARKS[year][SL, SL]
    nn = img.shape[0] / 2
    img[nn - 3:nn + 3, nn - 3:nn + 3] += STAR_IMG * 10 ** ((STAR_MAG - mag) * 0.4)

    plt.imshow(img, interpolation='nearest', cmap=cm.afmhot)
    plt.colorbar()
    plt.title('Year={} T_ccd={:.1f} Mag={:.1f}'.format(year, t_ccd, mag))
    if savefig:
        plt.savefig('star_{}_t{:.1f}_mag{:.1f}.png'.format(year, t_ccd, mag))
Exemple #3
0
def plot_darkcal(darkfile, Tccd, plotsymcol='-', label=None, step=None):
    """
    Plot a real dark cal, scaled from temp C{Tccd} to -19

    @param darkfile: FITS file containing a dark current map image.
    @param Tccd: CCD temperature (degC)
    @param plotsymcol: Matplotlib symbol/color specifierr
    @param label: Matplotlib plot label
    @param step: Matplotlib plot step specifier

    @return: C{(dark, x, y)}
      - C{dark}: Dark current map (scaled to temperature C{Tccd})
      - C{x, y}: Histogram values plotted
    """
    hdus = pyfits.open(darkfile)
    # Convert to an effective T_ccd = -19
    dark = hdus[0].data.flatten() / dark_models.temp_scalefac(Tccd)
    x, y = plot_dark(dark, label, plotsymcol, step=step)
    return dark, x, y
Exemple #4
0
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