From f916da899a9b24adad1543552527f707f16e2ddb Mon Sep 17 00:00:00 2001 From: Antoine Cyril David Hoffmann <ahoffman@spcpc606.epfl.ch> Date: Fri, 30 Oct 2020 15:47:47 +0100 Subject: [PATCH] Statistical analysis and 3D plots in phase space --- matlab/create_gif_3D.m | 49 ++++++++++++++++++++++++++++++++++++++++++ wk/analysis_stat_2D.m | 42 ++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 matlab/create_gif_3D.m create mode 100644 wk/analysis_stat_2D.m diff --git a/matlab/create_gif_3D.m b/matlab/create_gif_3D.m new file mode 100644 index 00000000..188349db --- /dev/null +++ b/matlab/create_gif_3D.m @@ -0,0 +1,49 @@ +title1 = GIFNAME; +FIGDIR = BASIC.RESDIR; +GIFNAME = [FIGDIR, GIFNAME,'.gif']; + +% Setup figure frame +fig = figure('Color','white','Position', [100, 100, 400, 400]); + plt = @(x) squeeze(reshape(x(:,:,1),[],1)); + scale_x = max(abs(plt(X(:,:,1)))); + scale_y = max(abs(plt(Y(:,:,1)))); + scale_z = max(abs(plt(Z(:,:,1)))); + plot3(plt(X)/scale_x,plt(Y)/scale_y,plt(Z)/scale_z,'.k','MarkerSize',MARKERSIZE); + view(VIEW); + colormap jet + axis tight manual % this ensures that getframe() returns a consistent size + in = 1; + nbytes = fprintf(2,'frame %d/%d',in,numel(FRAMES)); + for n = FRAMES % loop over selected frames + plt = @(x) squeeze(reshape(x(:,:,n),[],1)); + scale_x = max(abs(plt(X))); + scale_y = max(abs(plt(Y))); + scale_z = max(abs(plt(Z))); + plot3(plt(X)/scale_x,plt(Y)/scale_y,plt(Z)/scale_z,'.k','MarkerSize',MARKERSIZE); + view(VIEW); + xlabel(XNAME); ylabel(YNAME); zlabel(ZNAME); + title(['$t \approx$', sprintf('%.3d',ceil(T(n)))... + ,', scaling = ',sprintf('%.1e',scale_x)]); + grid on; + drawnow + % Capture the plot as an image + frame = getframe(fig); + im = frame2im(frame); + [imind,cm] = rgb2ind(im,32); + % Write to the GIF File + if in == 1 + imwrite(imind,cm,GIFNAME,'gif', 'Loopcount',inf); + else + imwrite(imind,cm,GIFNAME,'gif','WriteMode','append', 'DelayTime',DELAY); + end + % terminal info + while nbytes > 0 + fprintf('\b') + nbytes = nbytes - 1; + end + nbytes = fprintf(2,'frame %d/%d',n,numel(FRAMES)); + in = in + 1; + end + disp(' ') + disp(['Gif saved @ : ',GIFNAME]) + diff --git a/wk/analysis_stat_2D.m b/wk/analysis_stat_2D.m new file mode 100644 index 00000000..4add74bf --- /dev/null +++ b/wk/analysis_stat_2D.m @@ -0,0 +1,42 @@ +if 0 +%% ni ne phase space for different time windows +fig = figure; + t0 = 20; t1 = 20; [~,it0] = min(abs(t0-Ts2D)); [~,it1] = min(abs(t1-Ts2D)); + plt = @(x) squeeze(reshape(x(:,:,it0:it1),[],1)); + plot(plt(ni00),plt(ne00),'.'); + title(['$',num2str(Ts2D(it0)),'\leq t \leq',num2str(Ts2D(it1)),'$']); + xlabel('$n_i$'); ylabel('$n_e$'); +end + +if 0 +%% histograms +fig = figure; + t0 = 100; t1 = 100; [~,it0] = min(abs(t0-Ts2D)); [~,it1] = min(abs(t1-Ts2D)); + plt = @(x) squeeze(reshape(x(:,:,it0:it1),[],1)); + hist(plt(ni00),100); hold on + title(['$',num2str(Ts2D(it0)),'\leq t \leq',num2str(Ts2D(it1)),'$']); + xlabel('$n_i$'); +end + +if 0 +%% ni ne phi 3D phase space +fig = figure; + t0 = 20; t1 = 20; [~,it0] = min(abs(t0-Ts2D)); [~,it1] = min(abs(t1-Ts2D)); + plt = @(x) squeeze(reshape(x(:,:,it0:it1),[],1)); + plot3(plt(ni00),plt(ne00),plt(phi),'.','MarkerSize',0.5); + title(['$',num2str(Ts2D(it0)),'\leq t \leq',num2str(Ts2D(it1)),'$']); + xlabel('$n_i$'); ylabel('$n_e$'); zlabel('$\phi$'); grid on; +end + +t0 = 0; +skip_ = 1; +DELAY = 0.01*skip_; +FRAMES = floor(t0/(Ts2D(2)-Ts2D(1)))+1:skip_:numel(Ts2D); +if 0 +%% ni ne phi 3D phase space GIF +GIFNAME = ['ni_ne_phi_phase_space',sprintf('_%.2d',JOBNUM)]; +X = ne00; Y = ni00; Z = phi; T = Ts2D; +MARKERSIZE = 0.01; +XNAME = '$n_i$'; YNAME = '$n_e$'; ZNAME = '$\phi$'; VIEW = [1,-1,1]; +create_gif_3D +end \ No newline at end of file -- GitLab