<jupyter_start><jupyter_text>Covariance AnalysisBased on the computation of the two-point covariance, we will compute three properties: - Slope of the Covariance at the origin $\frac{dS^{(1)}_2(r)}{dr}|_{r=0}$ - The specific surface area $S_V$ - Chord length for each phase $l^{(i)}_C$<jupyter_code>import numpy as np
import pandas as pd
from scipy.optimize import curve_fit
import json
#strings to output and input locations
beadpack_dic = {
    "out_direc": "../../../analysis/covariance/beadpack/",
    "seed_min": 43,
    "seed_max": 64
}

berea_dic = {
    "out_direc": "../../../analysis/covariance/berea/",
    "seed_min": 43,
    "seed_max": 64
}

ketton_dic = {
    "out_direc": "../../../analysis/covariance/ketton/",
    "seed_min": 43,
    "seed_max": 64
}
data_dic = ketton_dic
out_direc = data_dic["out_direc"]<jupyter_output><empty_output><jupyter_text>Data Loading We load data using pandas from the given directory of the covariances.<jupyter_code>orig_cov_pph = pd.read_csv(out_direc+"orig_pph.csv")
orig_cov_gph = pd.read_csv(out_direc+"orig_gph.csv")<jupyter_output><empty_output><jupyter_text>We now compute the slope at the origin of the radial averaged covariance to evaluate the specific surface area. $$S_V = -4 \frac{dS^{(1)}_2(r)}{dr}|_{r=0}$$ We do this by fittin a straight line at the origin and fixing the intercept at $S^{(1)}_2(0)=\phi$Therefore the equation we are fitting is:$$y = ax + \phi$$<jupyter_code>def radial_average(cov):
    avg = np.mean(cov, axis=0)
    return avg


def straight_line_at_origin(porosity):
    def func(x, a):
        return a * x + porosity
    return func
original_average_pph = radial_average(orig_cov_pph.values.T)
original_average_gph = radial_average(orig_cov_gph.values.T)
N = 5
slope_pph, slope_pph_cov = curve_fit(straight_line_at_origin(original_average_pph[0]), range(0, N), original_average_pph[0:N])
slope_gph, slope_gph_cov = curve_fit(straight_line_at_origin(original_average_gph[0]), range(0, N), original_average_gph[0:N])
print slope_pph, slope_gph

specific_surface_orig = -4*slope_pph
print specific_surface_orig<jupyter_output>[-0.01369403] [-0.01367592]
[ 0.05477614]<jupyter_text>Finally we estimate the chord length of both phases by computing:$$l^{(i)}_C=-\frac{\phi^{(i)}}{\frac{dS^{(i)}_2(r)}{dr}|_{r=0}}$$<jupyter_code>chord_length_pph = -original_average_pph[0]/slope_pph
chord_length_gph = -original_average_gph[0]/slope_gph
print chord_length_pph, chord_length_gph
orig_data = {
    "slope_gph": float(slope_gph), "slope_pph": float(slope_pph), 
    "specific_surface": float(specific_surface_orig), 
    "chord_length_pph": float(chord_length_pph), "chord_length_gph":float(chord_length_gph)}
covariance_values = {}
covariance_values["orig"] = orig_data<jupyter_output><empty_output><jupyter_text>Synthetic Samples ComputationWe now perform the same computation for the synthetic samples<jupyter_code>for i in range(data_dic["seed_min"], data_dic["seed_max"]):
    cov_pph = pd.read_csv(out_direc+"S_"+str(i)+"_pph.csv")
    cov_gph = pd.read_csv(out_direc+"S_"+str(i)+"_gph.csv")
    
    average_pph = radial_average(cov_pph.values.T)
    average_gph = radial_average(cov_gph.values.T)
    
    slope_pph, slope_pph_cov = curve_fit(straight_line_at_origin(average_pph[0]), range(0, N), average_pph[0:N])
    slope_gph, slope_gph_cov = curve_fit(straight_line_at_origin(average_gph[0]), range(0, N), average_gph[0:N])

    
    specific_surface = -4*slope_pph

    
    chord_length_pph = -average_pph[0]/slope_pph
    chord_length_gph = -average_gph[0]/slope_gph

    data = {
    "slope_gph": float(slope_gph), "slope_pph": float(slope_pph), 
    "specific_surface": float(specific_surface), 
    "chord_length_pph": float(chord_length_pph), "chord_length_gph":float(chord_length_gph)}
    covariance_values["S_"+str(i)] = data<jupyter_output><empty_output><jupyter_text>Data Output to JSONAnd finally we dump everything to a json file that let's us use this data in future graphs and analysis.<jupyter_code>with open(out_direc+"covariance_data.json", "w") as f:
    json.dump(covariance_values, f)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13305865244789142, 'fraction_numerical': 0.017207949587978673, 'mean_word_length': 5.971283783783784, 'pattern_counts': {'":': 19, '<': 24, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '515751', 'license': 'MIT', 'n_tokens_mistral': 1658, 'n_tokens_neox': 1577, 'n_words': 293, 'path': 'code/notebooks/covariance/Covariance Analysis.ipynb', 'repo_name': 'lixuekai2001/PorousMediaGan', 'size': '4126'}