Take post-storm profile based on isgood parameter in .mat file

develop
Chris Leaman 6 years ago
parent 44e03892f3
commit 947d2093bd

@ -198,6 +198,17 @@ def parse_profiles_and_sites(profiles_mat):
site_rows = [] site_rows = []
site_counter = 0 site_counter = 0
# Our z values can come from these columns, depending on the isgood flag.
# Let's reoganise them into a list of list
z_names = ["Zpre", 'Zpost', 'Zrec1', 'Zrec2', 'Zrec3', 'Zrec4']
z_cols = [mat_data[col] for col in z_names]
z_sites = []
for cols in zip(*z_cols):
z_vals = []
for z_vector in zip(*cols):
z_vals.append([z[0] for z in z_vector])
z_sites.append(z_vals)
for i, site in enumerate(mat_data["site"]): for i, site in enumerate(mat_data["site"]):
logger.debug("Processing site {} of {}".format(i + 1, len(mat_data["site"]))) logger.debug("Processing site {} of {}".format(i + 1, len(mat_data["site"])))
@ -215,54 +226,70 @@ def parse_profiles_and_sites(profiles_mat):
# Want to calculation the orientation # Want to calculation the orientation
orientation = {} orientation = {}
for x, lat, lon, z_prestorm, z_poststorm, easting, northing in zip(
for x, lat, lon, z_site, easting, northing in zip(
mat_data["x"][i], mat_data["x"][i],
mat_data["lats"][i], mat_data["lats"][i],
mat_data["lons"][i], mat_data["lons"][i],
mat_data["Zpre"][i], z_sites[i],
mat_data["Zpost"][i],
mat_data["eastings"][i], mat_data["eastings"][i],
mat_data["northings"][i], mat_data["northings"][i],
): ):
# Only extract pre and post storm profile
for j, profile_type in enumerate(["prestorm", "poststorm"]):
if mat_data["isgood"][i][j] == 1: profile_type = None
for j, is_good in enumerate([1] + mat_data["isgood"][i]):
# Assumes the first profile is always good and is the prestorm profike
if j == 0:
profile_type = 'prestorm'
z = z_site[j]
land_lim = np.nan
# Skips bad profiles
elif is_good == 0:
continue
# Takes the first isgood profile as the post storm profile
else:
profile_type = 'poststorm'
z = z_site[j]
land_lim = mat_data["landlims"][i][j] land_lim = mat_data["landlims"][i][j]
survey_datetime = matlab_datenum_to_datetime(mat_data["surveydates"][i][j])
survey_datetime = matlab_datenum_to_datetime(mat_data["surveydates"][i][j])
if profile_type == "prestorm":
z = z_prestorm # Keep a record of the where the center of the profile is located, and the locations of the land
else: # and sea
z = z_poststorm
# TODO: This code isn't very transferrable. What if we don't have lat/lons at 200 m? Relook at this
# Keep a record of the where the center of the profile is located, and the locations of the land if x[0] == 200:
# and sea x_200_lat = lat[0]
x_200_lon = lon[0]
# TODO: This code isn't very transferrable. What if we don't have lat/lons at 200 m? Relook at this elif x[0] == 0:
if x[0] == 200: orientation["land_easting"] = easting[0]
x_200_lat = lat[0] orientation["land_northing"] = northing[0]
x_200_lon = lon[0] elif x[0] == 400:
elif x[0] == 0: orientation["sea_easting"] = easting[0]
orientation["land_easting"] = easting[0] orientation["sea_northing"] = northing[0]
orientation["land_northing"] = northing[0]
elif x[0] == 400: profile_rows.append(
orientation["sea_easting"] = easting[0] {
orientation["sea_northing"] = northing[0] "site_id": site_id,
"lon": lon[0],
profile_rows.append( "lat": lat[0],
{ "profile_type": profile_type,
"site_id": site_id, "x": x[0],
"lon": lon[0], "z": z,
"lat": lat[0], "land_lim": land_lim,
"profile_type": profile_type, "survey_datetime": survey_datetime,
"x": x[0], }
"z": z[0], )
"land_lim": land_lim,
"survey_datetime": survey_datetime, # Stop looking at profiles if we've got our post-storm profile
} if profile_type == 'poststorm':
) break
orientation = math.degrees( orientation = math.degrees(
math.atan2( math.atan2(
@ -306,8 +333,9 @@ def remove_zeros(df_profiles):
df_profiles.index.get_level_values("profile_type") == key[1] df_profiles.index.get_level_values("profile_type") == key[1]
) )
df_profile = df_profiles[idx_site] df_profile = df_profiles[idx_site]
x_last_ele = df_profile[df_profile.z != 0].index.get_level_values("x")[-1] x_last_ele = df_profile[df_profile.z == 0].index.get_level_values("x")[0]
df_profiles.loc[idx_site & (df_profiles.index.get_level_values("x") > x_last_ele), "z"] = np.nan df_profiles.loc[idx_site & (df_profiles.index.get_level_values("x") > x_last_ele),
"z"] = np.nan
logger.info("Removed zeros from end of profiles") logger.info("Removed zeros from end of profiles")
return df_profiles return df_profiles

Loading…
Cancel
Save