def get_CEA_generation(row, col, year, source_url):
    """Extract a generation data point from CEA data."""
    try:
        if row[col] == u'-':
            generation = pw.PlantGenerationObject()
        else:
            gen_gwh = float(row[col])
            generation = pw.PlantGenerationObject.create(gen_gwh,
                                                         year,
                                                         source=source_url)
    except:
        generation = pw.PlantGenerationObject()
    return generation
print("Loading Form 860-2")
wb860_2 = xlrd.open_workbook(RAW_FILE_NAME_860_2)
ws860_2 = wb860_2.sheet_by_name(TAB_NAME_860_2)
print("Loading Form 860-3")
wb860_3 = xlrd.open_workbook(RAW_FILE_NAME_860_3)
ws860_3 = wb860_3.sheet_by_name(TAB_NAME_860_3)

# read in plants from File 2 of EIA-860
print("Reading in plants...")
plants_dictionary = {}
for row_id in xrange(2, ws860_2.nrows):
	rv = ws860_2.row_values(row_id) # row value
	name = pw.format_string(rv[COLS_860_2['name']])
	idnr = pw.make_id(SAVE_CODE, int(rv[COLS_860_2['idnr']]))
	capacity = 0.0
	generation = pw.PlantGenerationObject()
	owner = pw.format_string(str(rv[COLS_860_2['owner']]))
	try:
		latitude = float(rv[COLS_860_2['lat']])
	except:
		latitude = pw.NO_DATA_NUMERIC
	try:
		longitude = float(rv[COLS_860_2['lng']])
	except:
		longitude = pw.NO_DATA_NUMERIC
	location = pw.LocationObject(u"", latitude, longitude)
	new_plant = pw.PowerPlant(idnr, name, plant_country=COUNTRY_NAME,
		plant_location=location, plant_coord_source=SOURCE_NAME,
		plant_owner=owner, plant_capacity=capacity,
		plant_generation=generation,
		plant_cap_year=YEAR, plant_source=SOURCE_NAME, plant_source_url=SOURCE_URL)
                    # first check this isn't an ID overlap
                    country2 = plants_dictionary[idnr_full].country
                    if country != country2:
                        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,
Beispiel #4
0
 except:
     print(u"-Error: Can't read fuel type for plant {0}.".format(name))
     fuel = pw.NO_DATA_SET
 try:
     latitude = float(row[latitude_col])
     longitude = float(row[longitude_col])
 except:
     latitude, longitude = pw.NO_DATA_NUMERIC, pw.NO_DATA_NUMERIC
 try:
     location = pw.format_string(row[location_col])
 except:
     location = pw.NO_DATA_UNICODE
 try:
     gen_gwh = float(
         pw.format_string(row[generation_col].replace(",", "")))
     generation = pw.PlantGenerationObject(gen_gwh)
 except:
     generation = pw.NO_DATA_OTHER
 try:
     owner = pw.format_string(row[owner_col])
 except:
     owner = pw.NO_DATA_UNICODE
 try:
     source = pw.format_string(row[source_col])
     if source == u"Open Government Portal":  # avoid duplication (can remove after updating FT)
         continue
 except:
     print(u"-Error: Can't read source for plant {0}.".format(name))
     source = pw.NO_DATA_UNICODE
 try:
     url = pw.format_string(row[url_col])
Beispiel #5
0
    row_grid = pw.format_string(rv[COLS['grid']], None)

    if row_grid == u"AISLADO":
        continue  # don't add islanded generators (not grid-connected)

    if row_fuel:

        if row_name:

            if current_plant_name:

                # assign ID number, make PowerPlant object, add to dictionary
                idnr = pw.make_id(SAVE_CODE, count)
                annual_generation = pw.PlantGenerationObject(
                    gwh=current_generation_sum,
                    start_date=gen_start,
                    end_date=gen_stop,
                    source=SOURCE_NAME)
                new_plant = pw.PowerPlant(plant_idnr=idnr,
                                          plant_name=current_plant_name,
                                          plant_owner=current_owner,
                                          plant_fuel=current_fuel_types,
                                          plant_country=COUNTRY_NAME,
                                          plant_capacity=current_capacity_sum,
                                          plant_cap_year=YEAR_OF_DATA,
                                          plant_source=SOURCE_NAME,
                                          plant_source_url=SOURCE_URL,
                                          plant_generation=annual_generation)
                plants_dictionary[idnr] = new_plant
                count += 1