Skip to content

Commit 7641e2e

Browse files
authored
Merge pull request #42 from Loop3D/fix_thicknesses
feat: added thickness calculator fields
2 parents e793d88 + b9abf4c commit 7641e2e

File tree

11 files changed

+261
-180
lines changed

11 files changed

+261
-180
lines changed

.github/workflows/release.yml

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,36 @@ permissions:
66
pull-requests: write
77

88
jobs:
9-
# linting:
10-
# name: Linting
11-
# runs-on: ubuntu-latest
12-
# steps:
13-
# - uses: actions/checkout@v4
14-
# - name: Install dependencies
15-
# run: |
16-
# python -m pip install --upgrade pip
17-
# pip install black ruff
18-
# - name: Autoformat with black
19-
# run: |
20-
# black .
21-
# - name: Lint with ruff
22-
# run: |
23-
# ruff check LoopProjectFile --fix
24-
# - uses: stefanzweifel/git-auto-commit-action@v5
25-
# with:
26-
# commit_message: "style: style fixes by ruff and autoformatting by black"
27-
9+
linting:
10+
name: Linting
11+
runs-on: ubuntu-24.04
12+
steps:
13+
- uses: actions/checkout@v4
14+
- name: Install dependencies
15+
run: |
16+
python -m pip install --upgrade pip
17+
pip install black ruff
18+
- name: Autoformat with black
19+
run: |
20+
black .
21+
- name: Lint with ruff
22+
run: |
23+
ruff check . --fix
24+
- name: Check for local changes
25+
run: |
26+
if [ -n "$(git status --porcelain)" ]; then
27+
git config --global user.name "github-actions[bot]"
28+
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
29+
git add .
30+
git commit -m "style: style fixes by ruff and autoformatting by black"
31+
fi
32+
- uses: stefanzweifel/git-auto-commit-action@v5
33+
with:
34+
commit_message: "style: style fixes by ruff and autoformatting by black"
2835

2936
pip-build-sdist:
3037
name: Build SDist
31-
runs-on: ubuntu-latest
38+
runs-on: ubuntu-24.04
3239
steps:
3340
- uses: actions/checkout@v4
3441

@@ -46,7 +53,7 @@ jobs:
4653
pip-test-sdist:
4754
name: Test sdist
4855
needs: pip-build-sdist
49-
runs-on: ubuntu-latest
56+
runs-on: ubuntu-24.04
5057
steps:
5158
- name: Download sdist from artifacts
5259
uses: actions/download-artifact@v4
@@ -70,7 +77,7 @@ jobs:
7077
fail-fast: false
7178
matrix:
7279
os:
73-
- ubuntu-latest
80+
- ubuntu-24.04
7481
- macos-latest
7582
- windows-latest
7683

@@ -98,13 +105,13 @@ jobs:
98105
fail-fast: false
99106
matrix:
100107
os:
101-
- ubuntu-latest
108+
- ubuntu-24.04
102109
- macos-latest
103110
- windows-latest
104111
python-version: ["3.9", "3.10", "3.11", "3.12"]
105112
include:
106-
- os: "ubuntu-latest"
107-
artifact: loopprojectfile-wheels-ubuntu-latest
113+
- os: "ubuntu-24.04"
114+
artifact: loopprojectfile-wheels-ubuntu-24.04
108115
- os: "macos-latest"
109116
artifact: loopprojectfile-wheels-macos-latest
110117
- os: "windows-latest"
@@ -146,7 +153,7 @@ jobs:
146153
fail-fast: false
147154
matrix:
148155
os:
149-
- ubuntu-latest
156+
- ubuntu-24.04
150157
- macos-latest
151158
- windows-latest
152159
python-version: ["3.9", "3.10", "3.11", "3.12"]
@@ -195,7 +202,7 @@ jobs:
195202

196203
release-please:
197204
needs: [pip-test-wheels, conda-build]
198-
runs-on: ubuntu-latest
205+
runs-on: ubuntu-24.04
199206
if: github.ref == 'refs/heads/master'
200207
steps:
201208
- uses: actions/checkout@v4

LoopProjectFile/DataCollection.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ def CreateObservationGroup(dataCollectionGroup):
7979
obGroup.createDimension("foldObservationIndex", None)
8080
obGroup.createDimension("foliationObservationIndex", None)
8181
obGroup.createDimension("discontinuityObservationIndex", None)
82-
obGroup.createDimension("stratigraphicObservationIndex", None)
82+
obGroup.createDimension("stratigraphicObservationIndex", None)
83+
8384
faultObservationType_t = obGroup.createCompoundType(
8485
LoopProjectFile.faultObservationType, "FaultObservation"
8586
)

LoopProjectFile/Extents.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# import netCDF4
22

3-
43
# Check extents of Loop Project File is valid
54
def CheckExtentsValid(rootGroup, xyzGridSize, verbose=False):
65
"""

LoopProjectFile/ExtractedInformation.py

Lines changed: 113 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import LoopProjectFile
33
import LoopProjectFile.LoopProjectFileUtils as LoopProjectFileUtils
44

5-
# import numpy
65

76

87
# Check Extracted Information valid if present
@@ -51,6 +50,14 @@ def GetStratigraphicInformationGroup(rootGroup, verbose=False):
5150
)
5251

5352

53+
def GetStratigraphicThicknessGroup(rootGroup, verbose=False):
54+
resp = GetExtractedInformationGroup(rootGroup, verbose)
55+
if resp["errorFlag"]:
56+
return resp
57+
else:
58+
return LoopProjectFileUtils.GetGroup(resp["value"], "StratigraphicThickness", verbose)
59+
60+
5461
def GetDrillholeDescriptionGroup(rootGroup, verbose=False):
5562
resp = GetExtractedInformationGroup(rootGroup, verbose)
5663
if resp["errorFlag"]:
@@ -255,8 +262,12 @@ def GetDiscontinuityLog(root, indexList=[], indexRange=(0, 0), verbose=False):
255262
)
256263

257264

258-
# Set stratigraphic log
259-
def SetStratigraphicLog(root, data, append=False, verbose=False):
265+
def SetStratigraphicLog(
266+
root,
267+
data,
268+
append=False,
269+
verbose=False
270+
):
260271
"""
261272
**SetStratigraphicLog** - Saves a list of strata in (formation,
262273
thickness) format into the netCDF Loop Project File
@@ -267,15 +278,19 @@ def SetStratigraphicLog(root, data, append=False, verbose=False):
267278
The root group node of a Loop Project File
268279
data: list of (formation, thickness)
269280
The data to save
281+
thickness_calculator_data: list of tuples
282+
Labels for thickness calculators (e.g., [('Label1', 'Label2', ...)])
283+
thickness_calculator_active_flags: list of tuples
284+
Flags for active thickness calculators (e.g., [('None', 'Active', ...)])
270285
append: bool
271286
Flag of whether to append new data to existing log
272287
verbose: bool
273288
A flag to indicate a higher level of console logging (more if True)
274289
275290
Returns
276291
-------
277-
dict {"errorFlag", "errorString"}
278-
errorString exist and contains error message only when errorFlag is
292+
dict {"errorFlag", "errorString"}
293+
errorString exists and contains error message only when errorFlag is
279294
True
280295
281296
"""
@@ -302,23 +317,28 @@ def SetStratigraphicLog(root, data, append=False, verbose=False):
302317
zlib=True,
303318
complevel=9,
304319
)
320+
305321
else:
306322
siGroup = resp["value"]
307323

308324
if siGroup:
309325
stratigraphicLayersLocation = siGroup.variables["stratigraphicLayers"]
326+
310327
index = 0
311328
if append:
312329
index = siGroup.dimensions["index"].size
313330
for i in data:
314331
stratigraphicLayersLocation[index] = i
315332
index += 1
316333
siGroup.setncattr("index_MaxValid", index)
334+
335+
317336
else:
318337
errStr = "(ERROR) Failed to create stratigraphic log group for strata setting"
319338
if verbose:
320339
print(errStr)
321340
response = {"errorFlag": True, "errorString": errStr}
341+
322342
return response
323343

324344

@@ -330,16 +350,9 @@ def GetStratigraphicLog(root, indexList=[], indexRange=(0, 0), verbose=False):
330350
else:
331351
siGroup = resp["value"]
332352
data = []
333-
maxValidIndex = min(
334-
siGroup.dimensions["index"].size, siGroup.getncattr("index_MaxValid")
335-
)
353+
maxValidIndex = min(siGroup.dimensions["index"].size, siGroup.getncattr("index_MaxValid"))
336354
# Select all option
337-
if (
338-
indexList == []
339-
and len(indexRange) == 2
340-
and indexRange[0] == 0
341-
and indexRange[1] == 0
342-
):
355+
if indexList == [] and len(indexRange) == 2 and indexRange[0] == 0 and indexRange[1] == 0:
343356
# Select all
344357
for i in range(0, maxValidIndex):
345358
data.append((siGroup.variables.get("stratigraphicLayers")[i]))
@@ -351,11 +364,7 @@ def GetStratigraphicLog(root, indexList=[], indexRange=(0, 0), verbose=False):
351364
data.append((siGroup.variables.get("stratigraphicLayers")[i]))
352365
response["value"] = data
353366
# Select based on indices range option
354-
elif (
355-
len(indexRange) == 2
356-
and indexRange[0] >= 0
357-
and indexRange[1] >= indexRange[0]
358-
):
367+
elif len(indexRange) == 2 and indexRange[0] >= 0 and indexRange[1] >= indexRange[0]:
359368
for i in range(indexRange[0], indexRange[1]):
360369
if int(i) >= 0 and int(i) < maxValidIndex:
361370
data.append((siGroup.variables.get("stratigraphicLayers")[i]))
@@ -368,6 +377,91 @@ def GetStratigraphicLog(root, indexList=[], indexRange=(0, 0), verbose=False):
368377
return response
369378

370379

380+
def SetStratigraphicThicknesses(root, data, headers=None,ncols=None,append=False, verbose=False):
381+
response = {"errorFlag": False}
382+
resp = GetExtractedInformationGroup(root)
383+
if resp["errorFlag"]:
384+
# Create Extracted Information Group as it doesn't exist
385+
eiGroup = root.createGroup("ExtractedInformation")
386+
else:
387+
eiGroup = resp["value"]
388+
389+
resp = GetStratigraphicThicknessGroup(root)
390+
if resp["errorFlag"]:
391+
stGroup = eiGroup.createGroup("StratigraphicThickness")
392+
stGroup.setncattr("index_MaxValid", -1)
393+
stGroup.createDimension("index", None)
394+
stratigraphicThicknessType_t = stGroup.createCompoundType(
395+
LoopProjectFile.stratigraphicThicknessType, "stratigraphicThickness"
396+
)
397+
stGroup.createVariable(
398+
"stratigraphicThicknesses",
399+
stratigraphicThicknessType_t,
400+
("index"),
401+
zlib=True,
402+
complevel=9,
403+
)
404+
else:
405+
stGroup = resp["value"]
406+
407+
if stGroup:
408+
stratigraphicThicknesses = stGroup.variables["stratigraphicThicknesses"]
409+
if headers:
410+
stGroup.setncattr("headers", headers)
411+
if ncols:
412+
stGroup.setncattr("ncols", ncols)
413+
index = 0
414+
if append:
415+
index = stGroup.dimensions["index"].size
416+
for i in data:
417+
stratigraphicThicknesses[index] = i
418+
index += 1
419+
stGroup.setncattr("index_MaxValid", index)
420+
else:
421+
errStr = "(ERROR) Failed to create stratigraphic log group for strata setting"
422+
if verbose:
423+
print(errStr)
424+
response = {"errorFlag": True, "errorString": errStr}
425+
426+
return response
427+
428+
429+
def GetStratigraphicThicknesses(root, indexList=[], indexRange=(0, 0), verbose=False):
430+
response = {"errorFlag": False}
431+
resp = GetStratigraphicThicknessGroup(root)
432+
if resp["errorFlag"]:
433+
response = resp
434+
else:
435+
siGroup = resp["value"]
436+
data = []
437+
maxValidIndex = min(siGroup.dimensions["index"].size, siGroup.getncattr("index_MaxValid"))
438+
# Select all option
439+
response['attributes'] = {a:siGroup.getncattr(a) for a in siGroup.ncattrs()}
440+
if indexList == [] and len(indexRange) == 2 and indexRange[0] == 0 and indexRange[1] == 0:
441+
# Select all
442+
for i in range(0, maxValidIndex):
443+
data.append((siGroup.variables.get("stratigraphicThicknesses")[i]))
444+
response["value"] = data
445+
# Select based on list of indices option
446+
elif indexList != []:
447+
for i in indexList:
448+
if int(i) >= 0 and int(i) < maxValidIndex:
449+
data.append((siGroup.variables.get("stratigraphicThicknesses")[i]))
450+
response["value"] = data
451+
# Select based on indices range option
452+
elif len(indexRange) == 2 and indexRange[0] >= 0 and indexRange[1] >= indexRange[0]:
453+
for i in range(indexRange[0], indexRange[1]):
454+
if int(i) >= 0 and int(i) < maxValidIndex:
455+
data.append((siGroup.variables.get("stratigraphicThicknesses")[i]))
456+
response["value"] = data
457+
else:
458+
errStr = "Non-implemented filter option"
459+
if verbose:
460+
print(errStr)
461+
response = {"errorFlag": True, "errorString": errStr}
462+
return response
463+
464+
371465
# Set drillhole log
372466
def SetDrillholeLog(root, data, append=False, verbose=False):
373467
"""

0 commit comments

Comments
 (0)