Exemple #1
0
                    if generation:
                        if not isinstance(existing_plant.generation, list):
                            existing_plant.generation = [pw.PlantGenerationObject(),]
                        existing_plant.generation.append(generation)
                    # if lat/long for this unit, overwrite previous data - may want to change this
                    if latitude and longitude:
                        new_location = pw.LocationObject(location, latitude, longitude)
                        existing_plant.location = new_location

                    # unclear how to handle owner, source, url, commissioning year

                else:
                    new_location = pw.LocationObject(location, latitude, longitude)
                    new_plant = pw.PowerPlant(plant_idnr=idnr_full, plant_name=name, plant_country=country,
                        plant_location=new_location, plant_coord_source=geolocation_source_string,
                        plant_fuel=fuel, plant_capacity=capacity,
                        plant_owner=owner, plant_generation=generation,
                        plant_source=source, plant_source_url=url,
                        plant_commissioning_year=commissioning_year)
                    plants_dictionary[idnr_full] = new_plant
                    country_plant_count += 1

        print("Read {:4d} plants from file {:}.".format(country_plant_count, afile))
        if country_plant_count == 0:
            countries_with_zero_plants.append(afile)

# report on overlapping IDs
if len(overlapping_ids) > 0:
    print(u"ERROR: ID overlaps for {0} plants in different countries; written to {1}.".format(len(overlapping_ids), OVERLAP_FILE))
    with open(OVERLAP_FILE, 'w') as f:
        f.write('idnr,country1,country2\n')
        for idnr, overlap in overlapping_ids.iteritems():
                try:
                    if rv[i] == "None": continue
                    fuel = pw.standardize_fuel(rv[i], fuel_thesaurus)
                    fuels.update(fuel)
                except:
                    continue

        new_location = pw.LocationObject(pw.NO_DATA_UNICODE,
                                         pw.NO_DATA_NUMERIC,
                                         pw.NO_DATA_NUMERIC)
        idnr = u"{:4}{:06d}".format("REF", count_unit)
        new_unit = pw.PowerPlant(plant_idnr=idnr,
                                 plant_name=name,
                                 plant_owner=owner,
                                 plant_fuel=fuels,
                                 plant_country=unicode(COUNTRY_NAME),
                                 plant_capacity=capacity_max,
                                 plant_cap_year=year_updated,
                                 plant_source=SOURCE_NAME,
                                 plant_source_url=DATASET_URL,
                                 plant_location=new_location)
        units_dictionary[idnr] = new_unit
        count_unit += 1

# Aggregate units to plant level
sorted_units = sorted(units_dictionary.values(),
                      key=lambda x: x.name)  # units are sorted by name
count_plant = 1
i = 0
while i < len(sorted_units) - 1:
    j = i + 1
    idnr = pw.make_id(SAVE_CODE, count_plant)
Exemple #3
0
    row['id'] for row in csv.DictReader(open(wiki_solar_exclusion))
]
with open(wiki_solar_file) as fin:
    wiki_solar = csv.DictReader(fin)
    for solar_plant in wiki_solar:
        if solar_plant['id'] in _exclude_list:
            continue
        country = country_lookup.get(solar_plant['country'], '')
        plant_idnr = 'WKS{0:07d}'.format(int(solar_plant['id']))
        plant_location = pw.LocationObject(latitude=float(solar_plant['lat']),
                                           longitude=float(solar_plant['lon']))
        plant = pw.PowerPlant(plant_idnr=plant_idnr,
                              plant_name=solar_plant['name'],
                              plant_country=country,
                              plant_capacity=float(solar_plant['capacity']),
                              plant_location=plant_location,
                              plant_coord_source='Wiki-Solar',
                              plant_source='Wiki-Solar',
                              plant_source_url='https://www.wiki-solar.org',
                              plant_primary_fuel='Solar')
        if (country in wiki_solar_skip) and \
        (solar_plant["country"] not in wiki_solar_whitelist):
            _n, _capacity = wiki_solar_skip[country]
            wiki_solar_skip[country] = (_n + 1, _capacity + plant.capacity)
            continue
        core_database[plant_idnr] = plant
        wiki_solar_count += 1
print("Loaded {0} plants from Wiki-Solar database.".format(wiki_solar_count))
for _country, _vals in wiki_solar_skip.iteritems():
    if _vals[0] != 0:
        print("...skipped {0} plants ({1} MW) for {2}.".format(
    except:
        print(u"-Error: Can't read data source for plant with name {0}".format(name))
        source = pw.NO_DATA_UNICODE

    try:
        data_date = (int(str(row[date_col])[0:4]))
    except:
        print(u"-Error:Can't read reference date for plant with name {0}".format(name))
        data_date = pw.NO_DATA_NUMERIC

    # assign ID number
    idnr = pw.make_id(SAVE_CODE, i)
    new_location = pw.LocationObject(pw.NO_DATA_UNICODE, latitude, longitude)
    new_plant = pw.PowerPlant(plant_idnr=idnr, plant_name=name, plant_country=COUNTRY_NAME,
        plant_owner=owner, plant_cap_year=data_date,
        plant_location=new_location, plant_coord_source=geolocation_source,
        plant_primary_fuel=primary_fuel, plant_capacity=capacity,
        plant_source=SOURCE_NAME_1, plant_source_url=SOURCE_URL_1)
    plants_dictionary[idnr] = new_plant

# use this for id incrementing in next file
max_id = i

# 2: read in NACEI renewable plants
book = xlrd.open_workbook(RAW_FILE_NAME_2, encoding_override=ENCODING)
sheet = book.sheet_by_name(TAB_NAME_2)

rv = sheet.row_values(0)
country_col = rv.index(COLNAMES_2[0])
name_col = rv.index(COLNAMES_2[1])
owner_col = rv.index(COLNAMES_2[2])
    except:
        print(u"-Error: Can't read country for plant {0}.".format(name))
        country = pw.NO_DATA_UNICODE

    owner = pw.format_string(row[owner_col])
    location = pw.format_string(row[location_col])

    # assign ID number
    idnr = pw.make_id(SAVE_CODE, idnr)
    new_location = pw.LocationObject(location, latitude, longitude)
    new_plant = pw.PowerPlant(plant_idnr=idnr,
                              plant_name=name,
                              plant_country=country,
                              plant_location=new_location,
                              plant_coord_source=geolocation_source,
                              plant_fuel=fuel,
                              plant_capacity=capacity,
                              plant_source=SAVE_CODE,
                              plant_source_url=SOURCE_URL,
                              plant_generation=generation,
                              plant_cap_year=2017)
    plants_dictionary[idnr] = new_plant

# report on plants read from file
print(u"...read {0} plants.".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, SAVE_DIRECTORY)
    #print(u"Plant: {0}; Owner(s): {1}".format(name, owner_full))
    """

    # assign ID number
    idnr = pw.make_id(SAVE_CODE, plant_id)

    # special coordinate corrections
    if idnr in special_coordinate_corrections.keys():
        latitude,longitude = special_coordinate_corrections[idnr]
        print(u"Special lat/long correction for plant {0}".format(idnr))
        geolocation_source = u"WRI"

    new_location = pw.LocationObject(pw.NO_DATA_UNICODE, latitude, longitude)
    new_plant = pw.PowerPlant(plant_idnr=idnr, plant_name=name, plant_country=COUNTRY_NAME,
        plant_location=new_location, plant_coord_source=geolocation_source,
        plant_primary_fuel=primary_fuel, plant_capacity=capacity,
        plant_source=SOURCE_NAME, plant_source_url=SOURCE_URL, plant_cap_year=SOURCE_YEAR,
        plant_commissioning_year=op_year)
    plants_dictionary[idnr] = new_plant

# report on plants read from file
print(u"...read {0} plants.".format(len(plants_dictionary)))
print(u"Found coordinates for {0} plants.".format(found_coordinates_count))
print(u"Found operational year for {0} plants.".format(found_operational_year_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))
Exemple #7
0
    except:
        print(u"-Error: Can't read data source for plant with name {0}".format(name))
        source = pw.NO_DATA_UNICODE

    try:
        data_date = (int(str(row[date_col])[0:4]))
    except:
        print(u"-Error:Can't read reference date for plant with name {0}".format(name))
        data_date = pw.NO_DATA_NUMERIC

    # assign ID number
    idnr = pw.make_id(SAVE_CODE, i)
    new_location = pw.LocationObject(pw.NO_DATA_UNICODE, latitude, longitude)
    new_plant = pw.PowerPlant(plant_idnr=idnr, plant_name=name, plant_country=COUNTRY_NAME,
        plant_owner=owner, plant_cap_year=data_date,
        plant_location=new_location, plant_coord_source=geolocation_source,
        plant_fuel=fuel, plant_capacity=capacity,
        plant_source=source, plant_source_url=SOURCE_URL_1)
    plants_dictionary[idnr] = new_plant

# use this for id incrementing in next file
max_id = i

# 2: read in NACEI renewable plants
book = xlrd.open_workbook(RAW_FILE_NAME_2, encoding_override=ENCODING)
sheet = book.sheet_by_name(TAB_NAME_2)

rv = sheet.row_values(0)
country_col = rv.index(COLNAMES_2[0])
name_col = rv.index(COLNAMES_2[1])
owner_col = rv.index(COLNAMES_2[2])
Exemple #8
0
            serial_id_val))
        latitude = pw.NO_DATA_NUMERIC
        longitude = pw.NO_DATA_NUMERIC
        geolocation_source = pw.NO_DATA_UNICODE

    # assign ID number from CEA locations file;
    # maintains IDs generated from previous CEA files
    idnr = plant_locations[serial_id_val]["gppd_id"]

    new_location = pw.LocationObject(pw.NO_DATA_UNICODE, latitude, longitude)
    new_plant = pw.PowerPlant(plant_idnr=idnr,
                              plant_name=name,
                              plant_country=COUNTRY_NAME,
                              plant_location=new_location,
                              plant_coord_source=geolocation_source,
                              plant_primary_fuel=primary_fuel,
                              plant_other_fuel=other_fuel,
                              plant_capacity=capacity,
                              plant_cap_year=DATA_YEAR,
                              plant_source=SOURCE_NAME,
                              plant_source_url=SOURCE_URL,
                              plant_generation=generation)
    plants_dictionary[idnr] = new_plant

# now find average commissioning year weighted by capacity
for serial_id_val, units in unit_list.iteritems():

    # get plant from dictionary
    plant_id = plant_locations[serial_id_val]["gppd_id"]
    plant = plants_dictionary[plant_id]
    if plant.capacity == 0:
        print(u"Warning: Plant {0} has zero capacity.".format(plant_id))
Exemple #9
0
            latitude = float(row[latitude_col])
            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_coord_source=SOURCE_NAME,
                                  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)
    # Get the pw_idnr
    idnr = pw.make_id(SAVE_CODE, plant_id)

    # Get the geolocation
    lat, lon = data_dict['Coordinates']
    location = pw.LocationObject(pw.NO_DATA_UNICODE, lat, lon)

    # Construct the PowerPlant object
    new_plant = pw.PowerPlant(
        plant_idnr=idnr,
        plant_name=page_name,
        plant_country=COUNTRY_NAME,
        plant_fuel='Coal',
        plant_capacity=data_dict.get('Power Capacity', pw.NO_DATA_NUMERIC),
        plant_location=location,
        plant_coord_source=SOURCE_NAME,
        plant_source=SOURCE_NAME,
        plant_source_url=url,
        plant_owner=data_dict.get('Owner', pw.NO_DATA_UNICODE),
        plant_commissioning_year=data_dict.get('Activity since',
                                               pw.NO_DATA_NUMERIC),
    )
    plants_dictionary[idnr] = new_plant

# Close the sqlite3 database connection
conn.close()

# Report on number of plants included
print("Loaded {0} plants to database.".format(len(plants_dictionary)))

# Write database to csv format
Exemple #11
0
                    pass
                else:
                    gwh += gen_gwh
            # TODO: give proper time bounds
            generation.append(pw.PlantGenerationObject.create(gwh, yr))

        # assign ID number
        idnr = pw.make_id(SAVE_CODE, plant_id)
        new_location = pw.LocationObject(pw.NO_DATA_UNICODE, latitude,
                                         longitude)
        new_plant = pw.PowerPlant(plant_idnr=idnr,
                                  plant_name=name,
                                  plant_owner=owner,
                                  plant_country=COUNTRY_NAME,
                                  plant_location=new_location,
                                  plant_coord_source=geolocation_source,
                                  plant_primary_fuel=primary_fuel,
                                  plant_capacity=capacity,
                                  plant_generation=generation,
                                  plant_source=SOURCE_NAME,
                                  plant_cap_year=year_updated,
                                  plant_source_url=SOURCE_URL)
        plants_dictionary[idnr] = new_plant
        count += 1

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

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

# save database