Skip to content

Commit

Permalink
updated code for spatial matching of supply weather outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven Eggimann committed Mar 26, 2019
1 parent e88ce69 commit 647e32b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def generate_weather_at_home_realisation(
"""
# Create result path
result_path_realizations = os.path.join(path_results, "_realizations")
result_path_realizations = "C:/AAA"
basic_functions.create_folder(result_path_realizations)

# Read in stiching table
Expand All @@ -45,9 +46,9 @@ def generate_weather_at_home_realisation(

for scenario_nr in scenarios:
realisation = realisations[scenario_nr]

for attribute in attributes:
columns = ['timestep', 'longitude', 'latitude', 'yearday', attribute]
columns = ['timestep', 'station_id', 'longitude', 'latitude', 'yearday', attribute]

print("... creating weather data for realisation " + str(realisation), flush=True)
realisation_out = []
Expand All @@ -69,11 +70,12 @@ def generate_weather_at_home_realisation(

for station_cnt in range(nr_stations_array):
attribute_station = attribute_data[station_cnt]
station_id = stations.loc[station_cnt]['station_id']
station_long = stations.loc[station_cnt]['longitude']
station_lat = stations.loc[station_cnt]['latitude']
for yearday in range(365):
realisation_out.append(
[sim_yr, station_long, station_lat, yearday, attribute_station[yearday]])
[sim_yr, station_id, station_long, station_lat, yearday, attribute_station[yearday]])

# Write data to csv
print("...writing out", flush=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def spatially_map_data(
stations_to_map_to['parameter'] = 0
stations_to_map_to['scenario'] = 0
stations_to_map_to['year'] = 0
stations_to_map_to['day'] = 0

# Read in MARIUS grid weather stations
print("... read in weather stations per attribute", flush=True)
Expand Down Expand Up @@ -71,31 +72,39 @@ def spatially_map_data(
closest_weather_ids[index][name_attribute] = closest_marius_station

# Weather and solar data for all scenarios
for scenario_nr in scenarios: #range(100):
for scenario_nr in scenarios:
scenario_name = scenario_names[scenario_nr]
print("... {} ".format(scenario_name), flush=True)

for name_attribute, attribute in data_types:
print(" ... {} ".format(name_attribute), flush=True)
print(" ... attribute_name: {} ".format(name_attribute), flush=True)
path_data = os.path.join(path_to_scenario_data, "weather_data_{}__{}.csv".format(scenario_name, attribute))
data = pd.read_csv(path_data)

for index in stations_to_map_to.index:
print(" ... {} ".format(index), flush=True)
closest_weather_station_id = closest_weather_ids[index][name_attribute]
closest_data = data.loc[closest_weather_station_id]

#region_id, Latitude, Longitude, region_name, scenario, parameter, value
stations_to_map_to.loc[index, 'scenario'] = scenario_nr
stations_to_map_to.loc[index, 'parameter'] = attribute
stations_to_map_to.loc[index, 'value'] = closest_data

# ----------------------------------------------------------
# Write out data
# ----------------------------------------------------------
df = pd.DataFrame(stations_to_map_to, columns=['station_id', 'latitude', 'longitude'])
result_file = os.path.join(result_out_path, "remapped_and_append_weather_data.csv")
stations_to_map_to.to_csv(result_file, index=False)
data = data.set_index("station_id")

for year in range(2015, 2051):
data_yr = data.loc[data['timestep'] == year]

for index in stations_to_map_to.index:
#print(" ... {} {}".format(index, closest_weather_station_id), flush=True)
closest_weather_station_id = closest_weather_ids[index][name_attribute]
closest_data = data_yr.loc[closest_weather_station_id]

for yearday in range(1, 366):
value = closest_data.loc[closest_data['yearday'] == yearday]
#region_id, Latitude, Longitude, region_name, scenario, parameter, value
stations_to_map_to.loc[index, 'scenario'] = scenario_nr
stations_to_map_to.loc[index, 'parameter'] = name_attribute
stations_to_map_to.loc[index, 'value'] = value
stations_to_map_to.loc[index, 'year'] = year
stations_to_map_to.loc[index, 'day'] = yearday

# ----------------------------------------------------------
# Write out data
# ----------------------------------------------------------
df = pd.DataFrame(stations_to_map_to, columns=['station_id', 'latitude', 'longitude'])
result_file = os.path.join(result_out_path, "remapped_and_append_weather_data__{}.csv".format(scenario_nr))
stations_to_map_to.to_csv(result_file, index=False)


def calc_distance_two_points(lat_from, long_from, lat_to, long_to):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
path_extracted_files = "X:/nismod/data/energy_demand/J-MARIUS_data" # Path to folder with extracted files
path_stiching_table = "X:/nismod/data/energy_demand/J-MARIUS_data/stitching_table/stitching_table_nf.dat" # Path to stiching table
path_results = "X:/nismod/data/energy_supply/weather_files" # Path to store results
path_input_coordinates = os.path.abspath("X:/nismod/data/energy_supply/regions_input.csv") # Path to file with coordinates to map onto
path_input_coordinates = os.path.abspath("X:/nismod/data/energy_supply/regions_input.csv") # Path to file with coordinates to map on to

extract_data = False
stich_together = True
Expand All @@ -43,7 +43,7 @@
# =================================
extract_weather_data.weather_dat_prepare(
path_extracted_files,
path_results)#,
path_results)
#years=[2020])
print("... finished extracting data")

Expand All @@ -54,7 +54,7 @@
create_realisation.generate_weather_at_home_realisation(
path_results=path_results,
path_stiching_table=path_stiching_table,
scenarios=[50, 51]) #range(60, 71))
scenarios=range(61, 101))
print("... finished creating realisations")

if append_closest_weather_data:
Expand All @@ -65,5 +65,5 @@
path_results=path_results,
path_weather_at_home_stations=os.path.join(path_results, "_cleaned_csv"),
path_input_coordinates=path_input_coordinates,
scenarios=range(100))
scenarios=[0]) #range(100))
print("... append closest weather information")

0 comments on commit 647e32b

Please sign in to comment.