def calculated_metadata(self, df=None, geometries=True, clean_cols=True, clean_rows=True): if df is None: df = self.to_dataframe(clean_cols=clean_cols, clean_rows=clean_rows) trajectories = {} for tid, tgroup in df.groupby('trajectory'): tgroup = tgroup.sort_values('t') first_row = tgroup.iloc[0] first_loc = Point(first_row.x, first_row.y) geometry = None if geometries: coords = list(unique_justseen(zip(tgroup.x, tgroup.y))) if len(coords) > 1: geometry = LineString(coords) elif coords == 1: geometry = first_loc trajectory = namedtuple('Trajectory', ['min_z', 'max_z', 'min_t', 'max_t', 'first_loc', 'geometry']) trajectories[tid] = trajectory( min_z=tgroup.z.min(), max_z=tgroup.z.max(), min_t=tgroup.t.min(), max_t=tgroup.t.max(), first_loc=first_loc, geometry=geometry ) meta = namedtuple('Metadata', ['min_t', 'max_t', 'trajectories']) return meta( min_t=df.t.min(), max_t=df.t.max(), trajectories=trajectories )
def calculated_metadata(self, df=None, geometries=True, clean_cols=True, clean_rows=True): if df is None: df = self.to_dataframe(clean_cols=clean_cols, clean_rows=clean_rows) trajectories = {} for tid, tgroup in df.groupby('trajectory'): tgroup = tgroup.sort_values('t') profiles = {} for pid, pgroup in tgroup.groupby('profile'): pgroup = pgroup.sort_values('t') first_row = pgroup.iloc[0] profile = namedtuple('Profile', ['min_z', 'max_z', 't', 'x', 'y', 'loc']) profiles[pid] = profile(min_z=pgroup.z.min(), max_z=pgroup.z.max(), t=first_row.t, x=first_row.x, y=first_row.y, loc=Point(first_row.x, first_row.y)) geometry = None first_row = tgroup.iloc[0] first_loc = Point(first_row.x, first_row.y) if geometries: # only extract non-null pairs null_coordinates = tgroup.x.isnull() | tgroup.y.isnull() coords = list( unique_justseen( zip(tgroup.x[~null_coordinates].tolist(), tgroup.y[~null_coordinates].tolist()))) if len(coords) > 1: geometry = LineString(coords) elif coords == 1: geometry = first_loc trajectory = namedtuple('Trajectory', [ 'min_z', 'max_z', 'min_t', 'max_t', 'profiles', 'first_loc', 'geometry' ]) trajectories[tid] = trajectory(min_z=tgroup.z.min(), max_z=tgroup.z.max(), min_t=tgroup.t.min(), max_t=tgroup.t.max(), profiles=profiles, first_loc=first_loc, geometry=geometry) meta = namedtuple('Metadata', ['min_z', 'max_z', 'min_t', 'max_t', 'trajectories']) return meta(min_z=df.z.min(), max_z=df.z.max(), min_t=df.t.min(), max_t=df.t.max(), trajectories=trajectories)
def calculated_metadata(self, df=None, geometries=True, clean_cols=True, clean_rows=True): if df is None: df = self.to_dataframe(clean_cols=clean_cols, clean_rows=clean_rows) profiles = {} for pid, pgroup in df.groupby('profile'): pgroup = pgroup.sort_values('t') first_row = pgroup.iloc[0] profile = namedtuple('Profile', ['min_z', 'max_z', 't', 'x', 'y', 'loc']) profiles[pid] = profile( min_z=pgroup.z.min(), max_z=pgroup.z.max(), t=first_row.t, x=first_row.x, y=first_row.y, loc=Point(first_row.x, first_row.y) ) geometry = None first_row = df.iloc[0] first_loc = Point(first_row.x, first_row.y) if geometries: coords = list(unique_justseen(zip(df.x, df.y))) if len(coords) > 1: geometry = LineString(coords) # noqa elif len(coords) == 1: geometry = first_loc # noqa meta = namedtuple('Metadata', ['min_z', 'max_z', 'min_t', 'max_t', 'profiles', 'first_loc', 'geometry']) return meta( min_z=df.z.min(), max_z=df.z.max(), min_t=df.t.min(), max_t=df.t.max(), profiles=profiles, first_loc=first_loc, geometry=geometry )