Skip to content

Commit

Permalink
fix: Fix strike conversion logic, Replace drift_prefix with ignore_co…
Browse files Browse the repository at this point in the history
…des option, remove opentopography dtm
  • Loading branch information
RoyThomsonMonash committed Nov 30, 2022
1 parent 07150ac commit 97d26ed
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 44 deletions.
4 changes: 3 additions & 1 deletion map2loop/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def __init__(self, map_data, verbose_level=VerboseLevel.ALL):
"use_fat": True,
"use_roi_clip": False,
"roi_clip_path": "",
"drift_prefix": ["None"],
"drift_prefix": [],
"ignore_codes": [],
"fault_fault_weight": 3,
"fault_weight": 1,
"formation_weight": 7,
Expand Down Expand Up @@ -254,6 +255,7 @@ def create_cmap(self):
i = 0
for key in self.colour_dict.keys():
self.colour_dict[key] = random_colours[i]
i=i+1

self.cmap = colors.ListedColormap(self.colour_dict.values(), name="geol_key")

Expand Down
18 changes: 6 additions & 12 deletions map2loop/m2l_interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,8 @@ def interpolate_orientations(
y[i] = a_pt[1]["geometry"].y + (np.random.ranf() * 0.01)
dip[i] = a_pt[1]["DIP"]

if c_l["otype"] == "strike":
dipdir[i] = a_pt[1]["DIPDIR"] + 90
else:
dipdir[i] = a_pt[1]["DIPDIR"]
# All orientation have been converted to dipdir
dipdir[i] = a_pt[1]["DIPDIR"]
i = i + 1

l = np.zeros(npts)
Expand Down Expand Up @@ -1173,10 +1171,8 @@ def interpolate_orientations_with_fat(
x[i] = a_pt["geometry"].x
y[i] = a_pt["geometry"].y
dip[i] = a_pt["DIP"]
if c_l["otype"] == "strike":
dipdir[i] = float(a_pt["DIPDIR"]) + 90
else:
dipdir[i] = a_pt["DIPDIR"]
# All orientation have been converted to dipdir
dipdir[i] = a_pt["DIPDIR"]
i = i + 1

for ind, a_pt in fat_orientations.iterrows():
Expand Down Expand Up @@ -2061,10 +2057,8 @@ def interpolate_orientation_grid(structures, calc, xcoords, ycoords, c_l):
y[i] = a_pt[1]["geometry"].y + (np.random.ranf())
dip[i] = a_pt[1]["DIP"]

if c_l["otype"] == "strike":
dipdir[i] = a_pt[1]["DIPDIR"] + 90
else:
dipdir[i] = a_pt[1]["DIPDIR"]
# All orientation have been converted to dipdir
dipdir[i] = a_pt[1]["DIPDIR"]

i = i + 1

Expand Down
15 changes: 7 additions & 8 deletions map2loop/m2l_map_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def check_all_maps(
geology = check_geology_map(
mapdata.get_map_data(Datatype.GEOLOGY),
config.c_l,
config.run_flags["drift_prefix"],
config.run_flags["ignore_codes"],
m2l_warnings,
m2l_errors,
verbose_level=verbose_level,
Expand Down Expand Up @@ -233,13 +233,12 @@ def check_structure_map(
)

# Check for strike and convert to dip direction
if c_l["otype"] == "strike" and "strike" in orientations.columns:
if c_l["otype"] == "strike" and c_l["dd"] in orientations.columns:
if verbose_level != VerboseLevel.NONE:
print("converting strike/dip orientation to dipdir/dip")
orientations[c_l["dd"]] = orientations.apply(
lambda row: row["strike"] + 90.0, axis=1
lambda row: row[c_l["dd"]] + 90.0, axis=1
)
c_l["otype"] = "dip direction"

# Check for duplicate column references
if c_l["sf"] == c_l["ds"]:
Expand Down Expand Up @@ -461,10 +460,6 @@ def check_geology_map(
if explode_intrusives:
geology = _explode_intrusives(geology, c_l)

# Convert types
geology[c_l["max"]] = geology[c_l["max"]].astype(np.float64)
geology[c_l["min"]] = geology[c_l["min"]].astype(np.float64)

unique_c = list(set(geology[c_l["c"]]))
if len(unique_c) < 2:
m2l_errors.append(
Expand Down Expand Up @@ -509,6 +504,10 @@ def check_geology_map(
m2l_warnings.append("No max age for geology polygons")
geology[c_l["max"]] = 100

# Convert types
geology[c_l["max"]] = geology[c_l["max"]].astype(np.float64)
geology[c_l["min"]] = geology[c_l["min"]].astype(np.float64)

if c_l["c"] not in geology.columns:
m2l_errors.append("Must have primary strat coding field for geology polygons")

Expand Down
17 changes: 2 additions & 15 deletions map2loop/m2l_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,22 +541,9 @@ def load_and_reproject_dtm(
dataset = memfile.open(**src_params)
dataset.write(nc_data, 1)
elif url.startswith("http"):
# Load open topography dataset as last resort
link = (
"https://portal.opentopography.org/otr/getdem?demtype=SRTMGL3&west="
+ str(tb_ll[0])
+ "&south="
+ str(tb_ll[1])
+ "&east="
+ str(tb_ll[2])
+ "&north="
+ str(tb_ll[3])
+ "&outputFormat=GTiff"
)

if verbose:
print("Attempting to load open topography dtm data from", link)
img = urlopen(link)
print("Attempting to load digital terrin from", url)
img = urlopen(url)
memfile = rasterio.io.MemoryFile(img.read())
dataset = memfile.open()
else:
Expand Down
19 changes: 11 additions & 8 deletions map2loop/mapdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from . import m2l_map_checker
from .m2l_enums import Datatype, Datastate, VerboseLevel
import warnings
from .topology import Topology
from . import m2l_utils, m2l_geometry, m2l_interpolation
import time
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -257,7 +256,7 @@ def check_map(self, datatype: Datatype):
self.data[Datatype.GEOLOGY] = m2l_map_checker.check_geology_map(
self.data[Datatype.GEOLOGY],
self.config.c_l,
self.config.run_flags["drift_prefix"],
self.config.run_flags["ignore_codes"],
_warnings,
_errors,
True,
Expand Down Expand Up @@ -346,7 +345,8 @@ def save_all_map_data(self, output_dir: str, extension: str = ".csv"):
def save_map_data(
self, output_dir: str, datatype: Datatype, extension: str = ".csv"
):
if self.data_states[datatype] == Datastate.CONVERTED:
if (self.data_states[datatype] == Datastate.CONVERTED
or self.data_states[datatype] == Datastate.COMPLETE):
try:
filename = os.path.join(output_dir, datatype.name, extension)
if extension == ".csv":
Expand Down Expand Up @@ -536,7 +536,7 @@ def export_wkt_format_files(self):
sub_lines.columns = ["WKT"] + list(sub_lines.columns[1:])
# Filter cells with a feature description containing the word 'fault'
mask = sub_lines["FEATURE"].str.contains(
"fault", na=False, case=False, regex=True
self.config.c_l["fault"], na=False, case=False, regex=True
)
sub_faults = sub_lines[mask]
sub_faults.to_csv(self.config.fault_filename_wkt, sep="\t", index=False)
Expand Down Expand Up @@ -580,10 +580,13 @@ def load_dtm(self):
time.sleep(1)
i += 1
else:
dtm = m2l_utils.load_and_reproject_dtm(
self.config.polygon, self.working_projection, url=source
)
success = True
try:
dtm = m2l_utils.load_and_reproject_dtm(
self.config.polygon, self.working_projection, url=source
)
success = True
except Exception as e:
warnings.warn(str(e))
if success is False:
raise NameError(
f"map2loop error: Could not access DTM server after {num_attempts} attempts"
Expand Down
7 changes: 7 additions & 0 deletions map2loop/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,9 +500,16 @@ def run(self):
print("ERROR: Error state set at ", self.errorStateMsg)
return

# Add drift_prefix to ignore_codes for ignoring units in geology layer
# TODO: Need to deprecate drift_prefix and remove from notebooks
if (type(self.config.run_flags["drift_prefix"]) == list
and type(self.config.run_flags["ignore_codes"]) == list):
self.config.run_flags["ignore_codes"] = self.config.run_flags["ignore_codes"] + self.config.run_flags["drift_prefix"]

# set orientation/structure data to recreate with dirty flag and unloaded state
# because half way through run process (merge_structure_with geology)
# the geopandas is fundamentally changed which breaks export_wkt_format_files call
# if the process is re-run (ie. run() is called again without __init__ or update_config)
# TODO: Fix so that both version of orientations are possible without reloading the file
self.map_data.data_states[Datatype.STRUCTURE] = Datastate.UNLOADED
self.map_data.dirtyflags[Datatype.STRUCTURE] = True
Expand Down

0 comments on commit 97d26ed

Please sign in to comment.