diff --git a/ppmpy/ppm.py b/ppmpy/ppm.py index 9f3b671..fb6cc98 100644 --- a/ppmpy/ppm.py +++ b/ppmpy/ppm.py @@ -111,6 +111,10 @@ import ipywidgets as widgets from datetime import date import pickle +from random import shuffle +from itertools import cycle +from scipy import stats +from multiprocessing import Pool # import collections # FH: turn of logging as described here: # https://github.com/matplotlib/matplotlib/issues/14523 @@ -118,6 +122,12 @@ import logging logging.getLogger('matplotlib').setLevel(logging.ERROR) +# provides a cycle of different line styles and markers for plotting in a colour blind friendly manner +lll= 2*['-', '--', ':', '-.'] +markers = ['X','h','<','>','s','^','d','X','p'] +shuffle(lll) +CB_color_cycle = ['#4daf4a', '#a65628', '#984ea3','#ff7f00', '#f781bf', '#377eb8','#999999', '#e41a1c', '#dede00'] + # The unit of G in the code is 10^{-3} g cm^3 s^{-2}. G_code = nuconst.grav_const*1000. # code unit of gravitaional code_mass = 5.025e-07 # code unit of mass in solar masses @@ -6515,7 +6525,7 @@ def spacetime_diagram(self, var_name, nt, fig, tlim=None, rlim=None, vlim=None, @savefig space_time.png width=6in In [136]: F4 = ppm.yprofile('F4') .....: import matplotlib.pyplot as plt - .....: fig2 = plt.figure(19) + .....: fig2 = pl.figure(19) .....: F4.spacetime_diagram('Ek',5,fig2) ''' @@ -8199,8 +8209,8 @@ def bucket_map(rprofile, quantity, limits = None, ticks = None, file_name = None theta2 = theta2[0:n_rows, :] value = value[0:n_rows] - #ifig = 1; plt.close(ifig); fig = plt.figure(ifig, figsize = (9, 4)) - #ifig = 1; plt.close(ifig); fig = plt.figure(ifig, figsize = (3.39, 2.4)) + #ifig = 1; pl.close(ifig); fig = pl.figure(ifig, figsize = (9, 4)) + #ifig = 1; pl.close(ifig); fig = pl.figure(ifig, figsize = (3.39, 2.4)) pl.clf() gs = gridspec.GridSpec(2, 1, height_ratios = [12, 1]) ax0 = pl.subplot(gs[0]) @@ -8239,7 +8249,7 @@ def bucket_map(rprofile, quantity, limits = None, ticks = None, file_name = None } cmap = LinearSegmentedColormap('my_cmap', cmap_points, gamma = gamma) #cmap_name = 'gist_earth_r' - #cmap = plt.get_cmap(cmap_name) + #cmap = pl.get_cmap(cmap_name) for i in range(phi2.shape[0]): t = (value[i] - cmap_min)/(cmap_max - cmap_min) if t < 0: t = 0. @@ -8262,10 +8272,10 @@ def fmt(x, pos): cb = ColorbarBase(ax1, cmap = cmap, norm = norm, ticks = ticks, \ format = ticker.FuncFormatter(fmt), orientation='horizontal') cb.set_label(r'$\Delta$r$_\mathrm{ub}$ / Mm') - #ropplt.tight_layout(h_pad = 2.) + #roppl.tight_layout(h_pad = 2.) pl.show() if file_name is not None: - #plt.savefig(file_name + '_' + cmap_name + '.pdf', bbox_inches = 'tight', facecolor = 'w', dpi = 332.7) + #pl.savefig(file_name + '_' + cmap_name + '.pdf', bbox_inches = 'tight', facecolor = 'w', dpi = 332.7) pl.savefig(file_name, bbox_inches = 'tight', facecolor = 'w', dpi = 332.7) def plot_Mollweide(rp_set, dump_min, dump_max, r1, r2, output_dir = None, Filename = None, ifig = 2): @@ -9050,8 +9060,8 @@ def plot_entr_v_ut(cases,c0, Ncycles,r1,r2, comp,metric,label,ifig = 3, label = 'MA07') pl.xlabel(r'log$_{10}$(v$_\perp$ / km s$^{-1}$)') pl.ylabel(r'log$_{10} ( \dot{\mathrm{M}}_\mathrm{e}$ / M$_\odot$ s$^{-1}$])') - #plt.xlim((0.9, 2.3)) - #plt.ylim((-9., -3.)) + #pl.xlim((0.9, 2.3)) + #pl.ylim((-9., -3.)) pl.legend(loc = 4) pl.tight_layout() @@ -11772,6 +11782,261 @@ def get_spherical_coordinates(self, theta, phi): else: return None +# ============================================================================ + + def __data_setup(self, varloc, dump, num_rays): + ''' + Grabs and organizes the data needed to run ray_analysis. + ''' + + run_res = self._rprofset.get('Nx',dump) #grabbing the run resolution + run_res = int(run_res) + + + data_points = int(run_res/4) + + radii = np.linspace(0,2685, data_points) + + ux = self.get('ux',fname=dump) + uy = self.get('uy',fname=dump) + uz = self.get('uz',fname=dump) + + npoints = self.sphericalHarmonics_lmax(2685)[-1] + gridlines = 0.1 + + #loading the data + u_r,u_theta,u_phi = self.get_spherical_components(ux, uy, uz) + ur_r, theta_r, phi_r = self.get_spherical_interpolation(u_r, 2685, npoints=npoints, plot_mollweide=True) + num_direcs = int(len(theta_r)) + + ind = np.random.randint(0, num_direcs, num_rays) #the directions you are looking outwards in + + + if varloc=='|ut|': + data = np.sqrt(np.power(u_theta,2.0) + np.power(u_phi,2.0)) + else: + data = self.get(varloc,fname=dump) + + avg_ray = [np.mean(self.get_spherical_interpolation(data, i, npoints=npoints, plot_mollweide=True)[0]) for i in radii] + avg_ray = np.array(avg_ray) + + all_rays = [self.get_spherical_interpolation(data, i, npoints=npoints, plot_mollweide=True)[0] for i in radii ] + all_rays = np.array(all_rays) + + # correcting for the proper units + if varloc=='|ut|': + avg_ray = avg_ray * 1e3 + all_rays = all_rays * 1e3 + elif varloc=='|w|': + avg_ray = avg_ray * 1e6 + all_rays = all_rays * 1e6 + + return [avg_ray, all_rays, data_points, ind, radii] + + def __data_sort(self, data, data_points, ind,num_rays): + ''' + Sorts the data from __data_setup into dictionaries for ease of use in ray_analysis + ''' + iter_list = [int(i) for i in range(num_rays)] + i=0 + rays=[] + while i