Пример #1
0
    def _agg_age_std_ages(self):
        age_tree = agetree(age.AGE_STANDARDIZED)

        # make the source and sink
        source = self.gen_draw_source()
        source.add_transform(
            fill_square,
            index_cols=[
                col for col in self.dimensions.index_names
                if col != "age_group_id"
            ],
            square_col="age_group_id",
            square_col_vals=[node.id for node in age_tree.leaves()])
        sink = self.gen_draw_sink()

        # constuct aggregator obj
        operator = WtdSum(index_cols=[
            col for col in self.dimensions.index_names if col != "age_group_id"
        ],
                          value_cols=self.dimensions.data_list(),
                          weight_df=self.std_age_weights,
                          weight_name="age_group_weight_value",
                          merge_cols=["age_group_id"])
        aggregator = AggSynchronous(draw_source=source,
                                    draw_sink=sink,
                                    index_cols=[
                                        col
                                        for col in self.dimensions.index_names
                                        if col != "age_group_id"
                                    ],
                                    aggregate_col="age_group_id",
                                    operator=operator)

        # run the tree
        aggregator.run(age_tree)
Пример #2
0
    def compute_sex_aggregates(self):
        sex_tree = sextree()

        # make the source and sink
        source = self.gen_draw_source()
        source.add_transform(
            fill_square,
            index_cols=[
                col for col in self.dimensions.index_names if col != "sex_id"
            ],
            square_col="sex_id",
            square_col_vals=[node.id for node in sex_tree.leaves()])
        sink = self.gen_draw_sink()

        # construct aggregator obj
        operator = WtdSum(
            index_cols=[
                col for col in self.dimensions.index_names if col != "sex_id"
            ],
            value_cols=self.dimensions.data_list(),
            weight_df=self.population,
            weight_name="population",
            merge_cols=["location_id", "year_id", "age_group_id", "sex_id"])
        aggregator = AggSynchronous(draw_source=source,
                                    draw_sink=sink,
                                    index_cols=[
                                        col
                                        for col in self.dimensions.index_names
                                        if col != "sex_id"
                                    ],
                                    aggregate_col="sex_id",
                                    operator=operator)

        # run the tree
        aggregator.run(sex_tree)
Пример #3
0
    def run_task(self, location_set_version_id, component):
        source = self.get_source(component)
        sink = self.get_sink(component)
        dimensions = self.dimensions.get_dimension_by_component(
            component, self.measure_id)

        # get the tree we are aggregating
        loc_trees = dbtrees.loctree(
            location_set_version_id=location_set_version_id, return_many=True)
        for loc_tree in loc_trees:

            # get the weight vals
            pop = get_population(
                self.como_version,
                age_group_id=dimensions.index_dim.get_level("age_group_id"),
                location_id=[node.id for node in loc_tree.nodes],
                year_id=dimensions.index_dim.get_level("year_id"),
                sex_id=dimensions.index_dim.get_level("sex_id"))
            pop = pop[[
                "age_group_id", "location_id", "year_id", "sex_id",
                "population"
            ]]

            # set up our aggregation operator
            operator = WtdSum(index_cols=[
                col for col in dimensions.index_names if col != "location_id"
            ],
                              value_cols=dimensions.data_list(),
                              weight_df=pop,
                              weight_name="population",
                              merge_cols=[
                                  "location_id", "year_id", "age_group_id",
                                  "sex_id"
                              ])

            # run our aggregation
            aggregator = AggMemEff(draw_source=source,
                                   draw_sink=sink,
                                   index_cols=[
                                       col for col in dimensions.index_names
                                       if col != "location_id"
                                   ],
                                   aggregate_col="location_id",
                                   operator=operator,
                                   chunksize=self.chunksize[component])

            # run the tree
            aggregator.run(loc_tree,
                           draw_filters={
                               "measure_id": [self.measure_id],
                               "year_id":
                               dimensions.index_dim.get_level("year_id"),
                               "sex_id":
                               dimensions.index_dim.get_level("sex_id")
                           },
                           n_processes=self.chunksize[component])
Пример #4
0
                    write_func=partial(standard_write_func, index=False))

    index_cols = [
        'rei_id', 'year_id', 'age_group_id', 'sex_id', 'measure_id',
        'metric_id'
    ]
    draw_cols = ['draw_{}'.format(i) for i in range(n_draws)]

    for lsid in location_set_id:
        popfile = os.path.join(drawdir, 'population_{}.csv'.format(lsid))
        population = pd.read_csv(popfile)

        # aggregation operator
        operator = WtdSum(
            index_cols=index_cols,
            value_cols=draw_cols,
            weight_df=population,
            weight_name='population',
            merge_cols=['location_id', 'year_id', 'age_group_id', 'sex_id'])
        # run aggregation
        aggregator = AggMemEff(draw_source=source,
                               draw_sink=sink,
                               index_cols=index_cols,
                               aggregate_col='location_id',
                               operator=operator)

        if lsid == 40:
            loc_trees = loctree(location_set_id=lsid,
                                gbd_round_id=gbd_round_id,
                                return_many=True)
            for tree in loc_trees:
                aggregator.run(tree, draw_filters={'rei_id': rei_id})