pydfnWorks
python wrapper for dfnWorks
plot_fracture_centers.py
Go to the documentation of this file.
1 """
2  :filename: plot_fracture_centers.py
3  :synopsis: Make plots of fracture centers for the entire network and by family
4  :version: 1.0
5  :maintainer: Jeffrey Hyman
6 .. moduleauthor:: Jeffrey Hyman <jhyman@lanl.gov>
7 """
8 
9 import matplotlib.pylab as plt
10 
11 
12 def plot_fracture_centers(params, families, fractures):
13  """ Creates histogram plots of fracture centers in the domain. First all fractures are plotted, then by family.
14 
15  Parameters
16  ------------
17  params : dictionary
18  General dictionary of output analysis code. Contains information on number of families, number of fractures, and colors.
19 
20  families: list of fracture family dictionaries
21  Created by get_family_information
22 
23  fractures: list of fracture dictionaries
24  Created by get_fracture_information
25 
26  Returns
27  --------
28  None
29 
30  Notes
31  -------
32  PDF files are dumped into dfnGen_output_report/figures. There is one figure for all fractures (all_fracture_centers.pdf) and one per family family_{family_id}_fracture_centers.pdf.
33  """
34 
35  print("--> Plotting Fracture Locations")
36 
37  for fam in families:
38  family_id = fam["Global Family"]
39  if params["verbose"]:
40  print(f"--> Working on fracture family {family_id}")
41  fig, axs = plt.subplots(nrows=2, ncols=2, figsize=(10, 7))
42 
43  for coord in ["x", "y", "z"]:
44  values_all = []
45  values_accepted = []
46  if params["verbose"]:
47  print(f"--> Working on {coord} coordinates ")
48 
49  for i in fam["fracture list - all"]:
50  values_all.append(fractures[i]["center"][coord])
51 
52  for i in fam["fracture list - final"]:
53  values_accepted.append(fractures[i]["center"][coord])
54 
55  # Come up with some smart way to get a good number of bins.
56  # This seems okay for now
57  num_bins = max(35, int(len(values_accepted) / 100))
58  # Pick axis for each component.
59  if coord == "x":
60  i = 0
61  j = 0
62  elif coord == "y":
63  i = 0
64  j = 1
65  elif coord == "z":
66  i = 1
67  j = 0
68 
69  tmp = [min(values_all), -0.5 * params["domain"][coord]]
70  min_val = min(tmp)
71  tmp = [max(values_all), 0.5 * params["domain"][coord]]
72  max_val = max(tmp)
73 
74  # Create and plot histograms
75  axs[i, j].hist(values_all,
76  bins=num_bins,
77  color=params["all_color"],
78  range=(min_val, max_val),
79  alpha=0.7,
80  edgecolor="k",
81  linewidth=0.5)
82 
83  axs[i, j].hist(values_accepted,
84  bins=num_bins,
85  color=params["final_color"],
86  range=(min_val, max_val),
87  alpha=0.7,
88  edgecolor="k",
89  linewidth=0.5)
90 
91  # Put in family region boundaries
92  if fam["Layer"]:
93  if coord == "z":
94  axs[i, j].axvline(fam[f"{coord}_min"], c="k", ls="--")
95  axs[i, j].axvline(fam[f"{coord}_max"], c="k", ls="--")
96 
97  elif fam["Region"]:
98  axs[i, j].axvline(fam[f"{coord}_min"], c="k", ls="--")
99  axs[i, j].axvline(fam[f"{coord}_max"], c="k", ls="--")
100 
101  # Always include domain boundaries
102  axs[i, j].axvline(-0.5 * params["domain"][coord], c="k")
103  axs[i, j].axvline(0.5 * params["domain"][coord], c="k")
104 
105  # Title and Axis
106  axs[i, j].set_title(f"Fracture Centers: {coord}-Coordinate",
107  fontsize=18)
108  axs[i, j].set_xlabel("Location [m]", fontsize=14)
109  axs[i, j].set_ylabel("Number of Fractures", fontsize=14)
110  # Clean up memory
111  del values_all, values_accepted
112 
113  # Create Legend in final subplot (lower right)
114  axs[1, 1].set_frame_on(False)
115  axs[1, 1].get_xaxis().set_visible(False)
116  axs[1, 1].get_yaxis().set_visible(False)
117  if fam["Region"]:
118  axs[1, 1].plot(0, 0, "k--", label="Region Boundary")
119  elif fam["Layer"]:
120  axs[1, 1].plot(0, 0, "k--", label="Layer Boundary")
121 
122  axs[1, 1].plot(0, 0, "k", label="Domain Boundary")
123 
124  axs[1, 1].plot(0,
125  0,
126  params["all_color"],
127  alpha=0.7,
128  linewidth=10,
129  label="All Accepted Fractures")
130  axs[1, 1].plot(0,
131  0,
132  params["final_color"],
133  alpha=0.7,
134  linewidth=10,
135  label="Fractures in the Connected Network")
136  axs[1, 1].legend(loc="center", fontsize=14, frameon=False)
137 
138  fig.tight_layout()
139  if family_id > 0:
140  fileout = f"family_{family_id}_centers.png"
141  else:
142  tmp = fam["Distribution"]
143  fileout = f"family_{tmp}_centers.png"
144 
145  if params["verbose"]:
146  print(f"--> Saving File {fileout}")
147  plt.savefig(f"{params['output_dir']}/family_{family_id}/{fileout}")
148  plt.clf()
149  plt.close()
150 
151  if params["verbose"]:
152  print("--> Complete")
153 
154  # Make plots of all fractures
155  fig, axs = plt.subplots(nrows=2, ncols=2, figsize=(10, 7))
156  for coord in ["x", "y", "z"]:
157  if params["verbose"]:
158  print(f"--> Working on {coord} coordinates ")
159 
160  for fam in families:
161  values_all = []
162  values_accepted = []
163 
164  family_id = fam["Global Family"]
165 
166  # for i in fam["fracture list - all"]:
167  # values_all.append(fractures[i]["center"][coord])
168 
169  for i in fam["fracture list - final"]:
170  values_accepted.append(fractures[i]["center"][coord])
171 
172  # Come up with some smart way to get a good number of bins.
173  # This seems okay for now
174  num_bins = max(35, int(len(values_accepted) / 100))
175  # Pick axis for each component.
176  if coord == "x":
177  i = 0
178  j = 0
179  elif coord == "y":
180  i = 0
181  j = 1
182  elif coord == "z":
183  i = 1
184  j = 0
185 
186  min_val = -0.5 * params["domain"][coord]
187  max_val = 0.5 * params["domain"][coord]
188  # Create and plot histograms
189  axs[i, j].hist(values_accepted,
190  bins=num_bins,
191  color=fam["color"],
192  range=(min_val, max_val),
193  alpha=0.7,
194  edgecolor="k",
195  linewidth=0.5)
196 
197  # Always include domain boundaries
198  axs[i, j].axvline(-0.5 * params["domain"][coord], c="k")
199  axs[i, j].axvline(0.5 * params["domain"][coord], c="k")
200 
201  # Title and Axis
202  axs[i, j].set_title(f"Fracture Centers: {coord}-Coordinate",
203  fontsize=18)
204  axs[i, j].set_xlabel("Location [m]", fontsize=14)
205  axs[i, j].set_ylabel("Number of Fractures", fontsize=14)
206  # Clean up memory
207  del values_all, values_accepted
208 
209  # Create Legend in final subplot (lower right)
210  axs[1, 1].set_frame_on(False)
211  axs[1, 1].get_xaxis().set_visible(False)
212  axs[1, 1].get_yaxis().set_visible(False)
213 
214  xy_coords = []
215  for i in range(8, 0, -1):
216  for j in [1, 3.5, 6]:
217  xy_coords.append((j, i))
218 
219  axs[1, 1].plot([2, 3], [9, 9], "k", linewidth=5)
220  axs[1, 1].text(x=3.25, y=8.9, s=f"Domain Boundary", fontsize="14")
221 
222  for i, fam in enumerate(families):
223  xx = [xy_coords[i][0], xy_coords[i][0] + 1.5]
224  yy = [xy_coords[i][1], xy_coords[i][1]]
225  axs[1, 1].plot(xx, yy, linewidth=20, alpha=0.4, color=fam["color"])
226  axs[1, 1].text(x=xy_coords[i][0] + 0.15,
227  y=xy_coords[i][1] - 0.15,
228  s=f"Family {fam['Global Family']}",
229  fontsize="14")
230 
231  axs[1, 1].axis([0.5, 8.5, xy_coords[i][1] - 1, 10])
232 
233  fig.tight_layout()
234 
235  fileout = f"all_fracture_centers.png"
236 
237  if params["verbose"]:
238  print(f"--> Saving File {fileout}")
239  plt.savefig(f"{params['output_dir']}/network/{fileout}")
240  plt.clf()
241  plt.close()
242 
243  if params["verbose"]:
244  print("--> Complete")