def make_analysis_forms( basepath="/orange/adamginsburg/web/secure/ALMA-IMF/October31Release/", base_form_url="https://docs.google.com/forms/d/e/1FAIpQLSczsBdB3Am4znOio2Ky5GZqAnRYDrYTD704gspNu7fAMm2-NQ/viewform?embedded=true", dontskip_noresid=False): import glob from diagnostic_images import load_images, show as show_images from astropy import visualization import pylab as pl savepath = f'{basepath}/quicklooks' try: os.mkdir(savepath) except: pass filedict = { (field, band, config, robust, selfcal): glob.glob( f"{field}/B{band}/{imtype}{field}*_B{band}_*_{config}_robust{robust}*selfcal{selfcal}*.image.tt0*.fits" ) for field in "G008.67 G337.92 W43-MM3 G328.25 G351.77 G012.80 G327.29 W43-MM1 G010.62 W51-IRS2 W43-MM2 G333.60 G338.93 W51-E G353.41" .split() for band in (3, 6) #for config in ('7M12M', '12M') for config in ('12M', ) #for robust in (-2, 0, 2) for robust in (0, ) for selfcal in ("", ) + tuple(range(0, 9)) for imtype in (('', ) if 'October31' in basepath else ('cleanest/', 'bsens/')) } badfiledict = {key: val for key, val in filedict.items() if len(val) == 1} print(f"Bad files: {badfiledict}") filedict = {key: val for key, val in filedict.items() if len(val) > 1} filelist = [key + (fn, ) for key, val in filedict.items() for fn in val] prev = 'index.html' flist = [] #for field in "G008.67 G337.92 W43-MM3 G328.25 G351.77 G012.80 G327.29 W43-MM1 G010.62 W51-IRS2 W43-MM2 G333.60 G338.93 W51-E G353.41".split(): ##for field in ("G333.60",): # for band in (3,6): # for config in ('7M12M', '12M'): # for robust in (-2, 0, 2): # # for not all-in-the-same-place stuff # fns = [x for x in glob.glob(f"{field}/B{band}/{field}*_B{band}_*_{config}_robust{robust}*selfcal[0-9]*.image.tt0*.fits") ] # for fn in fns: for ii, (field, band, config, robust, selfcal, fn) in enumerate(filelist): image = fn basename, suffix = image.split(".image.tt0") if 'diff' in suffix or 'bsens-cleanest' in suffix: continue outname = basename.split("/")[-1] if prev == outname + ".html": print( f"{ii}: {(field, band, config, robust, fn)} yielded the same prev " f"{prev} as last time, skipping.") continue jj = 1 while jj < len(filelist): if ii + jj < len(filelist): next_ = filelist[ii + jj][5].split(".image.tt0")[0].split( "/")[-1] + ".html" else: next_ = "index.html" if next_ == outname + ".html": jj = jj + 1 else: break assert next_ != outname + ".html" try: with warnings.catch_warnings(): warnings.filterwarnings('ignore') print(f"{ii}: {(field, band, config, robust, fn, selfcal)}" f" basename='{basename}', suffix='{suffix}'") imgs, cubes = load_images(basename, suffix=suffix) except KeyError as ex: print(ex) raise except Exception as ex: print(f"EXCEPTION: {type(ex)}: {str(ex)}") raise continue norm = visualization.ImageNormalize( stretch=visualization.AsinhStretch(), interval=visualization.PercentileInterval(99.95)) # set the scaling based on one of these... # (this call inplace-modifies logn, according to the docs) if 'residual' in imgs: norm(imgs['residual'][imgs['residual'] == imgs['residual']]) imnames_toplot = ('mask', 'model', 'image', 'residual') elif 'image' in imgs and dontskip_noresid: imnames_toplot = ( 'image', 'mask', ) norm(imgs['image'][imgs['image'] == imgs['image']]) else: print( f"Skipped {fn} because no image OR residual was found. imgs.keys={imgs.keys()}" ) continue pl.close(1) pl.figure(1, figsize=(14, 6)) show_images(imgs, norm=norm, imnames_toplot=imnames_toplot) pl.savefig(f"{savepath}/{outname}.png", dpi=150, bbox_inches='tight') metadata = { 'field': field, 'band': band, 'selfcal': selfcal, #get_selfcal_number(basename), 'array': config, 'robust': robust, 'finaliter': 'finaliter' in fn, } make_quicklook_analysis_form(filename=outname, metadata=metadata, savepath=savepath, prev=prev, next_=next_, base_form_url=base_form_url) metadata['outname'] = outname metadata['suffix'] = suffix if robust == 0: # only keep robust=0 for simplicity flist.append(metadata) prev = outname + ".html" #make_rand_html(savepath) make_index(savepath, flist) return flist
import pylab as pl from diagnostic_images import load_images, show imgs_before_b6, cubes_before_b6 = load_images('W51-E_B6_uid___A001_X1296_X215_continuum_merged_12M_robust0') imgs_after_b6, cubes_after_b6 = load_images('W51-E_B6_uid___A001_X1296_X215_continuum_merged_12M_robust0_selfcal1') show(imgs_before_b6, vmin=-0.001, vmax=0.01) pl.savefig("W51-E_B6_before_selfcal.png", bbox_inches='tight') show(imgs_after_b6, vmin=-0.001, vmax=0.01) pl.savefig("W51-E_B6_after_selfcal.png", bbox_inches='tight') show(imgs_before_b6, vmin=-0.001, vmax=0.3, zoom=[slice(380,900), slice(480,760)]) pl.savefig("W51-E_B6_before_selfcal_zoom.png", bbox_inches='tight') show(imgs_after_b6, vmin=-0.001, vmax=0.3, zoom=[slice(380,900), slice(480,760)]) pl.savefig("W51-E_B6_after_selfcal_zoom.png", bbox_inches='tight') imgs_before_b3, cubes_before_b3 = load_images('W51-E_B3_uid___A001_X1296_X10b_continuum_merged_12M_robust0') imgs_after_b3, cubes_after_b3 = load_images('W51-E_B3_uid___A001_X1296_X10b_continuum_merged_12M_robust0_selfcal1') show(imgs_before_b3, vmin=-0.001, vmax=0.01) pl.savefig("W51-E_B3_before_selfcal.png", bbox_inches='tight') show(imgs_before_b3, vmin=-0.001, vmax=0.1, zoom=[slice(680,1200),slice(850,1200)]) pl.savefig("W51-E_B3_before_selfcal_zoom.png", bbox_inches='tight') show(imgs_after_b3, vmin=-0.001, vmax=0.01) pl.savefig("W51-E_B3_after_selfcal.png", bbox_inches='tight')