-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Latin Hypercube Neutronic Sampling #10
base: main
Are you sure you want to change the base?
Changes from 1 commit
5352233
b1f3e4e
5fb7b85
f995797
a9ca809
f6797df
71d51d4
30bba7e
d89deca
b0e8814
786c062
50be3ad
a44887c
abe77b5
ebb7296
2e17eb6
677fa4e
2f53046
667a118
1a5e34a
39216a6
d0101a6
162d809
47cfb2a
88839e8
e2d25cb
a860836
2f3ac24
0d1e51e
c3f6ffc
22d0077
4e511cd
4681c38
202f162
73d4418
7cd54b2
390aec9
49a450e
c73d6c7
af30af4
f0c4c66
82d4db7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
""" | ||
from pyDOE import lhs | ||
import os | ||
import glob | ||
import numpy as np | ||
import tarfile | ||
|
||
|
@@ -26,7 +27,7 @@ | |
} | ||
|
||
dim = len(parameters.keys()) | ||
samples = 2 | ||
samples = 40 | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2 lines there |
||
def gen_hypercube(samples, N): | ||
"""Generate N-dimensional latin hypercube to sample dimensional reactor | ||
|
@@ -66,6 +67,10 @@ def fill_data_array(samples, parameters, cube): | |
# save to ndarray | ||
test_cases[sample_idx][dim] = b + cube[sample_idx][dim_idx] * a | ||
|
||
# write the data to a csv file | ||
np.savetxt("data.csv", test_cases, delimiter=',', | ||
header=','.join(test_cases.dtype.names)) | ||
|
||
return test_cases | ||
|
||
def write_inputs(sampling_data): | ||
|
@@ -90,11 +95,22 @@ def write_inputs(sampling_data): | |
filename = input.write_input(num, header_str) | ||
tarputs.add(filename) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be cleanest to delete the file as soon as possible after you add it to the tarfile. |
||
|
||
# write HTC input list | ||
htc_inputs = open('input_files.txt', 'w') | ||
htc_inputs.write('\n'.join(glob.glob("*.i"))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is the list of files you've just created, can't you generate it without a glob. Isn't it safer?
|
||
htc_inputs.close() | ||
|
||
tarputs.add('input_list.txt') | ||
tarputs.add('data.csv') | ||
tarputs.close() | ||
|
||
def write_input_list(): | ||
"""Write input list for HTC | ||
""" | ||
|
||
if __name__=='__main__': | ||
cube = gen_hypercube(samples, dim) | ||
data = fill_data_array(samples, parameters, cube) | ||
write_inputs(data) | ||
os.system('rm *.i') | ||
# cleanup | ||
os.system('rm *.i input_list.txt data.csv') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PEP8: missing blank line