From 04cea3ab51deef1d328d4e7e23542f9d9f2b75f6 Mon Sep 17 00:00:00 2001 From: glatterf42 Date: Wed, 13 Apr 2022 13:15:11 +0200 Subject: [PATCH] first commit --- __pycache__/directories.cpython-37.pyc | Bin 0 -> 367 bytes __pycache__/directories.cpython-38.pyc | Bin 0 -> 442 bytes __pycache__/write_spectra_jobs.cpython-37.pyc | Bin 0 -> 1716 bytes __pycache__/write_spectra_jobs.cpython-38.pyc | Bin 0 -> 2394 bytes agora_plot_power_spectra.py | 88 ++++++++++++++++++ directories.py | 15 +++ plot_cross_spectra.py | 67 +++++++++++++ plot_power_spectra.py | 65 +++++++++++++ plot_spectra.py | 60 ++++++++++++ prepare_spectral_evaluation_agora.py | 34 +++++++ prepare_spectral_evaluation_wavelets.py | 45 +++++++++ visualise_ics.py | 26 ++++++ write_spectra_jobs.py | 87 +++++++++++++++++ 13 files changed, 487 insertions(+) create mode 100644 __pycache__/directories.cpython-37.pyc create mode 100644 __pycache__/directories.cpython-38.pyc create mode 100644 __pycache__/write_spectra_jobs.cpython-37.pyc create mode 100644 __pycache__/write_spectra_jobs.cpython-38.pyc create mode 100644 agora_plot_power_spectra.py create mode 100644 directories.py create mode 100644 plot_cross_spectra.py create mode 100644 plot_power_spectra.py create mode 100644 plot_spectra.py create mode 100644 prepare_spectral_evaluation_agora.py create mode 100644 prepare_spectral_evaluation_wavelets.py create mode 100644 visualise_ics.py create mode 100644 write_spectra_jobs.py diff --git a/__pycache__/directories.cpython-37.pyc b/__pycache__/directories.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..fb6ade7fbf30668e821217669dffcaf0a8a9cd3d GIT binary patch literal 367 zcmZ9Hu};G<5QZH$ZK{Zhv8x9dvfw7b5+PL48H5B=7AuJz#ZnSSwjQ`R-x03K7)Duql4Qzoy5rFkH59%moNX8R8ztjo0D~dq`kDd-t*# zxDW30`3s5`<8`>xBDaDQ)sfdhkjGq;_?E;;8pr8POp;BKgyA+HY^`)k3ekn%fJc$% z{O8=(2)t61#wN(OA#sPRS~q8T$W9DY8R4h*xjPdwcsD|D&Vthd)$dgBrD(F}jf$6<=s9%GXvA<~n6=H-6kdjx#h z*?36@F+dCuyNF%cdm!U}brxP55Dp~O1$|rry%mN=7c`0|Q8YP^XnY#SVK@~lx721r zQz*huv>{`!4(^3pRwK65IWQ!cRk>xhgt;?q0Mdq2}Cyb(U2}|9wLx z1}`EnGq6lNY1F$L_v$|9QqMWB`z2auDm6{^dVlN5Q(-|WQ;&9Beu;xttF``ldnaaq wB5nJMcbD0QDc2ak;0x94gAN!`8wK{HT-SrkT+3AkR~?kGjaJax^9Ojo0W<=GegFUf literal 0 HcmV?d00001 diff --git a/__pycache__/write_spectra_jobs.cpython-37.pyc b/__pycache__/write_spectra_jobs.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e8a566cfb8795ac110e885cc2ea2911291e5ade7 GIT binary patch literal 1716 zcmZ`(TW{Mo6ecBElI3gMWJ!>sQ&C`mA7VRhJ8VHSbh!W5qHgS_u8A zCbz8!;5iKb7Z`#(L@?1J9BZD271kp?HasK8MpTGR&x|e4%IAg1_H0;Fh>Bj3I(aYA zGBt?#n@KEU|7ds>S|!C(jr~D2;;bW50z4sQQXy4RBXzQLYK#rvT(>K-r%SnQnd(KpbvC~#Js;i;1quk>rgCc?;y#F#-TB@JPa0(b#~w{VT1giK*V zR4a49-hM|Ojo2B2cSYi4=CVSi%mQ1^-&QjF4p-l-OiPfX2HDG5`N|^oYy3-nTFEL` zc2>H^7=i5Q1^ODjLZW!(WaVo-tpX}#<*a&A7S2g!7hS7jM^GF~hi`FPVt=ByI)lkZ z5J9035c(nnVOs9dX*e2%$#JXI^6b7UBA85;A3bdM!lVs?4joQ~yE%58$)k2}97d$Q zklWqdR7wS6=P|&!TsxlT2a_VqlVcW=of{2g%I9GMYVJ%*?S-zLPG?eW4awjsEM7RB zeD1i=ChNyEp$tmVAB0H|`HQ42K9u;pS(SPmTu7Y@#tM)^n)3t6!ia^5kcIdZ3XvJg zWuzmT$ig`b1(jOLrNKo2OZvk&CDP);hbNWRk^lL@tAo8}jj38=aIYX{E2C}{rY;;- z0^`}LW_?KSmGbZQA(OxL?@3oWi&KKjTlxq4@V&sVXYxJ^M?%_zFrrBiQ;7#&X+&8Z zavr7${~fXSA=lfF+ru=bZTMf?JdF7*_3hCm{KyGV6H(sIPj*X?f0FiiYji0a|9!m# zA^8I^2s_w?zKm_?WzE61^_d0;F9T)|VTH7PIAfUj{!LD>9z>DU_jkL>JW=LDWj>O| z{_a)>XdDJfk|sBbyBqi|5vwYsE2CtX*b4>QP4oW=z7H##_oU_fB<=e?2z<$zsv&8O z;IfIr9#auz35bO|CuJe!xypGJuvPG}HMKy`t6&hNfne&`cV|*;L*U|ha7I=6a;bv^ zvid3KlnLPefU%U# literal 0 HcmV?d00001 diff --git a/__pycache__/write_spectra_jobs.cpython-38.pyc b/__pycache__/write_spectra_jobs.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..9fca6ad84bf7584cdf38965ac6981be171101c21 GIT binary patch literal 2394 zcmaJ?&2QX96!+L(+w1*EHr+HyQ^2KsEs)*K(jurDRMPf<1QF0yRF;tC-I>k0@!HFb zw{0Ttg@D8bA#rUhB?k^%Iq)~|H_Vj_xpP1(A@QDfvx(A*8Tsco?~Ui*S1Q>G zv|oO>*ZvEnKXGunY1#ExxV2VebY7jmTP6Y zT$p$BFfSL{uFVQrFR~KTsqxgHCbhoP-SSkg)BIDN+Oz<=IW|v=J1YO1skF4B&@#wB z(>Xd%D|CULqt$K0twi%^WeZH*C*P|pidzA>vQOyZ4iUd4=e{MZa!dL8x?5$qhf2?{ zDElOnmS)m&CKbWDl1Wu&(hI8!UH#D@$~V8$+#RKMagW(IIr9@noj7vt4w>_r&z<$F z&U))w^U5_4TFq9=wr}{uq!;sRPMbxxeYY0~r!(Z7MM<~|Ujnd)emI1Mgp>4`6Z#@? zMC1=dFHY+A5ja_?5vlup`yswR_mf^tlXGIgItll^wl5eBxLoSTQQVEApyR<(iI^D{ z{OuU#q4HR_RWoE!bo`KcUB8pWT;{eo6YG;#OX{DtX)S9T^EpAOw`8`V)n!DalZy+7tbmv80U5Gj{ci-AZ%QFDKt< ztI8;!kTkzfMs}J%&<+*8m*{Dp>idv((L$or99TgHYwl2iR5KC-Ry9)_@c10rYSc;< z(B-L}8da1EsR>xjw58OV$>nE@qXO(P2fG*3;(~BUU@)#;zSL+3Q3C?qvjt0>wV`c~FE`r5Af%0H8aQif7%e~9 zcn`!$$TnQn^T&A@N83E08%HXHDH{h7M08_ZXiQ_1Zsp*P*ME_#wYs+FbI_a945B%J493u#O)By$5EM2XDxcOXHzjwU@Gut??} z@gQMRjfK=j;=`0quOCxsLW;thN%M~P$?f~MZ`S6x37>Hb0Sgbu+QbV8MF44G-g>aT zTgcAs!A{=#=|M}{(_11-DkriB=LP>tLv(mBNTk&bLKgXbCP`No28{OuA%Zv(zbd>A zdyPMA^x{5i0FN6Y=!;|5HwL>v@CaNJGSSFxcI+VULEIMg!LD3*UR{AD#U_A4Y~nz# z5(|1!wTY#vn)G&55pqge}RW>7MtnF>~i2h|eS775M_dp4FJtKA)dM zT@?ZA6+e%#gs_aTf^Y$#R_3cHUqrx4$6rEt8Q~QKbSHNZE+M>%a2eq>gx3+?0H_sT z6b$|*nB4pBCH``(oLWNl3ad1hrH~1I9Xf=z)Z4;ev(J(={(Z4 z|IMLw+{5yKOF`s$M;VbdKMY;%)@BRg3c~vcAGrFh&Gn{hik=@uadd>9I)d^)aq*Fc zL-f?1HLVnlnsL@4Cqzas)E1@bc{J{L9u$&Y!Le3Ja{xcPFlcjJQ5Jx}@Xw2Rz{DgF zc*seZW`U4eR&u&w>?e~jB02c+?U3J|=jI>z4;dCrAvGYqEPpHn;|Z|+Hs>*)6qpnL uXHpgf>pIk@VaPth6A6r(ZWWP+=yY}YV)X)&azUMkZV?p%GU+NY#{U5?rdTcj literal 0 HcmV?d00001 diff --git a/agora_plot_power_spectra.py b/agora_plot_power_spectra.py new file mode 100644 index 0000000..6959d09 --- /dev/null +++ b/agora_plot_power_spectra.py @@ -0,0 +1,88 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Wed Mar 16 15:12:21 2022 + +@author: ben +""" + +import pandas as pd +import matplotlib.pyplot as plt +from pathlib import Path +import scipy.special as sf +import numpy as np + +def Dplus( lambda0, a ): + return a * np.sqrt(1.0+lambda0*a**3) * sf.hyp2f1(3.0/2.0, 5.0/6.0, 11.0/6.0, -lambda0 * a**3 ) + +basedir = Path("/home/ben/sims/swiftsim/examples/agora/spectra/") + +#choose waveform and Lbox: +Lbox = 100.0 #only option as of now +Nres1 = 128 +# Nres2 = 256 +k0 = 2 * 3.14159265358979323846264338327950 / Lbox +knyquist1 = Nres1 * k0 +# knyquist2 = Nres2 * k0 +times = [0.166666, 0.333333, 0.5, 0.666666, 1.0] +# scale_factor = 0 # give index of a list above + +Omega_m = 0.272 +Omega_L = 0.728 +lambda_0 = Omega_L / Omega_m + +#find columns in file manually +#is k really in Mpc? Swift doesn't use /h internally at least. +columns = ["k [Mpc]", "Pcross", "P1", "err. P1", "P2", "err. P2", "P2-1", "err. P2-1", "modes in bin"] + +zstart = 100 +a_ics = 1 / (1 + zstart) +filename_ics = basedir / 'agora_ics_cross_spectrum' +df_ics = pd.read_csv(f'{filename_ics}.txt', sep=' ', skipinitialspace=True, header=None, names=columns, skiprows=1) +#only consider rows above resolution limit +df_ics = df_ics[df_ics['k [Mpc]'] >= k0] +p1_ics = df_ics['P1'] +D_squared_ics = Dplus(lambda0=lambda_0, a=a_ics) ** 2 +p1_ics_noramlised = p1_ics / D_squared_ics + +for scale_factor in range(len(times)): + filename = basedir / f"agora_a{scale_factor}_cross_spectrum" +# filename = basedir / f"{waveform}_{Lbox:.0f}/{waveform}_{Lbox:.0f}_ics_vsc_cross_spectrum" # for ICs +# savedir = Path(f"/home/ben/Pictures/swift/monofonic_tests/spectra/power_{waveform}_{Lbox:.0f}_ics_vsc") # for ICs +# plt.title(f"Power Spectra {waveform} L={Lbox:.0f} a=0.02 vsc") # for ICs + + + df = pd.read_csv(f"{filename}.txt", sep=" ", skipinitialspace=True, header=None, names=columns, skiprows=1) + + #only consider rows above resolution limit + df = df[df["k [Mpc]"] >= k0] + + k = df["k [Mpc]"] + p1 = df["P1"] + p1_error = df["err. P1"] + # p2 = df["P2"] + # p2_error = df["err. P2"] + # pcross = df["Pcross"] + + D_squared = Dplus(lambda0=lambda_0, a=times[scale_factor]) ** 2 + p1_normalised = p1 / D_squared + p1_ic_normalised = p1_normalised / p1_ics_noramlised + + # Plot the power spectra: + plt.loglog(k, p1_ic_normalised, label=f"{times[scale_factor]}") + # plt.loglog(k, p2, label="P2") + +plt.title(f"Power Spectra Agora 128") +savedir = Path(f"/home/ben/Pictures/swift/agora/spectra/power_spectra") + +plt.xlabel("k [Mpc]") +plt.ylabel("P") +plt.vlines(knyquist1, ymin=min(p1), ymax=max(p1), color="black", linestyles="dashed", label=f"k_ny {Nres1}") +# plt.vlines(knyquist2, ymin=min(p2), ymax=max(p2), color="black", linestyles="dashed", label=f"{Nres2}") +plt.legend() + +plt.savefig(f"{savedir}.png") + + + + diff --git a/directories.py b/directories.py new file mode 100644 index 0000000..cf7f880 --- /dev/null +++ b/directories.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Tue Mar 15 12:11:41 2022 + +@author: ben +""" + +from pathlib import Path + +spectra_basedir = Path("/home/ben/sims/spectra/") + +monofonic_tests_basedir = Path("/home/ben/sims/swift/monofonic_tests/") + +agora_test_basedir = Path('/home/ben/sims/swiftsim/examples/agora/') \ No newline at end of file diff --git a/plot_cross_spectra.py b/plot_cross_spectra.py new file mode 100644 index 0000000..b49be87 --- /dev/null +++ b/plot_cross_spectra.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Wed Mar 16 15:12:21 2022 + +@author: ben +""" + +import pandas as pd +import matplotlib.pyplot as plt +from pathlib import Path + +basedir = Path("/home/ben/sims/swift/monofonic_tests/spectra/") + +#choose Nres and Lbox: +waveforms = ['DB2', "DB4", "DB8", "shannon"] #DB2, DB4, DB8, shannon are all we have right now +Lbox = 100.0 #only option as of now +Nres = 256 #128 and 256 exist for now +k0 = 2 * 3.14159265358979323846264338327950 / Lbox +knyquist = Nres * k0 +a = [0.166666, 0.333333, 0.5, 0.666666, 1.0] +scale_factor = 4 # give index of a list above + + +for wave in waveforms: + filename = basedir / f"{wave}_{Lbox:.0f}/{wave}_{Lbox:.0f}_a{scale_factor}_cross_spectrum" + # filename = basedir / f"{wave}_{Lbox:.0f}/{wave}_{Lbox:.0f}_ics_vsc_cross_spectrum" # for ICs + + #find columns in file manually + #is k really in Mpc? Swift doesn't use /h internally at least. + columns = ["k [Mpc]", "Pcross", "P1", "err. P1", "P2", "err. P2", "P2-1", "err. P2-1", "modes in bin"] + + df = pd.read_csv(f"{filename}.txt", sep=" ", skipinitialspace=True, header=None, names=columns, skiprows=1) + + #only consider rows above resolution limit + df = df[df["k [Mpc]"] >= k0] + + k = df["k [Mpc]"] + p1 = df["P1"] + p1_error = df["err. P1"] + p2 = df["P2"] + p2_error = df["err. P2"] + pcross = df["Pcross"] + + + # Plot the Cross Correlation: + plt.plot(k, pcross, label=f"{wave}") + +# savedir = Path(f"/home/ben/Pictures/swift/monofonic_tests/spectra/cross_{Nres}_{Lbox:.0f}_ics_vsc") # for ICs +# plt.title(f"Cross correlation N={Nres} L={Lbox:.0f} a=0.02 vsc") # for ICs + +savedir = Path(f"/home/ben/Pictures/swift/monofonic_tests/spectra/cross_{Nres}_{Lbox:.0f}_a{scale_factor}") +plt.title(f"Cross correlation N={Nres} L={Lbox:.0f} a={a[scale_factor]}") + +plt.xscale("log") +plt.xlabel("k [Mpc]") +plt.ylabel("C = Pcross") +plt.ylim(0.8, 1.0) +plt.xlim(k[0], knyquist) +# plt.vlines(knyquist, ymin=min(p1), ymax=max(p1), color="black", linestyles="dashed", label=f"{Nres}") +plt.legend() + +plt.savefig(f"{savedir}.png") + + + + diff --git a/plot_power_spectra.py b/plot_power_spectra.py new file mode 100644 index 0000000..3a46db8 --- /dev/null +++ b/plot_power_spectra.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Wed Mar 16 15:12:21 2022 + +@author: ben +""" + +import pandas as pd +import matplotlib.pyplot as plt +from pathlib import Path + +basedir = Path("/home/ben/sims/swift/monofonic_tests/spectra/") + +#choose waveform and Lbox: +waveform = "shannon" #DB2, DB4, DB8 or shannon +Lbox = 100.0 #only option as of now +Nres1 = 128 +Nres2 = 256 +k0 = 2 * 3.14159265358979323846264338327950 / Lbox +knyquist1 = Nres1 * k0 +knyquist2 = Nres2 * k0 +a = [0.166666, 0.333333, 0.5, 0.666666, 1.0] +scale_factor = 4 # give index of a list above + +filename = basedir / f"{waveform}_{Lbox:.0f}/{waveform}_{Lbox:.0f}_a{scale_factor}_cross_spectrum" +# filename = basedir / f"{waveform}_{Lbox:.0f}/{waveform}_{Lbox:.0f}_ics_vsc_cross_spectrum" # for ICs +# savedir = Path(f"/home/ben/Pictures/swift/monofonic_tests/spectra/power_{waveform}_{Lbox:.0f}_ics_vsc") # for ICs +# plt.title(f"Power Spectra {waveform} L={Lbox:.0f} a=0.02 vsc") # for ICs + +#find columns in file manually +#is k really in Mpc? Swift doesn't use /h internally at least. +columns = ["k [Mpc]", "Pcross", "P1", "err. P1", "P2", "err. P2", "P2-1", "err. P2-1", "modes in bin"] + +df = pd.read_csv(f"{filename}.txt", sep=" ", skipinitialspace=True, header=None, names=columns, skiprows=1) + +#only consider rows above resolution limit +df = df[df["k [Mpc]"] >= k0] + +k = df["k [Mpc]"] +p1 = df["P1"] +p1_error = df["err. P1"] +p2 = df["P2"] +p2_error = df["err. P2"] +pcross = df["Pcross"] + + +# Plot the power spectra: +plt.loglog(k, p1, label="P1") +plt.loglog(k, p2, label="P2") + +plt.title(f"Power Spectra {waveform} L={Lbox:.0f} a={a[scale_factor]}") +savedir = Path(f"/home/ben/Pictures/swift/monofonic_tests/spectra/power_{waveform}_{Lbox:.0f}_a{scale_factor}") + +plt.xlabel("k [Mpc]") +plt.ylabel("P") +plt.vlines(knyquist1, ymin=min(p1), ymax=max(p1), color="black", linestyles="dashed", label=f"{Nres1}") +plt.vlines(knyquist2, ymin=min(p2), ymax=max(p2), color="black", linestyles="dashed", label=f"{Nres2}") +plt.legend() + +plt.savefig(f"{savedir}.png") + + + + diff --git a/plot_spectra.py b/plot_spectra.py new file mode 100644 index 0000000..4c2166e --- /dev/null +++ b/plot_spectra.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Wed Mar 16 15:12:21 2022 + +@author: ben +""" + +import pandas as pd +import matplotlib.pyplot as plt +from pathlib import Path + +basedir = Path("/home/ben/sims/swift/monofonic_tests/spectra/") + +#choose waveform and Lbox: +waveform = "DB8" #DB4, DB8 or shannon +Lbox = 100.0 #only option as of now +Nres1 = 128 +Nres2 = 256 +k0 = 2 * 3.14159265358979323846264338327950 / Lbox +knyquist1 = Nres1 * k0 +knyquist2 = Nres2 * k0 + +filename = basedir / f"{waveform}_{Lbox:.0f}/{waveform}_{Lbox:.0f}_cross_spectrum" + +#find columns in file manually +#is k really in Mpc? Swift doesn't use /h internally at least. +columns = ["k [Mpc]", "Pcross", "P1", "err. P1", "P2", "err. P2", "P2-1", "err. P2-1", "modes in bin"] + +df = pd.read_csv(f"{filename}.txt", sep=" ", skipinitialspace=True, header=None, names=columns, skiprows=1) + +#only consider rows above resolution limit +df = df[df["k [Mpc]"] >= k0] + +k = df["k [Mpc]"] +p1 = df["P1"] +p1_error = df["err. P1"] +p2 = df["P2"] +p2_error = df["err. P2"] +pcross = df["Pcross"] + + +# Plot the power spectra: +plt.loglog(k, p1) +plt.loglog(k, p2) +plt.title(f"Power Spectra {waveform} {Lbox:.0f}") +plt.xlabel("k [Mpc]") +plt.ylabel("P") +plt.vlines(knyquist1, ymin=min(p1), ymax=max(p1), color="black", linestyles="dashed", label=f"{Nres1}") +plt.vlines(knyquist2, ymin=min(p2), ymax=max(p2), color="black", linestyles="dashed", label=f"{Nres2}") +plt.legend() + +# Plot the cross correlation: +# plt.plot(k, pcross) +# plt.title(f"Cross correlation {waveform} {Lbox:.0f}") +# plt.xlabel("k [Mpc]") +# plt.ylabel("C = Pcross") + + + diff --git a/prepare_spectral_evaluation_agora.py b/prepare_spectral_evaluation_agora.py new file mode 100644 index 0000000..bd40582 --- /dev/null +++ b/prepare_spectral_evaluation_agora.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Tue Mar 15 12:00:49 2022 + +@author: ben +""" + +from sys import argv +from pathlib import Path +from write_spectra_jobs import write_spectra_jobs_agora +from directories import monofonic_tests_basedir, agora_test_basedir + +def main(scale_factor: int, Nres1: int, Nres2: int): + a = [0.166666, 0.333333, 0.5, 0.666666, 1.0] + print(f"Chose scale factor a = {a[scale_factor]} (index {scale_factor} / {len(a) - 1})") + + write_spectra_jobs_agora(scale_factor, Nres1, Nres2, + output_basedir=agora_test_basedir / "spectra/") + + + + +if __name__ == "__main__": + scale_factor = int(argv[1]) + Nres1 = int(argv[2]) + Nres2 = int(argv[3]) + + main( + scale_factor=scale_factor, + Nres1=Nres1, + Nres2=Nres2 + ) + diff --git a/prepare_spectral_evaluation_wavelets.py b/prepare_spectral_evaluation_wavelets.py new file mode 100644 index 0000000..2ad22b2 --- /dev/null +++ b/prepare_spectral_evaluation_wavelets.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Tue Mar 15 12:00:49 2022 + +@author: ben +""" + +from sys import argv +from pathlib import Path +from write_spectra_jobs import write_spectra_jobs +from directories import monofonic_tests_basedir + +def main(scale_factor: int, Nres1: int, Nres2: int, Lbox: float, waveforms: list): + a = [0.166666, 0.333333, 0.5, 0.666666, 1.0] + print(f"Chose scale factor a = {a[scale_factor]} (index {scale_factor} / {len(a) - 1})") + + for wave in waveforms: + write_spectra_jobs(scale_factor, Nres1, Nres2, Lbox, wave, + output_basedir=monofonic_tests_basedir / "spectra/") + + + + +if __name__ == "__main__": + if argv[5] == "all": + waveforms = ["DB2", "DB4", "DB6", "DB8", "DB10", "shannon"] + else: + waveforms = argv[5:len(argv)] + + assert len(waveforms) <= 6 + + scale_factor = int(argv[1]) + Nres1 = int(argv[2]) + Nres2 = int(argv[3]) + Lbox = float(argv[4]) + + main( + scale_factor=scale_factor, + Nres1=Nres1, + Nres2=Nres2, + Lbox=Lbox, + waveforms=waveforms + ) + diff --git a/visualise_ics.py b/visualise_ics.py new file mode 100644 index 0000000..617ea5c --- /dev/null +++ b/visualise_ics.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Mon Mar 21 10:13:36 2022 + +@author: ben +""" + +import h5py +from pathlib import Path + +directory = Path(r"/home/ben/sims/swift/monofonic_tests/DB4_256_100/") +file = h5py.File(directory / "ics_DB4_256_100_nan_test_40tasks.hdf5", "r") + +# directory = Path(r"/home/ben/monofonic-experimental/") +# file = h5py.File(directory / "ics_DB4_256_100.hdf5", "r") + +for key in file.keys(): + print(key) #for finding all header entries, which are: + +Header = file["Header"] +ICs_parameters = file["ICs_parameters"] +PartType1 = file["PartType1"] +Units = file["Units"] + +print(PartType1['Coordinates'][0:10]) \ No newline at end of file diff --git a/write_spectra_jobs.py b/write_spectra_jobs.py new file mode 100644 index 0000000..4b3f6c2 --- /dev/null +++ b/write_spectra_jobs.py @@ -0,0 +1,87 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Tue Mar 15 12:04:15 2022 + +@author: ben + +This currently only evaluates the last snapshot. +""" + +from sys import argv +from pathlib import Path +from directories import spectra_basedir, monofonic_tests_basedir, agora_test_basedir +import os +import stat + +def write_spectra_jobs(scale_factor: int, Nres1: int, Nres2: int, Lbox: float, form: str, output_basedir: Path): + Nres_max = max(Nres1, Nres2) + input_dir_1 = str(monofonic_tests_basedir) + f"/{form}_{Nres1}_{Lbox:.0f}" + input_dir_2 = str(monofonic_tests_basedir) + f"/{form}_{Nres2}_{Lbox:.0f}" + output_dir = output_basedir / f"{form}_{Lbox:.0f}" + output_dir_string = str(output_dir) + if output_dir.exists(): + print(output_dir, "already exists. Skipping...") + else: + print("creating", output_dir) + output_dir.mkdir() + + + script = f"""#!/bin/bash +set -u + +{spectra_basedir}/build/spectra --format=3 --output={output_dir_string}/{form}_{Lbox:.0f}_a{scale_factor} --ngrid={2 * Nres_max} --input={input_dir_1}/output_000{scale_factor}.hdf5 --input={input_dir_2}/output_000{scale_factor}.hdf5 + """ + + filename = output_dir / "generate_final_spectra.sh" + with (filename).open("w") as f: + f.write(script) + + permissions = os.stat(filename) + os.chmod(filename, permissions.st_mode | stat.S_IEXEC) + + + +def write_spectra_jobs_agora(scale_factor: int, Nres1: int, Nres2: int, output_basedir: Path): + Nres_max = max(Nres1, Nres2) + input_dir = str(agora_test_basedir) + output_dir = output_basedir + output_dir_string = str(output_dir) + if output_dir.exists(): + print(output_dir, "already exists. Skipping...") + else: + print("creating", output_dir) + output_dir.mkdir() + + script = f"""#!/bin/bash +set -u + +{spectra_basedir}/build/spectra --format=3 --output={output_dir_string}/agora_a{scale_factor} --ngrid={2 * Nres_max} --input={input_dir}/output_000{scale_factor}.hdf5 --input={input_dir}/output_000{scale_factor}.hdf5 + """ + + filename = output_dir / "generate_final_spectra.sh" + with (filename).open("w") as f: + f.write(script) + + permissions = os.stat(filename) + os.chmod(filename, permissions.st_mode | stat.S_IEXEC) + + + +if __name__ == "__main__": + if argv[5] == "all": + waveforms = ["DB2", "DB4", "DB6", "DB8", "DB10", "shannon"] + else: + waveforms = argv[5:len(argv)] + + assert len(waveforms) <= 6 + + for form in waveforms: + write_spectra_jobs( + scale_factor = int(argv[1]), + Nres1 = int(argv[2]), + Nres2 = int(argv[3]), + Lbox = float(argv[4]), + form = form, + output_dir = monofonic_tests_basedir / "spectra/" + ) \ No newline at end of file