Commit 2cac3544 authored by Lena Noack's avatar Lena Noack
Browse files

Add plot_snap.py file

parent 0befa827
import numpy as np
import matplotlib.pyplot as plt
import csv
import math
import matplotlib.cm as cm
import matplotlib.colors as colors
import os, sys
path = 'C:/Arbeit/Video_Venus_MOprofs/'
plot_path = path+'plot/'
file = None # 'PlotData_TWHDvRMt0011564.txt'
start = 0 # use higher number to exclude first time steps
end = 10000000000 # use lower number to exclude last time steps
def plot2D(xx,yy,data,title,time,colmap,vmin=None,vmax=None,nr_cont=10,name=None) :
y_scale = 5
fig = plt.figure(figsize=(2*y_scale+4.5,y_scale+1)) #4.5 for colorbar, 1 for figure title
ax = fig.add_subplot(111)
# plt.clf()
cmap = plt.get_cmap(colmap)
m = plt.cm.ScalarMappable(cmap=cmap)
cp = ax.contourf(xx, yy, data,nr_cont,cmap=cmap, vmin=vmin, vmax=vmax)
m.set_array(data)
m.set_clim(vmin, vmax)
plt.colorbar(m)
plt.axis('off')
# ax.set_title(title+' in '+str(time)+' Myr', fontsize=20)
time_str = str("{:2.1f}".format(float(time))) # time already as string but needs to be cut to lower precision
ax.set_title(title+' at '+time_str+' Myr', fontsize=20)
# plt.show()
if name!=None:
plt.savefig(name, format='png', bbox_inches='tight',dpi=100)
plt.close(fig)
#######################################################################
def make_plot_snap(filename):
letters_number = filename[9:-4]
#print(letters_number)
letters = letters_number[:-7]
number = letters_number[-7:] # stays string for plot names
#print(letters)
#print(int(number))
file1 = open(path+filename, 'r')
time = file1.readline() # time in Myr
xx_dim = file1.readline() # (x,y) dim of xx-coordinates
xx_val = file1.readline() # xx-coordinates
yy_dim = file1.readline() # (x,y) dim of yy-coordinates
yy_val = file1.readline() # yy-coordinates
xx_dim = xx_dim.split() # get two strings with integers each
xd = int(xx_dim[0])
yd = int(xx_dim[1])
xx_val = np.reshape(np.array(xx_val.split()).astype(float),(yd,xd))
yy_val = np.reshape(np.array(yy_val.split()).astype(float),(yd,xd))
def set_plot_values(title,cm,vmin=None,vmax=None,nr_cont=10,nameF=None):
f_dim = file1.readline() # dimension of field
f_val = file1.readline() # values as list
f_val = np.reshape(np.array(f_val.split()).astype(float),(yd,xd))
plot2D(xx_val,yy_val,f_val,title,time,cm,vmin=vmin,vmax=vmax,nr_cont=nr_cont,name=plot_path+nameF+number+'.png')
for letter in letters:
if letter == 'T':
set_plot_values('Temperature in K','magma',vmin=0,vmax=3500,nr_cont=20,nameF='T2D')
elif letter == 'D':
set_plot_values('Depletion','inferno',vmin=0,vmax=30,nr_cont=50,nameF='D2D')
elif letter == 'H':
set_plot_values('Heat sources','rainbow',vmin=0,vmax=80,nr_cont=100,nameF='H2D')
elif letter == 'W':
set_plot_values('Water fraction in ppm','RdBu',vmin=0,vmax=140,nr_cont=100,nameF='W2D')
elif letter == 'v':
set_plot_values('Velocity in cm/yr','rainbow',vmin=0,vmax=25,nr_cont=100,nameF='v2D')
elif letter == 'R':
# set_plot_values('Material parameters','rainbow',vmin=3,vmax=7,nr_cont=4,nameF='R2D')
# set_plot_values('Material parameters','Set2',vmin=3,vmax=7,nr_cont=4,nameF='R2D')
set_plot_values('Material parameters','Paired',vmin=3,vmax=7,nr_cont=4,nameF='R2D')
elif letter == 'M':
set_plot_values(r'Radial material exchange in $kg/(m^2 yr)$','inferno',nr_cont=50,nameF='M2D')
elif letter == 't':
set_plot_values('Temperature variations in K','RdBu',vmin=-100,vmax=100,nr_cont=20,nameF='dT2D')
else:
print('Unused letter found (',letter,')')
file1.close()
#######################################################################
def create_plots(path,file=None,start=0,end=10000000000):
plot_path = path+'plot/'
if os.path.isdir(plot_path)==False:
os.mkdir( plot_path );
os.chdir(path)
if file==None:
arr = [x for x in os.listdir() if x.startswith("PlotData")]
# print(arr)
for filename in arr:
letters_number = filename[9:-4]
number = int(letters_number[-7:])
if (number>=start and number<=end):
print(filename)
make_plot_snap(filename)
else:
make_plot_snap(file)
#######################################################################
create_plots(path,file,start=start,end=end)
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment