示例#1
0
    def completion_status():
        mc_iters = int(Scenario.get_scen_value('monte_carlo_iterations'))
        cur_mc = int(Processing.get_current_monte())
        total_runs = int(Processing.get_total_runs())

        total_mc = (mc_iters * total_runs) / int(Globals.npes)
        total_mc_executed = mc_iters * Processing.get_num_runs_exec_this_cpu(
        ) + cur_mc
        complete = min(total_mc_executed / total_mc, 1.0)

        Logger.log(
            f"Run= {Processing.get_current_run()} of {total_runs} MC= {cur_mc} of {mc_iters}"
        )
示例#2
0
    def grow(z, land1):
        deltatron = PGrid.get_deltatron()
        avg_slope = 0

        if Processing.get_processing_type() == Globals.mode_enum['predict']:
            Processing.set_current_year(
                Scenario.get_scen_value('prediction_start_date'))
        else:
            Processing.set_current_year(IGrid.igrid.get_urban_year(0))

        Utilities.init_grid(z.gridData)
        # print(z.gridData)
        if len(Scenario.get_scen_value('landuse_data_file')) > 0:
            Grow.landuse_init(deltatron.gridData, land1.gridData)

        seed = IGrid.igrid.get_urban_grid(0)
        Utilities.condition_gif(seed, z.gridData)

        if Scenario.get_scen_value('echo'):
            print("******************************************")
            if Processing.get_processing_type(
            ) == Globals.mode_enum['calibrate']:
                c_run = Processing.get_current_run()
                t_run = Processing.get_total_runs()
                print(f"Run = {c_run} of {t_run}"
                      f" ({100 * c_run / t_run:8.1f} percent complete)")

            print(
                f"Monte Carlo = {int(Processing.get_current_monte()) + 1} of "
                f"{Scenario.get_scen_value('monte_carlo_iterations')}")
            print(f"Processing.current_year = {Processing.get_current_year()}")
            print(f"Processing.stop_year = {Processing.get_stop_year()}")

        if Scenario.get_scen_value('logging') and int(
                Scenario.get_scen_value('log_processing_status')) > 0:
            Grow.completion_status()

        while Processing.get_current_year() < Processing.get_stop_year():
            # Increment Current Year
            Processing.increment_current_year()

            cur_yr = Processing.get_current_year()
            if Scenario.get_scen_value('echo'):
                print(f" {cur_yr}", end='')
                sys.stdout.flush()
                if (cur_yr +
                        1) % 10 == 0 or cur_yr == Processing.get_stop_year():
                    print()

            if Scenario.get_scen_value('logging'):
                Logger.log(f" {cur_yr}")
                if (cur_yr +
                        1) % 10 == 0 or cur_yr == Processing.get_stop_year():
                    Logger.log("")

            # Apply the Cellular Automaton Rules for this Year
            avg_slope, num_growth_pix, sng, sdc, og, rt, pop = Spread.spread(
                z, avg_slope)
            #print(f"rt: {rt}")
            sdg = 0  # this isn't passed into spread, but I don't know why then it's here
            Stats.set_sng(sng)
            Stats.set_sdg(sdc)
            #Stats.set_sdc(sdc)
            Stats.set_og(og)
            Stats.set_rt(rt)
            Stats.set_pop(pop)

            if Scenario.get_scen_value('view_growth_types'):
                if IGrid.using_gif:
                    filename = f"{Scenario.get_scen_value('output_dir')}z_growth_types" \
                               f"_{Processing.get_current_run()}_{Processing.get_current_monte()}_" \
                               f"{Processing.get_current_year()}.gif"
                else:
                    filename = f"{Scenario.get_scen_value('output_dir')}z_growth_types" \
                               f"_{Processing.get_current_run()}_{Processing.get_current_monte()}_" \
                               f"{Processing.get_current_year()}.tif"

                date = str(Processing.get_current_year())
                ImageIO.write_gif(z, Color.get_growth_table(), filename, date,
                                  IGrid.nrows, IGrid.ncols)

            if len(Scenario.get_scen_value('landuse_data_file')) > 0:
                Grow.grow_landuse(land1, num_growth_pix)
            else:
                Grow.grow_non_landuse(z.gridData)

            seed = IGrid.igrid.get_urban_grid(0)
            Utilities.condition_gif(seed, z.gridData)

            # do Statistics
            Stats.update(num_growth_pix)

            # do Self Modification
            Coeff.self_modify(Stats.get_growth_rate(),
                              Stats.get_percent_urban())
            Coeff.write_current_coeff(Processing.get_current_run(),
                                      Processing.get_current_monte(),
                                      Processing.get_current_year())