Commit 91636621 authored by Fabian Kovac's avatar Fabian Kovac
Browse files

[i] added todos and get INCA RR data in func

parent 91b97ef6
......@@ -2,8 +2,8 @@
# Title: Data Preparation for LINK Configs and Transmissions
# Author: Fabian Kovac <ds191008@fhstp.ac.at>
# Team: University of Applied Sciences St. Pölten
# Version: 1.1
# Last changed: 2021-06-21
# Version: 1.2
# Last changed: 2021-06-22
#
import sys
......@@ -201,8 +201,8 @@ def utm_to_lambert(lon: np.array, lat: np.array) -> tuple:
return x, y
def lambert_to_inca_coords(x: np.array, y: np.array) -> tuple:
"""Convert x and y of Lambert Conic Conformal Projection to INCA coordinates
def lambert_to_inca_idx(x: np.array, y: np.array) -> tuple:
"""Convert x and y of Lambert Conic Conformal Projection to INCA index
(rounded lambert coordinates)
Parameters:
......@@ -216,23 +216,24 @@ def lambert_to_inca_coords(x: np.array, y: np.array) -> tuple:
return np.round(x/1000, decimals = 0).astype(int), np.round(y/1000, decimals = 0).astype(int)
def get_inca_indices(datetimes: np.array, x: np.array, y: np.array) -> np.array:
"""Get indices of INCA RR data based on Lamber Conic Conformal Coordinates
def get_inca_data(inca_data: np.array, datetimes: np.array, x: np.array, y: np.array) -> np.array:
"""Get INCA RR data based on Lamber Conic Conformal Coordinates
Parameters:
inca_data (np.array): Tensor containing INCA RR data
datetimes (np.array): Vector containing datetimes of transmissions
x (np.array): Vector containing x values of LINK
y (np.array): Vector containing y values of LINK
Returns:
idx_times, idx, idy (np.array): Three vectors containing indices to INCA RR data
inca_RR (np.array): Vector containing INCA RR data based on datetimes and lambert coordinates
"""
# convert utm coordinates to lambert conic conformal projection
lccX, lccY = utm_to_lambert(x, y)
# convert lambert coordinates to INCA indices
idx, idy = lambert_to_inca_coords(lccX, lccY)
idx, idy = lambert_to_inca_idx(lccX, lccY)
# generate times of day in 15min (window) intervals
......@@ -242,11 +243,20 @@ def get_inca_indices(datetimes: np.array, x: np.array, y: np.array) -> np.array:
# generate times of LINK data
link_times = datetimes.map(lambda x: f'{x[-4:-2]}:{x[-2:]}')
# get LINK indices of INCA times
# get INCA indices of LINK times
idx_times = np.searchsorted(inca_times, link_times)
# return INCA data based on time indices and lambert coordinates
return idx_times, idx, idy
# get INCA RR data based on time indices and lambert coordinates
inca_RR = inca_data[idx_times, idy, idx]
# TODO: discuss retrieving INCA RR data
# currently data is based on the exact point of the link
# maybe get mean RR of 5x5 km grid around point?
# maybe get RR data based on conv2d with a 5x5 gaussian filter around point?
# --> let's discuss!
return inca_RR
def prep() -> None:
......@@ -260,7 +270,7 @@ def prep() -> None:
_log('\n******************************** READ FILES ********************************')
# read files
# read config and transmission files
df_config = pd.read_csv(file_config, sep = ';')
_log(f'Read config file with shape {df_config.shape}')
df_trans = pd.read_csv(file_trans, sep = ';')
......@@ -449,13 +459,10 @@ def prep() -> None:
inca_data = load_inca_data(dir_inca)
_log(f'Loaded INCA data from {str(dir_inca).split("/")[-1]}')
idx_times, IxStart, IyStart = get_inca_indices(df_link['DateTime'], df_link['XStart'], df_link['YStart'])
_, IxEnd, IyEnd = get_inca_indices(df_link['DateTime'], df_link['XEnd'], df_link['YEnd'])
_log('Calculated INCA RR indices based on lambert coordinates and datetimes')
df_link['RRStart'] = inca_data[idx_times, IyStart, IxStart]
df_link['RREnd'] = inca_data[idx_times, IyEnd, IxEnd]
_log('Set INCA RR data based on lambert coordinates')
# set INCA RR data based on datetime and coordinates
df_link['RRStart'] = get_inca_data(inca_data, df_link['DateTime'], df_link['XStart'], df_link['YStart'])
df_link['RREnd'] = get_inca_data(inca_data, df_link['DateTime'], df_link['XEnd'], df_link['YEnd'])
_log('Merged INCA RR data to LINK dataframe')
_log('\n******************************** SAVE FILES ********************************')
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment