diff --git a/docs/source/conf.py b/docs/source/conf.py index 3da1d259..23c2d829 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -60,11 +60,7 @@ "myst_parser", ] -source_suffix = { - ".rst": "restructuredtext", - ".txt": "markdown", - ".md": "markdown", -} +source_suffix = {".rst": "restructuredtext", ".txt": "markdown", ".md": "markdown"} # Add any paths that contain templates here, relative to this directory. templates_path = ["_templates"] @@ -84,18 +80,12 @@ "url": "https://github.com/loop3d/map2loop", "icon": "fab fa-github-square", }, - { - "name": "Twitter", - "url": "https://twitter.com/loop3d", - "icon": "fab fa-twitter-square", - }, + {"name": "Twitter", "url": "https://twitter.com/loop3d", "icon": "fab fa-twitter-square"}, ], # "navbar_start": ["navbar-logo", "navbar-version"], # "use_edit_page_button": True, "collapse_navigation": True, - "external_links": [ - {"name": "Loop3d", "url": "https://www.loop3d.org"}, - ], + "external_links": [{"name": "Loop3d", "url": "https://www.loop3d.org"}], } # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. @@ -109,18 +99,14 @@ # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = ["_static"] -autosummary_mock_imports = [ - "LoopStructural.interpolators._cython", -] +autosummary_mock_imports = ["LoopStructural.interpolators._cython"] # Sphinx gallery examples from LoopStructural.visualisation.sphinx_scraper import Scraper as LoopScraper from sphinx_gallery.sorting import ExampleTitleSortKey sphinx_gallery_conf = { "examples_dirs": ["../../examples/"], - "gallery_dirs": [ - "_auto_examples/" - ], # path to where to save gallery generated output + "gallery_dirs": ["_auto_examples/"], # path to where to save gallery generated output "image_scrapers": ("matplotlib", LoopScraper()), "within_subsection_order": ExampleTitleSortKey, "reference_url": {"LoopStructural": None}, diff --git a/examples/plot_hamersley.py b/examples/plot_hamersley.py index 12db3542..7da75baa 100644 --- a/examples/plot_hamersley.py +++ b/examples/plot_hamersley.py @@ -3,11 +3,10 @@ Hamersley, Western Australia ============================ """ + from map2loop.project import Project from map2loop.m2l_enums import VerboseLevel, Datatype -from map2loop.sorter import ( - SorterAlpha, -) +from map2loop.sorter import SorterAlpha from map2loop.sampler import SamplerSpacing #################################################################### diff --git a/map2loop/aus_state_urls.py b/map2loop/aus_state_urls.py index 3c3b10f4..e5de8efb 100644 --- a/map2loop/aus_state_urls.py +++ b/map2loop/aus_state_urls.py @@ -1,4 +1,3 @@ - class AustraliaStateUrls: aus_geology_urls = { "WA": "http://13.211.217.129:8080/geoserver/loop/wfs?service=WFS&version=1.0.0&request=GetFeature&typeName=loop:500k_geol_28350&bbox={BBOX_STR}&srs=EPSG:28350&outputFormat=shape-zip", @@ -8,7 +7,7 @@ class AustraliaStateUrls: "NSW": "http://13.211.217.129:8080/geoserver/NSW/wfs?service=WFS&version=1.1.0&request=GetFeature&typeName=NSW:ge_rockunit_lao2&bbox={BBOX_STR}&srs=EPSG:28355&outputFormat=shape-zip", "ACT": "", "TAS": "http://13.211.217.129:8080/geoserver/TAS/wfs?service=WFS&version=1.1.0&request=GetFeature&typeName=TAS:geol_poly_250_28355&bbox={BBOX_STR}&srs=EPSG:28355&outputFormat=shape-zip", - "NT": "" + "NT": "", } aus_structure_urls = { "WA": "http://13.211.217.129:8080/geoserver/loop/wfs?service=WFS&version=1.1.0&request=GetFeature&typeName=loop:waroxi_wa_28350&bbox={BBOX_STR}&srs=EPSG:28350&outputFormat=shape-zip", @@ -18,7 +17,7 @@ class AustraliaStateUrls: "NSW": "http://13.211.217.129:8080/geoserver/NSW/wfs?service=WFS&version=1.1.0&request=GetFeature&typeName=NSW:lao_struct_pt&bbox={BBOX_STR}&srs=EPSG:28355&outputFormat=shape-zip", "ACT": "", "TAS": "http://13.211.217.129:8080/geoserver/TAS/wfs?service=WFS&version=1.1.0&request=GetFeature&typeName=TAS:geol_struc_250_28355&bbox={BBOX_STR}&srs=EPSG:28355&outputFormat=shape-zip", - "NT": "" + "NT": "", } aus_fault_urls = { "WA": "http://13.211.217.129:8080/geoserver/loop/wfs?service=WFS&version=1.1.0&request=GetFeature&typeName=loop:500k_faults_28350&bbox={BBOX_STR}&srs=EPSG:28350&outputFormat=shape-zip", @@ -28,7 +27,7 @@ class AustraliaStateUrls: "NSW": "http://13.211.217.129:8080/geoserver/NSW/wfs?service=WFS&version=1.1.0&request=GetFeature&typeName=NSW:faults_joined_left_contains_drop_dups&bbox={BBOX_STR}&srs=EPSG:28355&outputFormat=shape-zip", "ACT": "", "TAS": "http://13.211.217.129:8080/geoserver/TAS/wfs?service=WFS&version=1.1.0&request=GetFeature&typeName=TAS:geol_line_250_28355&bbox={BBOX_STR}&srs=EPSG:28355&outputFormat=shape-zip", - "NT": "" + "NT": "", } aus_fold_urls = { "WA": "http://13.211.217.129:8080/geoserver/loop/wfs?service=WFS&version=1.1.0&request=GetFeature&typeName=loop:500k_faults_28350&bbox={BBOX_STR}&srs=EPSG:28350&outputFormat=shape-zip", @@ -38,7 +37,7 @@ class AustraliaStateUrls: "NSW": "http://13.211.217.129:8080/geoserver/NSW/wfs?service=WFS&version=1.1.0&request=GetFeature&typeName=NSW:folds_lao&bbox={BBOX_STR}&srs=EPSG:28355&outputFormat=shape-zip", "ACT": "", "TAS": "http://13.211.217.129:8080/geoserver/TAS/wfs?service=WFS&version=1.1.0&request=GetFeature&typeName=TAS:geol_line_250_28355&bbox={BBOX_STR}&srs=EPSG:28355&outputFormat=shape-zip", - "NT": "" + "NT": "", } aus_mindep_loopdata = { "WA": "http://13.211.217.129:8080/geoserver/loop/wfs?service=WFS&version=1.0.0&request=GetFeature&typeName=loop:mindeps_2018_28350&bbox={BBOX_STR}&srs=EPSG:28350&outputFormat=shape-zip", @@ -48,7 +47,7 @@ class AustraliaStateUrls: "NSW": "http://13.211.217.129:8080/geoserver/NSW/wfs?service=WFS&version=1.1.0&request=GetFeature&typeName=NSW:nsw_mindeps&bbox={BBOX_STR}&srs=EPSG:28355&outputFormat=shape-zip", "ACT": "", "TAS": "http://13.211.217.129:8080/geoserver/VIC/wfs?service=WFS&version=1.0.0&request=GetFeature&typeName=VIC:mindeps_2018_28350&bbox={BBOX_STR}&srs=EPSG:28350&outputFormat=shape-zip", - "NT": "" + "NT": "", } aus_config_urls = { "WA": "https://gist.githubusercontent.com/yohanderose/8f843de0dde531f009a3973cbdadcc9f/raw/cad97e91a71b4e4791629a6d384e2700095eb3b6/WA_meta.hjson", @@ -58,7 +57,7 @@ class AustraliaStateUrls: "NSW": "https://gist.githubusercontent.com/markjessell/0bcb02e6f3ae6da9f00f299b5f0a7f77/raw/09c8018e2d92c7f0051a45be4f9e19dc7cd9a30c/NSW.hjson", "ACT": "", "TAS": "https://gist.githubusercontent.com/markjessell/e6521f0d0b7a29014deb04996033554f/raw/296c364b618a49654e18eba10196fa3cc2aabd2f/TAS.hjson", - "NT": "" + "NT": "", } aus_clut_urls = { "WA": "https://gist.githubusercontent.com/yohanderose/8f7e2d57db9086fbe1a7c651b9e25996/raw/9144994d162662ec015321699c3658a8dbf57def/WA_clut.csv", @@ -68,5 +67,5 @@ class AustraliaStateUrls: "NSW": "", "ACT": "", "TAS": "", - "NT": "" + "NT": "", } diff --git a/map2loop/config.py b/map2loop/config.py index 72941c78..2b8dd144 100644 --- a/map2loop/config.py +++ b/map2loop/config.py @@ -18,53 +18,54 @@ class Config: fold_config: dict column names and keywords for fold mappings """ + def __init__(self): self.structure_config = { - "orientation_type": "dip direction", - "dipdir_column": "DIPDIR", - "dip_column": "DIP", - "description_column": "DESCRIPTION", - "bedding_text": "bedding", - "overturned_column": "DESCRIPTION", - "overturned_text": "overturned", - "objectid_column": "ID" - } + "orientation_type": "dip direction", + "dipdir_column": "DIPDIR", + "dip_column": "DIP", + "description_column": "DESCRIPTION", + "bedding_text": "bedding", + "overturned_column": "DESCRIPTION", + "overturned_text": "overturned", + "objectid_column": "ID", + } self.geology_config = { - "unitname_column": "UNITNAME", - "alt_unitname_column": "CODE", - "group_column": "GROUP", - "supergroup_column": "SUPERGROUP", - "description_column": "DESCRIPTION", - "minage_column": "MIN_AGE", - "maxage_column": "MAX_AGE", - "rocktype_column": "ROCKTYPE1", - "alt_rocktype_column": "ROCKTYPE2", - "sill_text": "sill", - "intrusive_text": "intrusive", - "volcanic_text": "volcanic", - "objectid_column": "ID", - "ignore_codes": ["cover"] - } + "unitname_column": "UNITNAME", + "alt_unitname_column": "CODE", + "group_column": "GROUP", + "supergroup_column": "SUPERGROUP", + "description_column": "DESCRIPTION", + "minage_column": "MIN_AGE", + "maxage_column": "MAX_AGE", + "rocktype_column": "ROCKTYPE1", + "alt_rocktype_column": "ROCKTYPE2", + "sill_text": "sill", + "intrusive_text": "intrusive", + "volcanic_text": "volcanic", + "objectid_column": "ID", + "ignore_codes": ["cover"], + } self.fault_config = { - "structtype_column": "FEATURE", - "fault_text": "fault", - "dip_null_value": "-999", - "dipdir_flag": "num", - "dipdir_column": "DIPDIR", - "dip_column": "DIP", - "dipestimate_column": "DIP_ESTIMATE", - "dipestimate_text": "'NORTH_EAST','NORTH',,'NOT ACCESSED'", - "name_column": "NAME", - "objectid_column": "ID" - } + "structtype_column": "FEATURE", + "fault_text": "fault", + "dip_null_value": "-999", + "dipdir_flag": "num", + "dipdir_column": "DIPDIR", + "dip_column": "DIP", + "dipestimate_column": "DIP_ESTIMATE", + "dipestimate_text": "'NORTH_EAST','NORTH',,'NOT ACCESSED'", + "name_column": "NAME", + "objectid_column": "ID", + } self.fold_config = { - "structtype_column": "FEATURE", - "fold_text": "fold", - "description_column": "DESCRIPTION", - "synform_text": "syncline", - "foldname_column": "NAME", - "objectid_column": "ID" - } + "structtype_column": "FEATURE", + "fold_text": "fold", + "description_column": "DESCRIPTION", + "synform_text": "syncline", + "foldname_column": "NAME", + "objectid_column": "ID", + } @beartype.beartype def update_from_dictionary(self, dictionary: dict, lower: bool = False): diff --git a/map2loop/map2model_wrapper.py b/map2loop/map2model_wrapper.py index 20273081..7d891f4e 100644 --- a/map2loop/map2model_wrapper.py +++ b/map2loop/map2model_wrapper.py @@ -6,7 +6,7 @@ import re -class Map2ModelWrapper(): +class Map2ModelWrapper: """ A wrapper around map2model functionality @@ -25,6 +25,7 @@ class Map2ModelWrapper(): verbose_level: m2l_enum.VerboseLevel A selection that defines how much console logging is output """ + def __init__(self, map_data, verbose_level: VerboseLevel = VerboseLevel.NONE): """ The initialiser for the map2model wrapper @@ -139,7 +140,7 @@ def run(self, verbose_level: VerboseLevel = None): self.map_data.get_bounding_box(), map2model_code_map, verbose_level == VerboseLevel.NONE, - "None" + "None", ) if verbose_level == VerboseLevel.ALL: print("map2model log:") @@ -148,7 +149,11 @@ def run(self, verbose_level: VerboseLevel = None): print("map2model complete") # Parse units sorted - units_sorted = pandas.read_csv(os.path.join(self.map_data.tmp_path, "map2model_data", "units_sorted.txt"), header=None, sep=' ') + units_sorted = pandas.read_csv( + os.path.join(self.map_data.tmp_path, "map2model_data", "units_sorted.txt"), + header=None, + sep=' ', + ) if units_sorted.shape == 0: self.sorted_units = [] else: @@ -156,13 +161,14 @@ def run(self, verbose_level: VerboseLevel = None): # Parse fault intersections out = [] - fault_fault_intersection_filename = os.path.join(self.map_data.tmp_path, "map2model_data", "fault-fault-intersection.txt") - if os.path.isfile(fault_fault_intersection_filename) and os.path.getsize(fault_fault_intersection_filename) > 0: - df = pandas.read_csv( - fault_fault_intersection_filename, - delimiter="{", - header=None, - ) + fault_fault_intersection_filename = os.path.join( + self.map_data.tmp_path, "map2model_data", "fault-fault-intersection.txt" + ) + if ( + os.path.isfile(fault_fault_intersection_filename) + and os.path.getsize(fault_fault_intersection_filename) > 0 + ): + df = pandas.read_csv(fault_fault_intersection_filename, delimiter="{", header=None) df[1] = list(df[1].str.replace("}", "", regex=False)) df[1] = [re.findall("\(.*?\)", i) for i in df[1]] # Valid escape for regex df[0] = list(df[0].str.replace("^[0-9]*, ", "", regex=True)) @@ -173,15 +179,20 @@ def run(self, verbose_level: VerboseLevel = None): for _, row in df.iterrows(): for i in numpy.arange(len(row[1])): - out += [[row[0], "Fault_"+row[1][i][0], row[1][i][1], float(row[1][i][2])]] + out += [[row[0], "Fault_" + row[1][i][0], row[1][i][1], float(row[1][i][2])]] df_out = pandas.DataFrame(columns=["Fault1", "Fault2", "Type", "Angle"], data=out) self.fault_fault_relationships = df_out # Parse unit fault relationships out = [] - unit_fault_intersection_filename = os.path.join(self.map_data.tmp_path, "map2model_data", "unit-fault-intersection.txt") - if os.path.isfile(unit_fault_intersection_filename) and os.path.getsize(unit_fault_intersection_filename) > 0: + unit_fault_intersection_filename = os.path.join( + self.map_data.tmp_path, "map2model_data", "unit-fault-intersection.txt" + ) + if ( + os.path.isfile(unit_fault_intersection_filename) + and os.path.getsize(unit_fault_intersection_filename) > 0 + ): df = pandas.read_csv(unit_fault_intersection_filename, header=None, sep='{') df[1] = list(df[1].str.replace("}", "", regex=False)) df[1] = df[1].astype(str).str.split(", ") @@ -190,7 +201,7 @@ def run(self, verbose_level: VerboseLevel = None): for _, row in df.iterrows(): for i in numpy.arange(len(row[1])): - out += [[row[0], "Fault_"+row[1][i]]] + out += [[row[0], "Fault_" + row[1][i]]] df_out = pandas.DataFrame(columns=["Unit", "Fault"], data=out) self.unit_fault_relationships = df_out @@ -198,9 +209,13 @@ def run(self, verbose_level: VerboseLevel = None): # Parse unit unit relationships units = [] links = [] - graph_filename = os.path.join(self.map_data.tmp_path, "map2model_data", "graph_all_None.gml.txt") + graph_filename = os.path.join( + self.map_data.tmp_path, "map2model_data", "graph_all_None.gml.txt" + ) if os.path.isfile(graph_filename) and os.path.getsize(graph_filename) > 0: - with open(os.path.join(self.map_data.tmp_path, "map2model_data", "graph_all_None.gml.txt")) as file: + with open( + os.path.join(self.map_data.tmp_path, "map2model_data", "graph_all_None.gml.txt") + ) as file: contents = file.read() segments = contents.split("\n\n") for line in segments[0].split("\n"): diff --git a/map2loop/sampler.py b/map2loop/sampler.py index 8d9d284f..ca5c6f66 100644 --- a/map2loop/sampler.py +++ b/map2loop/sampler.py @@ -13,6 +13,7 @@ class Sampler(ABC): Args: ABC (ABC): Derived from Abstract Base Class """ + def __init__(self): """ Initialiser of for Sampler @@ -49,6 +50,7 @@ class SamplerDecimator(Sampler): ie. decimation = 10 means take every tenth point Note: This only works on data frames with lists of points with columns "X" and "Y" """ + @beartype.beartype def __init__(self, decimation: int = 1): """ @@ -76,7 +78,7 @@ def sample(self, map_data: geopandas.GeoDataFrame) -> pandas.DataFrame: data["X"] = data.geometry.x data["Y"] = data.geometry.y data.reset_index(drop=True, inplace=True) - return pandas.DataFrame(data[::self.decimation].drop(columns="geometry")) + return pandas.DataFrame(data[:: self.decimation].drop(columns="geometry")) class SamplerSpacing(Sampler): @@ -86,6 +88,7 @@ class SamplerSpacing(Sampler): ie. spacing = 500 means take a sample every 500 metres Note: This only works on data frames that contain MultiPolgon, Polygon, MultiLineString and LineString geometry """ + @beartype.beartype def __init__(self, spacing: float = 50.0): """ diff --git a/map2loop/thickness_calculator.py b/map2loop/thickness_calculator.py index 7dcb278b..19f1c8f9 100644 --- a/map2loop/thickness_calculator.py +++ b/map2loop/thickness_calculator.py @@ -104,9 +104,9 @@ def compute( stratigraphic_order[i] in basal_unit_list and stratigraphic_order[i + 1] in basal_unit_list ): - contact1 = basal_contacts[ - basal_contacts["basal_unit"] == stratigraphic_order[i] - ]["geometry"].to_list()[0] + contact1 = basal_contacts[basal_contacts["basal_unit"] == stratigraphic_order[i]][ + "geometry" + ].to_list()[0] contact2 = basal_contacts[ basal_contacts["basal_unit"] == stratigraphic_order[i + 1] ]["geometry"].to_list()[0] @@ -126,9 +126,7 @@ def compute( # Maximum thickness is the horizontal distance between the minimum of these distances # Find row in unit_dataframe corresponding to unit and replace thickness value if it is -1 or larger than distance - idx = thicknesses.index[ - thicknesses["name"] == stratigraphic_order[i] - ].tolist()[0] + idx = thicknesses.index[thicknesses["name"] == stratigraphic_order[i]].tolist()[0] if thicknesses.loc[idx, "thickness"] == -1: val = distance @@ -145,7 +143,6 @@ def compute( # For any unit thickness that still hasn't been calculated (i.e. at -1) set to # the mean thickness of the other units thicknesses["thickness"] = thicknesses.apply( - lambda row: mean_thickness if row["thickness"] == -1 else row["thickness"], - axis=1, + lambda row: mean_thickness if row["thickness"] == -1 else row["thickness"], axis=1 ) return thicknesses diff --git a/map2loop/throw_calculator.py b/map2loop/throw_calculator.py index 5dd00856..96ca4605 100644 --- a/map2loop/throw_calculator.py +++ b/map2loop/throw_calculator.py @@ -12,6 +12,7 @@ class ThrowCalculator(ABC): Args: ABC (ABC): Derived from Abstract Base Class """ + def __init__(self): """ Initialiser of for Sorter @@ -29,7 +30,13 @@ def type(self): @beartype.beartype @abstractmethod - def compute(self, faults: pandas.DataFrame, stratigraphic_order: list, basal_contacts: geopandas.GeoDataFrame, map_data: MapData) -> pandas.DataFrame: + def compute( + self, + faults: pandas.DataFrame, + stratigraphic_order: list, + basal_contacts: geopandas.GeoDataFrame, + map_data: MapData, + ) -> pandas.DataFrame: """ Execute throw calculator method (abstract method) @@ -49,6 +56,7 @@ class ThrowCalculatorAlpha(ThrowCalculator): """ ThrowCalculator class which estimates fault throw values based on units, basal_contacts and stratigraphic order """ + def __init__(self): """ Initialiser for alpha version of the throw calculator @@ -56,7 +64,13 @@ def __init__(self): self.throw_calculator_label = "ThrowCalculatorAlpha" @beartype.beartype - def compute(self, faults: pandas.DataFrame, stratigraphic_order: list, basal_contacts: pandas.DataFrame, map_data: MapData) -> pandas.DataFrame: + def compute( + self, + faults: pandas.DataFrame, + stratigraphic_order: list, + basal_contacts: pandas.DataFrame, + map_data: MapData, + ) -> pandas.DataFrame: """ Execute throw calculator method takes fault data, basal_contacts and stratigraphic order and attempts to estimate fault throw. @@ -79,5 +93,7 @@ def compute(self, faults: pandas.DataFrame, stratigraphic_order: list, basal_con # unit (if we exclude map height changes and fault angle) # Set any remaining displacement values to default value - faults["avgDisplacement"] = faults.apply(lambda row: 100 if row["avgDisplacement"] == -1 else row["avgDisplacement"], axis=1) + faults["avgDisplacement"] = faults.apply( + lambda row: 100 if row["avgDisplacement"] == -1 else row["avgDisplacement"], axis=1 + ) return faults