forked from cooperkellyhansen/PyTexture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuilder.py
95 lines (69 loc) · 2.74 KB
/
builder.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import kosh
import os
"""
The purpose of the controller script is exactly as advertised:
to control the creation of python-based polycrystals by way of
the command line
PyTexture takes in a set of orientations in any given format,
create a polycrystal object, and contains methods to manipulate
these objects.
It utilizies Kosh to keep track of the data.
"""
try:
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
except AttributeError:
rank = 0
def main():
#
# Command line interface
#
parser = argparser.ArgumentParser()
parser.add_argument('--store_path', required=True)
parser.add_argument('--orientation_data_dir', required=True)
parser.add_argument('--mime_type', required=True)
parser.add_argument('--operators', default=None, choices=[])
parser.add_argument('--transformers' default=None, choices=[])
parser.add_argument('--ds_metadata', required=True,
help='metadata to describe the raw orientation data\
Format: {data_type: , \
orientation_format: ,\
grain_count: , }')
parser.add_argument('--ens_metadata', required=True,
help='metadata to describe the raw orientation data\
Format: {crystal_structure: ,\
data_source: }')
parser.add_argument('--processed_metadata', required=True,
help='metadata to describe processed data, \
Format: {origin: \
scaling:}')
parser.add_argument('--ensemble_name', required=True)
#NOTE: origin would be the dataset id of origin
store_path = args.store_path
#
# 1. Open a store, create datasets, and associate data
#
# open a new store
store = kosh.connect(store_path)
# create datasets with metadata and add to ensemble
# TODO: This could benefit from using enum for name in the future
dataset_name = 'SVE_'
ens = store.create_ensemble(name=ensemble_name, metadata=ens_metadata)
orientations = os.listdir(orientation_data_dir)
print('Building Kosh Store...')
for num, sve in enumerate(orientations):
ds = store.create(dataset_name+=num, metadata=ds_metadata)
ds.associate(sve, mime_type=mime_type)
ens.associate(ds)
#
# 2. From store, build Texture objects and save
#
print('Building Texture Objects and Saving...')
# Grab all relevant datasets
datasets = list(ens.find_datasets(data_type='Orientations'))
#
# 3. Choose attributes to calculate and save
#
if __name__ == '__main__':
if rank == 0:
main()