pydfnWorks
python wrapper for dfnWorks
plot_intersection_lengths.py
Go to the documentation of this file.
1 """
2  :filename: gen_output.py
3  :synopsis: Main driver for dfnGen output report
4  :version: 1.0
5  :maintainer: Jeffrey Hyman
6  :moduleauthor: Jeffrey Hyman <jhyman@lanl.gov>
7 """
8 
9 import matplotlib.pylab as plt
10 import seaborn as sns
11 import numpy as np
12 
13 
14 def plot_intersection_lengths(params, families):
15  """ Creates PDF plots of fracture intersection lengths in the domain. First all fractures are plotted, then by family.
16 
17  Parameters
18  ------------
19  params : dictionary
20  General dictionary of output analysis code. Contains information on number of families, number of fractures, and colors.
21 
22  families: list of fracture family dictionaries
23  Created by get_family_information
24 
25 
26  Returns
27  --------
28  None
29 
30  Notes
31  -------
32  For larger networks, it can take a long time to sort intersections by family.
33 
34  This function is only called with robust = True
35 
36  PDF files are dumped into family/figures. There is one figure for all fractures dfnGen_output_report/networks/ and one per family dfnGen_output_report/family_{family_id}
37 
38  Information about intersection modification during generation has not been include yet, but it should be.
39  """
40 
41  print("--> Plotting Intersection Distributions")
42 
43  # intersection_params = [" Number of Intersections"," Intersections Shortened",
44  # " Original Intersection (Before Intersection Shrinking) Length",
45  # " Intersection Length Discarded"," Final Intersection Length"]
46 
47  data = np.genfromtxt("intersection_list.dat", skip_header=1)
48  f1 = data[:, 0]
49  f2 = data[:, 1]
50  intersection_lengths = data[:, -1]
51  f1 = f1.astype(int)
52  f2 = f2.astype(int)
53  num_intersections = len(f1)
54  if params["verbose"]:
55  print(f"There are {num_intersections} intersections")
56  fig, axs = plt.subplots(figsize=(10, 7))
57  sns.kdeplot(intersection_lengths, color="k")
58  labs = ["Entire Network"]
59 
60  # search for families
61  idx = []
62  for i in range(num_intersections):
63  if params["verbose"] and i % 1000 == 0:
64  print(f"--> Intersection number {i}")
65  i1 = 0
66  i2 = 0
67  for fam in families:
68  if f1[i] > 0 and f2[i] > 0:
69  if f1[i] in fam["fracture list - final"]:
70  i1 = fam['Global Family']
71  if f2[i] in fam["fracture list - final"]:
72  i2 = fam['Global Family']
73  else:
74  i1 = 0
75  i2 = 0
76  idx.append((i1, i2))
77 
78  for fam in families:
79  if params["verbose"]:
80  print(f"--> Working on family {fam['Global Family']}")
81  family_lengths = []
82  for i in range(num_intersections):
83  if idx[i][0] == fam['Global Family'] or idx[i][1] == fam[
84  'Global Family']:
85  family_lengths.append(intersection_lengths[i])
86 
87  labs += [f"Family: {fam['Global Family']}"]
88  sns.kdeplot(family_lengths, color=fam["color"])
89 
90  plt.legend(loc="upper right", labels=labs, fontsize=14)
91  plt.xlabel("Intersection Length [m]", fontsize=24)
92  plt.ylabel("Density", fontsize=24)
93  axs.set_xticklabels(axs.get_xticks().astype(int), fontsize=14)
94  ticks = axs.get_yticks()
95  labels = [f"{val:0.2f}" for val in ticks]
96  axs.set_yticklabels(labels, fontsize=14)
97  plt.savefig(f"{params['output_dir']}/network/network_intersections.png")
98  plt.close()
99 
100  if params["verbose"]:
101  print(f"--> Individual Family Plots")
102 
103  # individual family plots
104  for fam in families:
105  fig, axs = plt.subplots(figsize=(10, 7))
106 
107  if params["verbose"]:
108  print(f"--> Working on family {fam['Global Family']}")
109  family_lengths = []
110  for i in range(num_intersections):
111  if idx[i][0] == fam['Global Family'] or idx[i][1] == fam[
112  'Global Family']:
113  family_lengths.append(intersection_lengths[i])
114 
115  sns.kdeplot(family_lengths, color=params["final_color"])
116  plt.xlabel("Intersection Length [m]", fontsize=24)
117  plt.ylabel("Density", fontsize=24)
118  axs.set_xticklabels(axs.get_xticks().astype(int), fontsize=16)
119  ticks = axs.get_yticks()
120  labels = [f"{val:0.2f}" for val in ticks]
121  axs.set_yticklabels(labels, fontsize=16)
122  plt.savefig(
123  f"{params['output_dir']}/family_{fam['Global Family']}/family_{fam['Global Family']}_intersections.png"
124  )
125  plt.close()