Пример #1
0
#		count_plants_with_generation += 1
#print('Of {0} total plants, {1} have reported generation data.'.format(len(core_database),count_plants_with_generation))
print('Estimating generation...')
estimated_plants = pw.estimate_generation(core_database)
print('...estimated for {0} plants.'.format(estimated_plants))

# STEP 5: Write the Global Power Plant Database
for dbname, data in database_additions.iteritems():
    print("Added {0} plants ({1} MW) from {2}.".format(data['count'],
                                                       data['capacity'],
                                                       dbname))

f_log.close()
print("Loaded {0} plants to the Global Power Plant Database.".format(
    len(core_database)))
pw.write_csv_file(core_database, DATABASE_CSV_SAVEFILE)
print("Global Power Plant Database built.")

# STEP 6: Dump Data
if DATA_DUMP:
    print("Dumping all the data...")
    # STEP 6.1: Label plants in datadump
    pw_idnrs = core_database.keys()
    for plant_id, plant in datadump.iteritems():
        if plant_id in pw_idnrs:
            plant.idnr = plant_id + ",Yes"
        else:
            plant.idnr = plant_id + ",No"

    # STEP 6.2: Add unused CARMA plants
    for plant_id, plant in carma_database.iteritems():
            geolocation_source = pw.NO_DATA_UNICODE
    else:
        location = pw.LocationObject()
        geolocation_source = pw.NO_DATA_UNICODE

    if create_new_plant:
        plant_idnr = pw.make_id(SAVE_CODE_GBR, count)
        count += 1
        new_plant = pw.PowerPlant(plant_idnr=plant_idnr,
                                  plant_name=name,
                                  plant_owner=owner,
                                  plant_country=COUNTRY_NAME,
                                  plant_capacity=capacity,
                                  plant_cap_year=DUKES_YEAR,
                                  plant_source=SOURCE_NAME,
                                  plant_source_url=SOURCE_URL,
                                  plant_location=location,
                                  plant_coord_source=geolocation_source,
                                  plant_fuel=fuel_type)
    plants_dictionary[plant_idnr] = new_plant

# report on plants read from file
print(u"Loaded {0} plants to database.".format(len(plants_dictionary)))

# write database to csv format
pw.write_csv_file(plants_dictionary, CSV_FILE_NAME)

# save database
pw.save_database(plants_dictionary, SAVE_CODE_GBR, SAVE_DIRECTORY)
print(u"Pickled database to {0}".format(SAVE_DIRECTORY))
    country = plant_info[0]
    fuel_index = plant_info[1]
    fuel_type = fuel_type_list[fuel_index]
    capacity = plant_info[2]
    year = plant_info[3]

    fuel_av_cf = average_capacity_factors[country][fuel_type]
    plants_for_generation_estimation[plant_id].append(fuel_av_cf)

    cap_sh_country = capacity / float(capacity_total_by_country[country])
    plants_for_generation_estimation[plant_id].append(cap_sh_country)

    cap_sh_country_fuel = capacity / float(
        capacity_by_country_by_fuel[country][fuel_type])
    plants_for_generation_estimation[plant_id].append(cap_sh_country_fuel)

    # now make prediction; translate from cf to generation (GWh)
    X_data = np.array(plants_for_generation_estimation[plant_id][1:]).reshape(
        1, -1)
    est_cf = est.predict(X_data)[0]
    if est_cf < 0 or est_cf > 1:
        print(u'ERROR: Estimated capacity factor outside of [0,1]')
    est_gen_gwh = est_cf * capacity / CF_CONVERSION_FACTOR
    plants[plant_id].estimated_generation_gwh = est_gen_gwh

# now write the result
pw.write_csv_file(plants, CSV_SAVEFILE)
print(u"Wrote data file with {0} total plants; {1} with estimated generation.".
      format(len(plants), len(plants_for_generation_estimation)))