Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workshop #5

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
0bd2561
back to gcc11
ryba183 May 5, 2020
2d9567d
Cloud Top Height
ryba183 Jul 23, 2020
a894010
Python3 update
ryba183 Jul 23, 2020
bdfc97a
Lasher_Trapp_ICMW
ryba183 Aug 5, 2020
590c633
Merge branch 'master' into Workshop
ryba183 Aug 5, 2020
ed62eef
Update latex_labels.py
ryba183 Aug 6, 2020
d0f3ba5
looking for error
ryba183 Aug 12, 2020
100aa74
Merge branch 'Workshop' of https://github.com/ryba183/UWLCM_plotting …
ryba183 Aug 13, 2020
3533d88
ICMW2020
ryba183 Aug 13, 2020
6f1c66b
Revert "Update latex_labels.py"
ryba183 Aug 13, 2020
a88d8fb
working
ryba183 Aug 13, 2020
c94291f
LWM
ryba183 Aug 28, 2020
5fa75f9
time series
ryba183 Sep 4, 2020
590c1fe
profs
ryba183 Sep 22, 2020
c0db4f2
ICMW_profs
ryba183 Sep 23, 2020
0e35c11
NC_vs_AF python3
ryba183 Sep 24, 2020
cde1e02
Workshops
ryba183 Oct 8, 2020
86c5545
ICMW_CC_2020
ryba183 Dec 3, 2020
d6ea764
Merge branch 'master' into Workshop
ryba183 Dec 3, 2020
4e3157d
working_on_rysy
ryba183 Dec 8, 2020
d0a1d85
Adiabatic Fraction ICMW2020
ryba183 Apr 15, 2021
3cf79dc
Merge branch 'Workshop' of https://github.com/ryba183/UWLCM_plotting …
ryba183 Apr 15, 2021
46ead79
preparation for randomness
ryba183 Aug 2, 2021
af2e716
paper prepare
ryba183 Aug 16, 2021
5a12c36
plots for paper
Aug 31, 2021
0990d78
plots for paper vol3
Sep 6, 2021
9ceb2c4
plots for paper vol4
Sep 8, 2021
60e67e7
cleaning
ryba183 Sep 8, 2021
ebedd07
cleaning
ryba183 Sep 8, 2021
41e1ba0
beter cloud base
ryba183 Sep 10, 2021
4114ec6
plots for paper vol4
Sep 10, 2021
c0ce1ba
plots for paper vol4
Sep 10, 2021
41e588d
plots for paper vol5
Sep 10, 2021
c0bf157
ICM maintenance problems
ryba183 Jan 1, 2022
c3413e6
Distribution plots
ryba183 Jan 20, 2022
a9202bc
RYSY
ryba183 Feb 15, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions Energy_spectrum/spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import matplotlib.pyplot as plt

#velocities = ["u", "v", "w"]
#velocities = ["u", "v", "w", "cloud_rw_mom3", "rv", "th", "RH", "aerosol_rw_mom3"]
velocities = ["u", "v", "w", "cloud_rw_mom3", "rv", "th", "RH", "aerosol_rw_mom3"]
#velocities = ["cloud_rw_mom3"]
velocities = ["w"]
# velocities = ["w"]

time_start = int(argv[1])
time_end = int(argv[2])
Expand All @@ -18,54 +18,54 @@

directories = argv[6:len(argv):2]
labels = argv[7:len(argv):2]
print directories, labels
print(directories, labels)

# read in nx, ny, nz
for directory, lab in zip(directories, labels):
w3d = h5py.File(directory + "/timestep" + str(time_start).zfill(10) + ".h5", "r")["u"][:,:,:]
w3d = h5py.File(directory + "/timestep" + str(time_start).zfill(10) + ".h5", "r")["u"][:,:]
nx, ny, nz = w3d.shape
Exy_avg = {}
for vel in velocities:
Exy_avg[vel] = np.zeros(((nx+1)/2))

for t in range(time_start, time_end+1, outfreq):
filename = directory + "/timestep" + str(t).zfill(10) + ".h5"
print filename
print(filename)

for vel in velocities:
w3d = h5py.File(filename, "r")[vel][:,:,:] # * 4. / 3. * 3.1416 * 1e3

w3d = h5py.File(filename, "r")[vel][:,:,:] # * 4. / 3. * 3.1416 * 1e3

for lvl in range(from_lvl, to_lvl+1):
w2d = w3d[:, :, lvl]

wkx = 1.0 / np.sqrt(nx - 1) * np.fft.rfft(w2d, axis = 0)
wky = 1.0 / np.sqrt(ny - 1) * np.fft.rfft(w2d, axis = 1)

#Ex = 0.5 * (np.abs(wkx) ** 2)
Ex = (np.abs(wkx) ** 2)
Ex = np.mean(Ex, axis = 1)
#Ey = 0.5 * (np.abs(wky) ** 2)
Ey = (np.abs(wky) ** 2)
Ey = np.mean(Ey, axis = 0)

Exy = 0.5 * (Ex + Ey)
Exy_avg[vel] += Exy

K = np.fft.rfftfreq(nx - 1)
# plt.loglog(K, Exy)
lmbd = 50. / K # assume dx=50m

if (t == time_start and lab==labels[0]):
plt.loglog(lmbd, 2e-1* K**(-5./3.) )

for vel in velocities:
Exy_avg[vel] /= (time_end - time_start) / outfreq + 1
Exy_avg[vel] /= to_lvl+1 - from_lvl
#crudely scale
# Exy_avg[vel] /= Exy_avg[vel][len(Exy_avg[vel])-1]
plt.loglog(lmbd, Exy_avg[vel] , linewidth=2, label=lab+"_"+vel)

plt.xlim(10**4,10**2)
plt.xlabel("l[m]")
plt.ylabel("PSD")
Expand Down
79 changes: 79 additions & 0 deletions Energy_spectrum/spectrum_2D.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# (C) Maciej Waruszewski

import h5py
import numpy as np
from sys import argv
import matplotlib.pyplot as plt

# velocities = ["u", "v", "w"]
# velocities = ["u", "v", "w", "cloud_rw_mom3", "rv", "th", "RH", "aerosol_rw_mom3"]
velocities = ["u", "w", "cloud_rw_mom3", "rv", "th", "RH", "actrw_rw_mom3"]
# velocities = ["cloud_rw_mom3", "actrw_rw_mom3"]
# velocities = ["u", "w"]

time_start = int(argv[1])
time_end = int(argv[2])
outfreq = int(argv[3])
from_lvl = int(argv[4])
to_lvl = int(argv[5])

directories = argv[6:len(argv):2]
labels = argv[7:len(argv):2]
print(directories, labels)

# read in nx, ny, nz
for directory, lab in zip(directories, labels):
w3d = h5py.File(directory + "/timestep" + str(time_start).zfill(10) + ".h5", "r")["u"][:,:]
nx, nz = w3d.shape
Exy_avg = {}
for vel in velocities:
Exy_avg[vel] = np.zeros(int((nx+1)/2))

for t in range(time_start, time_end+1, outfreq):
filename = directory + "/timestep" + str(t).zfill(10) + ".h5"
print(filename)

for vel in velocities:
if (vel == "cloud_rw_mom3") | (vel == "actrw_rw_mom3"):
w3d = h5py.File(filename, "r")[vel][:,:] * 4. / 3. * 3.1416 * 1e3
else:
w3d = h5py.File(filename, "r")[vel][:,:] # * 4. / 3. * 3.1416 * 1e3

for lvl in range(from_lvl, to_lvl+1):
w2d = w3d[:, lvl]
wkx = 1.0 / np.sqrt(nx - 1) * np.fft.rfft(w2d, axis = 0)

# wky = 1.0 / np.sqrt(nz - 1) * np.fft.rfft(w2d, axis = 1)

#Ex = 0.5 * (np.abs(wkx) ** 2)
Ex = (np.abs(wkx) ** 2)
# Ex = np.mean(Ex)
#Ey = 0.5 * (np.abs(wky) ** 2)
# Ey = (np.abs(wky) ** 2)
# Ey = np.mean(Ey, axis = 0)

# Exy = 0.5 * (Ex + Ey)
Exy = Ex
Exy_avg[vel] += Exy

K = np.fft.rfftfreq(nx - 1)
# plt.loglog(K, Exy)
lmbd = 100. / K # assume dx=50m

if (t == time_start and lab==labels[0]):
plt.loglog(lmbd, 2e-1* K**(-5./3.), label="-5/3" )

for vel in velocities:
Exy_avg[vel] /= (time_end - time_start) / outfreq + 1
Exy_avg[vel] /= to_lvl+1 - from_lvl
#crudely scale
# Exy_avg[vel] /= Exy_avg[vel][len(Exy_avg[vel])-1]
plt.loglog(lmbd, Exy_avg[vel] , linewidth=2, label=lab+"_"+vel)

plt.xlim(2*10**4,10**2)
plt.xlabel("l[m]")
plt.ylabel("PSD")
# plt.legend()
plt.grid(True, which='both', linestyle='--')
# plt.title("Mean PSD of w 322m<z<642m @3h")
plt.show()
101 changes: 101 additions & 0 deletions Energy_spectrum/spectrum_2D_multi_many.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# (C) Maciej Waruszewski

import h5py
import numpy as np
from sys import argv
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import os
'''
How to run

python3 spectrum_2D_multi_many.py 14400 18400 240 10 30 /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Energy/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/ "SD100" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/ "SD1000" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD10000/ "SD10000"
'''
# velocities = ["u", "v", "w"]
# velocities = ["u", "v", "w", "cloud_rw_mom3", "rv", "th", "RH", "aerosol_rw_mom3"]
# velocities = ["u", "w", "cloud_rw_mom3", "rv", "th", "RH", "actrw_rw_mom3"]
# velocities = ["cloud_rw_mom3", "actrw_rw_mom3"]
# velocities = ["cloud_rw_mom3"]
velocities = ["u", "w"]

time_start = int(argv[1])
time_end = int(argv[2])
outfreq = int(argv[3])
from_lvl = int(argv[4])
to_lvl = int(argv[5])
outfile = argv[6]
directories = argv[7:len(argv):2]
labels = argv[8:len(argv):2]

def Energy(directories, labels, velocities):
# read in nx, ny, nz
for directory, lab in zip(directories, labels):
# path_file = []
path_file = os.listdir(directory)
Exy_mean = {}
for path in path_file:
path_to_file = os.listdir(directory+path)
joined = os.path.join(directory,path)
#print(joined.split("/", -1)[-1])

Exy_avg_many = [0 for i in range(len(path_to_file))]
Exy_avg = [0 for i in range(len(velocities))]
# Exy_mean = [0 for i in range(len(velocities))]
print(joined+ "/timestep" + str(time_start).zfill(10) + ".h5", "elo")
for file in range(len(path_to_file)):
w3d = h5py.File(joined+ "/timestep" + str(time_start).zfill(10) + ".h5", "r")["u"][:,:]
print(joined+ "/timestep" + str(time_start).zfill(10) + ".h5")
# w3d = h5py.File(joined+'/'+path_to_file[file] + "/timestep" + str(time_start).zfill(10) + ".h5", "r")["u"][:,:]
nx, nz = w3d.shape
for vel in range(len(velocities)):
Exy_avg[vel] = np.zeros(int((nx+1)/2))
# Exy_avg_many[file][vel] =np.zeros(int((nx+1)/2))

for t in range(time_start, time_end+1, outfreq):
filename = joined+"/timestep" + str(t).zfill(10) + ".h5"
# filename = joined+'/'+path_to_file[file] + "/timestep" + str(t).zfill(10) + ".h5"
# print(filename)

for vel in range(len(velocities)):
if (velocities[vel] == "cloud_rw_mom3") | (velocities[vel] == "actrw_rw_mom3"):
w3d = h5py.File(filename, "r")[velocities[vel]][:,:] * 4. / 3. * 3.1416 * 1e3
else:
w3d = h5py.File(filename, "r")[velocities[vel]][:,:] # * 4. / 3. * 3.1416 * 1e3

for lvl in range(from_lvl, to_lvl+1):
w2d = w3d[:, lvl]
wkx = 1.0 / np.sqrt(nx - 1) * np.fft.rfft(w2d, axis = 0)
Ex = (np.abs(wkx) ** 2)
Exy = Ex
Exy_avg[vel] += Exy
Exy_avg_many[file] = Exy_avg[-len(velocities):]
Exy_mean[path] = np.mean(Exy_avg_many[file],axis=0)

K = np.fft.rfftfreq(nx - 1)
lmbd = 100. / K # assume dx=100m

for path in path_file:
Exy_mean[path] /= (time_end - time_start) / outfreq + 1
Exy_mean[path] /= to_lvl+1 - from_lvl
plt.loglog(lmbd, Exy_mean[path] , linewidth=2, label=velocities+'_'+lab+"_"+path)
'''
>>>>>>> 9ceb2c4e37b01d11666e449561e48044c01296e6
plt.loglog(lmbd, 2e-1* K**(-5./3.), label="-5/3" )
plt.xlim(2*10**4,10**2)
plt.xlabel("l[m]")
plt.ylabel("PSD")
plt.legend()
plt.grid(True, which='both', linestyle='--')
# plt.title("Mean PSD of w 322m<z<642m @3h")
<<<<<<< HEAD
#print(outfile + 'Energy_spc.png')
plt.savefig(outfile + 'Energy_spc_vel_u.png')

Energy(directories, labels)
=======
plt.savefig(outfile + 'Energy_spc.png')
plt.show()
'''
Energy(directories, labels, velocities[0])
# Energy(directories, labels, velocities[1])
84 changes: 84 additions & 0 deletions Energy_spectrum/spectrum_2D_multi_many_mod_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# (C) Maciej Waruszewski

import h5py
import numpy as np
from sys import argv
import matplotlib.pyplot as plt
import os
'''
How to run

python3 spectrum_2D_multi_many.py 14400 18400 240 10 30 /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Energy/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/ "SD100" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD1000/ "SD1000" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD10000/ "SD10000"

python3 spectrum_2D_multi_many_modyfikacje.py 14400 18400 240 10 30 /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Energy/ /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/VF/ "SD100_VF" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/multi/ "SD100_multi" /home/piotr-pc/Piotr/WORKSHOPS/Dane_do_AF_2D/Dane/SD100/tail/ "SD100_tail"

'''
# velocities = ["u", "v", "w"]
# velocities = ["u", "v", "w", "cloud_rw_mom3", "rv", "th", "RH", "aerosol_rw_mom3"]
# velocities = ["u", "w", "cloud_rw_mom3", "rv", "th", "RH", "actrw_rw_mom3"]
# velocities = ["cloud_rw_mom3", "actrw_rw_mom3"]
# velocities = ["cloud_rw_mom3"]
velocities = ["u", "w"]

time_start = int(argv[1])
time_end = int(argv[2])
outfreq = int(argv[3])
from_lvl = int(argv[4])
to_lvl = int(argv[5])
outfile = argv[6]
directories = argv[7:len(argv):2]
labels = argv[8:len(argv):2]


def Energy(directories, labels):
for directory, lab in zip(directories, labels):
path_file = os.listdir(directory)
Exy_mean = {}
Exy_avg_many = {}
Exy_avg = {}
for path in path_file:
path_to_file = os.listdir(directory+path)
joined = os.path.join(directory,path)
w3d = h5py.File(joined+"/"+path+"_out_lgrngn"+ "/timestep" + str(time_start).zfill(10) + ".h5", "r")["u"][:,:]
nx, nz = w3d.shape
for vel in velocities:
Exy_avg[path, vel] = np.zeros(int((nx+1)/2))
for t in range(time_start, time_end+1, outfreq):
filename = joined+"/"+path+"_out_lgrngn"+"/timestep" + str(t).zfill(10) + ".h5"
for vel in velocities:
if (vel == "cloud_rw_mom3") | (vel == "actrw_rw_mom3"):
w3d = h5py.File(filename, "r")[vel][:,:] * 4. / 3. * 3.1416 * 1e3
else:
w3d = h5py.File(filename, "r")[vel][:,:]
for lvl in range(from_lvl, to_lvl+1):
w2d = w3d[:, lvl]
wkx = 1.0 / np.sqrt(nx - 1) * np.fft.rfft(w2d, axis = 0)
Ex = (np.abs(wkx) ** 2)
Exy = Ex
Exy_avg[path, vel] += Exy

K = np.fft.rfftfreq(nx - 1)
lmbd = 100. / K # assume dx=100m
A = np.zeros((len(velocities), len(Exy_avg[path, vel]) ))
for vel in range(len(velocities)):
for path in path_file:
Exy_avg[path,velocities[vel]] /= (time_end - time_start) / outfreq + 1
Exy_avg[path,velocities[vel]] /= to_lvl+1 - from_lvl
# Exy_mean[directory, vel] = Exy_avg[vel]
A[vel,:] += Exy_avg[path,velocities[vel]]
# print(Exy_avg[path,velocities[vel]])
A = A/len(path_file)
plt.loglog(lmbd, A[vel] , linewidth=2, label=velocities[vel]+'_'+lab)

plt.loglog(lmbd, 2e-1* K**(-5./3.), label="-5/3" )
plt.xlim(2*10**4,10**2)
plt.xlabel("l[m]")
plt.ylabel("PSD")
plt.legend()
plt.grid(True, which='both', linestyle='--')
# plt.title("Mean PSD of w 322m<z<642m @3h")
plt.savefig(outfile + 'Energy_spc.png')
plt.show()

Energy(directories, labels)
# Energy(directories, labels, velocities[1])
Loading