Changeset 26865


Ignore:
Timestamp:
02/09/22 05:37:44 (3 years ago)
Author:
Mathieu Morlighem
Message:

NEW: added grounding line and icefront option to plot_transient_movie, and better handle output

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/m/plot/plot_transient_movie.m

    r25502 r26865  
    4242        end
    4343
     44        %Do we have an output?
     45        isavi = 0;
     46        isgif = 0;
     47        ismp4 = 0;
     48        if exist(options,'transient_movie_output'),
     49                filename=getfieldvalue(options,'transient_movie_output');
     50                [pathstr,name,ext] = fileparts(filename);
     51                if strcmp(ext,'.gif')
     52                        isgif = 1;
     53                elseif strcmp(ext,'.mp4')
     54                        ismp4 = 1;
     55                elseif strcmp(ext,'.avi')
     56                        isavi = 1;
     57                end
     58        end
     59        if isavi || ismp4
     60                vid=VideoWriter([filename(1:end-4),'.avi'],'Motion JPEG AVI');
     61                vid.FrameRate = 2;
     62                open(vid);
     63        end
     64
    4465        %calculate caxis
    4566        if ~exist(options,'caxis'),
     
    5374        end
    5475
     76
     77        %Process mesh once for all
     78        [x y z elements is2d isplanet]=processmesh(md,results(i).(field),options);
     79
    5580        %display movie
    5681        nstep=1;
     
    6085                if ~isempty(results(i).(field)),
    6186                        %process data
    62                         [x y z elements is2d isplanet]=processmesh(md,results(i).(field),options);
    6387                        [data datatype]=processdata(md,results(i).(field),options);
    6488
    6589                        clf;
    66                         titlestring=[field ' at time ' num2str(results(i).time,'%7.2f') ' year'];
     90                        titlestring=[field ' (time ' num2str(results(i).time,'%7.2f') ' yr)'];
    6791                        plot_unit(x,y,z,elements,data,is2d,isplanet,datatype,options)
    6892                        apply_options_movie(md,options,titlestring);
    6993
    70                         if exist(options,'transient_movie_output'),
    71                                 set(gcf,'Renderer','zbuffer','color','white'); %fixes a bug on Mac OS X (not needed in future Matlab version)
     94                        %Add grounding line
     95                        if exist(options,'groundingline')
     96                                contours=isoline(md, results(i).MaskOceanLevelset,'output','matrix');
     97                                hold on
     98                                plot(contours(:,1),contours(:,2),getfieldvalue(options,'groundingline'));
     99                        end
     100
     101                        %Add ice front
     102                        if exist(options,'icefront')
     103                                contours=isoline(md, results(i).MaskIceLevelset,'output','matrix');
     104                                hold on
     105                                plot(contours(:,1),contours(:,2),getfieldvalue(options,'icefront'));
     106                        end
     107
     108                        if isgif
     109                                frame=getframe(gcf);
     110                                im = frame2im(frame);
     111                                [imind,cmap] = rgb2ind(im,256);
     112                                if i==1
     113                                        imwrite(imind, cmap, filename, 'DelayTime',getfieldvalue(options,'transient_movie_time',.5), 'LoopCount',inf)
     114                                else
     115                                        imwrite(imind, cmap, filename, 'WriteMode','append');
     116                                end
     117                        elseif isavi || ismp4
     118                                F=getframe(gcf);
     119                                writeVideo(vid, F);
     120                        end
     121
     122                        if exist(options,'transient_movie_output')
     123                                %set(gcf,'Renderer','zbuffer','color','white'); %fixes a bug on Mac OS X (not needed in future Matlab version)
    72124                                if nstep==1,
    73125                                        %initialize images and frame
     
    87139
    88140        %output movie if requested.
    89         if exist(options,'transient_movie_output'),
    90                 filename=getfieldvalue(options,'transient_movie_output');
    91                 imwrite(images,map,filename,'DelayTime',getfieldvalue(options,'transient_movie_time',2),'LoopCount',inf)
     141        if isavi || ismp4
     142                close(vid);
     143        end
     144        if ismp4
     145                while(~exist([filename]))
     146                        disp(['Waiting for ' filename ]);
     147                        pause(1)
     148                end
     149                filename = filename(1:end-4);
     150                command=sprintf('ffmpeg -y -i %s.avi -c:v libx264 -crf 19 -preset slow -c:a libfaac -b:a 192k -ac 2 %s.mp4',filename,filename);
     151                system(command);
     152                filename = [filename '.mp4'];
     153                disp(['Movie saved also as ' filename]);
     154        end
     155        if isgif
     156                imwrite(images,map,filename,'DelayTime',getfieldvalue(options,'transient_movie_time',.5),'LoopCount',inf)
    92157        end
    93158
Note: See TracChangeset for help on using the changeset viewer.