Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
190 changes: 0 additions & 190 deletions map2loop/map2model_wrapper.py

This file was deleted.

68 changes: 5 additions & 63 deletions map2loop/mapdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -1360,11 +1360,10 @@ def calculate_bounding_box_and_projection(self):
def export_wkt_format_files(self):
"""
Save out the geology and fault GeoDataFrames in WKT format
This is used by map2model
This is used by topology
"""
# TODO: - Move away from tab seperators entirely (topology and map2model)

self.map2model_tmp_path = pathlib.Path(tempfile.mkdtemp())
# TODO: - Move away from tab seperators entirely (topology)
self.topology_tmp_path = pathlib.Path(tempfile.mkdtemp())

# Check geology data status and export to a WKT format file
self.load_map_data(Datatype.GEOLOGY)
Expand Down Expand Up @@ -1398,7 +1397,7 @@ def export_wkt_format_files(self):
geology["ROCKTYPE1"] = geology["ROCKTYPE1"].replace("", "None")
geology["ROCKTYPE2"] = geology["ROCKTYPE2"].replace("", "None")
geology.to_csv(
pathlib.Path(self.map2model_tmp_path) / "geology_wkt.csv", sep="\t", index=False
pathlib.Path(self.topology_tmp_path) / "geology_wkt.csv", sep="\t", index=False
)

# Check faults data status and export to a WKT format file
Expand All @@ -1413,7 +1412,7 @@ def export_wkt_format_files(self):
faults = self.get_map_data(Datatype.FAULT).copy()
faults.rename(columns={"geometry": "WKT"}, inplace=True)
faults.to_csv(
pathlib.Path(self.map2model_tmp_path) / "faults_wkt.csv", sep="\t", index=False
pathlib.Path(self.topology_tmp_path) / "faults_wkt.csv", sep="\t", index=False
)

@beartype.beartype
Expand Down Expand Up @@ -1448,63 +1447,6 @@ def get_value_from_raster(self, datatype: Datatype, x, y):
val = data.ReadAsArray(px, py, 1, 1)[0][0]
return val

@beartype.beartype
def __value_from_raster(self, inv_geotransform, data, x: float, y: float):
"""
Get the value from a raster dataset at the specified point

Args:
inv_geotransform (gdal.GeoTransform):
The inverse of the data's geotransform
data (numpy.array):
The raster data
x (float):
The easting coordinate of the value
y (float):
The northing coordinate of the value

Returns:
float or int: The value at the point specified
"""
px = int(inv_geotransform[0] + inv_geotransform[1] * x + inv_geotransform[2] * y)
py = int(inv_geotransform[3] + inv_geotransform[4] * x + inv_geotransform[5] * y)
# Clamp values to the edges of raster if past boundary, similiar to GL_CLIP
px = max(px, 0)
px = min(px, data.shape[0] - 1)
py = max(py, 0)
py = min(py, data.shape[1] - 1)
return data[px][py]

@beartype.beartype
def get_value_from_raster_df(self, datatype: Datatype, df: pandas.DataFrame):
"""
Add a 'Z' column to a dataframe with the heights from the 'X' and 'Y' coordinates

Args:
datatype (Datatype):
The datatype of the raster map to retrieve from
df (pandas.DataFrame):
The original dataframe with 'X' and 'Y' columns

Returns:
pandas.DataFrame: The modified dataframe
"""
if len(df) <= 0:
df["Z"] = []
return df
data = self.get_map_data(datatype)
if data is None:
logger.warning("Cannot get value from data as data is not loaded")
return None

inv_geotransform = gdal.InvGeoTransform(data.GetGeoTransform())
data_array = numpy.array(data.GetRasterBand(1).ReadAsArray().T)

df["Z"] = df.apply(
lambda row: self.__value_from_raster(inv_geotransform, data_array, row["X"], row["Y"]),
axis=1,
)
return df

@beartype.beartype
def extract_all_contacts(self, save_contacts=True):
Expand Down
Loading
Loading