def find_temp(images, t0=5.6, force_temp_scan=False, maps_dir=home + 'temperature_maps/'): x, y = images[0].shape n_wlens = len(images) n_temps = int((7.0 - t0) / 0.01) + 1 temp = np.arange(t0, 7.01, 0.01) try: if force_temp_scan: raise IOError model = np.memmap(filename=home + 'synth_emiss_1pars', dtype='float32', mode='r', shape=(n_temps, n_wlens)) except IOError: print 'No synthetic emission data found. Re-scanning temperature range.' resp = load_temp_responses() logt = np.arange(0, 15.05, 0.05) # Assume a width of the gaussian DEM distribution and normalise the height width = 0.1 height = 1.0 delta_t = logt[1] - logt[0] model = np.memmap(filename=home + 'synth_emiss_1pars', dtype='float32', mode='w+', shape=(n_temps, n_wlens)) for t, meantemp in enumerate(temp): dem = gaussian(logt, meantemp, width, height) f = resp * dem model[t, :] = np.sum(f, axis=1) * delta_t ### CHECK THIS AXIS! normmod = model[t, 2] model[t, :] = model[t, :] / normmod model.flush() ims_array = np.array([im.data for im in images]) print 'Calculating temperature values...', temps, fits = calc_fits(ims_array, model, temp, n_temps, n_wlens, x, y, 1) print 'Done.' tempmap = temps[:, :, 0], images[2].meta.copy(), fits # TODO: figure out how to change things in the header and save them. return tempmap
def find_temp(images, t0=5.6, force_temp_scan=False, maps_dir=home+'temperature_maps/'): x, y = images[0].shape n_wlens = len(images) n_temps = int((7.0 - t0) / 0.01) + 1 temp = np.arange(t0, 7.01, 0.01) try: if force_temp_scan: raise IOError model = np.memmap(filename=home+'synth_emiss_1pars', dtype='float32', mode='r', shape=(n_temps, n_wlens)) except IOError: print 'No synthetic emission data found. Re-scanning temperature range.' resp = load_temp_responses() logt = np.arange(0, 15.05, 0.05) # Assume a width of the gaussian DEM distribution and normalise the height width = 0.1 height = 1.0 delta_t = logt[1] - logt[0] model = np.memmap(filename=home+'synth_emiss_1pars', dtype='float32', mode='w+', shape=(n_temps, n_wlens)) for t, meantemp in enumerate(temp): dem = gaussian(logt, meantemp, width, height) f = resp * dem model[t, :] = np.sum(f, axis=1) * delta_t ### CHECK THIS AXIS! normmod = model[t, 2] model[t, :] = model[t, :] / normmod model.flush() ims_array = np.array([im.data for im in images]) print 'Calculating temperature values...', temps, fits = calc_fits(ims_array, model, temp, n_temps, n_wlens, x, y, 1) print 'Done.' tempmap = temps[:, :, 0], images[2].meta.copy(), fits # TODO: figure out how to change things in the header and save them. return tempmap
if verbose: print model.max(axis=0) else: model = None model = comm.bcast(model, root=0) if verbose: if rank == 0: print "Calculating temperature values..." print rank, images.shape, model.shape, parvals.shape, n_vals, n_wlens, x, y, n_params print [im.max() for im in images] print model.max(axis=0) if n_params == 1: parvals = parvals[:, 0] temps = calc_fits(images, model, parvals, n_vals, n_wlens, x, y, n_params) # Convert EM values to log scale if there are any if temps.shape[2] > 2: temps[..., 2] = np.log10(temps[..., 2]) if verbose: print "Done." # Get data all back in one place and save it temps = comm.gather(temps, root=0) if rank == 0: if verbose: print len(temps), temps[0].shape temp = np.zeros(shape=(x, y * size, n_params + 1)) for p in range(size): mini = (p / size) * temp.shape[1] maxi = ((p + 1) / size) * temp.shape[1]