Skip to content
Merged
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [3.1.8](https://github.com/Loop3D/map2loop/compare/v3.1.7...v3.1.8) (2024-06-20)


### Bug Fixes

* pin LPF to 0.1.3 ([f3766a8](https://github.com/Loop3D/map2loop/commit/f3766a83d0f09f293429cc975933cbf79b01c5a2))

## [3.1.7](https://github.com/Loop3D/map2loop/compare/v3.1.6...v3.1.7) (2024-06-18)


Expand Down
3 changes: 0 additions & 3 deletions conda/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ requirements:
- numpy
- geopandas
- map2model
- hjson
- loopprojectfile
- beartype
- owslib
Expand All @@ -30,7 +29,6 @@ requirements:
- pandas
- geopandas
- map2model
- hjson
- loopprojectfile
- beartype
- owslib
Expand All @@ -40,7 +38,6 @@ test:
- map2loop
- geopandas
- map2model
- hjson
- loopprojectfile
- beartype
- owslib
Expand Down
2 changes: 1 addition & 1 deletion dependencies.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ networkx
owslib
map2model
hjson
loopprojectfile>=0.1.3
loopprojectfile==0.1.3
beartype
55 changes: 40 additions & 15 deletions map2loop/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import urllib.error
import beartype
import hjson
import json
import urllib
import time
import pathlib
Expand Down Expand Up @@ -188,8 +189,9 @@ def update_from_file(
Update the config dictionary from the provided json filename or url

Args:
filename (str): Filename or URL of the JSON config file
filename (Union[pathlib.Path, str]): Filename or URL of the JSON config file
legacy_format (bool, optional): Whether the JSON is an old version. Defaults to False.
lower (bool, optional): convert keys to lowercase. Defaults to False.
"""
if legacy_format:
func = self.update_from_legacy_file
Expand All @@ -199,26 +201,49 @@ def update_from_file(
try:
filename = str(filename)

#if url, open the url
if filename.startswith("http") or filename.startswith("ftp"):
try_count = 10
try_count = 5
success = False
while try_count >= 0 and not success:
# try 5 times to access the URL
while try_count > 0 and not success:
try:
with urllib.request.urlopen(filename) as url_data:
data = hjson.load(url_data)
data = json.load(url_data)
func(data, lower)
success = True
except Exception as e:
# Catch a failed online access or file load, re-attempt
# a few times before throwing further

#case 1. handle url error
except urllib.error.URLError as e:
# wait 0.25 seconds before trying again
time.sleep(0.25)
try_count = try_count - 1
if try_count < 0:
raise e
# decrease the number of tries by 1
try_count -= 1
# if no more tries left, raise the error
if try_count <= 0:
raise urllib.error.URLError(f"Failed to access URL after multiple attempts: {filename}") from e

# case 2. handle json error
except json.JSONDecodeError as e:
raise json.JSONDecodeError(
f"Error decoding JSON data from URL: {filename}") from e
else:
with open(filename) as url_data:
data = hjson.load(url_data)
func(data, lower)
try:
with open(filename) as file_data:
data = json.load(file_data)
func(data, lower)
except FileNotFoundError as e:
err_string = f"The specified config file does not exist ({filename}).\n"
err_string += "Please check the file exists and is accessible, then try again.\n"
raise FileNotFoundError(err_string) from e
except json.JSONDecodeError as e:
raise json.JSONDecodeError(
f"Error decoding JSON data from file: {filename}"
) from e

except FileNotFoundError:
raise

except Exception:
err_string = f"There is a problem parsing the config file ({filename}).\n"
if filename.startswith("http"):
Expand All @@ -228,4 +253,4 @@ def update_from_file(
if not legacy_format:
err_string += "Also check if this is a legacy config file and add clut_file_legacy=True to the Project function\n"
err_string += "Check the contents for mismatched quotes or brackets!"
raise Exception(err_string)
raise Exception(err_string)
2 changes: 1 addition & 1 deletion map2loop/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "3.1.7"
__version__ = "3.1.8"
2 changes: 0 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ def get_description():
"pandas",
"geopandas",
"shapely",
"tqdm",
"networkx",
"owslib",
"hjson",
"loopprojectfile",
"map2model",
"beartype",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from map2loop.sampler import SamplerSpacing, SamplerDecimator
from map2loop.m2l_enums import Datatype
import map2loop
import numpy


def create_raster(output_path, bbox, epsg, pixel_size, value=100):
Expand Down Expand Up @@ -272,6 +273,7 @@ def test_compute(
result = interpolated_structure_thickness.compute(
units, stratigraphic_order, basal_contacts, samples, map_data
)

assert (
interpolated_structure_thickness.thickness_calculator_label == "InterpolatedStructure"
), 'Thickness_calc interpolated structure not being set properly'
Expand All @@ -284,11 +286,11 @@ def test_compute(
assert (
'ThicknessMean' in result.columns
), 'Thickness not being calculated in InterpolatedStructure calculator'
assert result['ThicknessMedian'].dtypes == float, 'ThicknessMedian column is not float'
assert result['ThicknessMedian'].dtypes == numpy.float64, 'ThicknessMedian column is not float'
assert (
'ThicknessStdDev' in result.columns
), 'Thickness std not being calculated in InterpolatedStructure calculator'
assert result['ThicknessStdDev'].dtypes == float, 'ThicknessStdDev column is not float'
assert result['ThicknessStdDev'].dtypes == numpy.float64, 'ThicknessStdDev column is not float'

# check for nas in thickness
assert result['ThicknessMedian'].isna().sum() == 0, 'ThicknessMedian column has NaNs'