From 1df2b593264ca765585e0a96c42eb74c2ed5866b Mon Sep 17 00:00:00 2001 From: Chris Leaman Date: Tue, 13 Nov 2018 09:02:37 +1100 Subject: [PATCH] Make parse_profile_features into proper function --- src/data/profile_features.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/data/profile_features.py b/src/data/profile_features.py index 742ee2b..16fc2d8 100644 --- a/src/data/profile_features.py +++ b/src/data/profile_features.py @@ -13,7 +13,7 @@ from shapely.ops import transform def shapes_from_shp(shp_file): """ - Parses a shape file and returns a list of shapely shapes + Parses a shape file and returns a list of shapely shapes, ids and properties :param shp_file: :return: """ @@ -158,27 +158,23 @@ def beach_profile_elevation(x_coord, df_profiles, profile_type, site_id): return np.interp(x_coord, df_profile.index.get_level_values('x'), df_profile['z']) -# todo -def get_sites_dune_crest_toe(): +def parse_profile_features(df_sites, df_profiles, dune_crest_shp, dune_toe_shp): """ - Reads dune crest and toe files and creates a pandas dataframe with crest/toe locations at each site_ + Reads dune crest and toe files and creates a pandas dataframe with crest/toe locations at each site :return: """ # Get site information. Base our profile features on each site - data_folder = './data/interim' - df_sites = pd.read_csv(os.path.join(data_folder, 'sites.csv'), index_col=[0]) - df_profiles = pd.read_csv(os.path.join(data_folder, 'profiles.csv'), index_col=[0, 1, 2]) df_profile_features = df_sites features = { 'dune_crest': { - 'file': './data/raw/profile_features/dune_crests.shp' + 'file': dune_crest_shp }, 'dune_toe': { - 'file': './data/raw/profile_features/dune_toes.shp' + 'file': dune_toe_shp }, } @@ -206,6 +202,16 @@ def get_sites_dune_crest_toe(): row.name), axis=1) - df_profile_features = df_profile_features.drop(columns=['beach', 'lat','lon','orientation']) - df_profile_features.to_csv('./data/interim/profile_features.csv') + df_profile_features = df_profile_features.drop(columns=['beach', 'lat', 'lon', 'orientation']) + return df_profile_features + +if __name__ == '__main__': + data_folder = './data/interim' + df_sites = pd.read_csv(os.path.join(data_folder, 'sites.csv'), index_col=[0]) + df_profiles = pd.read_csv(os.path.join(data_folder, 'profiles.csv'), index_col=[0, 1, 2]) + + dune_crest_shp = './data/raw/profile_features/dune_crests.shp' + dune_toe_shp = './data/raw/profile_features/dune_toes.shp' + df_profile_features = parse_profile_features(df_sites, df_profiles, dune_crest_shp, dune_toe_shp) + df_profile_features.to_csv('./data/interim/profile_features.csv')