Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Troubled Cell Detection
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Laura Christine Kühle
Troubled Cell Detection
Commits
78553b35
Commit
78553b35
authored
3 years ago
by
Laura Christine Kühle
Browse files
Options
Downloads
Patches
Plain Diff
Made all directories for the approximation local variables.
parent
c5861ec5
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
DG_Approximation.py
+14
-12
14 additions, 12 deletions
DG_Approximation.py
workflows/approximation.smk
+5
-3
5 additions, 3 deletions
workflows/approximation.smk
with
19 additions
and
15 deletions
DG_Approximation.py
+
14
−
12
View file @
78553b35
...
@@ -12,6 +12,7 @@ TODO: Force input_size for each ANN model to be stencil length
...
@@ -12,6 +12,7 @@ TODO: Force input_size for each ANN model to be stencil length
TODO: Combine ANN workflows
TODO: Combine ANN workflows
TODO: Unify use of
'
length
'
and
'
len
'
in naming
TODO: Unify use of
'
length
'
and
'
len
'
in naming
TODO: Add an environment file for Snakemake
TODO: Add an environment file for Snakemake
TODO: Make all directories local variable -> Done
Critical, but not urgent:
Critical, but not urgent:
TODO: Use cfl_number for updating, not just time
TODO: Use cfl_number for updating, not just time
...
@@ -121,8 +122,6 @@ class DGScheme:
...
@@ -121,8 +122,6 @@ class DGScheme:
Right boundary of interval. Default: 1.
Right boundary of interval. Default: 1.
verbose : bool, optional
verbose : bool, optional
Flag whether commentary in console is wanted. Default: False.
Flag whether commentary in console is wanted. Default: False.
plot_dir : str, optional
Path to directory in which plots are saved. Default:
'
test
'
.
history_threshold : float, optional
history_threshold : float, optional
Threshold when history will be recorded.
Threshold when history will be recorded.
Default: math.ceil(0.2/cfl_number).
Default: math.ceil(0.2/cfl_number).
...
@@ -153,7 +152,6 @@ class DGScheme:
...
@@ -153,7 +152,6 @@ class DGScheme:
self
.
_left_bound
=
kwargs
.
pop
(
'
left_bound
'
,
-
1
)
self
.
_left_bound
=
kwargs
.
pop
(
'
left_bound
'
,
-
1
)
self
.
_right_bound
=
kwargs
.
pop
(
'
right_bound
'
,
1
)
self
.
_right_bound
=
kwargs
.
pop
(
'
right_bound
'
,
1
)
self
.
_verbose
=
kwargs
.
pop
(
'
verbose
'
,
False
)
self
.
_verbose
=
kwargs
.
pop
(
'
verbose
'
,
False
)
self
.
_plot_dir
=
kwargs
.
pop
(
'
plot_dir
'
,
'
testing
'
)
self
.
_history_threshold
=
kwargs
.
pop
(
'
history_threshold
'
,
self
.
_history_threshold
=
kwargs
.
pop
(
'
history_threshold
'
,
math
.
ceil
(
0.2
/
self
.
_cfl_number
))
math
.
ceil
(
0.2
/
self
.
_cfl_number
))
self
.
_detector
=
detector
self
.
_detector
=
detector
...
@@ -203,7 +201,7 @@ class DGScheme:
...
@@ -203,7 +201,7 @@ class DGScheme:
self
.
_polynomial_degree
,
self
.
_num_grid_cells
,
self
.
_detector
,
self
.
_polynomial_degree
,
self
.
_num_grid_cells
,
self
.
_detector
,
self
.
_limiter
)
self
.
_limiter
)
def
approximate
(
self
,
data_name
):
def
approximate
(
self
,
data_dir
,
data_name
):
"""
Approximates projection.
"""
Approximates projection.
Initializes projection and evolves it in time. Each time step consists
Initializes projection and evolves it in time. Each time step consists
...
@@ -215,6 +213,8 @@ class DGScheme:
...
@@ -215,6 +213,8 @@ class DGScheme:
Attributes
Attributes
----------
----------
data_dir: str
Path to directory in which data is saved.
data_name : str
data_name : str
Name of data.
Name of data.
...
@@ -254,12 +254,12 @@ class DGScheme:
...
@@ -254,12 +254,12 @@ class DGScheme:
for
key
in
approx_stats
.
keys
()}
for
key
in
approx_stats
.
keys
()}
# Save approximation results in JSON format
# Save approximation results in JSON format
with
open
(
self
.
_plot
_dir
+
'
/
'
+
data_name
+
'
.json
'
,
'
w
'
)
\
with
open
(
data
_dir
+
'
/
'
+
data_name
+
'
.json
'
,
'
w
'
)
\
as
json_file
:
as
json_file
:
json_file
.
write
(
json
.
dumps
(
approx_stats
))
json_file
.
write
(
json
.
dumps
(
approx_stats
))
# Read approximation results
# Read approximation results
with
open
(
self
.
_plot
_dir
+
'
/
'
+
data_name
+
'
.json
'
)
as
json_file
:
with
open
(
data
_dir
+
'
/
'
+
data_name
+
'
.json
'
)
as
json_file
:
approx_stats
=
json
.
load
(
json_file
)
approx_stats
=
json
.
load
(
json_file
)
# Decode all ndarrays by converting lists
# Decode all ndarrays by converting lists
...
@@ -270,7 +270,7 @@ class DGScheme:
...
@@ -270,7 +270,7 @@ class DGScheme:
# and any detector-dependant plots
# and any detector-dependant plots
self
.
_detector
.
plot_results
(
**
approx_stats
)
self
.
_detector
.
plot_results
(
**
approx_stats
)
def
save_plots
(
self
,
plot_name
):
def
save_plots
(
self
,
plot_dir
,
plot_name
):
"""
Saves plotted results.
"""
Saves plotted results.
Sets plot directory, if not already existing, and saves plots
Sets plot directory, if not already existing, and saves plots
...
@@ -278,22 +278,24 @@ class DGScheme:
...
@@ -278,22 +278,24 @@ class DGScheme:
Parameters
Parameters
----------
----------
plot_dir: str
Path to directory in which plots are saved.
plot_name : str
plot_name : str
Name of plot.
Name of plot.
"""
"""
# Set paths for plot files if not existing already
# Set paths for plot files if not existing already
if
not
os
.
path
.
exists
(
self
.
_
plot_dir
):
if
not
os
.
path
.
exists
(
plot_dir
):
os
.
makedirs
(
self
.
_
plot_dir
)
os
.
makedirs
(
plot_dir
)
# Save plots
# Save plots
for
identifier
in
plt
.
get_figlabels
():
for
identifier
in
plt
.
get_figlabels
():
# Set path for figure directory if not existing already
# Set path for figure directory if not existing already
if
not
os
.
path
.
exists
(
self
.
_
plot_dir
+
'
/
'
+
identifier
):
if
not
os
.
path
.
exists
(
plot_dir
+
'
/
'
+
identifier
):
os
.
makedirs
(
self
.
_
plot_dir
+
'
/
'
+
identifier
)
os
.
makedirs
(
plot_dir
+
'
/
'
+
identifier
)
plt
.
figure
(
identifier
)
plt
.
figure
(
identifier
)
plt
.
savefig
(
self
.
_
plot_dir
+
'
/
'
+
identifier
+
'
/
'
+
plt
.
savefig
(
plot_dir
+
'
/
'
+
identifier
+
'
/
'
+
plot_name
+
'
.pdf
'
)
plot_name
+
'
.pdf
'
)
def
_reset
(
self
):
def
_reset
(
self
):
...
...
This diff is collapsed.
Click to expand it.
workflows/approximation.smk
+
5
−
3
View file @
78553b35
...
@@ -46,10 +46,12 @@ rule approximate_solution:
...
@@ -46,10 +46,12 @@ rule approximate_solution:
params.dg_params['detector_config']['model_state'] = input
params.dg_params['detector_config']['model_state'] = input
print(params.dg_params)
print(params.dg_params)
dg_scheme = DGScheme(
plot_dir=params.plot_dir,
**params.dg_params)
dg_scheme = DGScheme(**params.dg_params)
dg_scheme.approximate(wildcards.scheme)
dg_scheme.approximate(data_dir=params.plot_dir,
dg_scheme.save_plots(wildcards.scheme)
data_name=wildcards.scheme)
dg_scheme.save_plots(plot_dir=params.plot_dir,
plot_name=wildcards.scheme)
toc = time.perf_counter()
toc = time.perf_counter()
print(f'Time: {toc - tic:0.4f}s')
print(f'Time: {toc - tic:0.4f}s')
\ 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