def create_video(): #creating the video SpawnCommand("rm -f gpp_chlrphyl_movie/gpp_chlrphyl.avi") options = ("-r 5 -vcodec png -y -i " + "gpp_chlrphyl_movie/image-%04d.png -r 5 -vcodec msmpeg4v2 -qblur 0.01 -qscale 5 ") SpawnCommand("ffmpeg " + options + "gpp_chlrphyl_movie/gpp_chlrphyl.avi")
def plotrun(cube, foldername, scaleLBound, scaleUBound): # Delete all the image files in the directory to ensure that only those # created in the loop end up in the movie. print("Deleting all .png files in the " + foldername + " directory...") SpawnCommand("rm " + foldername + "/*.png") # Add a new coordinate containing the year. icat.add_year(cube, 'time') # Set the end index for the loop over years, and do the loop. tmin = 0 tmax = cube.shape[0] # We want the files to be numbered sequentially, starting # from 000.png; this is so that the ffmpeg command can grok them. index = 0 #scaleBarArray = scaleBar(lowerBound, upperBound) for time in range(tmin, tmax): fig = plt.figure(figsize=(6, 3), dpi=200) rect = 0, 0, 1200, 600 fig.add_axes(rect) geo_axes = plt.axes(projection=ccrs.PlateCarree()) geo_axes.outline_patch.set_visible(False) plt.margins(0, 0) fig.subplots_adjust(left=0, right=1, bottom=0, top=1) iplt.contourf(cube[time], 10, vmin=scaleLBound, vmax=scaleUBound, cmap='YlOrRd') plt.gca().coastlines(color='b') # plt.figure(frameon=False) # Extract the year value and display it (coordinates used are # those of the data). year = cube.coord('year')[time].points[0] plt.text(-160, 0, year, horizontalalignment='center', size='large', fontdict={'family': 'monospace'}, color='b') filename = str(foldername) + '/' + "%03d.png" % index print('Now plotting: ', filename) plt.savefig(filename, dpi=200) plt.close() index += 1 # Now make the movie from the image files by spawning the ffmpeg command. # The options (of which there are many) are somewhat arcane, but these ones work. print("Converting images to movie...") options = ("-r 5 -vcodec png -y -i " + foldername + "/%03d.png -r 5 -vcodec msmpeg4v2 -qblur 0.01 -qscale 5 ") SpawnCommand("ffmpeg " + options + foldername + ".mp4")
def create_video(): #creating the video SpawnCommand("ffmpeg -i image-%04d.png TemperatureVideo1.mp4") SpawnCommand('ffmpeg -i TemperatureVideo1.mp4 -filter:v "setpts=5.0*PTS" ssp585.mp4') print ("Deleting the unneeded images...") SpawnCommand("rm -f *.png") SpawnCommand("rm -f TemperatureVideo1.mp4")
def main(): # Delete all the image files in the current directory to ensure that only those # created in the loop end up in the movie. print "Deleting all .png files in this directory..." SpawnCommand("rm *.png") # Read all the temperature values. temperatures = iris.load_cube('temperatures.pp') # Get the range of values. minTemp = np.amin(temperatures.data) maxTemp = np.amax(temperatures.data) print "Range of temperatures is", minTemp, "to", maxTemp # Add a new coordinate containing the year. icat.add_year(temperatures, 'time') years = temperatures.coord('year') # Set the limits for the loop over years. minTime = 0 maxTime = temperatures.shape[0] print "Making images from year", years[minTime].points[0], "to", years[maxTime-1].points[0] for time in range(minTime, maxTime): # Contour plot the temperatures and add the coastline. iplt.contourf(temperatures[time], 10, vmin=minTemp, vmax=maxTemp, cmap='hot') plt.gca().coastlines() # We need to fix the boundary of the figure (otherwise we get a black border at left & top). # Cartopy removes matplotlib's axes.patch (which normally defines the boundary) and # replaces it with outline_patch and background_patch. It's the former which is causing # the black border. Get the axis object and make its outline patch invisible. ax = plt.gca() ax.outline_patch.set_visible(False) # Extract the year value and display it (coordinates used in locating the text are # those of the data). year = years[time].points[0] plt.text(0, -60, year, horizontalalignment='center') # Now save the plot in an image file. The files are numbered sequentially, starting # from 000.png; this is so that the ffmpeg command can grok them. filename = "%03d.png" % time plt.savefig(filename, bbox_inches='tight', pad_inches=0) # Discard the figure (otherwise the text will be overwritten # by the next iteration). plt.close() # Now make the movie from the image files by spawning the ffmpeg command. # The options (of which there are many) are somewhat arcane, but these ones work. print "Converting images to movie..." options = "-r 5 -vcodec png -y -i %03d.png -r 5 -vcodec msmpeg4v2 -qblur 0.01 -qscale 5" SpawnCommand("ffmpeg " + options + " plotTemperatures.avi")
def create_video(): #creating the video SpawnCommand("ffmpeg -i image-%04d.png TemperatureVideo1.mp4") SpawnCommand( 'ffmpeg -i TemperatureVideo1.mp4 -filter:v "setpts=5.0*PTS" ' + sys.argv[1] + '_scenario_' + sys.argv[2] + '.mp4') print("Deleting the unneeded images...") SpawnCommand("rm -f *.png") SpawnCommand("rm -f TemperatureVideo1.mp4")
def create_video(): #creating the video SpawnCommand("rm -f rainfall/rainfall.avi") options = ( "-r 5 -vcodec png -y -i " + "rainfall/image-%04d.png -r 5 -vcodec msmpeg4v2 -qblur 0.01 -qscale 5 " ) SpawnCommand("ffmpeg " + options + "rainfall/rainfall.avi") # SpawnCommand("ffmpeg -i rainfall/image-%04d.png rainfall/temp.mp4") # SpawnCommand('ffmpeg -i rainfall/temp.mp4 -filter:v "setpts=5.0*PTS" rainfall/rainfall.mp4') print("Deleting the unneeded images...")
def create_video(): #creating the video print "Converting images to movie..." options = ("-r 5 -vcodec png -y -i " + "image-%04d.png -r 5 -vcodec msmpeg4v2 -qblur 0.01 -qscale 5 ") SpawnCommand("ffmpeg " + options + "split.avi")
def main(): # Delete all the image files in the current directory to ensure that only those # created in the loop end up in the movie. print("\nDeleting all .png files in this directory...") SpawnCommand("rm -f *.png") print("Deleting all .mp4 files in this directory...") SpawnCommand("rm -f *.mp4") # Read all the temperature values and create a single cube containing this data print("Loading the data...") cubes = iris.cube.CubeList([]) months = [ 'jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec' ] for i in range(1850, 2015): for month in months: tempfile = 'tas_1850-2014/bc179a.p5' + str(i) + month + '.nc' cubes.append(iris.load_cube(tempfile)) temperatures = cubes.merge_cube() print("Data downloaded! Now Processing...") # Get the range of values. minTemp = np.amin(temperatures.data) maxTemp = np.amax(temperatures.data) print("Range of temperatures is ", minTemp, "ºK to ", maxTemp, "ºK.") # Add a new coordinate containing the year. icat.add_year(temperatures, 'time') years = temperatures.coord('year') # Set the limits for the loop over years. minTime = 0 maxTime = temperatures.shape[0] print("Making images from year", years[minTime].points[0], "to", years[maxTime - 1].points[0], "...") for time in range(minTime, maxTime): # Contour plot the temperatures and add the coastline. iplt.contourf(temperatures[time], 10, vmin=minTemp, vmax=maxTemp, cmap='RdBu_r') plt.gca().coastlines() # We need to fix the boundary of the figure (otherwise we get a black border at left & top). # Cartopy removes matplotlib's axes.patch (which normally defines the boundary) and # replaces it with outline_patch and background_patch. It's the former which is causing # the black border. Get the axis object and make its outline patch invisible. ax = plt.gca() ax.outline_patch.set_visible(False) # Extract the year value and display it (coordinates used in locating the text are # those of the data). year = years[time].points[0] plt.text(0, -60, year, horizontalalignment='center') # Now save the plot in an image file. The files are numbered sequentially, starting # from 000.png; this is so that the ffmpeg command can grok them. filename = "image-%04d.png" % time plt.savefig(filename, bbox_inches='tight', pad_inches=0) # Discard the figure (otherwise the text will be overwritten # by the next iteration). plt.close() print("images made! Now converting to .mp4...") SpawnCommand("ffmpeg -i image-%04d.png TemperatureVideo1.mp4") SpawnCommand( 'ffmpeg -i TemperatureVideo1.mp4 -filter:v "setpts=2.0*PTS" TemperatureVideo.mp4' ) print("Deleting the unneeded images...") SpawnCommand("rm -f *.png") SpawnCommand("rm -f TemperatureVideo1.mp4") print("Opening video...") myTime.sleep(5) SpawnCommand("open TemperatureVideo.mp4")
def main(): # Delete all the image files in the current directory to ensure that only those # created in the loop end up in the movie. print ("\nDeleting all .png files in this directory...") SpawnCommand("rm -f *.png") print("Loading the data...") # Read all the temperature values and create a single cube containing this data cubeList = iris.cube.CubeList([]) cubeList.extend(myload(1960, 2014, 'tas_1850-2014/bc179a.p5')) cubeList.extend(myload(2015, 2100, 'tas_2015-2100-ssp585/be653a.p5')) equalise_attributes(cubeList) temperatures = cubeList.merge_cube() baseYears = temperatures[ :29, :, :] baseYearsMean = baseYears.collapsed('time',iris.analysis.MEAN) # Calculate the difference in annual mean temperature from the mean baseline (returns a cube) anomaly = temperatures - baseYearsMean print("Data downloaded! Now Processing...") # Get the range of values. # Add a new coordinate containing the year. icat.add_year(anomaly, 'time') years = anomaly.coord('year') # Set the limits for the loop over years. minTime = 0 maxTime = temperatures.shape[0] print ("Making images from year", years[minTime].points[0], "to", years[maxTime-1].points[0], "...") for time in range(minTime, maxTime): # Contour plot the temperatures and add the coastline. iplt.contourf(anomaly[time], levels = (-6, -3, 0, 4, 8, 12, 16, 20, 25), colors = ('darkblue', 'blue', 'cyan', 'lightyellow', 'yellow', 'orange', 'darkorange', 'red')) #-6.4358826, 27.94899 plt.gca().coastlines() #plt.colorbar(boundaries = (-6, -3, 0, 4, 8, 12, 16, 20, 25), values = (-6, -3, 0, 4, 8, 12, 16, 20)) # We need to fix the boundary of the figure (otherwise we get a black border at left & top). # Cartopy removes matplotlib's axes.patch (which normally defines the boundary) and # replaces it with outline_patch and background_patch. It's the former which is causing # the black border. Get the axis object and make its outline patch invisible. ax = plt.gca() ax.outline_patch.set_visible(False) # Extract the year value and display it (coordinates used in locating the text are # those of the data). year = years[time].points[0] plt.text(0, -60, year, horizontalalignment='center') # Now save the plot in an image file. The files are numbered sequentially, starting # from 000.png; this is so that the ffmpeg command can grok them. filename = "image-%04d.png" % time plt.savefig(filename, bbox_inches='tight', pad_inches=0) # Discard the figure (otherwise the text will be overwritten # by the next iteration). plt.close() print('boundaries for colour = -6, -3, 0, 4, 8, 12, 16, 20, 25') print("images made! Now converting to .mp4...") create_video() print("Opening video...") myTime.sleep(5)
def main(): if len(sys.argv) != 3: sys.exit("program needs two arguments") if sys.argv[1] != 'ssp119' and sys.argv[1] != 'ssp585' and sys.argv[ 1] != 'ssp534OS': sys.exit("argument must be ssp119, ssp585 or ssp534OS") if sys.argv[2] != 'ssp119' and sys.argv[2] != 'ssp585' and sys.argv[ 2] != 'ssp534OS': sys.exit("argument must be ssp119, ssp585 or ssp534OS") # Delete all the image files in the current directory to ensure that only those # created in the loop end up in the movie. print("\nDeleting all .png files in this directory...") SpawnCommand("rm -f *.png") print("Loading the data...") # Read all the temperature values and create a single cube containing this data for i in range(1, 3): cubeList = iris.cube.CubeList([]) if sys.argv[i] == 'ssp585': cubeList.extend(myload(1960, 2014, 'tas_1850-2014/bc179a.p5')) cubeList.extend( myload(2015, 2100, 'tas_2015-2100-ssp585/be653a.p5')) elif sys.argv[i] == 'ssp119': cubeList.extend(myload(1960, 2014, 'tas_1850-2014/bc179a.p5')) cubeList.extend( myload(2015, 2100, 'tas_2015-2100-ssp119/bh409a.p5')) elif sys.argv[i] == 'ssp534OS': cubeList.extend(myload(1960, 2014, 'tas_1850-2014/bc179a.p5')) cubeList.extend(myload(2015, 2039, 'tas_2015-2100/be653a.p5')) cubeList.extend( myload(2040, 2100, 'tas_2015-2100-ssp534OS/bh409a.p5')) equalise_attributes(cubeList) temperatures = cubeList.merge_cube() if i == 1: leftCube = temperatures.intersection(longitude=(-181, 0), ignore_bounds=True) elif i == 2: rightCube = temperatures.intersection(longitude=(0, 180)) cubeList = iris.cube.CubeList([leftCube, rightCube]) temperatures = cubeList.concatenate_cube() baseYears = temperatures[:29, :, :] baseYearsMean = baseYears.collapsed('time', iris.analysis.MEAN) # Calculate the difference in annual mean temperature from the mean baseline (returns a cube) anomaly = temperatures - baseYearsMean print("Data downloaded! Now Processing...") # Get the range of values. # Add a new coordinate containing the year. icat.add_year(anomaly, 'time') years = anomaly.coord('year') # Set the limits for the loop over years. minTime = 0 maxTime = temperatures.shape[0] print("Making images from year", years[minTime].points[0], "to", years[maxTime - 1].points[0], "...") for time in range(minTime, maxTime): # Set up for larger image. figSize = [12, 6] fig = plt.figure(figsize=figSize, dpi=200) rect = 0, 0, 200 * figSize[0], 200 * figSize[1] fig.add_axes(rect) geo_axes = plt.axes(projection=ccrs.PlateCarree()) # We need to fix the boundary of the figure (otherwise we get a black border at left & top). # Cartopy removes matplotlib's axes.patch (which normally defines the boundary) and # replaces it with outline_patch and background_patch. It's the former which is causing # the black border. Get the axis object and make its outline patch invisible. geo_axes.outline_patch.set_visible(False) plt.margins(0, 0) fig.subplots_adjust(left=0, right=1, bottom=0, top=1) # Contour plot the temperatures and add the coastline. iplt.contourf(anomaly[time], levels=(-6, -3, 0, 4, 8, 12, 17, 22, 28), colors=('darkblue', 'blue', 'cyan', 'lightyellow', 'yellow', 'orange', 'darkorange', 'red')) #-6.4358826, 27.94899 plt.gca().coastlines() #plt.colorbar(boundaries = (-6, -3, 0, 4, 8, 12, 16, 20, 25), values = (-6, -3, 0, 4, 8, 12, 16, 20)) # Extract the year value and display it (coordinates used in locating the text are # those of the data). year = years[time].points[0] # Display year on both sides of the display. plt.text(-110, 0, year, horizontalalignment='center', verticalalignment='top', size='large', fontdict={'family': 'monospace'}) plt.text(70, 0, year, horizontalalignment='center', verticalalignment='top', size='large', fontdict={'family': 'monospace'}) # Add labels to halves of display. plt.text(-110, -60, str(sys.argv[1]), horizontalalignment='center', size='small', fontdict={'family': 'monospace'}) plt.text(70, -60, str(sys.argv[2]), horizontalalignment='center', size='small', fontdict={'family': 'monospace'}) # Draw a line along the division between the two halves. plt.plot([0, 0], [-90, 90], color='gray', linewidth=3) plt.plot([-179.8, -179.8], [-90, 90], color='gray', linewidth=3) # Now save the plot in an image file. The files are numbered sequentially, starting # from 000.png; this is so that the ffmpeg command can grok them. filename = "split/image-%04d.png" % time plt.savefig(filename, dpi=200) # Discard the figure (otherwise the text will be overwritten # by the next iteration). plt.close() print('boundaries for colour = -6, -3, 0, 4, 8, 12, 16, 20, 25') print("images made! Now converting to .mp4...") create_video() print("Opening video...") myTime.sleep(5)
def main(): # Delete all the image files in the current directory to ensure that only those # created in the loop end up in the movie. print("\nDeleting all .png files in this directory...") SpawnCommand("rm -f *.png") print("Deleting all .mp4 files in this directory...") SpawnCommand("rm -f *.mp4") # Read all the temperature values and create a single cube containing this data print("Loading the data...") temperatures = load_cubes_month_to_year(sys.argv[3], sys.argv[4], sys.argv[1]) print("Data downloaded! Now Processing...") # Get the range of values. bounds = max_min(sys.argv[2], temperatures) print("Range of temperatures is ", bounds[0], "K to ", bounds[1], "K.") # Add a new coordinate containing the year. icat.add_year(temperatures, 'time') years = temperatures.coord('year') # Set the limits for the loop over years. minTime = 0 maxTime = temperatures.shape[0] print("Making images from year", years[minTime].points[0], "to", years[maxTime - 1].points[0], "...") for time in range(minTime, maxTime): # Contour plot the temperatures and add the coastline. iplt.contourf(temperatures[time], 10, vmin=bounds[0], vmax=bounds[1], cmap='RdBu_r') plt.gca().coastlines() # We need to fix the boundary of the figure (otherwise we get a black border at left & top). # Cartopy removes matplotlib's axes.patch (which normally defines the boundary) and # replaces it with outline_patch and background_patch. It's the former which is causing # the black border. Get the axis object and make its outline patch invisible. ax = plt.gca() ax.outline_patch.set_visible(False) # Extract the year value and display it (coordinates used in locating the text are # those of the data). year = years[time].points[0] plt.text(0, -60, year, horizontalalignment='center') # Now save the plot in an image file. The files are numbered sequentially, starting # from 000.png; this is so that the ffmpeg command can grok them. filename = "image-%04d.png" % time plt.savefig(filename, bbox_inches='tight', pad_inches=0) # Discard the figure (otherwise the text will be overwritten # by the next iteration). plt.close() print("images made! Now converting to .mp4...") create_video() print("Opening video...") myTime.sleep(5) SpawnCommand('open ' + sys.argv[1] + '_scenario_' + sys.argv[2] + '.mp4')