Skip to content

Commit

Permalink
Fix PositionD parsing in config to make comma string work correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
rmjarvis committed Jul 9, 2024
1 parent 997d7c5 commit 7e50733
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ Performance Improvements
Bug Fixes
---------

- Fixed a bug in the config layer parsing of PositionD from a string. (#1299)
5 changes: 3 additions & 2 deletions galsim/config/value.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,9 @@ def _GetPositionValue(param):
"""Convert a tuple or a string that looks like "a,b" into a galsim.PositionD.
"""
try:
x = float(param[0])
y = float(param[1])
x, y = param
x = float(x)
y = float(y)
except (ValueError, TypeError):
try:
x, y = param.split(',')
Expand Down
6 changes: 6 additions & 0 deletions tests/test_config_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -1432,6 +1432,7 @@ def test_pos_value():
'val1' : galsim.PositionD(0.1,0.2),
'val2' : '0.1, 0.2',
'val3' : None,
'val4' : '123.4, 567.8'
'xy1' : { 'type' : 'XY', 'x' : 1.3, 'y' : 2.4 },
'ran1' : { 'type' : 'RandomCircle', 'radius' : 3 },
'ran2' : { 'type' : 'RandomCircle', 'radius' : 1, 'center' : galsim.PositionD(3,7) },
Expand Down Expand Up @@ -1487,6 +1488,10 @@ def test_pos_value():
val3 = galsim.config.ParseValue(config,'val3',config, galsim.PositionD)[0]
np.testing.assert_equal(val3, None)

val4 = galsim.config.ParseValue(config,'val4',config, galsim.PositionD)[0]
np.testing.assert_almost_equal(val4.x, 123.4)
np.testing.assert_almost_equal(val4.y, 567.8)

xy1 = galsim.config.ParseValue(config,'xy1',config, galsim.PositionD)[0]
np.testing.assert_almost_equal(xy1.x, 1.3)
np.testing.assert_almost_equal(xy1.y, 2.4)
Expand Down Expand Up @@ -1594,6 +1599,7 @@ def test_pos_value():
# Finally, these value got changed, so they won't match the original
# unless we manually set them back to the original strings.
clean_config['val2'] = '0.1, 0.2'
clean_config['val4'] = '123.4, 567.8'
clean_config['cur2'] = '@input.val2'
clean_config['input']['val2'] = '0.3, 0.4'
assert clean_config == orig_config
Expand Down

0 comments on commit 7e50733

Please sign in to comment.