12/13/2019
FantomRefined datファイル解説import numpy as np | |
import matplotlib.pyplot as plt | |
import glob | |
# extract data from a file | |
def get_data(file_name): | |
columns = [] | |
for line in open(file_name).readlines(): | |
items = line.rstrip().split() | |
if items[0] == "time": | |
time = float(items[1]) | |
elif items[0] == "dz": | |
dzs = [float(x) for x in items[1:]] | |
elif items[0] == "limit_depth": | |
pass | |
elif items[0] == "items": | |
pass | |
elif items[0] == "column": | |
columns.append({"number" :int(items[1]), "k_offset" :int(items[2]), | |
"center_x" :float(items[3]), "center_y" :float(items[4]), | |
"delta_x" : float(items[5]), "delta_y" :float(items[6]), | |
"btm_k" :int(items[7]), "sfc_k" :int(items[8]), | |
"btm_z" :float(items[9]), "sfc_z" :float(items[10]), | |
"container_i":int(items[11]), "container_j":int(items[12]), | |
"container_i":int(items[13]), "container_j":int(items[14]), | |
"status" :items[15], "variables" :{}}) | |
else: | |
columns[int(items[0])]["variables"][items[1]]=[float(x) for x in items[2:]] | |
return time, dzs, columns | |
if __name__ == '__main__': | |
# gathering dat files from folder | |
files = sorted(glob.glob("kasumi*.dat")) | |
# specifying the location for plotting surface level | |
target_x = 11375 | |
target_y = 10625 | |
# temporary read first file to obtain columns structure | |
t, dzs, columns = get_data(files[0]) | |
# finding the target column from location | |
for column in columns: | |
if column["center_x"]==target_x and column["center_y"]==target_y: | |
target_number = column["number"] | |
break; | |
# collecting surface level from all the files | |
time = [] | |
surface_level = [] | |
for file in files[:]: | |
print ("processing... ", file) | |
t, dzs, columns = get_data(file) | |
time.append(t/3600.0) # sec -> hour | |
surface_level.append(columns[target_number]["sfc_z"]) | |
# plot time variation of surface level | |
plt.title("Time variation of surface level") | |
plt.plot(time, surface_level, 'k-x') | |
plt.xlabel("Time (hours)") | |
plt.ylabel("Level (m)") | |
plt.savefig("surface_variation.png") | |
plt.show() |