@@ -8282,12 +8282,17 @@ def test_planarCompositePotential_explicit_units():
82828282
82838283def test_CompositePotential_turn_physical ():
82848284 # Test that turn_physical_on/off propagates to component potentials
8285- # This is the behavior described in the issue:
8286- # https://github.com/jobovy/galpy/issues/XXXX
8285+ # This is the behavior described in issue
8286+ # https://github.com/jobovy/galpy/issues/854
82878287 from galpy .potential import HernquistPotential , NFWPotential
82888288
82898289 ro , vo = 8.0 , 220.0
8290- combo_pot = NFWPotential () + HernquistPotential ()
8290+ # Initialize with physical units ON so turn_physical_off has something to do
8291+ combo_pot = NFWPotential (ro = ro , vo = vo ) + HernquistPotential (ro = ro , vo = vo )
8292+
8293+ # Components should start with physical on
8294+ assert combo_pot [0 ]._roSet , "Component should have roSet=True initially"
8295+ val_on = combo_pot [0 ](1 , 1 , 1 )
82918296
82928297 # Turn physical off - should propagate to components
82938298 combo_pot .turn_physical_off ()
@@ -8300,6 +8305,11 @@ def test_CompositePotential_turn_physical():
83008305 )
83018306 val_off = combo_pot [0 ](1 , 1 , 1 )
83028307
8308+ # Physical output scales by vo^2 relative to internal units
8309+ assert numpy .fabs (val_on / val_off / vo ** 2 - 1.0 ) < 1e-10 , (
8310+ "Component output should have changed by vo^2 after turn_physical_off"
8311+ )
8312+
83038313 # Turn physical on - should propagate to components
83048314 combo_pot .turn_physical_on (ro = ro , vo = vo )
83058315 assert combo_pot ._roSet , "CompositePotential should have roSet=True"
@@ -8309,10 +8319,10 @@ def test_CompositePotential_turn_physical():
83098319 assert combo_pot [1 ]._roSet , (
83108320 "Component should have roSet=True after turn_physical_on"
83118321 )
8312- val_on = combo_pot [0 ](1 , 1 , 1 )
8322+ val_on_again = combo_pot [0 ](1 , 1 , 1 )
83138323
8314- # Physical output should scale by vo^2 relative to internal units
8315- assert numpy .fabs (val_on / val_off / vo ** 2 - 1.0 ) < 1e-10 , (
8324+ # Should be back to physical units
8325+ assert numpy .fabs (val_on_again / val_off / vo ** 2 - 1.0 ) < 1e-10 , (
83168326 "Component output should be in physical units (scaled by vo^2) after turn_physical_on"
83178327 )
83188328
@@ -8321,10 +8331,19 @@ def test_CompositePotential_turn_physical():
83218331
83228332def test_planarCompositePotential_turn_physical ():
83238333 # Test that turn_physical_on/off propagates to component potentials
8334+ # This is the behavior described in issue
8335+ # https://github.com/jobovy/galpy/issues/854
83248336 from galpy .potential import HernquistPotential , NFWPotential
83258337
83268338 ro , vo = 8.0 , 220.0
8327- planar_combo = NFWPotential ().toPlanar () + HernquistPotential ().toPlanar ()
8339+ # Initialize with physical units ON so turn_physical_off has something to do
8340+ planar_combo = NFWPotential (ro = ro , vo = vo ).toPlanar () + HernquistPotential (
8341+ ro = ro , vo = vo
8342+ ).toPlanar ()
8343+
8344+ # Components should start with physical on
8345+ assert planar_combo [0 ]._roSet , "Component should have roSet=True initially"
8346+ val_on = planar_combo [0 ](1 , 1 )
83288347
83298348 # Turn physical off - should propagate to components
83308349 planar_combo .turn_physical_off ()
@@ -8337,6 +8356,11 @@ def test_planarCompositePotential_turn_physical():
83378356 )
83388357 val_off = planar_combo [0 ](1 , 1 )
83398358
8359+ # Physical output scales by vo^2 relative to internal units
8360+ assert numpy .fabs (val_on / val_off / vo ** 2 - 1.0 ) < 1e-10 , (
8361+ "Component output should have changed by vo^2 after turn_physical_off"
8362+ )
8363+
83408364 # Turn physical on - should propagate to components
83418365 planar_combo .turn_physical_on (ro = ro , vo = vo )
83428366 assert planar_combo ._roSet , "planarCompositePotential should have roSet=True"
@@ -8346,10 +8370,10 @@ def test_planarCompositePotential_turn_physical():
83468370 assert planar_combo [1 ]._roSet , (
83478371 "Component should have roSet=True after turn_physical_on"
83488372 )
8349- val_on = planar_combo [0 ](1 , 1 )
8373+ val_on_again = planar_combo [0 ](1 , 1 )
83508374
8351- # Physical output should scale by vo^2 relative to internal units
8352- assert numpy .fabs (val_on / val_off / vo ** 2 - 1.0 ) < 1e-10 , (
8375+ # Should be back to physical units
8376+ assert numpy .fabs (val_on_again / val_off / vo ** 2 - 1.0 ) < 1e-10 , (
83538377 "Component output should be in physical units (scaled by vo^2) after turn_physical_on"
83548378 )
83558379
@@ -8358,10 +8382,19 @@ def test_planarCompositePotential_turn_physical():
83588382
83598383def test_linearCompositePotential_turn_physical ():
83608384 # Test that turn_physical_on/off propagates to component potentials
8385+ # This is the behavior described in issue
8386+ # https://github.com/jobovy/galpy/issues/854
83618387 from galpy .potential import HernquistPotential , NFWPotential
83628388
83638389 ro , vo = 8.0 , 220.0
8364- lin_combo = NFWPotential ().toVertical (1.0 ) + HernquistPotential ().toVertical (1.0 )
8390+ # Initialize with physical units ON so turn_physical_off has something to do
8391+ lin_combo = NFWPotential (ro = ro , vo = vo ).toVertical (1.0 ) + HernquistPotential (
8392+ ro = ro , vo = vo
8393+ ).toVertical (1.0 )
8394+
8395+ # Components should start with physical on
8396+ assert lin_combo [0 ]._roSet , "Component should have roSet=True initially"
8397+ val_on = lin_combo [0 ](1 )
83658398
83668399 # Turn physical off - should propagate to components
83678400 lin_combo .turn_physical_off ()
@@ -8374,6 +8407,11 @@ def test_linearCompositePotential_turn_physical():
83748407 )
83758408 val_off = lin_combo [0 ](1 )
83768409
8410+ # Physical output scales by vo^2 relative to internal units
8411+ assert numpy .fabs (val_on / val_off / vo ** 2 - 1.0 ) < 1e-10 , (
8412+ "Component output should have changed by vo^2 after turn_physical_off"
8413+ )
8414+
83778415 # Turn physical on - should propagate to components
83788416 lin_combo .turn_physical_on (ro = ro , vo = vo )
83798417 assert lin_combo ._roSet , "linearCompositePotential should have roSet=True"
@@ -8383,10 +8421,10 @@ def test_linearCompositePotential_turn_physical():
83838421 assert lin_combo [1 ]._roSet , (
83848422 "Component should have roSet=True after turn_physical_on"
83858423 )
8386- val_on = lin_combo [0 ](1 )
8424+ val_on_again = lin_combo [0 ](1 )
83878425
8388- # Physical output should scale by vo^2 relative to internal units
8389- assert numpy .fabs (val_on / val_off / vo ** 2 - 1.0 ) < 1e-10 , (
8426+ # Should be back to physical units
8427+ assert numpy .fabs (val_on_again / val_off / vo ** 2 - 1.0 ) < 1e-10 , (
83908428 "Component output should be in physical units (scaled by vo^2) after turn_physical_on"
83918429 )
83928430
0 commit comments