@@ -1423,6 +1423,99 @@ def test_nutrientpool_overrides(self):
14231423 )
14241424 self .assertEqual (growingsurface .nutrient_pool .fraction_dry_n_to_fast , 0.71 )
14251425
1426+ """Test surface parameter override."""
1427+
1428+
1429+ def test_apply_surface_overrides (tmp_path ):
1430+ """Test surface overrides are applied in model load."""
1431+ import yaml
1432+ from wsimod .orchestration .model import Model
1433+
1434+ config = {
1435+ "arcs" : {
1436+ "arc1" : {
1437+ "name" : "arc1" ,
1438+ "in_port" : "land1" ,
1439+ "out_port" : "river1" ,
1440+ "type_" : "Arc" ,
1441+ "capacity" : 10 ,
1442+ "preference" : 1 ,
1443+ },
1444+ },
1445+ "nodes" : {
1446+ "land1" : {
1447+ "name" : "land1" ,
1448+ "type_" : "Land" ,
1449+ "percolation_residence_time" : 0.1 ,
1450+ "surfaces" : {
1451+ "Woodland" : {
1452+ "area" : 100 ,
1453+ "datum" : 10 ,
1454+ "type_" : "GrowingSurface" ,
1455+ "ET_depletion_factor" : 0.75 ,
1456+ "surface" : "Woodland" ,
1457+ },
1458+ "Grass" : {
1459+ "area" : 200 ,
1460+ "datum" : 20 ,
1461+ "type_" : "GrowingSurface" ,
1462+ "ET_depletion_factor" : 0.75 ,
1463+ "surface" : "Grass" ,
1464+ },
1465+ },
1466+ },
1467+ "river1" : {
1468+ "name" : "river1" ,
1469+ "type_" : "River" ,
1470+ },
1471+ },
1472+ "overrides" : {
1473+ "arcs" : {
1474+ "arc1" : {
1475+ "name" : "arc1" ,
1476+ "type_" : "Arc" ,
1477+ "capacity" : 20 ,
1478+ }
1479+ },
1480+ "nodes" : {
1481+ "land1" : {
1482+ "surfaces" : {
1483+ "Woodland" : {
1484+ "surface" : "Woodland" ,
1485+ "type_" : "GrowingSurface" ,
1486+ "area" : 1000 ,
1487+ "ET_depletion_factor" : 0.8 ,
1488+ }
1489+ },
1490+ "percolation_residence_time" : 1 ,
1491+ "name" : "land1" ,
1492+ "type_" : "Land" ,
1493+ }
1494+ },
1495+ },
1496+ }
1497+
1498+ # Create the config file
1499+ with (tmp_path / "config.yml" ).open ("w" ) as f :
1500+ yaml .dump (config , f )
1501+
1502+ # Load in the model
1503+ model = Model ()
1504+ model .load (tmp_path )
1505+
1506+ # Perform the test
1507+ assert hasattr (model .nodes ["land1" ], "surfaces" )
1508+ assert hasattr (model .nodes ["land1" ].get_surface ("Woodland" ), "surface" )
1509+ assert hasattr (model .nodes ["land1" ].get_surface ("Grass" ), "surface" )
1510+ assert model .arcs ["arc1" ].capacity == 20
1511+ assert model .arcs ["arc1" ].preference == 1
1512+ assert model .nodes ["land1" ].percolation_residence_time == 1
1513+ assert model .nodes ["land1" ].get_surface ("Woodland" ).datum == 10
1514+ assert model .nodes ["land1" ].get_surface ("Grass" ).area == 200
1515+ assert model .nodes ["land1" ].get_surface ("Grass" ).datum == 20
1516+ assert model .nodes ["land1" ].get_surface ("Woodland" ).area == 1000
1517+ assert model .nodes ["land1" ].get_surface ("Woodland" ).ET_depletion_factor == 0.8
1518+
14261519
14271520if __name__ == "__main__" :
14281521 unittest .main ()
0 commit comments