Skip to content

Commit

Permalink
Merge pull request #3653 from architecture-building-systems/update-we…
Browse files Browse the repository at this point in the history
…ather-helper

Update weather source file
  • Loading branch information
reyery authored Sep 6, 2024
2 parents 7704480 + 8679e53 commit f9a3fbb
Show file tree
Hide file tree
Showing 5 changed files with 13,731 additions and 14,658 deletions.
4 changes: 4 additions & 0 deletions cea/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,8 @@ def decode(self, value):


class WeatherPathParameter(Parameter):
THIRD_PARTY_WEATHER_SOURCES = ['climate.onebuilding.org']

def initialize(self, parser):
self._locator = None # cache the InputLocator in case we need it again as they can be expensive to create
self._extensions = ['epw']
Expand All @@ -563,6 +565,8 @@ def decode(self, value):
# allow using shortcuts
weather_path = self.locator.get_weather(
[w for w in self.locator.get_weather_names() if w.lower().startswith(value.lower())][0])
elif value in self.THIRD_PARTY_WEATHER_SOURCES:
weather_path = value
else:
raise cea.ConfigError(f"Invalid weather path: {value}")
return weather_path
Expand Down
53 changes: 29 additions & 24 deletions cea/datamanagement/weather_helper/generate_weather_data_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,44 @@
fiona.drvsupport.supported_drivers['LIBKML'] = 'rw'

URL_LIST = [
"https://climate.onebuilding.org/WMO_Region_1_Africa/Region1_Africa_EPW_Processing_locations.kml",
"https://climate.onebuilding.org/WMO_Region_2_Asia/Region2_Asia_EPW_Processing_locations.kml",
"https://climate.onebuilding.org/WMO_Region_2_Asia/Region2_Region6_Russia_EPW_Processing_locations.kml",
"https://climate.onebuilding.org/WMO_Region_3_South_America/Region3_South_America_EPW_Processing_locations.kml",
"https://climate.onebuilding.org/WMO_Region_4_North_and_Central_America/Region4_Canada_EPW_Processing_locations.kml",
"https://climate.onebuilding.org/WMO_Region_4_North_and_Central_America/Region4_USA_EPW_Processing_locations.kml",
"https://climate.onebuilding.org/WMO_Region_4_North_and_Central_America/Region4_NA_CA_Caribbean_EPW_Processing_locations.kml",
"https://climate.onebuilding.org/WMO_Region_4_North_and_Central_America/Region4_CaliforniaClimateZones_EPW_Processing_locations.kml",
"https://climate.onebuilding.org/WMO_Region_4_North_and_Central_America/Region4_Canada_NRC_Future_TMY_Year_EPW_Processing_locations.kml",
"https://climate.onebuilding.org/WMO_Region_4_North_and_Central_America/Region4_Canada_NRC_Future_Extreme_Warm_Year_EPW_Processing_locations.kml",
"https://climate.onebuilding.org/WMO_Region_4_North_and_Central_America/Region4_Canada_NRC_Future_Extreme_Cold_Year_EPW_Processing_locations.kml",
"https://climate.onebuilding.org/WMO_Region_4_North_and_Central_America/Region4_Canada_NRC_Future_Avg_Year_EPW_Processing_locations.kml",
"https://climate.onebuilding.org/WMO_Region_5_Southwest_Pacific/Region5_Southwest_Pacific_EPW_Processing_locations.kml",
"https://climate.onebuilding.org/WMO_Region_6_Europe/Region6_Europe_EPW_Processing_locations.kml",
"https://climate.onebuilding.org/WMO_Region_6_Europe/Region2_Region6_Russia_EPW_Processing_locations.kml",
"https://climate.onebuilding.org/WMO_Region_7_Antarctica/Region7_Antarctica_EPW_Processing_locations.kml"
"https://climate.onebuilding.org/sources/Region1_Africa_TMYx_EPW_Processing_locations.xlsx",
"https://climate.onebuilding.org/sources/Region2_Asia_TMYx_EPW_Processing_locations.xlsx",
"https://climate.onebuilding.org/sources/Region2_Region6_Russia_TMYx_EPW_Processing_locations.xlsx",
"https://climate.onebuilding.org/sources/Region3_South_America_TMYx_EPW_Processing_locations.xlsx",
"https://climate.onebuilding.org/sources/Region4_USA_TMYx_EPW_Processing_locations.xlsx",
"https://climate.onebuilding.org/sources/Region4_Canada_TMYx_EPW_Processing_locations.xlsx",
"https://climate.onebuilding.org/sources/Region4_NA_CA_Caribbean_TMYx_EPW_Processing_locations.xlsx",
"https://climate.onebuilding.org/sources/Region5_Southwest_Pacific_TMYx_EPW_Processing_locations.xlsx",
"https://climate.onebuilding.org/sources/Region6_Europe_TMYx_EPW_Processing_locations.xlsx",
"https://climate.onebuilding.org/sources/Region7_Antarctica_TMYx_EPW_Processing_locations.xlsx",
]

WEATHER_DATA_LOCATION = os.path.join(os.path.realpath(os.path.dirname(__file__)), 'weather.geojson')


def main():
# Combine for global data
kmls = [gpd.read_file(url) for url in URL_LIST]
global_gdf = pd.concat(kmls)
excels = [pd.read_excel(url) for url in URL_LIST]
global_df = pd.concat(excels)

# Filter NA
global_gdf = global_gdf[global_gdf['description'].notna()]
# Filter for latest TMYx url
latest_tmyx = global_gdf[global_gdf["description"].str.contains("TMYx.2007-2021")]
latest_tmyx["url"] = latest_tmyx["description"].str.extract(r'https?://climate.onebuilding.org/([^ ]+\.zip)')

latest_tmyx[["url", "geometry"]].to_file(WEATHER_DATA_LOCATION)
latest_tmyx = global_df[global_df["URL"].str.contains("TMYx.2009-2023")].set_index("WMO")

# Get second latest TMYx
second_latest_tmyx = global_df[global_df["URL"].str.contains("TMYx.2007-2021")].set_index("WMO")
diff_tmyx = second_latest_tmyx.loc[second_latest_tmyx.index.difference(latest_tmyx.index)]

# Combine latest and diff TMYx
combined_tmyx = pd.concat([latest_tmyx, diff_tmyx])
combined_tmyx["url"] = combined_tmyx["URL"].str.extract(r'https?://climate.onebuilding.org/([^ ]+\.zip)')

# Write to geojson
gdf = gpd.GeoDataFrame(
combined_tmyx,
geometry=gpd.points_from_xy(combined_tmyx["Longitude (E+/W-)"], combined_tmyx["Latitude (N+/S-)"]),
crs="EPSG:4326"
)
gdf[["url", "geometry"]].to_file(WEATHER_DATA_LOCATION, index=False)


if __name__ == '__main__':
Expand Down
Loading

0 comments on commit f9a3fbb

Please sign in to comment.