Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ output/*/index.html

# Sphinx
docs/_build
tutorials/1_basic_popgen_setup/*all_controls_ipu
47 changes: 26 additions & 21 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,38 @@ language: python

python:
- "2.7"
- "3.5"
- "3.6"

#before_install:
# - sudo apt-get install liblapack-dev gfortran

# command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors
# install:
# - travis_wait pip install -r requirements.txt


before_install:
- wget http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh
- chmod +x miniconda.sh
- ./miniconda.sh -b
- export PATH=/home/travis/miniconda/bin:$PATH
# Update conda itself
- conda update --yes conda
# The next couple lines fix a crash with multiprocessing
# on Travis and are not specific to using Miniconda
- sudo rm -rf /dev/shm
- sudo ln -s /run/shm /dev/shm

install:
- conda create --yes -n popgen_venv python=$TRAVIS_PYTHON_VERSION pip numpy scipy pandas PyYAML
- sudo apt-get update
# We do this conditionally because it saves us some downloading if the
# version is the same.
- if [[ "$TRAVIS_PYTHON_VERSION" == "2.7" ]]; then
wget https://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86_64.sh -O miniconda.sh;
else
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh;
fi
- bash miniconda.sh -b -p $HOME/miniconda
- export PATH="$HOME/miniconda/bin:$PATH"
- hash -r
- conda config --set always_yes yes --set changeps1 no
- conda update -q conda
# Useful for debugging any issues with conda
- conda info -a

- conda create -q -n popgen_venv python=$TRAVIS_PYTHON_VERSION pip numpy scipy pandas PyYAML pytest
- source activate popgen_venv
- pip install pytest
- python setup.py install

# command to run tests, e.g. python setup.py test
script:
- py.test







2 changes: 2 additions & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ Contributors
------------

* Daehyun You
* Jeffrey Newman <[email protected]>

8 changes: 7 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
History
-------

2.1.b1 (March 23, 2017)
+++++++++++++++++++++++

* Updated for Python 3.5+


2.0.b1 (June 4, 2015)
++++++++++++++++++
+++++++++++++++++++++

* This is the first non-production release of PopGen 2.0
15 changes: 3 additions & 12 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
=============================
==================================
Synthetic Population Generator 2.0
=============================
==================================

.. image:: https://badge.fury.io/py/popgen.png
:target: http://badge.fury.io/py/popgen
Expand All @@ -12,15 +12,6 @@ Synthetic Population Generator 2.0
:target: https://pypi.python.org/pypi/popgen


Synthetic Population Generator 2.0


Features
--------

For PopGen 2.1
* Automatic data validator
* Census data importer
This fork contains code that has been modified to be compatible with Python 2.7 and 3.5 and up.

For PopGen 2.2
* Output Data Analyzer with charting and table generation capabilities
4 changes: 2 additions & 2 deletions bin/popgen_run
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def run():
"""
args = sys.argv[1:]

print args
print (args)

if len(args) != 1:
raise ArgumentsError(
Expand All @@ -35,6 +35,6 @@ def run():
p_obj = Project(config_loc=args[0])
p_obj.load_project()
p_obj.run_scenarios()
print "Time it took: %.4f" % (time.time() - t)
print ("Time it took: %.4f" % (time.time() - t))

run()
2 changes: 2 additions & 0 deletions popgen/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from .project import Project

__version__ = '2.1.b2' # now for Python 3!
9 changes: 5 additions & 4 deletions popgen/config.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import yaml


Expand All @@ -16,7 +17,7 @@ def wrap_config_value(value):
then attribute access x.attribute1.attribute2 is used to access "Value".
Also, x.attribute can be used to access the dictionary {attribute: 'value'}
"""
if isinstance(value, basestring):
if isinstance(value, str):
return value

try:
Expand Down Expand Up @@ -45,7 +46,7 @@ def __getitem__(self, key):
def return_value(self, key):
try:
value = self._data[key]
except KeyError, e:
except KeyError as e:
raise ConfigError(
"Key - %s doesn't exist in the YAML configuration" % key)
return value
Expand Down Expand Up @@ -78,5 +79,5 @@ def write_to_file(self, filepath):

config_dict = yaml.load(yaml_f)
config_obj = Config(config_dict)
print config_obj.project.name
print config_obj["project"]["name"]
print (config_obj.project.name)
print (config_obj["project"]["name"])
7 changes: 4 additions & 3 deletions popgen/data.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from __future__ import print_function
import os

import pandas as pd
import numpy as np

from config import ConfigError
from .config import ConfigError


class DB(object):
Expand Down Expand Up @@ -89,8 +90,8 @@ def enumerate_geo_ids_for_scenario(self, scenario_config):
self.geo_ids = []
for region_id in self.region_ids:
self.geo_ids += self.get_geo_ids_for_region(region_id)
except ConfigError, e:
print "KeyError", e
except ConfigError as e:
print ("KeyError", e)
self.geo_ids = self.geo_ids_all
# self.sample_geo_ids = self.sample_geo_ids_all
self.region_ids = self.region_ids_all
Expand Down
5 changes: 3 additions & 2 deletions popgen/draw.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import pandas as pd
import numpy as np
from scipy import stats
Expand Down Expand Up @@ -86,11 +87,11 @@ def _return_cumulative_probability(self, geo_sample_weights):

def _pick_households(self, geo_id_frequencies, geo_cumulative_weights):
last = 0
rand_numbers = np.random.random(geo_id_frequencies.sum())
rand_numbers = np.random.random(int(geo_id_frequencies.sum()))
list_rows_syn_subpop = []
for column in self.geo_frequencies.columns.values:
rows = self.geo_row_idx[column]
column_frequency = geo_id_frequencies[column]
column_frequency = int(geo_id_frequencies[column])
column_bins = np.searchsorted(geo_cumulative_weights[column],
(rand_numbers[
last:last + column_frequency]),
Expand Down
7 changes: 4 additions & 3 deletions popgen/ipf.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import copy

import numpy as np
Expand Down Expand Up @@ -62,7 +63,7 @@ def __init__(self, seed_all, seed, idx, marginals, ipf_config,
def run_ipf(self):
self.frequencies = self._correct_zero_cell_issue()
# self.frequencies = self.seed["frequency"].values
for c_iter in xrange(self.ipf_iters):
for c_iter in range(self.ipf_iters):
# print "Iter:", c_iter
self._adjust_cell_frequencies()
# Checks for convergence every 5 iterations
Expand Down Expand Up @@ -273,7 +274,7 @@ def _run_ipf_all_geos(self, entity, seed_geo, seed_all, row_idx, marginals,
sample_geo_id = geo_corr_to_sample.loc[geo_id,
self.sample_geo_name]
if isinstance(sample_geo_id, pd.Series):
seed_geo_levels_list = range(len(seed_geo.index.names))
seed_geo_levels_list = tuple(range(len(seed_geo.index.names)))
seed_for_geo_id = (seed_geo.loc[sample_geo_id.tolist()]
.sum(level=seed_geo_levels_list[1:]))
# print (seed_geo.loc[sample_geo_id.tolist()])
Expand Down Expand Up @@ -340,7 +341,7 @@ def _get_stacked_constraints(self, constraints_list):

def _get_columns_constraints_dict(self, constraints_dict):
columns_constraints_dict = {}
for entity, constraints in constraints_dict.iteritems():
for entity, constraints in constraints_dict.items():
columns_constraints_dict[entity] = (constraints
.index.values.tolist())
# print columns_constraints_dict
Expand Down
Loading