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 5c8ff6d commit 2fdb9db
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Performance Improvements
Bug Fixes
---------

<<<<<<< HEAD
- Fixed a bug that could lead to overflow in extremely large images. (#1017)
- Fixed a slight error in the Moffat maxk calculation. (#1208, #1210)
- Fixed a bug that prevented Eval types from generating lists in config files in some contexts.
Expand Down Expand Up @@ -127,3 +128,8 @@ Changes from v2.5.2 to v2.5.3
- Added ScaleFlux and ScaleWavelength photon ops. (#1289)
- Deprecated ChromaticObject.atRedshift. (#1291)
- Various fixes to work with numpy 2.0. (#1297)

Changes from v2.5.3 to v2.5.4
=============================

- 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 2fdb9db

Please sign in to comment.