longitude, latitude = pyproj.transform(osgb36, wgs84, x_coordinate,
                                                   y_coordinate)
            geolocation_source = SOURCE_NAME_REPD
        except:
            print(u"-Error: Can't read location for plant {0}.".format(name))
            latitude, longitude = pw.NO_DATA_NUMERIC, pw.NO_DATA_NUMERIC
            geolocation_source = pw.NO_DATA_UNICODE
        try:
            owner = pw.format_string(row[owner_col])
        except:
            print(u"-Error: Can't read owner for plant {0}.".format(name))
            owner = u""

        # now process plant
        plant_idnr = pw.make_id(SAVE_CODE_GBR, idnr)
        new_location = pw.LocationObject(latitude=latitude,
                                         longitude=longitude)
        new_plant = pw.PowerPlant(plant_idnr=plant_idnr,
                                  plant_name=name,
                                  plant_owner=owner,
                                  plant_country=country,
                                  plant_capacity=capacity,
                                  plant_cap_year=REPD_YEAR,
                                  plant_source=SOURCE_NAME,
                                  plant_source_url=SOURCE_URL,
                                  plant_location=new_location,
                                  plant_coord_source=geolocation_source,
                                  plant_fuel=fuel_type)
        plants_dictionary[plant_idnr] = new_plant

# load and process DUKES file
book = xlrd.open_workbook(RAW_FILE_NAME_DUKES)
            owner = u"Unknown"
        try:
            country = pw.standardize_country(row[country_col],
                                             country_thesaurus)
        except:
            print("Error: Can't read country for plant {0}.".format(name))
            country = u"Unknown"
        # try:
        #     generation_GWh = float(row[generation_col]) / 1000
        # except:
        #     print("Error: Can't read generation for plant {0}".format(name))
        #     generation_GWh = 0.0

        # assign ID number
        idnr = pw.make_id(SAVE_CODE, idnr)
        new_location = pw.LocationObject("", 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,
                                  plant_owner=owner)
        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)
                row[capacity_col]))  # note: may need to convert to MW
        except:
            print(u"Error: Can't read capacity for plant {0}.".format(name))
        try:
            fuel = pw.standardize_fuel(row[fuel_col], fuel_thesaurus)
        except:
            print(u"Error: Can't read fuel type for plant {0}.".format(name))
        try:
            latitude = float(row[latitude_col])
            longitude = float(row[longitude_col])
        except:
            latitude, longitude = pw.NO_DATA_NUMERIC, pw.NO_DATA_NUMERIC

        # assign ID number
        idnr = pw.make_id(SAVE_CODE, count)
        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_fuel=fuel,
                                  plant_capacity=capacity,
                                  plant_source=SOURCE_NAME,
                                  plant_source_url=SOURCE_URL)
        plants_dictionary[idnr] = new_plant
        count += 1

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

# write database to csv format
示例#4
0
    if fuel_type_str:
        if '+' in fuel_type_str:
            fuel_type = None
        else:
            fuel_type = pw.standardize_fuel(fuel_type_str, fuel_thesaurus)

    if name_str:  # if true, this row begins a new plant
        # first process the previous plant unless this is the first entry
        if i > START_ROW:
            print i
            print fuel_type_set
            raw_input()
            total_capacity = sum(capacity_list)
            average_year_built = sum(year_built_list) / len(
                year_built_list)  # TODO: fix this
            new_location = pw.LocationObject(latitude=0.0, longitude=0.0)
            new_plant = pw.PowerPlant(plant_idnr=plant_idnr,
                                      plant_name=name,
                                      plant_country=COUNTRY_NAME,
                                      plant_capacity=total_capacity,
                                      plant_fuel=fuel_type_set,
                                      plant_source=URL,
                                      plant_location=new_location)
            plants_dictionary[plant_idnr] = new_plant
            print("Recording plant {0} with ID: {1}, capacity: {2}, fuel: {3}".
                  format(name, plant_idnr, total_capacity, fuel_type_set))

        # next process this plant

        name = pw.format_string(name_str)
        plant_idnr = pw.make_id(SAVE_CODE, i)
                        if idnr_full not in overlapping_ids.keys():
                            overlapping_ids[idnr_full] = {'country1': country, 'country2': country2}
                        # don't treat this as a unit
                        continue

                    # update plant
                    existing_plant = plants_dictionary[idnr_full]
                    existing_plant.capacity += capacity
                    # append generation object - may want to sum generation instead?
                    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_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
示例#6
0
	"REU": "France",
	# The Virgin Islands of the United States
	"VIR": "United States of America",
})
wiki_solar_skip = {
	'United States of America': (0, 0)
}
wiki_solar_whitelist = ['PRI']

wiki_solar_count = 0
with open(wiki_solar_file) as fin:
	wiki_solar = csv.DictReader(fin)
	for solar_plant in wiki_solar:
		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)
示例#7
0
            current_owner = pw.NO_DATA_UNICODE
            current_capacity_sum = 0.0
            current_generation_sum = 0.0

        else:
            continue

# now assign locations and commissioning years
location_not_found = 0
year_not_found = 0

for idnr, plant in plants_dictionary.iteritems():

    if plant.name in locations_dictionary.keys():
        coords = locations_dictionary[plant.name]
        plants_dictionary[idnr].location = pw.LocationObject(
            pw.NO_DATA_UNICODE, coords[0], coords[1])
        plants_dictionary[idnr].coord_source = SOURCE_NAME
    else:
        location_not_found += 1
        plants_dictionary[idnr].coord_source = pw.NO_DATA_UNICODE

    if plant.name in commissioning_years_dictionary.keys():
        plants_dictionary[
            idnr].commissioning_year = commissioning_years_dictionary[
                plant.name]
    else:
        year_not_found += 1
"""
print("Locations not found for these plants:")
location_not_found.sort(key = lambda x:x.capacity, reverse=True)
for plant in location_not_found:
# now assign locations and commissioning years
location_not_found = 0
year_not_found = 0

for idnr, plant in plants_dictionary.iteritems():
    aux = aux_plant_info[plant.name]
    lat, lon = aux['latitude'], aux['longitude']
    try:
        flat = float(lat)
        flon = float(lon)
    except:
        location_not_found += 1
        plants_dictionary[idnr].coord_source = pw.NO_DATA_UNICODE
    else:
        plant.location = pw.LocationObject(pw.NO_DATA_UNICODE, flat, flon)
        plant.coord_source = SOURCE_NAME
    try:
        year = float(aux['commissioning_year'])
    except:
        year_not_found += 1
    else:
        plant.commissioning_year = year

print(
    "Missing location for {0} plants; missing commissioning year for {1} plants."
    .format(location_not_found, year_not_found))

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

	if 'Coordinates' not in data_dict:
		print 'Skipping plant {0} because there is no coordinate information'.format(page_name)
		continue

	if 'Power Capacity' not in data_dict or not isinstance(data_dict['Power Capacity'], float):
		print 'Skipping plant {0} because there is no capacity information'.format(page_name)
		continue

	# 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
        if gen_type.lower() == u"hydro power":
            fuels = set([u"Hydro"])
        elif gen_type.lower() == u"wind power":
            fuels = set([u"Wind"])
        else:
            fuels = pw.NO_DATA_SET
            for i in COLS["fuel_type"]:
                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