|
| 1 | +disp( 'This code requires ffmpeg.exe from http://ffmpeg.zeranoe.com/builds/ to be placed in the same folder.' ); |
| 2 | + |
| 3 | +ShockNames = { 'epsilon_AT_5_5', 'epsilon_GA' 'epsilon_GN' 'epsilon_tau' 'epsilon_phi' 'epsilon_beta' }; |
| 4 | +VariableNames = { 'C', 'K', 'I', 'E', 'F', 'Q', 'J', 'L', 'H', 'N', 'SN', 'SD', 'muN', 'U' }; |
| 5 | +SpecificIndices = [ 1, 1; 5, 5 ]; |
| 6 | +SpatialShockIndices = 1; |
| 7 | + |
| 8 | +IRFLength = 400; |
| 9 | +ShockScale = 10; |
| 10 | + |
| 11 | +InterpolationAmount = 3; |
| 12 | + |
| 13 | +SpatialDimensions = 2; |
| 14 | +SpatialPointsPerDimension = 8; |
| 15 | + |
| 16 | +SpatialNumPoints = SpatialPointsPerDimension ^ SpatialDimensions; |
| 17 | + |
| 18 | +SpatialIndices = cell( 1, SpatialDimensions ); |
| 19 | +[ SpatialIndices{:} ] = ndgrid( 1:SpatialPointsPerDimension ); |
| 20 | +SpatialIndices = cellfun( @( c ) c(:), SpatialIndices, 'UniformOutput', false ); |
| 21 | +SpatialIndices = cell2mat( SpatialIndices ); |
| 22 | + |
| 23 | +GridSizeCell = repmat( { SpatialPointsPerDimension }, 1, SpatialDimensions ); |
| 24 | + |
| 25 | +XIRF = ( 1:IRFLength ) / 4; |
| 26 | +ZeroIRF = zeros( IRFLength, 1 ); |
| 27 | + |
| 28 | +if SpatialDimensions == 2 |
| 29 | + InterpolationMultiplier = 2 ^ InterpolationAmount; |
| 30 | + [ SurfaceX, SurfaceY ] = meshgrid( ( 0 : ( SpatialPointsPerDimension * InterpolationMultiplier ) ) / ( SpatialPointsPerDimension * InterpolationMultiplier ) ); |
| 31 | +end |
| 32 | + |
| 33 | +FigureHandle = figure( 1 ); |
| 34 | +figure( FigureHandle ); |
| 35 | +robot = java.awt.Robot; |
| 36 | +robot.keyPress(java.awt.event.KeyEvent.VK_ALT); %// send ALT |
| 37 | +robot.keyPress(java.awt.event.KeyEvent.VK_SPACE); %// send SPACE |
| 38 | +robot.keyRelease(java.awt.event.KeyEvent.VK_SPACE); %// release SPACE |
| 39 | +robot.keyRelease(java.awt.event.KeyEvent.VK_ALT); %// release ALT |
| 40 | +robot.keyPress(java.awt.event.KeyEvent.VK_X); %// send X |
| 41 | +robot.keyRelease(java.awt.event.KeyEvent.VK_X); %// release X |
| 42 | +pause( 0.1 ); |
| 43 | + |
| 44 | +FigureHandle.PaperPositionMode = 'auto'; |
| 45 | +FigureHandle.Color = [ 1 1 1 ]; |
| 46 | +colormap( parula( 2 ^ 16 ) ); |
| 47 | + |
| 48 | +FolderName = 'Results'; |
| 49 | +[ mkdirStatus, ~, ~ ] = mkdir( FolderName ); |
| 50 | +assert( mkdirStatus == 1 ); |
| 51 | +cd( FolderName ); |
| 52 | + |
| 53 | +for ShockIdx = 1 : length( ShockNames ) |
| 54 | + ShockName = ShockNames{ ShockIdx }; |
| 55 | + for VariableIdx = 1 : length( VariableNames ) |
| 56 | + VariableName = VariableNames{ VariableIdx }; |
| 57 | + |
| 58 | + FolderName = [ VariableName '_' ShockName ]; |
| 59 | + [ mkdirStatus, ~, ~ ] = mkdir( FolderName ); |
| 60 | + assert( mkdirStatus == 1 ); |
| 61 | + cd( FolderName ); |
| 62 | + |
| 63 | + AggregatedVariableName = [ 'log_' VariableName '_' ShockName ]; |
| 64 | + if isfield( oo_.irfs, AggregatedVariableName ) |
| 65 | + CurrentPercentIRF = 100 * ShockScale * oo_.irfs.( AggregatedVariableName )( 1:IRFLength ); |
| 66 | + plot( XIRF, CurrentPercentIRF, 'k-' ); |
| 67 | + hold on; |
| 68 | + plot( XIRF, ZeroIRF, 'r--' ); |
| 69 | + hold off; |
| 70 | + drawnow; |
| 71 | + savefig( FigureHandle, 'Aggregate', 'compact' ); |
| 72 | + saveas( FigureHandle, 'Aggregate', 'meta' ); |
| 73 | + end |
| 74 | + |
| 75 | + PercentIRF = zeros( GridSizeCell{:}, IRFLength ); |
| 76 | + for Point = 1 : SpatialNumPoints |
| 77 | + CurrentIndices = SpatialIndices( Point, : ); |
| 78 | + CurrentIndicesCell = num2cell( CurrentIndices ); |
| 79 | + CurrentIndicesString = sprintf( repmat( '_%d', 1, SpatialDimensions ), CurrentIndices ); |
| 80 | + PercentIRF( CurrentIndicesCell{:}, : ) = 100 * ShockScale * oo_.irfs.( [ 'log_' VariableName CurrentIndicesString '_' ShockName ] )( 1:IRFLength ); |
| 81 | + end |
| 82 | + |
| 83 | + for SpecificIndexIdx = 1 : size( SpecificIndices, 1 ) |
| 84 | + CurrentIndices = SpecificIndices( SpecificIndexIdx, : ); |
| 85 | + CurrentIndicesCell = num2cell( CurrentIndices ); |
| 86 | + CurrentIndicesString = sprintf( repmat( '_%d', 1, SpatialDimensions ), CurrentIndices ); |
| 87 | + CurrentPercentIRF = squeeze( PercentIRF( CurrentIndicesCell{:}, : ) ); |
| 88 | + plot( XIRF, CurrentPercentIRF, 'k-' ); |
| 89 | + hold on; |
| 90 | + plot( XIRF, ZeroIRF, 'r--' ); |
| 91 | + hold off; |
| 92 | + drawnow; |
| 93 | + savefig( FigureHandle, CurrentIndicesString, 'compact' ); |
| 94 | + saveas( FigureHandle, CurrentIndicesString, 'meta' ); |
| 95 | + end |
| 96 | + |
| 97 | + if ( SpatialDimensions == 2 ) && ismember( ShockIdx, SpatialShockIndices ) |
| 98 | + |
| 99 | + Video = VideoWriter( 'Video', 'Archival' ); %#ok<TNMLP> |
| 100 | + Video.FrameRate = 4 * InterpolationMultiplier; |
| 101 | + % Video.Quality = 100; |
| 102 | + open( Video ); |
| 103 | + |
| 104 | + [ mkdirStatus, ~, ~ ] = mkdir( 'Frames' ); |
| 105 | + assert( mkdirStatus == 1 ); |
| 106 | + cd( 'Frames' ); |
| 107 | + |
| 108 | + PercentIRF = [ PercentIRF( :, :, : ), PercentIRF( :, 1, : ); PercentIRF( 1, :, : ), PercentIRF( 1, 1, : ) ]; |
| 109 | + PercentIRF = interp3( PercentIRF, InterpolationAmount ); |
| 110 | + minPercentIRF = min( PercentIRF(:) ); |
| 111 | + maxPercentIRF = max( PercentIRF(:) ); |
| 112 | + |
| 113 | + for Period = 1 : size( PercentIRF, 3 ) |
| 114 | + CurrentSurface = PercentIRF( :, :, Period ); |
| 115 | + pcolor( SurfaceX, SurfaceY, CurrentSurface ); |
| 116 | + shading interp; |
| 117 | + axis square; |
| 118 | + caxis( [ minPercentIRF, maxPercentIRF ] ); |
| 119 | + colorbar; |
| 120 | + drawnow; |
| 121 | + |
| 122 | + if ( mod( Period - 1, 4 * InterpolationMultiplier ) == 0 ) || ( Period == size( PercentIRF, 3 ) ) |
| 123 | + FileName = num2str( Period ); |
| 124 | + savefig( FigureHandle, FileName, 'compact' ); |
| 125 | + saveas( FigureHandle, FileName, 'png' ); |
| 126 | + end |
| 127 | + |
| 128 | + % Axis = gca; |
| 129 | + % Axis.Units = 'pixels'; |
| 130 | + % AxisPosition = ceil( Axis.Position ); |
| 131 | + % Margin = max( ceil( Axis.TightInset ) ); |
| 132 | + % Rectangle = [ -Margin, -Margin, AxisPosition(3) + 2 * Margin, AxisPosition(4) + 2 * Margin ]; |
| 133 | + % Frame = getframe( Axis, Rectangle ); |
| 134 | + |
| 135 | + Frame = getframe( FigureHandle ); |
| 136 | + |
| 137 | + writeVideo( Video, Frame ); |
| 138 | + end |
| 139 | + |
| 140 | + cd( '..' ); |
| 141 | + |
| 142 | + close( Video ); |
| 143 | + |
| 144 | + dos( '..\ffmpeg.exe -i Video.mj2 -filter "setsar=sar=1" -crf 15 -preset slow Video.mp4', '-echo' ); |
| 145 | + delete Video.mj2 |
| 146 | + |
| 147 | + end |
| 148 | + |
| 149 | + cd( '..' ); |
| 150 | + end |
| 151 | +end |
| 152 | + |
| 153 | +cd( '..' ); |
0 commit comments