-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Rename estimation module * Add apply_estimation function * Fix estimation preprocessing and application * Fix filepaths * Fix estimation after running on anon data * Update tests * Update utils and config * Optimise for memory usage * Refactor for combined output run * Fix get_estimation_data period parameter * Remove get_qv_df function * Make is_close tolerance explicit
- Loading branch information
1 parent
e5ed3c2
commit 0559c73
Showing
10 changed files
with
203 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import glob | ||
|
||
import pandas as pd | ||
|
||
from mbs_results.calculate_estimation_weights import ( | ||
calculate_calibration_factor, | ||
calculate_design_weight, | ||
) | ||
from mbs_results.pre_processing_estimation import get_estimation_data | ||
|
||
# from mbs_results.validate_estimation import validate_estimation | ||
|
||
|
||
def apply_estimation(population_path, sample_path, period, **config): | ||
""" | ||
Read population frame and sample, merge key variables onto df then derive | ||
and validate estimation weights. | ||
Parameters | ||
---------- | ||
population_path : str | ||
filepath for population frame data | ||
sample_path : str | ||
filepath for sample data | ||
period : str | ||
name of column containing period | ||
Returns | ||
------- | ||
population frame with calibration group, sampled flag, design weight and | ||
calibration factor | ||
Raises | ||
------ | ||
`ValueError` | ||
""" | ||
population_files = glob.glob(population_path) | ||
sample_files = glob.glob(sample_path) | ||
|
||
estimation_df_list = [] | ||
|
||
for population_file, sample_file in zip(population_files, sample_files): | ||
estimation_data = get_estimation_data( | ||
population_file, sample_file, period, **config | ||
) | ||
|
||
estimation_data = calculate_design_weight(estimation_data, period, **config) | ||
estimation_data = calculate_calibration_factor( | ||
estimation_data, period, **config | ||
) | ||
|
||
estimation_df_list.append(estimation_data) | ||
|
||
estimation_df = pd.concat(estimation_df_list, ignore_index=True) | ||
|
||
# validate_estimation(estimation_df, **config) | ||
|
||
return estimation_df |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.