Skip to content

Commit

Permalink
Merge pull request #156 from prio-data/pgm_models
Browse files Browse the repository at this point in the history
Add all pgm level models
  • Loading branch information
Polichinel authored Nov 13, 2024
2 parents dda62fd + d59466f commit 021e50b
Show file tree
Hide file tree
Showing 286 changed files with 21,948 additions and 1,182 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -211,5 +211,8 @@ cython_debug/
*.bak

# txt logs

*.txt

# logs
*.log
*.log.*
158 changes: 158 additions & 0 deletions common_querysets/queryset_bad_blood.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
from viewser import Queryset, Column

def generate():

qs_natsoc = (Queryset('fatalities003_pgm_natsoc','priogrid_month')

.with_column(Column('ln_ged_sb_dep', from_loa='priogrid_month', from_column='ged_sb_best_sum_nokgi')
.transform.missing.replace_na()
.transform.ops.ln()
)

.with_column(Column('ln_ged_sb', from_loa='priogrid_month', from_column='ged_sb_best_sum_nokgi')
.transform.ops.ln()
.transform.missing.fill()
)

.with_column(Column('imr_mean', from_loa='priogrid_year', from_column='imr_mean')
.transform.missing.fill()
.transform.missing.replace_na()
)

.with_column(Column('mountains_mean', from_loa='priogrid_year', from_column='mountains_mean')
.transform.missing.fill()
.transform.missing.replace_na()
)

.with_column(Column('dist_diamsec', from_loa='priogrid', from_column='dist_diamsec_s_wgs')
.transform.missing.fill()
.transform.missing.replace_na()
)

.with_column(Column('dist_petroleum', from_loa='priogrid', from_column='dist_petroleum_s_wgs')
.transform.missing.fill()
.transform.missing.replace_na()
)

.with_column(Column('agri_ih', from_loa='priogrid_year', from_column='agri_ih')
.transform.missing.fill()
.transform.missing.replace_na()
)

.with_column(Column('barren_ih', from_loa='priogrid_year', from_column='barren_ih')
.transform.missing.fill()
.transform.missing.replace_na()
)

.with_column(Column('forest_ih', from_loa='priogrid_year', from_column='forest_ih')
.transform.missing.fill()
.transform.missing.replace_na()
)

.with_column(Column('pasture_ih', from_loa='priogrid_year', from_column='pasture_ih')
.transform.missing.fill()
.transform.missing.replace_na()
)

.with_column(Column('savanna_ih', from_loa='priogrid_year', from_column='savanna_ih')
.transform.missing.fill()
.transform.missing.replace_na()
)

.with_column(Column('shrub_ih', from_loa='priogrid_year', from_column='shrub_ih')
.transform.missing.fill()
.transform.missing.replace_na()
)

.with_column(Column('urban_ih', from_loa='priogrid_year', from_column='urban_ih')
.transform.missing.fill()
.transform.missing.replace_na()
)

.with_column(Column('ln_pop_gpw_sum', from_loa='priogrid_year', from_column='pop_gpw_sum')
.transform.ops.ln()
.transform.missing.fill()
.transform.missing.replace_na()
)

.with_column(Column('ln_ttime_mean', from_loa='priogrid_year', from_column='ttime_mean')
.transform.ops.ln()
.transform.missing.fill()
.transform.missing.replace_na()
)

.with_column(Column('ln_gcp_mer', from_loa='priogrid_year', from_column='gcp_mer')
.transform.ops.ln()
.transform.missing.fill()
.transform.missing.replace_na()
)

.with_column(Column('ln_bdist3', from_loa='priogrid_year', from_column='bdist3')
.transform.ops.ln()
.transform.missing.fill()
.transform.missing.replace_na()
)

.with_column(Column('ln_capdist', from_loa='priogrid_year', from_column='capdist')
.transform.ops.ln()
.transform.missing.fill()
.transform.missing.replace_na()
)

.with_column(Column('greq_1_excluded', from_loa='priogrid_year', from_column='excluded')
.transform.bool.gte(1)
.transform.missing.fill()
.transform.missing.replace_na()
)

.with_column(Column('decay_ged_sb_1', from_loa='priogrid_month', from_column='ged_sb_best_sum_nokgi')
.transform.missing.replace_na()
.transform.bool.gte(1)
.transform.temporal.time_since()
.transform.temporal.decay(24)
.transform.missing.replace_na()
)

.with_column(Column('decay_ged_sb_25', from_loa='priogrid_month', from_column='ged_sb_best_sum_nokgi')
.transform.missing.replace_na()
.transform.bool.gte(25)
.transform.temporal.time_since()
.transform.temporal.decay(24)
.transform.missing.replace_na()
)

.with_column(Column('decay_ged_os_1', from_loa='priogrid_month', from_column='ged_os_best_sum_nokgi')
.transform.missing.replace_na()
.transform.bool.gte(1)
.transform.temporal.time_since()
.transform.temporal.decay(24)
.transform.missing.replace_na()
)

.with_column(Column('splag_1_1_sb_1', from_loa='priogrid_month', from_column='ged_sb_best_sum_nokgi')
.transform.missing.replace_na()
.transform.bool.gte(1)
.transform.temporal.time_since()
.transform.temporal.decay(24)
.transform.spatial.lag(1,1,0,0)
.transform.missing.replace_na()
)

.with_column(Column('splag_1_decay_ged_sb_1', from_loa='priogrid_month', from_column='ged_sb_best_sum_nokgi')
.transform.missing.replace_na()
.transform.bool.gte(1)
.transform.temporal.time_since()
.transform.temporal.decay(24)
.transform.spatial.lag(1,1,0,0)
.transform.missing.replace_na()
)

.with_theme('fatalities')
.describe("""Fatalities natural and social geography, pgm level
Predicting ln(fatalities) using natural and social geography features
""")
)

return qs_natsoc
Loading

0 comments on commit 021e50b

Please sign in to comment.