-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4e8141f
commit 65d3a2b
Showing
5 changed files
with
126 additions
and
2 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
openfisca_france_data/assets/aggregats/demographie/README transition depuis INSEE.txt
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,2 @@ | ||
Le tableur est issu de https://www.insee.fr/fr/statistiques/5894083?sommaire=5760764 , onglet population. | ||
Quelques changements ont été faits pour mieux le parser : conversion en csv, séparateur des milliers mis à "." plutôt qu'à " " (dans Fichier/Options/Options avancées/Utiliser les séparateurs systèmes/Séparateur des milliers), 105 + changé en 105. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import numpy as np | ||
from numpy import minimum as min_ | ||
|
||
from openfisca_france.model.base import * # noqa analysis:ignore | ||
from openfisca_core.reforms import Reform | ||
|
||
import logging | ||
|
||
log = logging.getLogger(__name__) | ||
def create_calibration_tax_benefit_system(survey_scenario = None): | ||
class variables_pour_calibration(Reform): | ||
name = 'variables_pour_calibration' | ||
|
||
def apply(self): | ||
|
||
class age_calage(Variable): | ||
value_type = str | ||
entity = Individu | ||
label = "Age censuré pour calage" | ||
definition_period = YEAR | ||
unit = 'years' | ||
is_period_size_independent = True | ||
set_input = set_input_dispatch_by_period | ||
|
||
def formula(individu, period): | ||
age = individu('age', period.first_month) | ||
return min_(age, 100) | ||
|
||
self.add_variable(age_calage) | ||
scenario_for_calibration = variables_pour_calibration(survey_scenario) | ||
return scenario_for_calibration |
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,47 @@ | ||
import os | ||
|
||
import pytest | ||
|
||
from openfisca_survey_manager.calibration import Calibration # type: ignore | ||
from openfisca_france_data import openfisca_france_data_location | ||
from openfisca_france_data.model.calage import create_dic_calage | ||
from openfisca_france_data.reforms.variables_calibration import create_calibration_tax_benefit_system | ||
from openfisca_france_data.erfs_fpr.scenario import ( # type: ignore | ||
ErfsFprSurveyScenario, | ||
) | ||
from openfisca_france_data import france_data_tax_benefit_system | ||
|
||
@pytest.fixture | ||
def location() -> str: | ||
return openfisca_france_data_location | ||
|
||
|
||
def test_calage(survey_scenario, fake_input_data, location, year: int = 2015): | ||
# On ititialise le survey scenario | ||
survey_scenario2 = ErfsFprSurveyScenario.create( | ||
tax_benefit_system = create_calibration_tax_benefit_system(france_data_tax_benefit_system), | ||
period = year, | ||
) | ||
survey_scenario = survey_scenario2 | ||
|
||
# On charge les données | ||
input_data = fake_input_data(year) | ||
|
||
# On fait la calibration | ||
parameters = dict( | ||
method = "logit", | ||
invlo = 3, | ||
up = 3, | ||
) | ||
|
||
base_year = 2013 | ||
|
||
target_margins_by_variable = create_dic_calage(year, base_year, ["age"]) | ||
|
||
calibration_kwargs = {'target_margins_by_variable': target_margins_by_variable, 'parameters': parameters} | ||
|
||
# On initialise le survey scenario | ||
survey_scenario.init_from_data(data = dict(input_data_frame = input_data), calibration_kwargs = calibration_kwargs) | ||
weight_base = sum(survey_scenario.calculate_variable("wprm", period = base_year)) | ||
|
||
assert weight_base < sum(survey_scenario.calculate_variable("wprm", period = year)) |