count_plants_with_generation = 0 #for plant_id,plant in powerwatch_database.iteritems(): # if plant.generation != pw.NO_DATA_OTHER: # count_plants_with_generation += 1 #print('Of {0} total plants, {1} have reported generation data.'.format(len(powerwatch_database),count_plants_with_generation)) print('Estimating generation...') estimated_plants = pw.estimate_generation(powerwatch_database) print('...estimated for {0} plants.'.format(estimated_plants)) # STEP 6: Write PowerWatch 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 PowerWatch.".format(len(powerwatch_database))) pw.write_csv_file(powerwatch_database,POWERWATCH_CSV_SAVEFILE) print("PowerWatch built.") # STEP 7: Dump Data if DATA_DUMP: print("Dumping all the data...") # STEP 7.1: Label plants in datadump pw_idnrs = powerwatch_database.keys() for plant_id,plant in powerwatch_datadump.iteritems(): if plant_id in pw_idnrs: plant.idnr = plant_id + ",Yes" else: plant.idnr = plant_id + ",No" # STEP 7.2: Add unused CARMA plants for plant_id,plant in carma_database.iteritems():
longitude = float(row[longitude_col]) except: coord_skip_count += 1 continue country = row[ country_col] # note: this is the ISO3 code so no need to convert # assign ID number idnr = pw.make_id(SAVE_CODE, idval) new_location = pw.LocationObject(pw.NO_DATA_UNICODE, latitude, longitude) new_plant = pw.PowerPlant(plant_idnr=idnr, plant_name=name, plant_country=country, plant_location=new_location, plant_source=SOURCE_NAME, plant_source_url=SOURCE_URL) plants_dictionary[idnr] = new_plant # report on plants read from file print(u"...read {0} plants.".format(len(plants_dictionary))) print("Skipped {0} plants because of missing lat/long coordinates.".format( coord_skip_count)) # write database to csv format pw.write_csv_file(plants_dictionary, CSV_FILE_NAME) # # save database pw.save_database(plants_dictionary, SAVE_CODE, 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)))