Skip to content

Commit

Permalink
updated weather generation scirpt for supply model
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven Eggimann committed Mar 27, 2019
1 parent 647e32b commit 170a237
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@ def spatially_map_data(
# Read in input stations and coordinages to map
stations_to_map_to = pd.read_csv(path_input_coordinates)

# Append new columns
stations_to_map_to['value'] = 0
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)
attributes = ['wss', 'rsds']
Expand Down Expand Up @@ -72,6 +65,7 @@ def spatially_map_data(
closest_weather_ids[index][name_attribute] = closest_marius_station

# Weather and solar data for all scenarios
stations_to_map_to_list = []
for scenario_nr in scenarios:
scenario_name = scenario_names[scenario_nr]
print("... {} ".format(scenario_name), flush=True)
Expand All @@ -91,20 +85,37 @@ def spatially_map_data(
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
value = closest_data.loc[closest_data['yearday'] == yearday][attribute]

list_entry = (
stations_to_map_to.loc[index, 'region_id'],
stations_to_map_to.loc[index, 'Latitude'],
stations_to_map_to.loc[index, 'Longitude'],
stations_to_map_to.loc[index, 'region_name'],
scenario_nr,
name_attribute,
value,
year,
yearday)

stations_to_map_to_list.append(list_entry)

# ----------------------------------------------------------
# Write out data
# ----------------------------------------------------------
df = pd.DataFrame(stations_to_map_to, columns=['station_id', 'latitude', 'longitude'])
stations_to_map_to_out = pd.DataFrame(
stations_to_map_to_list,
columns=[
'region_id', 'latitude', 'longitude', 'region_name',
'scenario',
'prameter',
'value',
'year',
'day'
])

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)
stations_to_map_to_out.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 @@ -33,8 +33,8 @@
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
append_closest_weather_data = False
stich_together = False
append_closest_weather_data = True

if extract_data:
# =================================
Expand All @@ -44,7 +44,6 @@
extract_weather_data.weather_dat_prepare(
path_extracted_files,
path_results)
#years=[2020])
print("... finished extracting data")

if stich_together:
Expand All @@ -54,7 +53,7 @@
create_realisation.generate_weather_at_home_realisation(
path_results=path_results,
path_stiching_table=path_stiching_table,
scenarios=range(61, 101))
scenarios=range(80, 101))
print("... finished creating realisations")

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

0 comments on commit 170a237

Please sign in to comment.