Skip to content

Commit 4975072

Browse files
committed
uses new parameter format for non-demographic growth
1 parent 252d690 commit 4975072

File tree

5 files changed

+109
-64
lines changed

5 files changed

+109
-64
lines changed

model/activity_resampling.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,12 @@ def non_demographic_adjustment(self):
213213
):
214214
return self
215215

216-
year_exponent = self.run_params["year"] - self.params["start_year"]
216+
match self.params["non-demographic_adjustment"]["value-type"]:
217+
case "year-on-year-growth":
218+
year_exponent = self.run_params["year"] - self.params["start_year"]
219+
case x:
220+
raise ValueError(f"invalid value-type: {x}")
221+
217222
factor = pd.Series(params).rename("non-demographic_adjustment") ** year_exponent
218223
factor.index.names = ["ndggrp"]
219224
return self._update(factor)

model/model.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,10 @@ def generate_param_values(prm, valid_range):
240240
rng,
241241
model_runs - 1,
242242
),
243+
"non-demographic_adjustment": {
244+
k: generate_param_values(v, inrange_0_5)
245+
for k, v in params["non-demographic_adjustment"]["values"].items()
246+
},
243247
# generate param values for the different items in params: this will traverse the dicts
244248
# until a value is reached that isn't a dict. Then it will generate the required amount
245249
# of values for that parameter
@@ -252,7 +256,6 @@ def generate_param_values(prm, valid_range):
252256
("repat_local", inrange_1_5),
253257
("repat_nonlocal", inrange_1_5),
254258
("baseline_adjustment", inrange_0_5),
255-
("non-demographic_adjustment", inrange_0_5),
256259
("activity_avoidance", inrange_0_1),
257260
("efficiencies", inrange_0_1),
258261
]

queue/sample_params.json

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -825,43 +825,47 @@
825825
}
826826
},
827827
"non-demographic_adjustment": {
828-
"ip": {
829-
"elective": [
830-
1,
831-
1.02
832-
],
833-
"non-elective": [
834-
1,
835-
1.02
836-
],
837-
"maternity": [
838-
1,
839-
1.02
840-
]
841-
},
842-
"op": {
843-
"first": [
844-
1,
845-
1.02
846-
],
847-
"followup": [
848-
1,
849-
1.02
850-
],
851-
"procedure": [
852-
1,
853-
1.02
854-
]
855-
},
856-
"aae": {
857-
"ambulance": [
858-
1,
859-
1.02
860-
],
861-
"walk-in": [
862-
1,
863-
1.02
864-
]
828+
"variant": "ndg-test",
829+
"value-type": "year-on-year-growth",
830+
"values": {
831+
"ip": {
832+
"elective": [
833+
1,
834+
1.02
835+
],
836+
"non-elective": [
837+
1,
838+
1.02
839+
],
840+
"maternity": [
841+
1,
842+
1.02
843+
]
844+
},
845+
"op": {
846+
"first": [
847+
1,
848+
1.02
849+
],
850+
"followup": [
851+
1,
852+
1.02
853+
],
854+
"procedure": [
855+
1,
856+
1.02
857+
]
858+
},
859+
"aae": {
860+
"ambulance": [
861+
1,
862+
1.02
863+
],
864+
"walk-in": [
865+
1,
866+
1.02
867+
]
868+
}
865869
}
866870
},
867871
"activity_avoidance": {

tests/test_activity_resampling.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,13 @@ def test_non_demographic_adjustment(
491491
"aae": {"ambulance": 5, "walk-in": 6},
492492
},
493493
}
494-
aa_mock._model_iteration.params = {"start_year": 2020}
494+
aa_mock._model_iteration.params = {
495+
"start_year": 2020,
496+
"non-demographic_adjustment": {
497+
"variant": "ndg-test",
498+
"value-type": "year-on-year-growth",
499+
},
500+
}
495501

496502
u_mock = mocker.patch(
497503
"model.activity_resampling.ActivityResampling._update", return_value="update"
@@ -505,6 +511,29 @@ def test_non_demographic_adjustment(
505511
assert u_mock.call_args[0][0].to_dict() == expected
506512

507513

514+
def test_non_demographic_adjustment_invalid_value_type(mock_activity_resampling):
515+
# arrange
516+
aa_mock = mock_activity_resampling
517+
aa_mock._model_iteration.model.model_type = "ip"
518+
aa_mock._model_iteration.run_params = {
519+
"year": 2021,
520+
"non-demographic_adjustment": {
521+
"ip": {"elective": 1, "non-elective": 2},
522+
},
523+
}
524+
aa_mock._model_iteration.params = {
525+
"start_year": 2020,
526+
"non-demographic_adjustment": {
527+
"variant": "ndg-test",
528+
"value-type": "invalid",
529+
},
530+
}
531+
532+
# act
533+
with pytest.raises(ValueError, match="invalid value-type: invalid"):
534+
aa_mock.non_demographic_adjustment()
535+
536+
508537
def test_apply_resampling(mock_activity_resampling):
509538
# arrange
510539
aa_mock = mock_activity_resampling

tests/test_model.py

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,12 @@ def mock_model():
4040
"repat_nonlocal": {"ip": {"elective": {"Other": [1.3, 1.5]}}},
4141
"baseline_adjustment": {"ip": {"elective": {"Other": [1.5, 1.7]}}},
4242
"non-demographic_adjustment": {
43-
"a": {"a_a": [1, 1.2], "a_b": [1, 1.2]},
44-
"b": {"b_a": [1, 1.2], "b_b": [1, 1.2]},
43+
"variant": "ndg-test",
44+
"variant-type": "year-on-year-growth",
45+
"values": {
46+
"a": {"a_a": [1, 1.2], "a_b": [1, 1.2]},
47+
"b": {"b_a": [1, 1.2], "b_b": [1, 1.2]},
48+
},
4549
},
4650
"activity_avoidance": {
4751
"ip": {
@@ -79,19 +83,19 @@ def mock_run_params():
7983
"variant": ["a", "a", "b", "a"],
8084
"seeds": [1, 2, 3, 4],
8185
"health_status_adjustment": [1, 2, 3, 4, 5],
82-
"covid_adjustment": [1, 1, 2, 3],
83-
"waiting_list_adjustment": {
84-
"ip": {"100": [1] * 4, "120": [2] * 4},
85-
"op": {"100": [3] * 4, "120": [4] * 4},
86-
},
87-
"expat": {"ip": {"elective": {"Other": [1, 4, 5, 6]}}},
88-
"repat_local": {"ip": {"elective": {"Other": [1, 7, 8, 9]}}},
89-
"repat_nonlocal": {"ip": {"elective": {"Other": [1, 10, 11, 12]}}},
90-
"baseline_adjustment": {"ip": {"elective": {"Other": [1, 13, 14, 15]}}},
9186
"non-demographic_adjustment": {
92-
"a": {"a_a": [1, 16, 17, 18], "a_b": [1, 19, 20, 21]},
93-
"b": {"b_a": [1, 22, 23, 24], "b_b": [1, 25, 26, 27]},
87+
"a": {"a_a": [1, 1, 2, 3], "a_b": [1, 4, 5, 6]},
88+
"b": {"b_a": [1, 7, 8, 9], "b_b": [1, 10, 11, 12]},
9489
},
90+
"covid_adjustment": [1, 13, 14, 15],
91+
"waiting_list_adjustment": {
92+
"ip": {"100": [1, 1, 1, 1], "120": [2, 2, 2, 2]},
93+
"op": {"100": [3, 3, 3, 3], "120": [4, 4, 4, 4]},
94+
},
95+
"expat": {"ip": {"elective": {"Other": [1, 16, 17, 18]}}},
96+
"repat_local": {"ip": {"elective": {"Other": [1, 19, 20, 21]}}},
97+
"repat_nonlocal": {"ip": {"elective": {"Other": [1, 22, 23, 24]}}},
98+
"baseline_adjustment": {"ip": {"elective": {"Other": [1, 25, 26, 27]}}},
9599
"activity_avoidance": {
96100
"ip": {"a_a": [1, 28, 29, 30], "a_b": [1, 31, 32, 33]},
97101
"op": {"a_a": [1, 34, 35, 36], "a_b": [1, 37, 38, 39]},
@@ -467,15 +471,19 @@ def get_next_n(*args): # pylint: disable=unused-argument
467471
"variant": "b",
468472
"seed": 3,
469473
"health_status_adjustment": 3,
470-
"covid_adjustment": 2,
471474
"non-demographic_adjustment": {
472-
"a": {"a_a": 17, "a_b": 20},
473-
"b": {"b_a": 23, "b_b": 26},
475+
"a": {"a_a": 2, "a_b": 5},
476+
"b": {"b_a": 8, "b_b": 11},
474477
},
475-
"expat": {"ip": {"elective": {"Other": 5}}},
476-
"repat_local": {"ip": {"elective": {"Other": 8}}},
477-
"repat_nonlocal": {"ip": {"elective": {"Other": 11}}},
478-
"baseline_adjustment": {"ip": {"elective": {"Other": 14}}},
478+
"covid_adjustment": 14,
479+
"waiting_list_adjustment": {
480+
"ip": {"100": 1, "120": 2},
481+
"op": {"100": 3, "120": 4},
482+
},
483+
"expat": {"ip": {"elective": {"Other": 17}}},
484+
"repat_local": {"ip": {"elective": {"Other": 20}}},
485+
"repat_nonlocal": {"ip": {"elective": {"Other": 23}}},
486+
"baseline_adjustment": {"ip": {"elective": {"Other": 26}}},
479487
"activity_avoidance": {
480488
"ip": {"a_a": 29, "a_b": 32},
481489
"op": {"a_a": 35, "a_b": 38},
@@ -485,10 +493,6 @@ def get_next_n(*args): # pylint: disable=unused-argument
485493
"ip": {"b_a": 47, "b_b": 50},
486494
"op": {"b_a": 53, "b_b": 56},
487495
},
488-
"waiting_list_adjustment": {
489-
"ip": {"100": 1, "120": 2},
490-
"op": {"100": 3, "120": 4},
491-
},
492496
"year": 2020,
493497
},
494498
),

0 commit comments

Comments
 (0)