Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Thick Section Point Density
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
QIM
Tools
Thick Section Point Density
Commits
b976e848
Commit
b976e848
authored
3 years ago
by
hanste
Browse files
Options
Downloads
Patches
Plain Diff
Added files from local to remote
parent
51ac4e21
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
run.py
+119
-0
119 additions, 0 deletions
run.py
with
119 additions
and
0 deletions
run.py
0 → 100644
+
119
−
0
View file @
b976e848
import
os
import
re
import
warnings
from
collections
import
defaultdict
import
numpy
as
np
import
matplotlib.pyplot
as
plt
from
tqdm
import
tqdm
from
measure
import
measure_cumulative_volume
,
measure_cumulative_points
def
parse_params
(
path
):
with
open
(
os
.
path
.
join
(
path
,
'
params.txt
'
))
as
f
:
lines
=
f
.
readlines
()
coords
=
[]
thickness
=
[]
for
line
in
lines
:
if
'
origin
'
in
line
:
coords
=
[
float
(
x
)
for
x
in
re
.
findall
(
'
-?\d+\.?[0-9]*
'
,
line
)]
if
'
thickness
'
in
line
:
thickness
=
[
float
(
x
)
for
x
in
re
.
findall
(
'
-?\d+\.?[0-9]*
'
,
line
)]
if
len
(
coords
)
!=
3
:
print
(
f
"
found
{
len
(
coords
)
}
coordinates when looking for
'
origin
'
in params.txt
"
)
if
len
(
thickness
)
!=
1
:
print
(
f
"
found
{
len
(
coords
)
}
coordinates when looking for
'
origin
'
in params.txt
"
)
thickness
=
thickness
[
0
]
return
coords
,
thickness
def
load_contours
(
path
):
contour_dir
=
os
.
path
.
join
(
path
,
'
domain_contours
'
)
file_fnames
=
os
.
listdir
(
contour_dir
)
z_values
=
[
float
(
file_fname
[
2
:
-
4
])
for
file_fname
in
file_fnames
]
z_values
,
file_fnames
=
zip
(
*
sorted
(
zip
(
z_values
,
file_fnames
)))
contours
=
[]
for
file_fname
,
z
in
zip
(
file_fnames
,
z_values
):
X
=
np
.
loadtxt
(
os
.
path
.
join
(
contour_dir
,
file_fname
))
Xp
=
np
.
pad
(
X
,
((
0
,
1
),
(
0
,
0
)),
mode
=
'
wrap
'
)
contours
.
append
((
z
,
X
))
return
contours
def
load_points
(
path
):
point_dirs
=
[
os
.
path
.
join
(
path
,
path_name
)
for
path_name
in
os
.
listdir
(
path
)
if
path_name
.
startswith
(
'
points_marker_
'
)]
marker_names
=
[
dir_name
.
split
(
'
points_marker_
'
)[
-
1
]
for
dir_name
in
point_dirs
]
points
=
defaultdict
(
list
)
for
point_dir
,
marker_name
in
zip
(
point_dirs
,
marker_names
):
file_fnames
=
os
.
listdir
(
point_dir
)
z_values
=
[
float
(
file_fname
[
2
:
-
4
])
for
file_fname
in
file_fnames
]
z_values
,
file_fnames
=
zip
(
*
sorted
(
zip
(
z_values
,
file_fnames
)))
for
file_fname
,
z
in
zip
(
file_fnames
,
z_values
):
X
=
np
.
loadtxt
(
os
.
path
.
join
(
point_dir
,
file_fname
))
points
[
marker_name
].
append
((
z
,
X
))
return
points
def
write_csv
(
path
,
R
,
dP
,
dV
):
intdP
=
dP
[
1
:]
-
dP
[:
-
1
]
intdV
=
dV
[
1
:]
-
dV
[:
-
1
]
with
warnings
.
catch_warnings
():
warnings
.
simplefilter
(
"
ignore
"
)
Dens
=
dP
/
dV
intDens
=
intdP
/
intdV
with
open
(
path
,
'
w
'
)
as
f
:
f
.
write
(
'
,
'
.
join
([
'
Cummulative Reading
'
,
''
,
''
,
''
,
''
,
'
Interval Reading
\n
'
]))
f
.
write
(
'
,
'
.
join
([
'
Distance
'
,
'
Point Counts
'
,
'
Volume (mu^3)
'
,
'
Density (n/mu^3)
'
,
''
,
'
Interval start (mu)
'
,
'
Interval end (mu)
'
,
'
Point Counts (n)
'
,
'
Volume (mu^3)
'
,
'
Density (n/mu^3)
\n
'
]))
for
i0
,
i1
,
a
,
b
,
c
,
d
,
e
,
v
in
zip
(
R
[:
-
1
],
R
[
1
:],
dP
,
dV
,
Dens
,
intdP
,
intdV
,
intDens
):
f
.
write
(
f
'
{
i0
}
,
{
a
}
,
{
b
}
,
{
c
}
,,
{
i0
}
,
{
i1
}
,
{
d
}
,
{
e
}
,
{
v
}
\n
'
)
def
run
(
base_dir
):
R
=
np
.
arange
(
0
,
3001
,
125
)
output_dir
=
'
output
'
os
.
makedirs
(
output_dir
,
exist_ok
=
True
)
for
experiment
in
tqdm
(
os
.
listdir
(
base_dir
),
desc
=
'
experiment
'
):
for
reading
in
os
.
listdir
(
os
.
path
.
join
(
base_dir
,
experiment
)):
#if reading != '7566':
# continue
data_dir
=
os
.
path
.
join
(
base_dir
,
experiment
,
reading
)
origin
,
thickness
=
parse_params
(
data_dir
)
contours
=
sorted
(
load_contours
(
data_dir
))
points
=
load_points
(
data_dir
)
for
marker
in
points
.
keys
():
all_points
=
sorted
(
points
[
marker
])
dV
=
[]
dP
=
[]
for
sec_contour
,
sec_points
in
zip
(
contours
,
all_points
):
if
sec_contour
[
0
]
!=
sec_points
[
0
]:
raise
ValueError
(
'
z-coordinate misalignment, does points and contour have corresponding z-value
'
)
z
,
P
=
sec_contour
dV
.
append
(
measure_cumulative_volume
(
z
,
P
,
thickness
,
origin
,
R
))
z
,
X
=
sec_points
dP
.
append
(
measure_cumulative_points
(
z
,
X
,
thickness
,
origin
,
R
))
dP
=
np
.
sum
(
dP
,
axis
=
0
)
dV
=
np
.
sum
(
dV
,
axis
=
0
)
fname
=
f
'
{
experiment
}
_
{
reading
}
_
{
marker
}
.csv
'
path
=
os
.
path
.
join
(
output_dir
,
fname
)
write_csv
(
path
,
R
,
dP
,
dV
)
if
__name__
==
'
__main__
'
:
base_dir
=
'
data
'
run
(
base_dir
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment