Skip to content

Commit

Permalink
v2.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
fbordignon committed Aug 7, 2024
1 parent e5c64f5 commit e55f2dd
Show file tree
Hide file tree
Showing 265 changed files with 14,477 additions and 8,023 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "src/submodules/pyedt"]
path = src/submodules/pyedt
url = git@github.com:ltracegeo/pyedt.git
[submodule "src/submodules/porespy"]
path = src/submodules/porespy
url = git@github.com:ltracegeo/porespy.git
Expand Down
11 changes: 10 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,26 @@ authorized_licenses = [
"BSD-3-clause",
"BSD 3-Clause",
"BSD License",
"CC-BY",
"GNU Library or Lesser General Public License (LGPL)",
"GNU Lesser General Public License v2 or later (LGPLv2+)",
"ISC License (ISCL)",
"LGPL",
"LGPL-3.0",
"MIT",
"MIT License",
"Mozilla Public License 2.0 (MPL 2.0)",
"new BSD",
"OSI Approved",
"Python Software Foundation",
"Historical Permission Notice and Disclaimer (HPND)",
"Other/Proprietary"
]
unauthorized_licenses = [
"GNU General Public License v3 (GPLv3)"
]
[tool.liccheck.authorized_packages]
# The packages below are listed as "Other/Proprietary"
# They use Intel licenses that allow distribution
mkl = ">=2022.2.1"
tbb = ">=2021.12.0"
intel-openmp = ">=2022.2.1"
21 changes: 15 additions & 6 deletions src/ltrace/ltrace/algorithms/detect_cups.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,18 @@ def detect_rock_cylinder(array):
PADDING = 15


def find_suitable_null_value(array):
if np.issubdtype(array.dtype, np.floating):
return int(array.min()) - 1
if np.issubdtype(array.dtype, np.signedinteger):
return array.min() - 1
if np.issubdtype(array.dtype, np.unsignedinteger):
return 0


def crop_cylinder(array, cylinder):
x, y, r, z_min, z_max = cylinder
min_ = array.min()
null_value = np.array(find_suitable_null_value(array)).astype(array.dtype)
x_min, x_max = round(x - r), round(x + r)
y_min, y_max = round(y - r), round(y + r)
z_min, z_max = round(z_min), round(z_max)
Expand All @@ -178,10 +187,10 @@ def crop_cylinder(array, cylinder):
dist = np.sqrt((xx - r) ** 2 + (yy - r) ** 2)
mask = dist <= r
mask = mask[np.newaxis, ...]
array = (array * mask) + (~mask * min_)
array = (array * mask) + (~mask * null_value)

array = np.pad(array, ((0, 0), (PADDING, PADDING), (PADDING, PADDING)), mode="constant", constant_values=min_)
return array
array = np.pad(array, ((0, 0), (PADDING, PADDING), (PADDING, PADDING)), mode="constant", constant_values=null_value)
return array, null_value


def get_origin_offset(cylinder):
Expand Down Expand Up @@ -314,10 +323,10 @@ def full_detect(array, callback=lambda *args: None):
logging.debug(f"x, y, r, z0, z1 = {cylinder}")

callback(50, "Cropping cylinder")
rock = crop_cylinder(array, cylinder)
rock, null_value = crop_cylinder(array, cylinder)
callback(70, "Detecting cups")
cup_left, cup_right = isolated_cups_slice(array, cylinder)
refs = detect_cups_from_sides(cup_left, cup_right)
if refs:
logging.debug(f"(Q - T) / (A - T) = {quartz_ratio(refs)}")
return rock, refs, cylinder
return rock, null_value, refs, cylinder
5 changes: 1 addition & 4 deletions src/ltrace/ltrace/algorithms/supervised/mrcnn/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -849,11 +849,8 @@ def download_trained_weights(coco_model_path, verbose=1):
"""
if verbose > 0:
print("Downloading pretrained model to " + coco_model_path + " ...")
with open(coco_model_path, "wb") as out:
resp = urllib.request.urlopen(COCO_MODEL_URL)
with urllib.request.urlopen(COCO_MODEL_URL) as resp, open(coco_model_path, "wb") as out:
shutil.copyfileobj(resp, out)
resp.close()

if verbose > 0:
print("... done downloading pretrained model!")

Expand Down
3,772 changes: 0 additions & 3,772 deletions src/ltrace/ltrace/assets/trained_models/ca-bundle.crt

This file was deleted.

58 changes: 33 additions & 25 deletions src/ltrace/ltrace/assets_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,65 @@
import json


ROOT = Path(__file__).resolve().absolute().parent / "assets"
PUBLIC = ROOT / "public"
PRIVATE = ROOT / "private"


def get_asset(asset_name):
"""Returns the asset's absolute Path given a relative path from this dir."""
"""Returns the asset's absolute Path given a relative path from either public or private dir.
Do not include 'public' or 'private' in the path.
"""
if isinstance(asset_name, str):
asset_name = Path(asset_name)

absolute_path = Path(__file__).resolve().absolute().parent / "assets" / asset_name
if not absolute_path.exists():
raise RuntimeError("Invalid asset: {}".format(absolute_path))

return absolute_path
private_path = PRIVATE / asset_name
if private_path.exists():
return private_path

public_path = PUBLIC / asset_name
if public_path.exists():
return public_path

def get_trained_model(model_name):
return get_asset(Path("trained_models") / Path(model_name))
return None


def get_trained_models(environment=None):
models_path = Path(__file__).resolve().absolute().parent / "assets" / "trained_models"

if environment:
models_path = models_path / environment
def get_trained_models(environment):
models_path = Path(__file__).resolve().absolute().parent / "assets" / "models"

extensions = [".h5", ".pth"]
models = [file for file in models_path.glob("**/*") if file.suffix in extensions]
models = []
for root_path in (PUBLIC, PRIVATE):
models_path = root_path / environment
models += [file for file in models_path.glob("**/*") if file.suffix in extensions]
return models


def get_trained_models_with_metadata(environment):
models_path = Path(__file__).resolve().absolute().parent / "assets" / "trained_models"
models_path = models_path / environment

models = []
for subdir in models_path.iterdir():
if not subdir.is_dir():
for root_path in (PUBLIC, PRIVATE):
models_path = root_path / environment
if not models_path.is_dir():
continue
base = subdir.name
pth = subdir / f"{base}.pth"
for subdir in models_path.iterdir():
if not subdir.is_dir():
continue
base = subdir.name
pth = subdir / f"model.pth"

assert pth.exists(), f"Directory {base} exists but file {pth} does not exist"
assert pth.exists(), f"Directory {base} exists but file {pth} does not exist"

models.append(subdir)
models.append(subdir)
return models


def get_metadata(model_dir):
model_dir = Path(model_dir)
with open(model_dir / f"{model_dir.name}.json") as f:
with open(model_dir / f"meta.json") as f:
metadata = json.load(f)
return metadata


def get_pth(model_dir):
model_dir = Path(model_dir)
return model_dir / f"{model_dir.name}.pth"
return model_dir / f"model.pth"
11 changes: 11 additions & 0 deletions src/ltrace/ltrace/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,14 @@ class ImageLogConst:

# The default layout ID value for the ImageLogData module.
DEFAULT_LAYOUT_ID_START_VALUE = 15000


class ImageLogInpaintConst:
"""
Constants for ImageLogInpaint module
"""

SEGMENT_ID = "Segment_1"
TEMP_SEGMENTATION_NAME = "Inpaint_Segmentation_ImageLog"
TEMP_LABEL_MAP_NAME = "Inpaint_Mask_ImageLog"
TEMP_VOLUME_NAME = "Inpaint_Volume_ImageLog"
3 changes: 0 additions & 3 deletions src/ltrace/ltrace/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ def detect_csv_file_delimiter(filepath, encoding, whitelist=[",", ";"]):
# read in non binary with encoding, to detect delimiter
with open(filepath, "r", encoding=encoding) as file:
data = file.readlines(50)
if not data:
return None

counters = {}
for delimiter in whitelist:
count = number_of_delimiters_per_line(data, delimiter)
Expand Down
4 changes: 2 additions & 2 deletions src/ltrace/ltrace/image/core_box/core_boxes_image_file.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections import namedtuple
from ltrace.assets_utils import get_trained_model
from ltrace.assets_utils import get_asset
from ltrace.image.core_box.core_box import CoreBox
from ltrace.slicer.helpers import concatenateImageArrayVertically, resizeRgbArray
from ltrace.units import safe_atof
Expand Down Expand Up @@ -306,7 +306,7 @@ def __extract_cores_info(self, img):
from ltrace.image.segmentation import TF_RGBImageArrayBinarySegmenter

CoreBoxesImageFile.BinarySegmenterModel = TF_RGBImageArrayBinarySegmenter(
get_trained_model("unet-binary-segop.h5"), gpuEnabled=self.__gpuEnabled
get_asset("unet-binary-segop.h5"), gpuEnabled=self.__gpuEnabled
)

for core_cut in self.__split_cores(img, number_of_cores):
Expand Down
Loading

0 comments on commit e55f2dd

Please sign in to comment.