Skip to content

Commit a53a1dc

Browse files
committed
download raw data from UN
1 parent dda53bf commit a53a1dc

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

ogcore/demographics.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ def get_fert(
146146
df = get_un_data(
147147
"68", country_id=country_id, start_year=start_year, end_year=end_year
148148
)
149+
if download_path:
150+
df.to_csv(os.path.join(download_path, "raw_fert_data_UN.csv"), index=False)
149151
# CLean and rebin data
150152
for y in range(start_year, end_year + 1):
151153
df_y = df[(df.age >= min_age) & (df.age <= max_age) & (df.year == y)]
@@ -232,6 +234,8 @@ def get_mort(
232234
df = get_un_data(
233235
"80", country_id=country_id, start_year=start_year, end_year=end_year
234236
)
237+
if download_path:
238+
df.to_csv(os.path.join(download_path, "raw_mort_data_UN.csv"), index=False)
235239
# CLean and rebin data
236240
for y in range(start_year, end_year + 1):
237241
df_y = df[(df.age >= min_age) & (df.age <= max_age) & (df.year == y)]
@@ -345,6 +349,8 @@ def get_pop(
345349
start_year=start_year - 1,
346350
end_year=start_year - 1,
347351
)
352+
if download_path:
353+
pre_pop_data.to_csv(os.path.join(download_path, "raw_pre_pop_data_UN.csv"), index=False)
348354
pre_pop_sample = pre_pop_data[
349355
(pre_pop_data["age"] >= min_age)
350356
& (pre_pop_data["age"] <= max_age)
@@ -397,6 +403,8 @@ def get_pop(
397403
end_year=end_year
398404
+ 2, # note go to + 2 because needed to infer immigration for end_year
399405
)
406+
if download_path:
407+
pop_data.to_csv(os.path.join(download_path, "raw_pop_data_UN.csv"), index=False)
400408
# CLean and rebin data
401409
for y in range(start_year, end_year + 2):
402410
pop_data_sample = pop_data[
@@ -663,7 +671,7 @@ def get_pop_objs(
663671
pre_pop_dist=None,
664672
country_id=UN_COUNTRY_CODE,
665673
initial_data_year=START_YEAR - 1,
666-
final_data_year=START_YEAR + 2, # as default data year goes until T1
674+
final_data_year=START_YEAR + 2,
667675
GraphDiag=True,
668676
download_path=None,
669677
):
@@ -733,8 +741,8 @@ def get_pop_objs(
733741
final_data_year,
734742
)
735743
assert E + S <= max_age - min_age + 1
736-
assert initial_data_year >= 2011 and initial_data_year <= 2100
737-
assert final_data_year >= 2011 and final_data_year <= 2100
744+
assert initial_data_year >= 2011 and initial_data_year <= 2100 - 1
745+
assert final_data_year >= 2011 and final_data_year <= 2100 - 1
738746
# Ensure that the last year of data used is before SS transition assumed
739747
# Really, it will need to be well before this
740748
assert final_data_year > initial_data_year

0 commit comments

Comments
 (0)