# Open output file and extract specific energy absorbed try: f = h5py.File(model, 'r') energy = f['iteration_%05i' % (len(f) - 1)]['specific_energy'] except IOError: break # Extract PAH energy energy = energy[isize, :, :, :] # Append to lists energies.append(np.mean(energy) / normalization[isize]) names.append(os.path.basename(model).replace('.rtout', '').replace('energy_%s_' % model_name, '').replace('_', ' ').strip()) # Create list of group numbers groups = [group(name) for name in names] # Convert to Numpy arrays and sort energies, names, groups = np.array(energies), np.array(names), np.array(groups) key = np.array(zip(groups, energies), dtype=[('groups', int), ('energies', float)]) order = np.argsort(key, order=['groups', 'energies']) energies, names, groups = energies[order], names[order], groups[order] # Create pie chart figure print len(energies) ax.text(xmin, ymax - isize * dy - isize * ddy + 0.02 / h, labels[isize], va='bottom', ha='left', size=8, color='black') make_percent_bar(ax, energies, names, [xmin, xmax,
def extract(model): # Check that file is valid if not os.path.basename(model).startswith('basic_') or not os.path.basename(model).endswith('.rtout'): raise Exception("Only basic_*.rtout files should be specified") # Extract model name model_name = os.path.basename(model).replace('.rtout', '').replace('basic_', '') m = ModelOutput('models/basic/basic_%s.rtout' % model_name) for image_set in range(3): if image_set == 0: n_x = 1 n_y = 1 image_set_name = 'total' elif image_set == 1: n_x = 130 n_y = 1 image_set_name = 'lon' elif image_set == 2: n_x = 1 n_y = 40 image_set_name = 'lat' flux = np.zeros((n_y, n_x, n_groups, n_wav)) print "Direct source emission" try: wav, nufnu_all = m.get_image(group=image_set, component='source_emit', units='MJy/sr', source_id='all') except IOError: return for source_id in range(n_sources): nufnu = nufnu_all[source_id, 0, :, :, :] spec_type = t_default['Type'][source_id].strip().upper() group_id = group(spec_type) flux[:, :, group_id, :] += nufnu print "Direct dust emission" wav, nufnu_all = m.get_image(group=image_set, component='dust_emit', units='MJy/sr', dust_id='all') for dust_id in range(n_dust): nufnu = nufnu_all[dust_id, 0, :, :, :] flux[:, :, 5 + dust_id, :] += nufnu print "Scattered source emission" wav, nufnu = m.get_image(group=image_set, component='source_scat', units='MJy/sr') nufnu = nufnu[0, :, :, :] flux[:, :, 8, :] += nufnu print "Scattered dust emission" wav, nufnu = m.get_image(group=image_set, component='dust_scat', units='MJy/sr') nufnu = nufnu[0, :, :, :] flux[:, :, 8, :] += nufnu # Convolve with filters flux_conv = np.zeros((len(filters), n_y, n_x, n_groups)) for i, filtname in enumerate(filters): transmission = rebin_filter(filtname, c / (wav * 1.e-4)) flux_conv[i, :, :, :] = np.sum(transmission[np.newaxis, np.newaxis, np.newaxis, :] * flux, axis=3) pyfits.writeto('models/basic/images_%s_%s.fits' % (image_set_name, model_name), flux, clobber=True) pyfits.writeto('models/basic/images_%s_%s_conv.fits' % (image_set_name, model_name), flux_conv, clobber=True)
import sys, os path = os.getcwd() + '/tests' sys.path.append(path) from auth import login, register, verifyCode from trips import createTrip from groups import group from users import updateUser # temporary implementation; will be focused on workflows # createTrip() group() updateUser()