Skip to content

Commit

Permalink
Add obtaining CFs with Atlite
Browse files Browse the repository at this point in the history
  • Loading branch information
awongel committed Aug 28, 2024
1 parent e16768f commit 5599fc3
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions capacity_factors_atlite/get_US_CFs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import atlite
import cartopy.io.shapereader as shpreader
import geopandas as gpd
from shapely.geometry import box
import pandas as pd
import logging
from argparse import ArgumentParser

def main(year):

logging.basicConfig(level=logging.INFO)

shpfilename = shpreader.natural_earth(
resolution="10m", category="cultural", name="admin_0_countries"
)
reader = shpreader.Reader(shpfilename)
US = gpd.GeoSeries(
{r.attributes["NAME_EN"]: r.geometry for r in reader.records()},
crs={"init": "epsg:4326"}).reindex(["United States of America"])

# Only keep contiguous US
contiguous_48_bbox = box(minx=-125, miny=24.396308, maxx=-66.93457, maxy=49.384358)
# Clip the US geometry to the bounding box
CONUS = US.geometry.intersection(contiguous_48_bbox)

# Loop over the years
logging.info(f"Processing {year}")

# Define the cutout; this will not yet trigger any major operations
cutout = atlite.Cutout(
path=f"conus-{year}", module="era5", bounds=CONUS.unary_union.bounds, time=slice(f"{year}-01", f"{year}-12"))
# This is where all the work happens (this can take some time).
cutout.prepare()

# Extract the wind power generation capacity factors
wind_power_generation = cutout.wind(
"Vestas_V112_3MW",
shapes=CONUS,
per_unit=True
)

# Extract the solar power generation capacity factors
solar_power_generation = cutout.pv(
panel="CSi",
orientation='latitude_optimal',
shapes=CONUS,
tracking="horizontal",
per_unit=True)

solar_power_generation = solar_power_generation.to_pandas().rename(columns={"United States of America": "solar_cf"})
wind_power_generation = wind_power_generation.to_pandas().rename(columns={"United States of America": "wind_cf"})

# Save the data as a csv
solar_power_generation.to_csv(f"CONUS_solar_CF_{year}.csv")
wind_power_generation.to_csv(f"CONUS_wind_CF_{year}.csv")

if __name__ == "__main__":
parser = ArgumentParser()
parser.add_argument("--year", type=int, help="Get data for this year")
args = parser.parse_args()
main(args.year)

0 comments on commit 5599fc3

Please sign in to comment.