def lateral_2d_to_api_lateral(lateral_2d: Lateral2D, session: Session) -> Lateral: try: values = parse_timeseries(lateral_2d.timeseries) except (ValueError, TypeError): raise SchematisationError( f"Incorrect timeseries format for lateral 2D with id: {lateral_2d.id}" ) offset = values[0][0] if offset > 0: # Shift timeseries to start at t=0 values = [[x[0] - offset, x[1]] for x in values] # x,y is correct (4.294348493375471, 52.033176579129936) until we alter the API point = json.loads(session.scalar(lateral_2d.the_geom.ST_AsGeoJSON())) return Lateral( offset=int(values[0][0]), values=values, point=point, units="m3/s", interpolate=False, )