Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demographics.py and build_and_test.yml #4

Merged
merged 2 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,31 @@ on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.9", "3.10"]

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
persist-credentials: false

- name: Setup Python
uses: actions/setup-python@v4
- name: Setup Miniconda using Python ${{ matrix.python-version }}
uses: conda-incubator/setup-miniconda@v2
with:
miniforge-variant: Mambaforge
auto-update-conda: true
activate-environment: ogusa-dev
environment-file: environment.yml
python-version: ${{ matrix.python-version }}
auto-activate-base: false

- name: Build
shell: bash -l {0}
run: |
conda init bash
conda env create
conda activate ogusa-dev
pip install -e .
pip install pytest-cov
pip install pytest-pycodestyle
Expand Down
83 changes: 43 additions & 40 deletions ogusa/demographics.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,25 +152,26 @@ def get_fert(
# pp.plot_fert_rates(fert_rates, age_midp, totpers, min_age, max_age,
# fert_rates, fert_rates, output_dir=OUTPUT_DIR)

output_dir = OUTPUT_DIR
# Using pyplot here until update to OG-Core mort rates plotting function
plt.plot(
np.arange(totpers),
fert_rates,
)
plt.xlabel(r"Age $s$")
plt.ylabel(r"Fertility rate")
plt.legend(loc="upper left")
# plt.text(
# -5,
# -0.2,
# "Source: United Nations Population Prospects.",
# fontsize=9,
# )
plt.tight_layout(rect=(0, 0.03, 1, 1))
output_path = os.path.join(output_dir, "fert_rates")
plt.savefig(output_path)
plt.close()
if graph:
output_dir = OUTPUT_DIR
# Using pyplot here until update to OG-Core mort rates plotting function
plt.plot(
np.arange(totpers),
fert_rates,
)
plt.xlabel(r"Age $s$")
plt.ylabel(r"Fertility rate")
plt.legend(loc="upper left")
# plt.text(
# -5,
# -0.2,
# "Source: United Nations Population Prospects.",
# fontsize=9,
# )
plt.tight_layout(rect=(0, 0.03, 1, 1))
output_path = os.path.join(output_dir, "fert_rates")
plt.savefig(output_path)
plt.close()

return fert_rates

Expand All @@ -182,7 +183,7 @@ def get_mort(
country_id=UN_COUNTRY_CODE,
start_year=START_YEAR,
end_year=END_YEAR,
graph=True,
graph=False,
):
"""
This function generates a vector of mortality rates by model period
Expand Down Expand Up @@ -297,6 +298,7 @@ def get_imm_rates(
country_id=UN_COUNTRY_CODE,
start_year=START_YEAR,
end_year=END_YEAR,
graph=False,
):
"""
Calculate immigration rates by age as a residual given population
Expand Down Expand Up @@ -380,26 +382,27 @@ def get_imm_rates(
# Final estimated immigration rates are the averages over 3 years
imm_rates = imm_mat.mean(axis=0)

output_dir = OUTPUT_DIR
# Using pyplot here until update to OG-Core mort rates plotting function
plt.plot(
np.arange(totpers),
imm_rates,
label="Estimated",
)
plt.xlabel(r"Age $s$")
plt.ylabel(r"Immigration Rates")
plt.legend(loc="upper left")
plt.text(
-5,
-0.2,
"Source: United Nations Population Prospects.",
fontsize=9,
)
plt.tight_layout(rect=(0, 0.03, 1, 1))
output_path = os.path.join(output_dir, "imm_rates_w_un_data.png")
plt.savefig(output_path)
plt.close()
if graph:
output_dir = OUTPUT_DIR
# Using pyplot here until update to OG-Core mort rates plotting function
plt.plot(
np.arange(totpers),
imm_rates,
label="Estimated",
)
plt.xlabel(r"Age $s$")
plt.ylabel(r"Immigration Rates")
plt.legend(loc="upper left")
plt.text(
-5,
-0.2,
"Source: United Nations Population Prospects.",
fontsize=9,
)
plt.tight_layout(rect=(0, 0.03, 1, 1))
output_path = os.path.join(output_dir, "imm_rates_w_un_data.png")
plt.savefig(output_path)
plt.close()

return imm_rates

Expand Down
Loading