Make parse_profile_features into proper function

master
Chris Leaman 6 years ago
parent 60869a338e
commit 1df2b59326

@ -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
},
}
@ -207,5 +203,15 @@ def get_sites_dune_crest_toe():
axis=1)
df_profile_features = df_profile_features.drop(columns=['beach', 'lat', 'lon', 'orientation'])
df_profile_features.to_csv('./data/interim/profile_features.csv')
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')

Loading…
Cancel
Save