def MakeTable(Obs_data,Obs_xml,filename): head_amanzi = [] coordinates = [] mymodel = model_linear_materials_serial_1d.createFromXML(filename) p_atm = 101325.0 rho = 998.2 g = 9.80665 for obs in Obs_data.observations.itervalues(): coordinates.append([obs.coordinate[0], obs.coordinate[2]]) # Convert from pressure to hydraulic head. # This isn't really great, but it gets us there for the moment. p = obs.data h = [(p[i] - p_atm) / (rho*g) + obs.coordinate[2] for i in xrange(len(p))] head_amanzi.append(str(h).rstrip(']').lstrip('[')) head_analytic = list(mymodel.head(numpy.array(coordinates))) x = prettytable.PrettyTable(["x [m]", "z [m]", "Analytic [m]","Amanzi [m]"]) x.padding_width = 1 x.hrules = 1 for coords, h_analytic, h_amanzi in zip(coordinates,head_analytic,head_amanzi): x.add_row([coords[0],coords[1],"%.4f" % float(h_analytic),"%.4f" % float(h_amanzi)]) if os.path.exists("table_values.txt"): os.remove("table_values.txt") table_file = open("table_values.txt", "w+") table_file.write(x.get_string()) table_file.close()
def plotTestModel(filename, cmap, axes1, Obs_xml, Obs_data): # Instantiate the analytic solution mymodel = model_linear_materials_serial_1d.createFromXML(filename) table_values = [] # Create a set of points to plot the solution x = numpy.linspace(mymodel.x_0, mymodel.x_1, 11) coords = numpy.zeros((11, 2)) coords[:, 0] = x # Plot a line for each z-coordinate in the observations for (z_val, color) in cmap.iteritems(): coords[:, 1] = z_val head = mymodel.head(coords) axes1.plot(x, head, color, label='$z = %0.2f $' % z_val) axes1.legend(loc="upper right", fancybox=True, shadow=True)