Skip to content

Commit 67a3258

Browse files
committed
fixed position distrtibution reading, added helper functions for seedlists
1 parent ea76c44 commit 67a3258

File tree

5 files changed

+331
-31
lines changed

5 files changed

+331
-31
lines changed

CHANGELOG.rst

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ All notable changes to this project will be documented in this file.
66
The format is based on `Keep a Changelog`_,
77
and this project adheres to `Semantic Versioning`_.
88

9+
`1.3.3`_ - 2020-08-31
10+
--------------------------
11+
Added
12+
'''''
13+
- Helper functions for SeedList class.
14+
15+
Fixed
16+
'''''''
17+
- Dictionary conversion issue with lists of SciPy distributions.
18+
- XML tags in documentation on position distributions.
19+
20+
921
`1.3.2`_ - 2020-07-11
1022
--------------------------
1123
Added
@@ -129,7 +141,8 @@ Added
129141

130142
.. LINKS
131143
132-
.. _`Unreleased`: https://github.com/kip-hart/MicroStructPy/compare/v1.3.2...HEAD
144+
.. _`Unreleased`: https://github.com/kip-hart/MicroStructPy/compare/v1.3.3...HEAD
145+
.. _`1.3.3`: https://github.com/kip-hart/MicroStructPy/compare/v1.3.2...v1.3.3
133146
.. _`1.3.2`: https://github.com/kip-hart/MicroStructPy/compare/v1.3.1...v1.3.2
134147
.. _`1.3.1`: https://github.com/kip-hart/MicroStructPy/compare/v1.3.0...v1.3.1
135148
.. _`1.3.0`: https://github.com/kip-hart/MicroStructPy/compare/v1.2.2...v1.3.0

docs/source/cli/material.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,13 +521,13 @@ coordinates while the second has a coupled distribution.
521521
<scale> 1 </scale>
522522
</size>
523523
<position> <!-- x -->
524-
<dist_type> binom </dist>
524+
<dist_type> binom </dist_type>
525525
<loc> 0.5 </loc>
526526
<n> 9 </n>
527527
<p> 0.5 </p>
528528
</position>
529529
<position> <!-- y -->
530-
<dist_type> uniform </dist>
530+
<dist_type> uniform </dist_type>
531531
<loc> 0 </loc>
532532
<scale> 10 </scale>
533533
</position>

src/microstructpy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
import microstructpy.seeding
55
import microstructpy.verification
66

7-
__version__ = '1.3.2'
7+
__version__ = '1.3.3'

src/microstructpy/cli.py

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,42 +1015,37 @@ def dict_convert(dictionary, filepath='.'):
10151015
.. _xmltodict: https://github.com/martinblech/xmltodict
10161016
"""
10171017

1018-
if type(dictionary) is list:
1018+
# Convert lists
1019+
if isinstance(dictionary, list):
10191020
return [dict_convert(d) for d in dictionary]
10201021

1021-
new_dict = collections.OrderedDict()
1022-
for key in dictionary:
1023-
val = dictionary[key]
1024-
if type(val) in (dict, collections.OrderedDict):
1025-
new_val = dict_convert(val, filepath)
1022+
# Convert strings
1023+
if isinstance(dictionary, str):
1024+
return _misc.from_str(dictionary)
10261025

1027-
# Exception for scipy.stats distributions
1028-
if 'dist_type' in val:
1029-
new_val = _dist_convert(new_val)
1026+
# Convert Nones
1027+
if dictionary is None:
1028+
return {}
10301029

1031-
elif type(val) is list:
1032-
if type(val[0]) is str:
1033-
new_val = [_misc.from_str(v) for v in val]
1034-
else:
1035-
new_val = dict_convert(val, filepath)
1036-
1037-
elif val is None:
1038-
new_val = {}
1039-
1040-
# Exception for filepaths
1041-
elif any([s in key.lower() for s in ('filename', 'directory')]):
1030+
# Convert filepaths
1031+
for key in dictionary:
1032+
val = dictionary[key]
1033+
if any([s in key.lower() for s in ('filename', 'directory')]):
10421034
if not os.path.isabs(val) and filepath:
10431035
new_val = os.path.abspath(os.path.join(filepath, val))
10441036
else:
10451037
new_val = val
1038+
dictionary[key] = new_val
10461039

1047-
elif type(val) is str:
1048-
new_val = _misc.from_str(val)
1049-
1050-
else:
1051-
err_str = 'Cannot parse type for: ' + str(type(val))
1052-
raise ValueError(err_str)
1040+
# Convert SciPy.stats distributions
1041+
if 'dist_type' in dictionary:
1042+
return _dist_convert(dictionary)
10531043

1044+
# Convert Dictionaries
1045+
new_dict = collections.OrderedDict()
1046+
for key in dictionary:
1047+
val = dictionary[key]
1048+
new_val = dict_convert(val, filepath)
10541049
new_dict[key] = new_val
10551050
return new_dict
10561051

@@ -1059,7 +1054,8 @@ def _dist_convert(dist_dict):
10591054
"""Convert distribution dictionary to distribution"""
10601055

10611056
dist_type = dist_dict['dist_type'].strip().lower()
1062-
params = {k: v for k, v in dist_dict.items() if k != 'dist_type'}
1057+
params = {k: _misc.from_str(v) for k, v in dist_dict.items()}
1058+
del params['dist_type']
10631059

10641060
if dist_type == 'cdf':
10651061
cdf_filename = params['filename']

0 commit comments

Comments
 (0)