def recalibrate():
    """
    Rerun the WFC3 calibration pipeline to flatten the (potentially)
    variable ramps
    """
    import matplotlib as mpl
    mpl.rcParams['backend'] = 'agg'

    import glob
    import os
    
    import stsci.tools
    from sgas import reprocess_wfc3
    
    # In RAW
    files=glob.glob('*raw.fits')
    reprocess_wfc3.show_ramps_parallel(files, cpu_count=4)

    files=glob.glob('*raw.fits')
    reprocess_wfc3.reprocess_parallel(files)
    
def preprocess():
    """
    Drizzle and align the other bands
    """
    
    # In Prep
    
    import grizli
    import grizli.prep
    
    import os
    
    import glob
    import numpy as np
    import sgas
    
    # other bands from the Gladders program
    files=glob.glob('../RAW/ic2*_flt.fits')
    visits, xx = grizli.utils.parse_flt_files(files=files, uniquename=True)
    
    # Alignment list, generated by GBr
    radec = os.path.join(sgas.get_data_path(), 'sdssj0851+3331-f160w.radec')
    
    # Copy aligment guess files
    os.system('cp {0}/*align_guess .'.format(sgas.get_data_path()))
    
    all_failed = []
    Skip=True
    
    # This main loop does all of the alignment and background subtraction
    for visit in visits:
        
        if os.path.exists('%s.failed' %(visit['product'])):
            all_failed.append(visit)
        
        if (os.path.exists('%s_drz_sci.fits' %(visit['product']))) & (Skip):
            continue
        
        print(visit['product'])   
        
        try:
            status = grizli.prep.process_direct_grism_visit(direct=visit, grism={}, radec=radec, skip_direct=False, align_mag_limits=[14,23], tweak_max_dist=8, tweak_threshold=8, align_tolerance=8, tweak_fit_order=2)
        except:
            fp = open('%s.failed' %(visit['product']), 'w')
            fp.write('\n')
            fp.close()
                        
            continue
                    
        if os.path.exists('%s.failed' %(visit['product'])):
            os.remove('%s.failed' %(visit['product']))
        
    # Make both images have the same pixel grid
    visits[1]['reference'] = 'sdssj0851+3331-c2i-06-293.0-f125w_drz_sci.fits'
    
    # Drizzle them, North-up and with 0.06" pixels
    grizli.prep.drizzle_overlaps(visits, parse_visits=False, pixfrac=0.8, scale=0.06, skysub=False, final_wht_type='IVM', check_overlaps=False)
    
    
    