def compute_geom_constraints(dirname, inversion_rdiffs, max_fluences): filename = lambda name: os.path.join(dirname, name) print output.div_line print "computing geometry parameters domain constraints" count_rm = params.ext_opt_geom_resolution[0] count_rb = params.ext_opt_geom_resolution[1] Rm = np.linspace(params.ext_opt_geom_mediumradius[0], params.ext_opt_geom_mediumradius[1], count_rm) Rb = np.linspace(params.ext_opt_geom_beamradius[0], params.ext_opt_geom_beamradius[1], count_rb) inversion_rdiff_max = params.ext_opt_inversion_rdiff_max fluence_max = params.ext_opt_fluence_max contours = [ (max_fluences.T, fluence_max, "damage"), ] contour_comps = [1.0] rm_depop = np.interp(inversion_rdiff_max, inversion_rdiffs[::-1], Rm[::-1]) xvals = [(rm_depop, "depopulation")] xval_comps = [-1.0] if params.graphs: print output.status_writing dirname = os.path.join(dirname, output.opt_geom_rel_path) dirname = output.init_dir(dirname) plot.plot_contour(filename("constraints"), "Geometry Parameters Domain Constraints", (Rm, None, None, output.medium_radius_label), (Rb, None, None, output.beam_radius_label), contours, xvals=xvals) return (contours, xvals, None), (contour_comps, xval_comps, None)
def compute_pump_constraints(dirname, inversion_rdiffs, max_fluences): filename = lambda name: os.path.join(dirname, name) print output.div_line print "computing pumping parameters domain constraints" active_medium = core.create_medium(None) count_tau = params.ext_opt_pump_resolution[0] count_pwr = params.ext_opt_pump_resolution[1] Tau = np.linspace(params.ext_opt_pump_duration[0], params.ext_opt_pump_duration[1], count_tau) Pwr = np.linspace(params.ext_opt_pump_power[0], params.ext_opt_pump_power[1], count_pwr) inversion_rdiff_max = params.ext_opt_inversion_rdiff_max fluence_max = params.ext_opt_fluence_max contours = [ (inversion_rdiffs.T, inversion_rdiff_max, "depopulation"), (max_fluences.T, fluence_max, "damage"), ] contour_comps = [1.0, 1.0] if params.graphs: print output.status_writing dirname = os.path.join(dirname, output.opt_pump_rel_path) graph_types = [ (dirname, Pwr,output. pump_power_label), (os.path.join(dirname, output.alt_plot_rel_path), Pwr * params.pump_efficiency / active_medium.volume, output.eff_power_density_label), ] for dirname, Y, ylabel in graph_types: dirname = output.init_dir(dirname) plot.plot_contour(filename("constraints"), "Pumping Parameters Domain Constraints", (Tau, None, None, output.pump_duration_label), (Y, None, None, ylabel), contours) return (contours, None, None), (contour_comps, None, None)
def fexc_finh_sweep(neuronp, filt_tau=.01, k_trans=5, max_u=6., max_f=1000., npts=10, fname_pre='', max_proc=None, close=False): alpha = max_u/max_f fexc = np.linspace(0, max_f, npts) finh = np.linspace(0, max_f, npts) fexc_g, finh_g = np.meshgrid(fexc, finh) lam_g = fexc_g+finh_g u_g = alpha*(fexc_g-finh_g) s_g = np.sqrt(lam_g/(2.*neuronp['tau_syn'])) tuning_th = th_lif_fi(u_g, neuronp['tau_m'], neuronp['tref'], neuronp['xt']) T = 2. dt = .0001 io_collector = LIF_IO_Collector( dt=dt, T=T, alpha=alpha, neuronp=neuronp, filt_tau=filt_tau, k_trans=k_trans) tuning, dev1s_l, dev1s_u = io_collector.collect_io_stats( fexc=fexc_g, finh=finh_g, ret_devs=True, max_proc=max_proc) # E[u] fig, ax = plot_contour( fexc_g, finh_g, u_g, contourfp={'cmap': plt.cm.BrBG}, contourp={'colors': 'r'}, figp={'figsize': (8, 6)}, xlabel=r'$f_{exc}$', xlabelp={'fontsize': 20}, ylabel=r'$f_{inh}$', ylabelp={'fontsize': 20}, title=r'$E[u]$', titlep={'fontsize': 20}) plot_scatter( fexc_g, finh_g, scatterp={'c': 'm', 'marker': '+', 'alpha': .5}, ax=ax, xlim=(fexc[0], fexc[-1]), ylim=(finh[0], finh[-1]), close=close, fname=FIGDIR+fname_pre+'fe_fi_u.png', savep={'dpi': 200}) # a(E[u])) fig, ax = plot_contour( fexc_g, finh_g, tuning_th, contourfp={'cmap': plt.cm.copper}, contourp={'colors': 'r'}, figp={'figsize': (8, 6)}, xlabel=r'$f_{exc}$', xlabelp={'fontsize': 20}, ylabel=r'$f_{inh}$', ylabelp={'fontsize': 20}, title=r'$a(E[u])$', titlep={'fontsize': 20}) plot_scatter( fexc_g, finh_g, scatterp={'c': 'm', 'marker': '+', 'alpha': .5}, ax=ax, xlim=(fexc[0], fexc[-1]), ylim=(finh[0], finh[-1]), close=close, fname=FIGDIR+fname_pre+'fe_fi_tuning_th.png', savep={'dpi': 200}) # sqrt(Var(u)) fig, ax = plot_contour( fexc_g, finh_g, s_g, contourfp={'cmap': plt.cm.PuOr}, contourp={'colors': 'r'}, figp={'figsize': (8, 6)}, xlabel=r'$f_{exc}$', xlabelp={'fontsize': 20}, ylabel=r'$f_{inh}$', ylabelp={'fontsize': 20}, title=r'$\sigma(f_{exc}+f_{inh})$', titlep={'fontsize': 20}) plot_scatter(fexc_g, finh_g, scatterp={'c': 'm', 'marker': '+', 'alpha': .5}, ax=ax, xlim=(fexc[0], fexc[-1]), ylim=(finh[0], finh[-1]), close=close, fname=FIGDIR+fname_pre+'fe_fi_noise.png', savep={'dpi': 200}) # E[a(u)] fig, ax = plot_contour( fexc_g, finh_g, tuning, contourfp={'cmap': plt.cm.copper}, contourp={'colors': 'r'}, figp={'figsize': (8, 6)}, xlabel=r'$f_{exc}$', xlabelp={'fontsize': 20}, ylabel=r'$f_{inh}$', ylabelp={'fontsize': 20}, title=r'$E[a(u)]$', titlep={'fontsize': 20}) plot_scatter( fexc_g, finh_g, scatterp={'c': 'm', 'marker': '+', 'alpha': .5}, ax=ax, xlim=(fexc[0], fexc[-1]), ylim=(finh[0], finh[-1]), close=close, fname=FIGDIR+fname_pre+'fe_fi_noisy_tuning.png', savep={'dpi': 200}) # Var(a(u)) fig, ax = plot_contour( fexc_g, finh_g, dev1s_l, contourfp={'cmap': plt.cm.winter}, contourp={'colors': 'r'}, subplotp=(1, 2, 1), figp={'figsize': (16, 6)}, xlabel=r'$f_{exc}$', xlabelp={'fontsize': 20}, ylabel=r'$f_{inh}$', ylabelp={'fontsize': 20}, title=r'$-\sigma\%(a(u))$', titlep={'fontsize': 20}) plot_scatter( fexc_g, finh_g, scatterp={'c': 'm', 'marker': '+', 'alpha': .5}, ax=ax, xlim=(fexc[0], fexc[-1]), ylim=(finh[0], finh[-1])) fig, ax = plot_contour( fexc_g, finh_g, dev1s_u, contourfp={'cmap': plt.cm.winter}, contourp={'colors': 'r'}, fig=fig, subplotp=(1, 2, 2), xlabel=r'$f_{exc}$', xlabelp={'fontsize': 20}, ylabel=r'$f_{inh}$', ylabelp={'fontsize': 20}, title=r'$+\sigma\%(a(u))$', titlep={'fontsize': 20}) plot_scatter( fexc_g, finh_g, scatterp={'c': 'm', 'marker': '+', 'alpha': .5}, ax=ax, xlim=(fexc[0], fexc[-1]), ylim=(finh[0], finh[-1]), close=close, fname=FIGDIR+fname_pre+'fe_fi_noisy_tuning.png', savep={'dpi': 200})
contour_hs_1 = c[1] contour_v_50 = hdc_contour_50.coordinates[0][0] contour_hs_50 = hdc_contour_50.coordinates[0][1] c = sort_points_to_form_continous_line(hdc_contour_50.coordinates[0][0], hdc_contour_50.coordinates[0][1], do_search_for_optimal_start=True) contour_v_50 = c[0] contour_hs_50 = c[1] fig = plt.figure(figsize=(5, 5), dpi=150) ax = fig.add_subplot(111) # Plot the two lower contours. plot_contour(x=contour_v_lowest, y=contour_hs_lowest, ax=ax, line_style='r-') plot_contour(x=contour_v_1, y=contour_hs_1, ax=ax, line_style='r-') # Compute the median hs conditonal on v. x = np.linspace(0, 35, 100) d1 = fit.mul_var_dist.distributions[1] a = d1.scale.a b = d1.scale.b c = d1.scale.c y = a + b * np.power(x, c) # Plot the 50-year contour and the sample.
plot_mesh(num_nodes_x, num_nodes_y, length_x, length_y) # if quad_order is not None: # fill = raw['fill'].reshape(( # (num_nodes_x - 1) * quad_order, # (num_nodes_y - 1) * quad_order, # )) # boundary = raw['boundary'].reshape(( # (num_nodes_x - 1) * quad_order, # (num_nodes_y - 1) * quad_order, # )) # plot_contour(gpt_mesh, fill, plot_fill=True) # plot_contour(gpt_mesh, boundary, plot_boundary=True) if 1: phi = np.asarray(raw['phi']) phi[phi <= 0] = 0 phi[phi > 0] = 1 multipliers = phi.reshape((num_nodes_x, num_nodes_y), order='F') plot_contour(mesh, multipliers, plot_fill=True) else: multipliers = raw['multipliers'].reshape( (num_nodes_x - 1, num_nodes_y - 1)) plot_contour(mesh, multipliers, plot_fill=True) plot_save(save='save/save%03i.png' % counter) counter += 1 filename = 'save/data%03i.pkl' % counter import movie
hs_outside, v_outside, hs_inside, v_inside = \ points_outside(contour_hs_50, contour_v_50, np.asarray(df[df.columns[2]].values), np.asarray(df[df.columns[1]].values)) print('Number of points outside the contour: ' + str(len(hs_outside))) #%% fig = plt.figure(figsize=(5, 5), dpi=150) ax = fig.add_subplot(111) # Plot the 1-year contour. plot_contour(x=contour_v_1, y=contour_hs_1, ax=ax, contour_label=str(T1) + '-yr contour', x_label=label_v, y_label=label_hs, line_style='b--') # Plot the 50-year contour and the sample. plotted_sample = PlottedSample(x=np.asarray(sample_v), y=np.asarray(sample_hs), ax=ax, x_inside=v_inside, y_inside=hs_inside, x_outside=v_outside, y_outside=hs_outside, return_period=T50) plot_contour(x=contour_v_50, y=contour_hs_50,
from outer import encContour from height import height from plot import plot_contour from matplotlib import pyplot as plt import cv2 import numpy as np import copy import math import sys cnt1 = encContour('man_front.jpg') cnt2 = encContour('man_side.jpg') image = cv2.imread('man_front.jpg') plot_contour(cnt1= cnt1, cnt2= cnt2) #cv2.drawContours(image,cnt1,-1,(255),3) #cv2.imshow('front image',image) #cv2.waitKey(0) #print((cnt)) ''' #test for encContour image = cv2.imread(url) cnt = encContour(url) cv2.drawContours(image,cnt,-1,(255),3) cv2.imshow('image',image) cv2.waitKey(0) cv2.destroyAllWindows() '''
hdc_contour_1.coordinates[0][1], do_search_for_optimal_start=True) contour_hs_1 = c[0] contour_tz_1 = c[1] c = sort_points_to_form_continous_line(hdc_contour_20.coordinates[0][0], hdc_contour_20.coordinates[0][1], do_search_for_optimal_start=True) contour_hs_20 = c[0] contour_tz_20 = c[1] fig = plt.figure(figsize=(5, 5), dpi=150) ax = fig.add_subplot(111) # Plot the lowest density contour. plot_contour(x=contour_tz_lowest, y=contour_hs_lowest, ax=ax, line_style='r-') # Compute the median tz conditonal on hs. hs = np.linspace(0, 14, 100) d1 = fit.mul_var_dist.distributions[1] c1 = d1.scale.a c2 = d1.scale.b tz = c1 + c2 * np.sqrt(np.divide(hs, 9.81)) # Plot the 1-year contour. plot_contour(x=contour_tz_1, y=contour_hs_1, ax=ax, line_style='r-') # Plot the 20-year contour and the sample. plotted_sample = PlottedSample(x=np.asarray(sample_tz), y=np.asarray(sample_hs), ax=ax,
# Delete interval centers that were not used. interval_centers = np.delete(interval_centers, deleted_centers) # Create Figure 1 of the paper. fig = plt.figure(figsize=(10, 5), dpi=150) # Plot dataset A and the 20-year contour. ax = fig.add_subplot(121) plotted_sample_a = PlottedSample(x=np.asarray(a_tz), y=np.asarray(a_hs), ax=ax, return_period=return_period_20) plot_contour(x=contour_tz_20, y=contour_hs_20, ax=ax, contour_label=str(return_period_20) + '-yr contour', x_label=label_tz, y_label=label_hs, line_style='b-', plotted_sample=plotted_sample_a) plt.legend(['20-year contour', '10 years of observations'], loc='upper left', frameon=False) plt.title('Dataset A') # Plot dataset D and the 50-year contour. ax2 = fig.add_subplot(122) plotted_sample_d = PlottedSample(x=np.asarray(d_v), y=np.asarray(d_hs), ax=ax2, return_period=return_period_50) plot_contour(x=contour_v_50,
from outer import encContour from height import height from plot import plot_contour from matplotlib import pyplot as plt import cv2 import numpy as np import copy import math import sys cnt1 = encContour('man_front.jpg') cnt2 = encContour('man_side.jpg') image = cv2.imread('man_front.jpg') plot_contour(cnt1=cnt1, cnt2=cnt2) #cv2.drawContours(image,cnt1,-1,(255),3) #cv2.imshow('front image',image) #cv2.waitKey(0) #print((cnt)) ''' #test for encContour image = cv2.imread(url) cnt = encContour(url) cv2.drawContours(image,cnt,-1,(255),3) cv2.imshow('image',image) cv2.waitKey(0) cv2.destroyAllWindows() '''
# Plot the environmental contours. fig = plt.figure(figsize=(5, 5), dpi=150) ax = fig.add_subplot(111) for i, contour in enumerate(contours): if i == 0: plotted_sample = PlottedSample(x=np.asarray(dataset_d_v), y=np.asarray(dataset_d_hs), ax=ax, label='dataset D') contour_label = str(return_period) + '-yr contour' plot_contour(x=contour.c[0], y=contour.c[1], ax=ax, contour_label=contour_label, x_label=label_v, y_label=label_hs, line_style='b-', alpha=0.4, plotted_sample=plotted_sample) else: plot_contour(x=contour.c[0], y=contour.c[1], line_style='b-', alpha=0.4, ax=ax) if DO_COMPUTE_CONFIDENCE_INTERVAL and DO_PLOT_ANGLE_LINES: for j, (line_v, line_hs) in enumerate(zip(theta_line_v, theta_line_hs)): if i == 0: plt.plot(line_v, line_hs, 'r-')
# Find datapoints that exceed the 20-yr contour. v_outside, hs_outside, v_inside, hs_inside = \ points_outside(contour_v_50, contour_hs_50, np.asarray(sample_v), np.asarray(sample_hs)) print('Number of points outside the contour: ' + str(len(v_outside))) fig = plt.figure(figsize=(5, 5), dpi=150) ax = fig.add_subplot(111) # Plot the 1-year contour. plot_contour(x=contour_v_1, y=contour_hs_1, ax=ax, contour_label=str(return_period_1) + '-yr contour', line_style='b--') # Compute the median hs conditonal on v. x = np.linspace(0, 35, 100) d1 = fit.mul_var_dist.distributions[1] a = d1.scale.a b = d1.scale.b c = d1.scale.c y = a + b * np.power(x, c) # Plot the 50-year contour and the sample. plotted_sample = PlottedSample(x=np.asarray(sample_v), y=np.asarray(sample_hs), ax=ax,
fig = plt.figure(figsize=(5, 5), dpi=150) ax = fig.add_subplot(111) plotted_sample = PlottedSample(x=np.asarray(sample_tz), y=np.asarray(sample_hs), ax=ax, x_inside=tz_inside, y_inside=hs_inside, x_outside=tz_outside, y_outside=hs_outside, return_period=T20) # Plot the 1-year contour. plot_contour(x=contour_tz_1, y=contour_hs_1, ax=ax, contour_label=str(T1) + '-yr contour', x_label=label_tz, y_label=label_hs, line_style='b--', plotted_sample=plotted_sample) # Plot the 20-year contour and the sample. plot_contour(x=contour_tz_20[~nan_mask], y=contour_hs_20[~nan_mask], ax=ax, contour_label=str(T20) + '-yr contour', x_label=label_tz, y_label=label_hs, line_style='b-') #, # plotted_sample=plotted_sample) plt.title('Dataset ' + DATASET_CHAR) plt.show()
contour_v_50 = hdc_contour_50.coordinates[0][1] contour_hs_50 = hdc_contour_50.coordinates[0][0] c = sort_points_to_form_continous_line(hdc_contour_50.coordinates[0][0], hdc_contour_50.coordinates[0][1], do_search_for_optimal_start=True) contour_v_50 = c[1] contour_hs_50 = c[0] fig = plt.figure(figsize=(5, 5), dpi=150) ax = fig.add_subplot(111) # Plot the two lower contours. plot_contour(x=contour_v_lowest, y=contour_hs_lowest, ax=ax, contour_label=str(return_period_lowest) + '-yr contour', line_style='r-') plot_contour(x=contour_v_1, y=contour_hs_1, ax=ax, contour_label=str(return_period_1) + '-yr contour', line_style='r-') # Plot the 50-year contour and the sample. plotted_sample = PlottedSample(x=np.asarray(sample_v), y=np.asarray(sample_hs), ax=ax, return_period=return_period_50) plot_contour(x=contour_v_50,
contour_hs_1 = c[0] contour_tz_1 = c[1] c = sort_points_to_form_continous_line(hdc_contour_20.coordinates[0][0], hdc_contour_20.coordinates[0][1], do_search_for_optimal_start=True) contour_hs_20 = c[0] contour_tz_20 = c[1] fig = plt.figure(figsize=(5, 5), dpi=150) ax = fig.add_subplot(111) # Plot the lowest density contour. plot_contour(x=contour_tz_lowest, y=contour_hs_lowest, ax=ax, contour_label=str(return_period_lowest) + '-yr contour', line_style='r-') # Plot the 1-year contour. plot_contour(x=contour_tz_1, y=contour_hs_1, ax=ax, contour_label=str(return_period_1) + '-yr contour', line_style='r-') # Plot the 20-year contour and the sample. plotted_sample = PlottedSample(x=np.asarray(sample_tz), y=np.asarray(sample_hs), ax=ax, return_period=return_period_20)
# Find datapoints that exceed the 20-yr contour. hs_outside, tz_outside, hs_inside, tz_inside = \ points_outside(contour_hs_20, contour_tz_20, np.asarray(sample_hs), np.asarray(sample_tz)) print('Number of points outside the contour: ' + str(len(hs_outside))) fig = plt.figure(figsize=(5, 5), dpi=150) ax = fig.add_subplot(111) # Plot the 1-year contour. plot_contour(x=contour_tz_1, y=contour_hs_1, ax=ax, contour_label=str(return_period_1) + '-yr contour', line_style='b--') # Compute the median tz conditonal on hs. hs = np.linspace(0, 14, 100) d1 = fit.mul_var_dist.distributions[1] c1 = d1.scale.a c2 = d1.scale.b tz = c1 + c2 * np.sqrt(np.divide(hs, 9.81)) # Plot the 20-year contour and the sample. plotted_sample = PlottedSample(x=np.asarray(sample_tz), y=np.asarray(sample_hs), ax=ax, x_inside=tz_inside,
# Find datapoints that exceed the 20-yr contour. hs_outside, tz_outside, hs_inside, tz_inside = \ points_outside(contour_hs_20, contour_tz_20, np.asarray(sample_hs), np.asarray(sample_tz)) print('Number of points outside the contour: ' + str(len(hs_outside))) fig = plt.figure(figsize=(5, 5), dpi=150) ax = fig.add_subplot(111) # Plot the 1-year contour. plot_contour(x=contour_tz_1, y=contour_hs_1, ax=ax, contour_label=str(return_period_1) + '-yr contour', x_label=label_tz, y_label=label_hs, line_style='b--') # Plot the 20-year contour and the sample. plotted_sample = PlottedSample(x=np.asarray(sample_tz), y=np.asarray(sample_hs), ax=ax, x_inside=tz_inside, y_inside=hs_inside, x_outside=tz_outside, y_outside=hs_outside, return_period=return_period_20) plot_contour(x=contour_tz_20, y=contour_hs_20,
# Find datapoints that exceed the 20/50-yr contour. x_outside, y_outside, x_inside, y_inside = \ points_outside(contour_x_long, contour_y_long, np.asarray(sample_x), np.asarray(sample_y)) print('Number of points outside the contour: ' + str(len(x_outside))) fig = plt.figure(figsize=(5, 5), dpi=150) ax = fig.add_subplot(111) # Plot the 1-year contour. plot_contour(x=contour_x_1, y=contour_y_1, ax=ax, contour_label='1-yr contour', line_style='b--') # Plot the 20/50-year contour and the sample. plotted_sample = PlottedSample(x=np.asarray(sample_x), y=np.asarray(sample_y), ax=ax, x_inside=x_inside, y_inside=y_inside, x_outside=x_outside, y_outside=y_outside, return_period=return_period_long_tr) plot_contour( x=contour_x_long, y=contour_y_long,