def reduce_crosscans(map_name, lowhigh='high'): make_apex_cubes.build_cube_2014(map_name, lowhigh=lowhigh, posang=[50,70], datasets=[x for x,y in make_apex_cubes.datasets_2014.items() if map_name in y], extra_suffix='_lscans') make_apex_cubes.build_cube_2014(map_name, lowhigh=lowhigh, posang=[140,160], datasets=[x for x,y in make_apex_cubes.datasets_2014.items() if map_name in y], extra_suffix='_bscans') fileb = os.path.join(outdir, 'APEX_H2CO_2014_{0}_{1}_bscans.fits'.format(map_name, lowhigh)) filel = os.path.join(outdir, 'APEX_H2CO_2014_{0}_{1}_lscans.fits'.format(map_name, lowhigh)) cubeb = fits.getdata(fileb) cubel = fits.getdata(filel) assert cubeb.shape == cubel.shape cube_comb = plait.plait_cube([cubeb,cubel], angles=[0, 90], scale=3) header = fits.getheader(fileb) hdu = fits.PrimaryHDU(data=cube_comb, header=header) hdu.writeto(os.path.join(outdir, '{0}_{1}_plait.fits'.format(map_name, lowhigh)), clobber=True)
def reduce_all_cubes_for_map(mapname, lowhigh='high', **kwargs): for dataset,maps in make_apex_cubes.datasets_2014.items(): if mapname in maps: date = dataset[-10:] both_directions = True try: make_apex_cubes.build_cube_2014(mapname, lowhigh=lowhigh, posang=[50,70], datasets=[dataset], extra_suffix='_cal{0}_lscans'.format(date), **kwargs) except IndexError: both_directions = False try: make_apex_cubes.build_cube_2014(mapname, lowhigh=lowhigh, posang=[140,160], datasets=[dataset], extra_suffix='_cal{0}_bscans'.format(date), **kwargs) except IndexError: both_directions = False if both_directions: fileb = os.path.join(outdir, 'APEX_H2CO_2014_{1}_{2}_cal{0}_bscans.fits'.format(date, mapname, lowhigh)) filel = os.path.join(outdir, 'APEX_H2CO_2014_{1}_{2}_cal{0}_lscans.fits'.format(date, mapname, lowhigh)) cubeb = fits.getdata(fileb) cubel = fits.getdata(filel) if cubeb.shape != cubel.shape: header = FITS_tools.fits_overlap(fileb, filel) hdb = fits.getheader(fileb) # Add back 3rd dimension... HACK for key in hdb: if key[0] == 'C' and key.strip()[-1] == '3': header[key] = hdb[key] FITS_tools.regrid_fits_cube(fileb, outheader=header, outfilename=fileb, clobber=True) FITS_tools.regrid_fits_cube(filel, outheader=header, outfilename=filel, clobber=True) cubeb = fits.getdata(fileb) cubel = fits.getdata(filel) if cubeb.shape != cubel.shape: log.fatal("Cube shapes don't match: {0}, {1}".format(cubeb.shape,cubel.shape)) raise ValueError cube_comb = plait.plait_cube([cubeb,cubel], angles=[0, 90], scale=5) cube_comb_naive = (cubeb+cubel)/2. header = fits.getheader(fileb) fits.PrimaryHDU(data=cube_comb, header=header).writeto(os.path.join(outdir, '{1}_{2}_cal{0}_plait.fits'.format(date, mapname, lowhigh)), clobber=True)
def reduce_all_cubes_for_map(mapname, lowhigh='high', **kwargs): for dataset, maps in make_apex_cubes.datasets_2014.items(): if mapname in maps: date = dataset[-10:] both_directions = True try: make_apex_cubes.build_cube_2014( mapname, lowhigh=lowhigh, posang=[50, 70], datasets=[dataset], extra_suffix='_cal{0}_lscans'.format(date), **kwargs) except IndexError: both_directions = False try: make_apex_cubes.build_cube_2014( mapname, lowhigh=lowhigh, posang=[140, 160], datasets=[dataset], extra_suffix='_cal{0}_bscans'.format(date), **kwargs) except IndexError: both_directions = False if both_directions: fileb = os.path.join( outdir, 'APEX_H2CO_2014_{1}_{2}_cal{0}_bscans.fits'.format( date, mapname, lowhigh)) filel = os.path.join( outdir, 'APEX_H2CO_2014_{1}_{2}_cal{0}_lscans.fits'.format( date, mapname, lowhigh)) cubeb = fits.getdata(fileb) cubel = fits.getdata(filel) if cubeb.shape != cubel.shape: header = FITS_tools.fits_overlap(fileb, filel) hdb = fits.getheader(fileb) # Add back 3rd dimension... HACK for key in hdb: if key[0] == 'C' and key.strip()[-1] == '3': header[key] = hdb[key] FITS_tools.regrid_fits_cube(fileb, outheader=header, outfilename=fileb, clobber=True) FITS_tools.regrid_fits_cube(filel, outheader=header, outfilename=filel, clobber=True) cubeb = fits.getdata(fileb) cubel = fits.getdata(filel) if cubeb.shape != cubel.shape: log.fatal("Cube shapes don't match: {0}, {1}".format( cubeb.shape, cubel.shape)) raise ValueError cube_comb = plait.plait_cube([cubeb, cubel], angles=[0, 90], scale=5) cube_comb_naive = (cubeb + cubel) / 2. header = fits.getheader(fileb) fits.PrimaryHDU(data=cube_comb, header=header).writeto(os.path.join( outdir, '{1}_{2}_cal{0}_plait.fits'.format( date, mapname, lowhigh)), clobber=True)
'MAP_003', lowhigh='high', posang=[140, 160], datasets=[ x for x, y in make_apex_cubes.datasets_2014.items() if 'MAP_003' in y ], extra_suffix='_bscans') fileb = os.path.join(outdir, 'APEX_H2CO_2014_MAP_003_high_bscans.fits') filel = os.path.join(outdir, 'APEX_H2CO_2014_MAP_003_high_lscans.fits') cubeb = fits.getdata(fileb) cubel = fits.getdata(filel) assert cubeb.shape == cubel.shape cube_comb = plait.plait_cube([cubeb, cubel], angles=[0, 90], scale=5) cube_comb_naive = (cubeb + cubel) / 2. header = fits.getheader(fileb) fits.PrimaryHDU(data=cube_comb, header=header).writeto(os.path.join('MAP_003_high_plait.fits'), clobber=True) fits.PrimaryHDU(data=cube_comb_naive, header=header).writeto(os.path.join(outdir, 'MAP_003_high_naive.fits'), clobber=True) fits.PrimaryHDU(data=cube_comb_naive - cube_comb, header=header).writeto(os.path.join(outdir, 'MAP_003_high_diff.fits'), clobber=True)
paths.april2014path, 'APEX_H2CO_2014_MAP_006_{0}_cal2014-05-30_lscans.fits'.format( lowhigh))) cube730b = fits.getdata( os.path.join( paths.april2014path, 'APEX_H2CO_2014_MAP_006_{0}_cal2014-07-31_bscans.fits'.format( lowhigh))) cube730l = fits.getdata( os.path.join( paths.april2014path, 'APEX_H2CO_2014_MAP_006_{0}_cal2014-07-30_lscans.fits'.format( lowhigh))) cube730comb = plait.plait_cube([cube730b, cube730l], angles=[0, 90], scale=5) cube530comb = plait.plait_cube([cube530b, cube530l], angles=[0, 90], scale=5) import pylab as pl fig2 = pl.figure(2) fig2.clf() ax2 = fig2.gca() ax2.grid() data = [] for threshold in np.logspace(-0.6, 1.1, 10): mask = (cube530comb > threshold) & (cube730comb > threshold) if not np.any(mask):
make_apex_cubes.build_cube_2014('MAP_003', lowhigh='high', posang=[140,160], datasets=[x for x,y in make_apex_cubes.datasets_2014.items() if 'MAP_003' in y], extra_suffix='_bscans') fileb = os.path.join(outdir, 'APEX_H2CO_2014_MAP_003_high_bscans.fits') filel = os.path.join(outdir, 'APEX_H2CO_2014_MAP_003_high_lscans.fits') cubeb = fits.getdata(fileb) cubel = fits.getdata(filel) assert cubeb.shape == cubel.shape cube_comb = plait.plait_cube([cubeb,cubel], angles=[0, 90], scale=5) cube_comb_naive = (cubeb+cubel)/2. header = fits.getheader(fileb) fits.PrimaryHDU(data=cube_comb, header=header).writeto(os.path.join('MAP_003_high_plait.fits'), clobber=True) fits.PrimaryHDU(data=cube_comb_naive, header=header).writeto(os.path.join(outdir, 'MAP_003_high_naive.fits'), clobber=True) fits.PrimaryHDU(data=cube_comb_naive-cube_comb, header=header).writeto(os.path.join(outdir, 'MAP_003_high_diff.fits'), clobber=True) import pylab as pl pl.figure(1, figsize=(12,12)) pl.clf() for ii,scale in enumerate((1,5,10)): cube_comb = plait.plait_cube([cubeb,cubel], angles=[0, 90], scale=scale) integ_plait = cube_comb[900:990,:,:].mean(axis=0) integ_naive = cube_comb_naive[900:990,:,:].mean(axis=0) integ_plait = cube_comb[2515:2605,:,:].mean(axis=0)
hd = fits.getheader(fn1) # Add back 3rd dimension... HACK for key in hd: if key[0] == 'C' and key.strip()[-1] == '3': header[key] = hd[key] for fn in files: FITS_tools.regrid_fits_cube(fn, outheader=header, outfilename=fn, clobber=True) cube530b = fits.getdata(os.path.join(paths.april2014path, 'APEX_H2CO_2014_MAP_006_{0}_cal2014-05-30_bscans.fits'.format(lowhigh))) cube530l = fits.getdata(os.path.join(paths.april2014path, 'APEX_H2CO_2014_MAP_006_{0}_cal2014-05-30_lscans.fits'.format(lowhigh))) cube730b = fits.getdata(os.path.join(paths.april2014path, 'APEX_H2CO_2014_MAP_006_{0}_cal2014-07-31_bscans.fits'.format(lowhigh))) cube730l = fits.getdata(os.path.join(paths.april2014path, 'APEX_H2CO_2014_MAP_006_{0}_cal2014-07-30_lscans.fits'.format(lowhigh))) cube730comb = plait.plait_cube([cube730b,cube730l], angles=[0, 90], scale=5) cube530comb = plait.plait_cube([cube530b,cube530l], angles=[0, 90], scale=5) import pylab as pl fig2 = pl.figure(2) fig2.clf() ax2 = fig2.gca() ax2.grid() data = [] for threshold in np.logspace(-0.6,1.1,10): mask = (cube530comb>threshold)&(cube730comb>threshold) if not np.any(mask): log.info("Skip threshold {0} for {1} because no data".format(threshold, lowhigh)) continue