def vpvs_ratio_test(_: unittest.TestCase): granularity = 0.001 depth_spacing = 10000 counter = 0 sd_array = UCVM.create_max_seismicdata_array() for x_val in \ custom_range(float(target.corners["bl"]["e"]), float(target.corners["tr"]["e"]) + granularity, granularity): for y_val in \ custom_range(float(target.corners["bl"]["n"]), float(target.corners["tr"]["n"]) + granularity, granularity): for z_val in custom_range(0, target.max_depth + depth_spacing, depth_spacing): sd_array[counter].original_point = Point(x_val, y_val, z_val) sd_array[counter].converted_point = Point(x_val, y_val, z_val) if counter == len(sd_array) - 1: UCVM.query(sd_array, name, ["velocity"]) _test_vpvs_ratio(sd_array) counter = 0 else: counter += 1 _test_vpvs_ratio(sd_array[0:counter])
def mesh_extract_single(information: dict, slices: str=None, interval: str=None, **kwargs) -> bool: """ Given a dictionary containing the relevant parameters for the extraction, extract the material properties for a single process. Args: information (dict): The dictionary containing the metadata defining the extraction. Returns: True, when successful. It will raise an error if the extraction is not successful. """ internal_mesh = InternalMesh(information) if slices is not None: internal_mesh.do_slices(slices) elif interval is not None: internal_mesh.do_interval(interval) sd_array = UCVM.create_max_seismicdata_array(min(internal_mesh.total_size, 250000), 1) print("\nThere are a total of " + humanize.intcomma(internal_mesh.total_size) + " grid points " "to extract.\nWe can extract " + humanize.intcomma(len(sd_array)) + " points at once.\n" "\nStarting extraction...\n") information["minimums"]["vp"] = float(information["minimums"]["vp"]) information["minimums"]["vs"] = float(information["minimums"]["vs"]) if internal_mesh.format == "awp": _mesh_extract_single_awp(sd_array, information, internal_mesh, slices, interval) elif internal_mesh.format == "rwg": _mesh_extract_single_rwg(sd_array, information, internal_mesh) print("\nExtraction done.") return True
def vpvs_ratio_test(_: unittest.TestCase): granularity = 0.001 depth_spacing = 10000 counter = 0 sd_array = UCVM.create_max_seismicdata_array() for x_val in \ custom_range(float(target.corners["bl"]["e"]), float(target.corners["tr"]["e"]) + granularity, granularity): for y_val in \ custom_range(float(target.corners["bl"]["n"]), float(target.corners["tr"]["n"]) + granularity, granularity): for z_val in custom_range(0, target.max_depth + depth_spacing, depth_spacing): sd_array[counter].original_point = Point( x_val, y_val, z_val) sd_array[counter].converted_point = Point( x_val, y_val, z_val) if counter == len(sd_array) - 1: UCVM.query(sd_array, name, ["velocity"]) _test_vpvs_ratio(sd_array) counter = 0 else: counter += 1 _test_vpvs_ratio(sd_array[0:counter])
def extract(self): num_points = int(math.ceil((self.profile_properties.depth - self.profile_point.z_value) / self.profile_properties.spacing)) + 1 self.sd_array = UCVM.create_max_seismicdata_array(num_points) for i in range(0, num_points): self.sd_array[i].original_point.x_value = self.profile_point.x_value self.sd_array[i].original_point.y_value = self.profile_point.y_value if self.profile_point.depth_elev == UCVM_DEPTH: self.sd_array[i].original_point.z_value = \ self.profile_point.z_value + (i * self.profile_properties.spacing) else: self.sd_array[i].original_point.depth_elev = UCVM_ELEVATION self.sd_array[i].original_point.z_value = \ self.profile_point.z_value - (i * self.profile_properties.spacing) UCVM.query(self.sd_array, self.cvms)
def etree_extract_mpi(information: dict, rows: str=None, interval: str=None) -> bool: from mpi4py import MPI comm = MPI.COMM_WORLD rank = comm.Get_rank() size = comm.Get_size() stats = _calculate_etree_stats( information, int(information["properties"]["columns"]), int(information["properties"]["rows"]) ) start_rc = [1, 1] end_rc = [int(information["properties"]["rows"]), int(information["properties"]["columns"])] if rows is not None: if "-" in rows: parts = rows.split("-") start_rc = [int(parts[0]), 1] end_rc = [int(parts[1]), int(information["properties"]["columns"])] else: start_rc = [int(rows), 1] end_rc = [int(rows), int(information["properties"]["columns"])] elif interval is not None: if "-" in interval: parts = interval.split("-") parts1 = parts[0].split(",") start_rc = [int(parts1[0]), int(parts1[1])] parts2 = parts[1].split(",") end_rc = [int(parts2[0]), int(parts2[1])] else: interval = interval.split(",") start_rc = [int(interval[0]), int(interval[1])] end_rc = [int(interval[0]), int(interval[1])] if rank == 0: schema = "float Vp; float Vs; float density;".encode("ASCII") path = (os.path.join(information["out_dir"], information["etree_name"] + ".e")).encode("ASCII") if sys.byteorder == "little" and sys.platform != "darwin": if start_rc[0] == 1 and start_rc[1] == 1: ep = UCVMCCommon.c_etree_open(path, 578) else: ep = UCVMCCommon.c_etree_open(path, 2) else: if start_rc[0] == 1 and start_rc[1] == 1: ep = UCVMCCommon.c_etree_open(path, 1538) else: ep = UCVMCCommon.c_etree_open(path, 2) UCVMCCommon.c_etree_registerschema(ep, schema) rcs_to_extract = [] current_rc = start_rc while not (current_rc[0] == end_rc[0] and current_rc[1] == end_rc[1] + 1): if current_rc[1] > int(information["properties"]["columns"]): current_rc[0] += 1 current_rc[1] = 1 rcs_to_extract.append((current_rc[0], current_rc[1])) current_rc[1] += 1 total_extracted = 0 is_done = [False for _ in range(size - 1)] while True: data = comm.recv(source=MPI.ANY_SOURCE) if data["code"] == "start": if len(rcs_to_extract) > 0: comm.send(rcs_to_extract.pop(0), dest=data["source"]) else: comm.send("done", dest=data["source"]) is_done[data["source"] - 1] = True elif data["code"] == "write": print("[Node %d] Writing data from node %d to file." % (rank, data["source"]), flush=True) _etree_writer(ep, data["data"][0], data["data"][1], data["data"][2]) total_extracted += data["data"][2] print("[Node %d] Data written successfully!" % rank, flush=True) elif data["code"] == "new": if len(rcs_to_extract) > 0: comm.send(rcs_to_extract.pop(0), dest=data["source"]) else: comm.send("done", dest=data["source"]) is_done[data["source"] - 1] = True print("[Node %d] Writing data from node %d to file." % (rank, data["source"]), flush=True) _etree_writer(ep, data["data"][0], data["data"][1], data["data"][2]) total_extracted += data["data"][2] print("[Node %d] Data written successfully!" % rank, flush=True) if False not in is_done: break metadata_string = ("Title:%s Author:%s Date:%s %u %s %f %f %f %f %f %f %u %u %u" % ( str(information["author"]["title"]).replace(" ", "_"), str(information["author"]["person"]).replace(" ", "_"), str(information["author"]["date"]).replace(" ", "_"), 3, "Vp(float);Vs(float);density(float)", float(information["corners"]["bl"]["y"]), float(information["corners"]["bl"]["x"]), float(information["dimensions"]["x"]), float(information["dimensions"]["y"]), 0, float(information["dimensions"]["z"]), int(stats["max_ticks"]["width"]), int(stats["max_ticks"]["height"]), int(stats["max_ticks"]["depth"]) )).encode("ASCII") print("[Node %d] Total number of octants extracted: %d." % (rank, total_extracted), flush=True) UCVMCCommon.c_etree_setappmeta(ep, metadata_string) UCVMCCommon.c_etree_close(ep) else: done = False print("[Node %d] Maximum points per section is %d." % (rank, stats["max_points"]), flush=True) sd_array = UCVM.create_max_seismicdata_array(stats["max_points"], 1) count = 0 comm.send({"source": rank, "data": "", "code": "start"}, dest=0) while not done: row_col = comm.recv(source=0) if row_col == "done": break print("[Node %d] Received instruction to extract column (%d, %d)." % (rank, row_col[0], row_col[1]), flush=True) data = _extract_mpi(rank, sd_array, information, stats, row_col[1] - 1, row_col[0] - 1) count += data[2] print("[Node %d] Finished extracting column (%d, %d)" % (rank, row_col[0], row_col[1])) comm.send({"source": rank, "data": data, "code": "new"}, dest=0) print("[Node %d] Finished extracting %d octants." % (rank, count), flush=True) return True
def etree_extract_single(information: dict, rows: str=None, interval: str=None) -> bool: schema = "float Vp; float Vs; float density;".encode("ASCII") path = (os.path.join(information["out_dir"], information["etree_name"] + ".e")).encode("ASCII") start_rc = [1, 1] end_rc = [int(information["properties"]["rows"]), int(information["properties"]["columns"])] if rows is not None: if "-" in rows: parts = rows.split("-") start_rc = [int(parts[0]), 1] end_rc = [int(parts[1]), int(information["properties"]["columns"])] else: start_rc = [int(rows), 1] end_rc = [int(rows), int(information["properties"]["columns"])] elif interval is not None: if "-" in interval: parts = interval.split("-") parts1 = parts[0].split(",") start_rc = [int(parts1[0]), int(parts1[1])] parts2 = parts[1].split(",") end_rc = [int(parts2[0]), int(parts2[1])] else: interval = interval.split(",") start_rc = [int(interval[0]), int(interval[1])] end_rc = [int(interval[0]), int(interval[1])] if sys.byteorder == "little" and sys.platform != "darwin": if start_rc[0] == 1 and start_rc[1] == 1: ep = UCVMCCommon.c_etree_open(path, 578) else: ep = UCVMCCommon.c_etree_open(path, 2) else: if start_rc[0] == 1 and start_rc[1] == 1: ep = UCVMCCommon.c_etree_open(path, 1538) else: ep = UCVMCCommon.c_etree_open(path, 2) UCVMCCommon.c_etree_registerschema(ep, schema) octant_count = 0 stats = _calculate_etree_stats( information, int(information["properties"]["columns"]), int(information["properties"]["rows"]) ) sd_array = UCVM.create_max_seismicdata_array(stats["max_points"], 1) print("Maximum points per section is %d" % stats["max_points"]) current_rc = start_rc while not (current_rc[0] == end_rc[0] and current_rc[1] == end_rc[1] + 1): if current_rc[1] > int(information["properties"]["columns"]): current_rc[0] += 1 current_rc[1] = 1 count = _extract_single(ep, sd_array, information, stats, current_rc[1] - 1, current_rc[0] - 1) if count is not None: octant_count += count else: raise Exception("HELP!") current_rc[1] += 1 print(str(octant_count) + " octants were extracted.") metadata_string = ("Title:%s Author:%s Date:%s %u %s %f %f %f %f %f %f %u %u %u" % ( str(information["author"]["title"]).replace(" ", "_"), str(information["author"]["person"]).replace(" ", "_"), str(information["author"]["date"]).replace(" ", "_"), 3, "Vp(float);Vs(float);density(float)", float(information["corners"]["bl"]["y"]), float(information["corners"]["bl"]["x"]), float(information["dimensions"]["x"]), float(information["dimensions"]["y"]), 0, float(information["dimensions"]["z"]), int(stats["max_ticks"]["width"]), int(stats["max_ticks"]["height"]), int(stats["max_ticks"]["depth"]) )).encode("ASCII") UCVMCCommon.c_etree_setappmeta(ep, metadata_string) UCVMCCommon.c_etree_close(ep) return True
def plot(self, basic: bool = False): if self.needs_extraction: self.extract() else: # Read in the already extracted data. with open(self.extras["save_file"], "rb") as fd: self.extracted_data = np.load(fd) init_array = UCVM.create_max_seismicdata_array(self.QUERY_AT_ONCE, 1) lons = np.zeros(self.slice_properties.num_x * self.slice_properties.num_y, dtype=float).reshape(self.slice_properties.num_y, self.slice_properties.num_x) lats = np.zeros(self.slice_properties.num_x * self.slice_properties.num_y, dtype=float).reshape(self.slice_properties.num_y, self.slice_properties.num_x) data = np.zeros(self.slice_properties.num_x * self.slice_properties.num_y, dtype=float).reshape(self.slice_properties.num_y, self.slice_properties.num_x) topography = None if "features" in self.extras["plot"] and \ "topography" in self.extras["plot"]["features"] and \ str(self.extras["plot"]["features"]["topography"]).lower().strip() == "yes": topography = np.zeros( self.slice_properties.num_x * self.slice_properties.num_y, dtype="<f8").reshape(self.slice_properties.num_y, self.slice_properties.num_x) if str(self.extras["plot"]["property"]).lower().strip() == "vp": position = 0 self.bounds = [ 0, 0.35, 0.70, 1.00, 1.35, 1.70, 2.55, 3.40, 4.25, 5.10, 5.95, 6.80, 7.65, 8.50 ] self.ticks = [ 0, 0.85, 1.70, 2.55, 3.40, 4.25, 5.10, 5.95, 6.80, 7.65, 8.50 ] self.plot_cbar_label = "Vp (km/s)" elif str(self.extras["plot"]["property"]).lower().strip() == "vs": position = 1 self.bounds = [ 0, 0.20, 0.40, 0.60, 0.80, 1.00, 1.50, 2.00, 2.50, 3.00, 3.50, 4.00, 4.50, 5.00 ] self.ticks = [ 0, 0.50, 1.00, 1.50, 2.00, 2.50, 3.00, 3.50, 4.00, 4.50, 5.00 ] self.plot_cbar_label = "Vs (km/s)" elif str(self.extras["plot"]["property"]).lower().strip() == "density": position = 2 self.bounds = [ 0, 0.20, 0.40, 0.60, 0.80, 1.00, 1.50, 2.00, 2.50, 3.00, 3.50, 4.00, 4.50, 5.00 ] self.ticks = [ 0, 0.50, 1.00, 1.50, 2.00, 2.50, 3.00, 3.50, 4.00, 4.50, 5.00 ] self.plot_cbar_label = "Density (kg/m^3)" elif str(self.extras["plot"]["property"]).lower().strip() == "qp": position = 3 elif str(self.extras["plot"]["property"]).lower().strip() == "qs": position = 4 elif str(self.extras["plot"] ["property"]).lower().strip() == "elevation": position = 0 self.bounds = [-4, -3, -2, -1, 0, 1, 2, 3, 4] self.ticks = [-4, -3, -2, -1, 0, 1, 2, 3, 4] self.plot_cbar_label = "Elevation (km)" elif str(self.extras["plot"]["property"]).lower().strip() == "vs30": position = 0 self.bounds = [ 0, 0.20, 0.40, 0.60, 0.80, 1.00, 1.50, 2.00, 2.50, 3.00, 3.50, 4.00, 4.50, 5.00 ] self.ticks = [ 0, 0.50, 1.00, 1.50, 2.00, 2.50, 3.00, 3.50, 4.00, 4.50, 5.00 ] self.plot_cbar_label = "Vs (km/s)" elif str(self.extras["plot"]["property"]).lower().strip() == "z10": position = 0 self.bounds = [ 0, 1.00, 2.00, 3.00, 4.00, 5.00, 6.00, 7.00, 8.00, 9.00, 10.00 ] self.ticks = self.bounds self.plot_cbar_label = "Depth (km)" elif str(self.extras["plot"]["property"]).lower().strip() == "z25": position = 1 self.bounds = [ 0, 1.00, 2.00, 3.00, 4.00, 5.00, 6.00, 7.00, 8.00, 9.00, 10.00 ] self.ticks = self.bounds self.plot_cbar_label = "Depth (km)" else: position = 0 im = InternalMesh.from_parameters( self.origin, { "num_x": self.slice_properties.num_x, "num_y": self.slice_properties.num_y, "num_z": 1, "rotation": self.slice_properties.rotation, "spacing": self.slice_properties.spacing, "projection": self.origin.projection }, self.cvms, "") im_iterator = AWPInternalMeshIterator(im, 0, im.total_size, len(init_array), init_array) num_queried = next(im_iterator) i = 0 j = 0 while num_queried > 0: for datum in init_array[0:num_queried]: new_pt = datum.original_point.convert_to_projection( UCVM_DEFAULT_PROJECTION) lons[j][i] = new_pt.x_value lats[j][i] = new_pt.y_value if str(self.extras["plot"]["property"]).lower().strip() == "elevation" or \ str(self.extras["plot"]["property"]).lower().strip() == "vs30": data[j][i] = self.extracted_data[ j * self.slice_properties.num_x + i] / 1000 elif str(self.extras["plot"]["property"]).lower().strip() == "z10" or \ str(self.extras["plot"]["property"]).lower().strip() == "z25": data[j][i] = self.extracted_data[( (j * self.slice_properties.num_x) + i) * 2 + position] / 1000 else: data[j][i] = self.extracted_data[( (j * self.slice_properties.num_x) + i) * 6 + position] / 1000 if topography is not None: topography[j][i] = self.extracted_data[( (j * self.slice_properties.num_x) + i) * 6 + 5] / 1000 i += 1 if i == self.slice_properties.num_x: i = 0 j += 1 try: num_queried = next(im_iterator) except StopIteration: break # Ok, now that we have the 2D array of lons, lats, and data, let's call on our inherited # classes show_plot function to actually show the plot. return super(HorizontalSlice, self).show_plot(lons, lats, data, True, topography=topography, basic=basic)
def plot(self, prop: str = "vp", basic: bool = False): init_array = UCVM.create_max_seismicdata_array( self.dataset1.slice_properties.num_x * self.dataset1.slice_properties.num_y, 1) lons = np.zeros(self.dataset1.slice_properties.num_x * self.dataset1.slice_properties.num_y, dtype=float).reshape( self.dataset1.slice_properties.num_y, self.dataset1.slice_properties.num_x) lats = np.zeros(self.dataset1.slice_properties.num_x * self.dataset1.slice_properties.num_y, dtype=float).reshape( self.dataset1.slice_properties.num_y, self.dataset1.slice_properties.num_x) data = np.zeros(self.dataset1.slice_properties.num_x * self.dataset1.slice_properties.num_y, dtype=float).reshape( self.dataset1.slice_properties.num_y, self.dataset1.slice_properties.num_x) self.bounds = [-20, -15, -10, -5, 0, 5, 10, 15, 20] self.ticks = self.bounds self.plot_cbar_label = "Percentage difference." if str(prop).lower().strip() == "vp": position = 0 elif str(prop).lower().strip() == "vs": position = 1 elif str(prop).lower().strip() == "density": position = 2 elif str(prop).lower().strip() == "qp": position = 3 elif str(prop).lower().strip() == "qs": position = 4 elif str(prop).lower().strip() == "elevation": position = 0 elif str(prop).lower().strip() == "vs30": position = 0 else: position = 0 im = InternalMesh.from_parameters( self.dataset1.origin, { "num_x": self.dataset1.slice_properties.num_x, "num_y": self.dataset1.slice_properties.num_y, "num_z": 1, "rotation": self.dataset1.slice_properties.rotation, "spacing": self.dataset1.slice_properties.spacing, "projection": self.dataset1.origin.projection }, self.dataset1.cvms, "") im_iterator = AWPInternalMeshIterator(im, 0, im.total_size, len(init_array), init_array) num_queried = next(im_iterator) i = 0 j = 0 while num_queried > 0: for datum in init_array[0:num_queried]: new_pt = datum.original_point.convert_to_projection( UCVM_DEFAULT_PROJECTION) lons[j][i] = new_pt.x_value lats[j][i] = new_pt.y_value data[j][i] = self.extracted_data[ (j * self.dataset1.slice_properties.num_x + i) * 6 + position] i += 1 if i == self.dataset1.slice_properties.num_x: i = 0 j += 1 try: num_queried = next(im_iterator) except StopIteration: break # Ok, now that we have the 2D array of lons, lats, and data, let's call on our inherited # classes show_plot function to actually show the plot. return super(Difference, self).show_plot(lons, lats, data, True, basic=basic)
def plot(self, prop: str="vp", basic: bool=False): init_array = UCVM.create_max_seismicdata_array(self.dataset1.slice_properties.num_x * self.dataset1.slice_properties.num_y, 1) lons = np.zeros(self.dataset1.slice_properties.num_x * self.dataset1.slice_properties.num_y, dtype=float).reshape(self.dataset1.slice_properties.num_y, self.dataset1.slice_properties.num_x) lats = np.zeros(self.dataset1.slice_properties.num_x * self.dataset1.slice_properties.num_y, dtype=float).reshape(self.dataset1.slice_properties.num_y, self.dataset1.slice_properties.num_x) data = np.zeros(self.dataset1.slice_properties.num_x * self.dataset1.slice_properties.num_y, dtype=float).reshape(self.dataset1.slice_properties.num_y, self.dataset1.slice_properties.num_x) self.bounds = [-20, -15, -10, -5, 0, 5, 10, 15, 20] self.ticks = self.bounds self.plot_cbar_label = "Percentage difference." if str(prop).lower().strip() == "vp": position = 0 elif str(prop).lower().strip() == "vs": position = 1 elif str(prop).lower().strip() == "density": position = 2 elif str(prop).lower().strip() == "qp": position = 3 elif str(prop).lower().strip() == "qs": position = 4 elif str(prop).lower().strip() == "elevation": position = 0 elif str(prop).lower().strip() == "vs30": position = 0 else: position = 0 im = InternalMesh.from_parameters( self.dataset1.origin, { "num_x": self.dataset1.slice_properties.num_x, "num_y": self.dataset1.slice_properties.num_y, "num_z": 1, "rotation": self.dataset1.slice_properties.rotation, "spacing": self.dataset1.slice_properties.spacing, "projection": self.dataset1.origin.projection }, self.dataset1.cvms, "" ) im_iterator = AWPInternalMeshIterator(im, 0, im.total_size, len(init_array), init_array) num_queried = next(im_iterator) i = 0 j = 0 while num_queried > 0: for datum in init_array[0:num_queried]: new_pt = datum.original_point.convert_to_projection(UCVM_DEFAULT_PROJECTION) lons[j][i] = new_pt.x_value lats[j][i] = new_pt.y_value data[j][i] = self.extracted_data[(j * self.dataset1.slice_properties.num_x + i) * 6 + position] i += 1 if i == self.dataset1.slice_properties.num_x: i = 0 j += 1 try: num_queried = next(im_iterator) except StopIteration: break # Ok, now that we have the 2D array of lons, lats, and data, let's call on our inherited # classes show_plot function to actually show the plot. return super(Difference, self).show_plot(lons, lats, data, True, basic=basic)