right=0.97, bottom=0.05, top=0.94, wspace=0.26, hspace=0.38) for row in range(4): cstep = CSTEPS[row] for col in range(4): pix = PIXEL_SIZES[col] * ARCSEC_TO_RADIAN # Generate the input map offx = 1.3 * pix offy = -0.8 * pix A = MakeEmptyFitsDim(1.0, LAT * DEGREE_TO_RADIAN, pix, N, M) B = MakeEmptyFitsDim(1.0, LAT * DEGREE_TO_RADIAN, pix, N, M) G = MakeEmptyFitsDim(1.0 + offx, LAT * DEGREE_TO_RADIAN + offy, pix, N, M) G[0].data = np.asarray(randn(N, M), np.float32) + 2.0 J, I = indices((N, M), np.float32) for i in range(1000): K = 4.0 * log(2.0) / (clip(2.0 + 1.0 * randn(), 2.0, 99)**2.0) G[0].data += 98.0 * rand() * exp(-K * ((J - N * rand())**2.0 + (I - M * rand())**2.0)) G[0].data = clip(G[0].data, 1.0, +100.0) G[0].data[0:3, :] = 0.0 G[0].data[-3:, :] = 0.0 G[0].data[:, 0:3] = 0.0 G[0].data[:, -3:] = 0.0 if (1): # rotate the input image
for itest in range(0, len(NN)): N = NN[itest] M = NN[itest] J, I = indices((N, M)) I250 = 10.0 + 2.0 * cos(0.05 * I) + 2.0 * sin(0.05 * J) T = 15.0 + 2.0 * sin(0.1 * I) B = 1.8 + 0.2 * sin(0.1 * J) um = asarray([160.0, 250.0, 350.0, 500.0], float32) # wavelengths [um] freq = um2f(um) FF, dFF = [], [] for iband in range(len(um)): y = (I250 * ModifiedBlackbody_250(freq[iband], T, B)).reshape(N, M) dy = 0.03 * y y += dy * randn(N, M) F = MakeEmptyFitsDim(1.0, 0.0, 10.0 * ARCSEC_TO_RADIAN, N, M) dF = MakeEmptyFitsDim(1.0, 0.0, 10.0 * ARCSEC_TO_RADIAN, N, M) F[0].data = y.reshape(N, M) dF[0].data = dy.reshape(N, M) FF.append(F) dFF.append(dF) # MBB fits # (1) python t0 = time.time() PI, PT, PB = FitModifiedBlackbody_simple(um, FF, dFF, FF[1][0].data.copy(), 15.0, 1.8) RES[itest, 0] = time.time() - t0 # (2) OpenCL on CPU t0 = time.time() CI, CT, CB = MBB_fit_CL_FITS(freq, FF, dFF, GPU=0) RES[itest, 1] = time.time() - t0
from ISM.Extinction import * from ISM.Extinction.Nicer import * from ISM.FITS.FITS import MakeEmptyFitsDim # Select a target cloud ra0 = HMS2RAD( 15, 39, 42.0) de0 = DMS2RAD( -7, 10, 0.0) box = 60.0*ARCMIN_TO_RADIAN # map size in radians pix = 0.5*ARCMIN_TO_RADIAN # pixel size fwhm = 3.0*ARCMIN_TO_RADIAN # fwhm of the Av map npix = int(box/pix) # map size as number of pixels # Read 2Mass stars for a reference field (OFF field) coo, mag, dmag = read_2mass_www(ra0, de0+box, box_size=0.5*box, filename='OFF.2Mass') # Read 2Mass stars for the ON field COO, MAG, DMAG = read_2mass_www(ra0, de0 , box_size=box, filename='ON.2Mass') # Make a template FITS image for the extinction map and the error map F = MakeEmptyFitsDim(ra0, de0, 0.5*ARCMIN_TO_RADIAN, npix, npix) dF = MakeEmptyFitsDim(ra0, de0, 0.5*ARCMIN_TO_RADIAN, npix, npix) # Choose extinction curve EX_AV = get_AX_AV(['J', 'H', 'Ks'], Rv=3.1) # Calculate extinction and save the results to FITS files NICER_with_OpenCL(F, COO, MAG, DMAG, mag, dmag, EX_AV, FWHM=3.0*ARCMIN_TO_RADIAN, CLIP=3.0, GPU=0, dF=dF) F.writeto( 'test_Av.fits' , overwrite=True) dF.writeto('test_dAv.fits', overwrite=True)
except: pass sys.path.append(ISM_DIRECTORY) from ISM.Defs import * from ISM.FITS.FITS import MakeEmptyFitsDim, Reproject, convolve_map_fast, ConvolveFitsPyCL, ConvolveFitsBeamPyCL import montage_wrapper as montage import matplotlib.ticker as ticker from astropy.convolution import convolve as astropy_convolve from astropy.convolution import Gaussian2DKernel from scipy.signal import convolve as scipy_convolve import time import numpy as np N = 256 # map size pix = 10.0 * ARCSEC_TO_RADIAN FITS = MakeEmptyFitsDim(1.0, 0.0, pix, N, N) FITS[0].data = asarray(3.0 + randn(N, N), float32) FITS[0].data = clip(FITS[0].data, 1.0, 10.0) fwhm_pix = 7.3 fwhm_rad = fwhm_pix * pix sigma_pix = fwhm_pix / sqrt(8.0 * log(2.0)) kernel = Gaussian2DKernel(x_stddev=sigma_pix) if (kernel.shape[0] % 2 == 0): print("kernel dimensions must be odd") sys.exit() AP = astropy_convolve(FITS[0].data.copy(), kernel, boundary='extend') if (0): CL = ConvolveFitsBeamPyCL(FITS, kernel, border='ignore')[0].data.copy() else:
threads = 1 DIMS = np.asarray(np.logspace(np.log10(32.0), np.log10(16384.2), 10), int32) # DIMS = np.asarray(np.logspace(np.log10(32.0), np.log10( 8192.2), 9), int32) # DIMS = np.asarray(np.logspace(np.log10(32.0), np.log10( 4096.2), 8), int32) # DIMS = np.asarray(np.logspace(np.log10(32.0), np.log10(1024.1), 6), int32) # DIMS = np.asarray(np.logspace(np.log10(32.0), np.log10(512.1), 5), int32) TA = np.zeros(len(DIMS), np.float32) TC = np.zeros((len(DIMS), 4), np.float32) # tP, tB, tK, TC TG1 = np.zeros((len(DIMS), 4), np.float32) # tP, tB, tK, TC TG2 = np.zeros((len(DIMS), 4), np.float32) # tP, tB, tK, TC for III in range(len(DIMS)): # loop over different map sizes # Generate the input map N, M = int(DIMS[III]), int(DIMS[III]) print("--- %d %d---" % (M, M)) A = MakeEmptyFitsDim(1.0, 0.0, 10.0 * DEGREE_TO_RADIAN / N, N, M) B = MakeEmptyFitsDim(1.0, 0.0, 10.0 * DEGREE_TO_RADIAN / N, N, M) G = MakeEmptyFitsDim(1.0 + offx, 0.0 + offy, 10.0 * DEGREE_TO_RADIAN / N * scale, N, M) G[0].data = np.asarray(randn(N, M), np.float32) + 5.0 J, I = indices((N, M), np.float32) for i in range(30): K = 4.0 * log(2.0) / (clip(2.0 + 1.0 * randn(), 2.0, 99)**2.0) G[0].data += 100.0 * rand() * exp(-K * ((J - N * rand())**2.0 + (I - M * rand())**2.0)) G[0].data[0:3, :] = 0.0 G[0].data[-3:, :] = 0.0 G[0].data[:, 0:3] = 0.0 G[0].data[:, -3:] = 0.0 if (1): # rotate the input image rot = 30 * DEGREE_TO_RADIAN