Skip to content

Commit 1e37d96

Browse files
authored
Merge branch 'mobt_877_implement_qrf' into mobt_877_implement_qrf_extra
2 parents b6fbcb8 + 2d8319b commit 1e37d96

4 files changed

Lines changed: 11 additions & 5 deletions

improver/calibration/load_and_apply_quantile_regression_random_forest.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def __init__(
3232
feature_config: dict[str, list[str]],
3333
target_cube_name: str,
3434
transformation: str = None,
35-
pre_transform_addition: float = 0,
35+
pre_transform_addition: float = None,
3636
):
3737
"""Initialise the plugin.
3838
@@ -131,6 +131,10 @@ def _get_inputs(
131131
)
132132
raise ValueError(msg)
133133

134+
if not qrf_model:
135+
# The specified model doesn't exist and the forecast will not be calibrated
136+
return forecast_cube
137+
134138
# If target diagnostic not a feature in the training then remove.
135139
if self.target_cube_name not in self.feature_config.keys():
136140
cube_inputs.remove(forecast_cube)

improver/calibration/load_and_train_quantile_regression_random_forest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ def _split_cubes_and_parquet_files(self, file_paths):
7878
truth_table_path = file_path
7979
if forecast_table_path and truth_table_path:
8080
break
81+
except OSError:
82+
print("The directory doesn't exist, calibration is skipped for this cycle")
83+
return
8184

8285
if len(self.feature_config.keys()) not in [
8386
len(cube_inputs),
@@ -122,6 +125,7 @@ def _read_parquet_files(
122125
("experiment", "==", self.experiment),
123126
]
124127
]
128+
125129
for file in Path(forecast_table_path).glob("**/*.parquet"):
126130
if pq.read_schema(file).get_all_field_indices("percentile"):
127131
altered_schema = FORECAST_SCHEMA
@@ -162,6 +166,7 @@ def _read_parquet_files(
162166
truth_df = pd.read_parquet(
163167
truth_table_path, filters=filters, schema=TRUTH_SCHEMA, engine="pyarrow"
164168
)
169+
165170
truth_df["time"] = pd.to_datetime(truth_df["time"], unit="ns", utc=True)
166171

167172
if truth_df.empty:

improver/calibration/quantile_regression_random_forest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,7 @@ def __init__(
501501
f"and cbrt. The transformation supplied was {self.transformation}."
502502
)
503503
raise ValueError(msg)
504+
print(pre_transform_addition)
504505
self.pre_transform_addition = pre_transform_addition
505506

506507
def _reverse_transformation(self, forecast_cube: Cube):

improver/cli/apply_quantile_regression_random_forest.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ def process(
1414
*file_paths: cli.inputpath,
1515
feature_config: cli.inputjson,
1616
target_cube_name: str,
17-
n_estimators: int = 100,
1817
transformation: str = None,
1918
pre_transform_addition: float = 0,
2019
):
@@ -52,8 +51,6 @@ def process(
5251
A string containing the cube name of the forecast to be
5352
calibrated. This will be used to separate it from the rest of the
5453
feature cubes, if present.
55-
n_estimators (int):
56-
Number of trees in the forest.
5754
transformation (str):
5855
Transformation to be applied to the data before fitting.
5956
pre_transform_addition (float):
@@ -71,7 +68,6 @@ def process(
7168
file_paths,
7269
feature_config=feature_config,
7370
target_cube_name=target_cube_name,
74-
n_estimators=n_estimators,
7571
transformation=transformation,
7672
pre_transform_addition=pre_transform_addition,
7773
)

0 commit comments

Comments
 (0)