Please consider responding to a brief user needs survey.

Slight tweaks while rerunning CG, PR, RI

parent 155ca8e1
......@@ -138,7 +138,7 @@ sorted_pt_flds = ['SplitSort', 'seg_x', 'seg_y', 'seg_lon', 'seg_lat',
'Dist_Seg', 'Dist_MHWbay', 'DistSegDH', 'DistSegDL', 'DistSegArm',
'ptZ', 'ptSlp', 'ptZmhw',
'GeoSet', 'SubType', 'VegDens', 'VegType',
'sort_ID', 'TRANSECTID', 'DD_ID', 'Azimuth',
'sort_ID', 'TRANSECTID', 'DD_ID', 'MHW', 'Azimuth',
'LRR', 'SL_x', 'SL_y', 'Bslope',
'DL_x', 'DL_y', 'DL_z', 'DL_zmhw', 'DL_snapX','DL_snapY',
'DH_x', 'DH_y', 'DH_z', 'DH_zmhw', 'DH_snapX','DH_snapY',
......
......@@ -128,12 +128,18 @@ def join_columns(df1, df2, id_fld='ID', how='outer'):
def adjust2mhw(df, MHW, fldlist=['DH_z', 'DL_z', 'Arm_z'], fill=-99999):
"""Add elevation fields with values adjusted to MHW, stored in '[fieldname]mhw'"""
# If fill values present in df, replace with nan to perform adjustment and then replace
input_fill=False
if (df == fill).any().any():
input_fill = True
df.replace(fill, np.nan, inplace=True)
for f in fldlist:
df = df.drop(f+'mhw', axis=1, errors='ignore')
df[f+'mhw'] = df[f].subtract(MHW)
# df[f+'mhw'] = df[f].subtract(MHW)
if 'MHW' in df.columns:
print('Using MHW column in dataframe for MHW adjustment.')
df[f+'mhw'] = df[f].subtract(df['MHW'])
else:
df[f+'mhw'] = df[f].subtract(MHW)
if input_fill:
df.fillna(fill, inplace=True)
return(df)
......@@ -180,14 +186,14 @@ def add_latlon(df, proj_code):
return(df)
def calc_trans_distances(df, MHW=''):
def calc_trans_distances(df, MHW=None):
"""Calculate the transect distances: DistDH, DistDL, DistArm, and conditionally adjust to MHW."""
df2 = pd.DataFrame({'DistDH': np.hypot(df.SL_x - df.DH_x, df.SL_y - df.DH_y),
'DistDL': np.hypot(df.SL_x - df.DL_x, df.SL_y - df.DL_y),
'DistArm': np.hypot(df.SL_x - df.Arm_x, df.SL_y - df.Arm_y)},
index=df.index)
df = join_columns(df, df2)
if len(MHW):
if MHW:
df = adjust2mhw(df, MHW)
return(df)
......@@ -212,24 +218,32 @@ def prep_points(df, tID_fld, pID_fld, MHW=None, fill=-99999, old2newflds={}):
df = sort_pts(df, tID_fld, pID_fld)
# Calculate pt distance from dunes and bayside shore
# df = adjust2mhw(df, MHW)
df = calc_trans_distances(df)
df = calc_trans_distances(df, MHW)
df = calc_pt_distances(df)
return(df)
def aggregate_z(df, MHW, id_fld, zfld, fill):
"""Aggregate ptZmhw to max and mean and join to transects"""
# If data frame has fills, replace with NaNs
input_fill=False
if (df == fill).any().any():
input_fill = True
df.replace(fill, np.nan, inplace=True)
# If present, use the MHW column as adjustment value, otherwise use the input value.
if 'MHW' in df.columns:
print('Using MHW column in dataframe for MHW adjustment.')
ptzmhw = df[zfld].subtract(df['MHW'])
else:
ptzmhw = df[zfld].subtract(MHW)
# Add elevation adjusted to MHW column
df = (df.drop(zfld+'mhw', axis=1, errors='ignore')
.join(df[zfld].subtract(MHW), rsuffix='mhw'))
# get mean only if > 80% of points have elevation
.join(ptzmhw.rename(zfld), rsuffix='mhw'))
# Get mean only if > 80% of points have elevation
meanf = lambda x: x.mean() if float(x.count())/x.size > 0.8 else np.nan
# zmhw = df.groupby(id_fld)[zfld+'mhw'].agg({'mean_Zmhw':meanf,
# 'max_Zmhw':np.max})
zmhw = df.groupby(id_fld)[zfld+'mhw'].agg([meanf,max]).rename(columns={'<lambda>':'mean_Zmhw','max':'max_Zmhw'})
zmhw = (df.groupby(id_fld)[zfld+'mhw'].agg([meanf, max])
.rename(columns={'<lambda>':'mean_Zmhw','max':'max_Zmhw'}))
df = join_columns(df, zmhw, id_fld)
# Restore fills for output if input had fill values
if input_fill:
df.fillna(fill, inplace=True)
return(df, zmhw)
......
......@@ -10,7 +10,7 @@
"\n",
"***\n",
"\n",
"Extract barrier island metrics along transects for Barrier Island Geomorphology Bayesian Network. See the project [README](https://github.com/esturdivant-usgs/BI-geomorph-extraction/blob/master/README.md) and the Methods Report (Zeigler et al., in review). \n",
"Extract barrier island metrics along transects for Barrier Island Geomorphology Bayesian Network. See the project [README](https://code.usgs.gov/cmgp/bi-transect-extractor/blob/master/README.md) and the Methods Report (Zeigler et al., 2019). \n",
"\n",
"\n",
"## Pre-requisites:\n",
......@@ -199,8 +199,8 @@
"trans_df.to_pickle(os.path.join(scratch_dir, 'trans_df.pkl'))\n",
"\n",
"# Display\n",
"print(\"\\nHeader of transects dataframe (rows 1-5 out of {}): \".format(len(trans_df)))\n",
"trans_df.head()"
"print(\"\\nSample of select rows in transects dataframe (rows 1-5 out of {}): \".format(len(trans_df)))\n",
"trans_df.loc[:,['sort_ID', 'TRANSECTID', 'LRR', 'Azimuth', 'DD_ID', 'MHW', 'Development']].sample(10)"
]
},
{
......
Markdown is supported
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