Commit 4bae15af authored by Dion Haefner's avatar Dion Haefner

correlation test now passes

parent 4211b796
......@@ -14,20 +14,16 @@ from dorie.utilities.text_to_bool import text_to_bool
def evaluate(iniinfo,runtime):
h5_path = iniinfo["generator.fft.outputPath"] + "/YField.h5"
with h5py.File(h5_path, 'r') as f:
y_data = np.exp(np.array(f.get("/YField"), dtype=np.float64))
y_data = np.array(f.get("/YField"), dtype=np.float64)
print("Operating on file: {}".format(h5_path))
# Calculate autocorrelation and correlation lengths
if text_to_bool(iniinfo["_correlation.padding"]):
print("padding with zeros")
ac = statistics.autocorrelation(y_data, pad=np.array(y_data.shape)*2-1)
else:
ac = statistics.autocorrelation(y_data)
rank = len(y_data.shape)
ac = statistics.autocorrelation(y_data)
rank = y_data.ndim
dx = np.array(iniinfo["generator.extensions"].split(), dtype=float) / y_data.shape
assert(len(dx) == rank)
cl = [integrate.simps(ac,dx=dxi,axis=rank-i-1).flat[0] for i, dxi in enumerate(dx)]
cl = [integrate.simps(ac,dx=dxi,axis=i).flat[0] for i, dxi in enumerate(dx)][::-1]
# Compare to given values
cl_ini = iniinfo["generator.fft.correlationLengths"].split()
......@@ -35,11 +31,11 @@ def evaluate(iniinfo,runtime):
if "_correlation.abstol" in iniinfo:
abstol = float(iniinfo["_correlation.abstol"])
else:
abstol = 1E-6
abstol = 1E-4
if "_correlation.reltol" in iniinfo:
reltol = float(iniinfo["_correlation.reltol"])
else:
reltol = 1E-2
reltol = 0.1
passed = np.allclose(cl,cl_ini,rtol=reltol,atol=abstol)
# Print output
......@@ -50,7 +46,8 @@ def evaluate(iniinfo,runtime):
print("- pass\n")
else:
print("- fail\n")
plt.imshow(ac)
if rank == 2:
plt.imshow(ac,norm=mpl.colors.LogNorm())
plt.colorbar()
plt.savefig("ac-{}.png".format(iniinfo["__name"].split("/")[-1]))
return bool(passed)
import numpy as np
from scipy import integrate
from scipy import integrate, signal
def norm_L2(a,x):
a_squared = np.squeeze(a**2)
......@@ -23,9 +23,10 @@ def autocorrelation(H, pad=None):
:param pad: Pads each axis of the input with pad[i] zeros before and after each FFT.
"""
pad = np.array(H.shape) if pad is None else pad
H = H - np.mean(H)
ft_signal = np.fft.fftn(H,pad)
B = np.fft.ifftn(np.abs(ft_signal)**2,pad)
autocovariance = np.real(B)
return autocovariance[[slice(0,n) for n in H.shape]] / autocovariance.flat[0]
#pad = np.array(H.shape) if pad is None else pad
#H = H - np.mean(H)
#ft_signal = np.fft.fftn(H,pad)
#B = np.fft.ifftn(np.abs(ft_signal)**2,pad)
reverse = [slice(n,0,-1) for n in H.shape]
autocovariance = signal.fftconvolve(H,H[reverse],mode="full")[reverse]
return autocovariance / autocovariance.flat[0]
......@@ -20,7 +20,7 @@ dorie_add_system_test(dorie reference_3d.mini)
# dorie pfg
dorie_add_system_test(dorie-pfg parfield.mini)
dorie_add_system_test(dorie-pfg parfield_muphi.mini)
#dorie_add_system_test(dorie-pfg correlation.mini)
dorie_add_system_test(dorie-pfg correlation.mini)
# dorie plot
dorie_add_system_test(dorie plot.mini)
......
......@@ -6,18 +6,20 @@ _asset_path = "${CMAKE_CURRENT_LIST_DIR}"
_evaluation = correlation
[_correlation]
padding = true
reltol = 0.2
[general]
generator = fft
overwrite = true
[generator]
dimensions = 2, 3 | expand dim
extensions = 1 1, 1 1 1 | expand dim
[generator.fft]
dimensions = 2, 3 | expand dim
outputPath = fft_fields/
N = 2048 2048, 128 128 128 | expand dim
variance = 0.2
correlationLengths = .0039 .00195, .0313 .0625 .0781 | expand dim
correlationLengths = .004 .005, .05 .06 .08 | expand dim
newEV = true
newField = true
Markdown is supported
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