rebinned_cube_local[:, :, k] = rebinned_slice rebinned_u_slice = po.rebin(cube_u[:, :, k], rebinned_shape) # re-bin 2d array before convolving to make things faster rebinned_cube_u_local[:, :, k] = rebinned_u_slice if args.debug and k % slice_slab == 0: logbook.final_pix_size = args.galsize/np.shape(rebinned_cube_local)[0] dummy = po.plotmap(rebinned_cube_local[:, :, k], 'slice ' + str(k) + ': after rebinning', 'junk', 'ergs/s/A/pixel', args, logbook, makelog=True) po.mydiag('[' + str(comm.rank) + '] ' + 'Deb 77: in ergs/s/A/pixel: after rebinning', dummy, args) print_mpi('Integrated flux in slice '+str(k)+' after convolution (and resampling) = %.4E ergs/s/A'%np.sum(result), args) if not args.silent: print_mpi('Rebinned slice ' + str(k) + ' of ' + str(core_end) + ' slices at: {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now()), args) if args.debug and slice is not None and k % slice_slab == 0: print_mpi('Pausing for 10...', args) plt.pause(10) comm.Barrier() comm.Allreduce(MPI.IN_PLACE, rebinned_cube_local, op=MPI.SUM) comm.Allreduce(MPI.IN_PLACE, rebinned_cube_u_local, op=MPI.SUM) if rank == 0: rebinned_cube_local /= final_res ** 2 # to change units from ergs/s/A/pixel to ergs/s/A/pc^2 rebinned_cube_local = np.ma.masked_where(rebinned_cube_local < 0., rebinned_cube_local) po.write_fits(args.rebinned_filename, rebinned_cube_local, args) rebinned_cube_u_local /= final_res ** 2 # to change units from ergs/s/A/pixel to ergs/s/A/pc^2 rebinned_cube_u_local = np.ma.masked_where(rebinned_cube_u_local < 0., rebinned_cube_u_local) po.write_fits(args.rebinned_u_filename, rebinned_cube_u_local, args) t_diff = MPI.Wtime() - t_start ### Stop stopwatch ### print_master( 'Parallely: time taken for rebinning of ' + str(nslice) + ' slices with ' + str(ncores) + ' cores= ' + str( t_diff / 60.) + ' min', args)
# python routine to simply change the units of PPV cubes in a folder, by a factor # -Ayan, May 2017 import os HOME = os.getenv('HOME') + '/' from astropy.io import fits import sys sys.path.append(HOME + 'models/enzo_model_code/') import numpy as np import plotobservables as p galsize = 26. # kpc input_dir = '/avatar/acharyya/enzo_models/ppvcubes3/' output_dir = '/avatar/acharyya/enzo_models/ppvcubes3b/' list = os.listdir(input_dir) for file in list: if file[-5:] != '.fits': continue data = fits.open(input_dir + file)[0].data g = np.shape(data)[0] data /= (galsize * 1000. / g)**2 # convert from ergs/s to ergs/s/pc^2 p.write_fits(output_dir + file, data, fill_val=np.nan) print 'Finished!'
' cells', args) prefix = '[' + str(rank) + '] ' comm.Barrier() t_start = MPI.Wtime() ### Start stopwatch ### ppv_local, ppv_u_local = po.makeobservable( cube, args, logbook, properties, core_start, core_end, prefix) # performing operation on cube comm.Barrier() comm.Allreduce(MPI.IN_PLACE, ppv_local, op=MPI.SUM) comm.Allreduce(MPI.IN_PLACE, ppv_u_local, op=MPI.SUM) if rank == 0: ppv_local = np.ma.masked_where(ppv_local < 0., ppv_local) po.write_fits(logbook.fitsname, ppv_local, args) po.write_fits(logbook.fitsname_u, ppv_u_local, args) t_diff = MPI.Wtime() - t_start ### Stop stopwatch ### print_master( 'Parallely: time taken for make-observable of ' + str(nslice) + ' slices with ' + str(ncores) + ' cores= ' + str(t_diff / 60.) + ' min', args) else: po.myprint('Making slices to observables, in series...', args) time_temp = time.time() ppv, ppv_u = po.makeobservable(cube, args, logbook, properties, 0, nslice, '') # performing operation on cube po.write_fits(logbook.fitsname, ppv, args) po.write_fits(logbook.fitsname_u, ppv_u, args)
' cells at: {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now()), args) comm.Barrier() comm.Allreduce(MPI.IN_PLACE, mapcube_local, op=MPI.SUM) comm.Allreduce(MPI.IN_PLACE, errorcube_local, op=MPI.SUM) if rank == 0: if args.debug: po.myprint( 'Deb120: Trying to calculate some statistics on the cube of shape (' + str(np.shape(mapcube_local)[0]) + ',' + str(np.shape(mapcube_local)[1]) + ',' + str(np.shape(mapcube_local)[2]) + '), please wait...', args) po.mydiag('Deb121: in ergs/s/pc^2: for mapcube', mapcube_local, args) po.myprint( 'Deb120: Trying to calculate some statistics on the cube of shape (' + str(np.shape(errorcube_local)[0]) + ',' + str(np.shape(errorcube_local)[1]) + ',' + str(np.shape(errorcube_local)[2]) + '), please wait...', args) po.mydiag('Deb121: in ergs/s/pc^2: for mapcube', errorcube_local, args) po.write_fits(logbook.fittedcube, mapcube_local, args) po.write_fits(logbook.fittederror, errorcube_local, args) t_diff = MPI.Wtime() - t_start ### Stop stopwatch ### print_master( 'Parallely: time taken for fitting of ' + str(ncells) + ' cells with ' + str(ncores) + ' cores= ' + str(t_diff / 60.) + ' min', args)
if not args.silent: print_mpi( 'Convolved slice ' + str(k) + ' of ' + str(core_end) + ' slices at: {:%Y-%m-%d %H:%M:%S}'.format( datetime.datetime.now()), args) if args.debug and slice is not None and k % slice_slab == 0: print_mpi('Pausing for 10...', args) plt.pause(10) comm.Barrier() comm.Allreduce(MPI.IN_PLACE, convolved_cube_local, op=MPI.SUM) if rank == 0: convolved_cube_local = np.ma.masked_where(convolved_cube_local < 0., convolved_cube_local) po.write_fits(args.convolved_filename, convolved_cube_local, args) t_diff = MPI.Wtime() - t_start ### Stop stopwatch ### print_master( 'Parallely: time taken for convolution of ' + str(nslice) + ' slices with ' + str(ncores) + ' cores= ' + str(t_diff / 60.) + ' min', args) # ------------------------------------------------------------------------------------------- ''' # rank 0 needs buffer space to gather data if comm.rank == 0: gbuf = np.empty( (np.shape(convolved_cube)[0], np.shape(convolved_cube)[1], ncores) ) else: gbuf = None for i_base in range(0, nslice, ncores): k = i_base + comm.rank