Skip to content

Commit

Permalink
Merge pull request #952 from jdebacker/demog_plots
Browse files Browse the repository at this point in the history
Merging
  • Loading branch information
rickecon authored Jul 30, 2024
2 parents d76096f + 410af1c commit 19c90fc
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 21 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.11.14] - 2024-07-30 12:00:00

### Added

- Aesthetic updates to plotting functions in `parameter_plots.py` and `demographics.py`

## [0.11.13] - 2024-07-28 12:00:00

### Added
Expand Down Expand Up @@ -270,7 +276,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Version [0.7.0] on August 30, 2021 was the first time that the OG-USA repository was detached from all of the core model logic, which was named OG-Core. Before this version, OG-USA was part of what is now the [`OG-Core`](https://github.com/PSLmodels/OG-Core) repository. In the next version of OG-USA, we adjusted the version numbering to begin with 0.1.0. This initial version of 0.7.0, was sequential from what OG-USA used to be when the OG-Core project was called OG-USA.
- Any earlier versions of OG-USA can be found in the [`OG-Core`](https://github.com/PSLmodels/OG-Core) repository [release history](https://github.com/PSLmodels/OG-Core/releases) from [v.0.6.4](https://github.com/PSLmodels/OG-Core/releases/tag/v0.6.4) (Jul. 20, 2021) or earlier.


[0.11.14]: https://github.com/PSLmodels/OG-Core/compare/v0.11.13...v0.11.14
[0.11.13]: https://github.com/PSLmodels/OG-Core/compare/v0.11.11...v0.11.13
[0.11.11]: https://github.com/PSLmodels/OG-Core/compare/v0.11.10...v0.11.11
[0.11.10]: https://github.com/PSLmodels/OG-Core/compare/v0.11.9...v0.11.10
Expand Down
2 changes: 1 addition & 1 deletion ogcore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
from ogcore.txfunc import *
from ogcore.utils import *

__version__ = "0.11.13"
__version__ = "0.11.14"
24 changes: 18 additions & 6 deletions ogcore/demographics.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,19 +206,23 @@ def get_fert(

# Create plots if needed
if graph:
if start_year == end_year:
years_to_plot = [start_year]
else:
years_to_plot = [start_year, end_year]
if plot_path is not None:
pp.plot_fert_rates(
[fert_rates_2D],
start_year=start_year,
years_to_plot=[start_year, end_year],
years_to_plot=years_to_plot,
path=plot_path,
)
return fert_rates_2D
else:
fig = pp.plot_fert_rates(
[fert_rates_2D],
start_year=start_year,
years_to_plot=[start_year, end_year],
years_to_plot=years_to_plot,
)
return fert_rates_2D, fig
else:
Expand Down Expand Up @@ -296,19 +300,23 @@ def get_mort(

# Create plots if needed
if graph:
if start_year == end_year:
years_to_plot = [start_year]
else:
years_to_plot = [start_year, end_year]
if plot_path is not None:
pp.plot_mort_rates_data(
mort_rates_2D,
start_year,
[start_year, end_year],
years_to_plot,
path=plot_path,
)
return mort_rates_2D, infmort_rate_vec
else:
fig = pp.plot_mort_rates_data(
mort_rates_2D,
start_year,
[start_year, end_year],
years_to_plot,
)
return mort_rates_2D, infmort_rate_vec, fig
else:
Expand Down Expand Up @@ -631,19 +639,23 @@ def get_imm_rates(

# Create plots if needed
if graph:
if start_year == end_year:
years_to_plot = [start_year]
else:
years_to_plot = [start_year, end_year]
if plot_path is not None:
pp.plot_imm_rates(
imm_rates_2D,
start_year,
[start_year, end_year],
years_to_plot,
path=plot_path,
)
return imm_rates_2D
else:
fig = pp.plot_imm_rates(
imm_rates_2D,
start_year,
[start_year, end_year],
years_to_plot,
)
return imm_rates_2D, fig
else:
Expand Down
20 changes: 8 additions & 12 deletions ogcore/parameter_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import os
import matplotlib.pyplot as plt
import matplotlib
from cycler import cycler
from ogcore.constants import GROUP_LABELS
from ogcore import utils, txfunc
from ogcore.constants import DEFAULT_START_YEAR, VAR_LABELS
Expand Down Expand Up @@ -34,7 +33,6 @@ def plot_imm_rates(
"""
# create line styles to cycle through
plt.rc("axes", prop_cycle=(cycler("linestyle", [":", "-.", "-", "--"])))
fig, ax = plt.subplots()
for y in years_to_plot:
i = start_year - y
Expand All @@ -46,7 +44,7 @@ def plot_imm_rates(
plt.legend(loc="upper left")
plt.text(
-5,
-0.023,
-0.05,
"Source: " + source,
fontsize=9,
)
Expand Down Expand Up @@ -258,7 +256,7 @@ def plot_ability_profiles(
return fig
else:
fig_path = os.path.join(path, "ability_profiles")
plt.savefig(fig_path, bbox_inches="tight")
plt.savefig(fig_path, bbox_inches="tight", dpi=300)


def plot_elliptical_u(p, plot_MU=True, include_title=False, path=None):
Expand Down Expand Up @@ -389,7 +387,6 @@ def plot_fert_rates(
"""
# create line styles to cycle through
plt.rc("axes", prop_cycle=(cycler("linestyle", [":", "-.", "-", "--"])))
fig, ax = plt.subplots()
for y in years_to_plot:
i = start_year - y
Expand Down Expand Up @@ -441,7 +438,6 @@ def plot_mort_rates_data(
"""
# create line styles to cycle through
plt.rc("axes", prop_cycle=(cycler("linestyle", [":", "-.", "-", "--"])))
fig, ax = plt.subplots()
for y in years_to_plot:
i = start_year - y
Expand Down Expand Up @@ -706,7 +702,7 @@ def gen_3Dscatters_hist(df, s, t, output_dir):
)
filename = "ETR_age_" + str(s) + "_Year_" + str(t) + "_data.png"
fullpath = os.path.join(output_dir, filename)
fig.savefig(fullpath, bbox_inches="tight")
fig.savefig(fullpath, bbox_inches="tight", dpi=300)
plt.close()

# Plot 3D histogram for all data
Expand Down Expand Up @@ -737,7 +733,7 @@ def gen_3Dscatters_hist(df, s, t, output_dir):
)
filename = "Hist_Age_" + str(s) + "_Year_" + str(t) + ".png"
fullpath = os.path.join(output_dir, filename)
fig.savefig(fullpath, bbox_inches="tight")
fig.savefig(fullpath, bbox_inches="tight", dpi=300)
plt.close()

# Plot 3D scatterplot of MTRx data
Expand All @@ -755,7 +751,7 @@ def gen_3Dscatters_hist(df, s, t, output_dir):
)
filename = "MTRx_Age_" + str(s) + "_Year_" + str(t) + "_data.png"
fullpath = os.path.join(output_dir, filename)
fig.savefig(fullpath, bbox_inches="tight")
fig.savefig(fullpath, bbox_inches="tight", dpi=300)
plt.close()

# Plot 3D scatterplot of MTRy data
Expand All @@ -773,7 +769,7 @@ def gen_3Dscatters_hist(df, s, t, output_dir):
)
filename = "MTRy_Age_" + str(s) + "_Year_" + str(t) + "_data.png"
fullpath = os.path.join(output_dir, filename)
fig.savefig(fullpath, bbox_inches="tight")
fig.savefig(fullpath, bbox_inches="tight", dpi=300)
plt.close()

# Garbage collection
Expand Down Expand Up @@ -855,7 +851,7 @@ def txfunc_graph(
ax.plot_surface(X_grid, Y_grid, txrate_grid, cmap=cmap1, linewidth=0)
filename = tx_label + "_age_" + str(s) + "_Year_" + str(t) + "_vsPred.png"
fullpath = os.path.join(output_dir, filename)
fig.savefig(fullpath, bbox_inches="tight")
fig.savefig(fullpath, bbox_inches="tight", dpi=300)
plt.close()

# Make comparison plot with truncated income domains
Expand Down Expand Up @@ -908,7 +904,7 @@ def txfunc_graph(
tx_label + "trunc_age_" + str(s) + "_Year_" + str(t) + "_vsPred.png"
)
fullpath = os.path.join(output_dir, filename)
fig.savefig(fullpath, bbox_inches="tight")
fig.savefig(fullpath, bbox_inches="tight", dpi=300)
plt.close()


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="ogcore",
version="0.11.13",
version="0.11.14",
author="Jason DeBacker and Richard W. Evans",
license="CC0 1.0 Universal (CC0 1.0) Public Domain Dedication",
description="A general equilibribum overlapping generations model for fiscal policy analysis",
Expand Down

0 comments on commit 19c90fc

Please sign in to comment.