Skip to content

Commit

Permalink
Allow referencing stream harp times to UBX time
Browse files Browse the repository at this point in the history
  • Loading branch information
glopesdev committed May 3, 2024
1 parent cce3e7e commit 0829e53
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 31 deletions.
12 changes: 3 additions & 9 deletions pluma/export/ogcapi/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@

def convert_dataset_to_geoframe(
dataset,
sampling_dt: datetime.timedelta = datetime.timedelta(seconds=1),
rereference_to_ubx_time: bool = False
sampling_dt: datetime.timedelta = datetime.timedelta(seconds=1)
):

streams_to_export = {}
Expand All @@ -41,10 +40,6 @@ def convert_dataset_to_geoframe(
out = out.join(out_columns)
out.index.name = 'time'

if rereference_to_ubx_time:
offset = dataset.streams.UBX.positiondata['Time_UTC'][0] - out.index[0]
out.index += offset

geometry = gpd.points_from_xy(
x=out['Longitude'],
y=out['Latitude'],
Expand All @@ -56,11 +51,10 @@ def convert_dataset_to_geoframe(
def export_dataset_to_geojson(
dataset,
filename,
sampling_dt: datetime.timedelta = datetime.timedelta(seconds=1),
rereference_to_ubx_time: bool = False
sampling_dt: datetime.timedelta = datetime.timedelta(seconds=1)
):

out = convert_dataset_to_geoframe(dataset, sampling_dt, rereference_to_ubx_time)
out = convert_dataset_to_geoframe(dataset, sampling_dt)
export_geoframe_to_geojson(out, filename)

def export_geoframe_to_geojson(
Expand Down
65 changes: 43 additions & 22 deletions pluma/schema/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,19 @@ def add_ubx_georeference(self,
self.georeference.clockreference.referenceid =\
ubxstream.clockreference.referenceid

def reload_streams(self,
schema: Union[DotMap, Stream, None] = None,
force_load: bool = False) -> None:
@staticmethod
def _iter_schema_streams(schema: Union[DotMap, Stream, None] = None):
if isinstance(schema, Stream):
yield schema
elif isinstance(schema, DotMap):
for _stream in schema.values():
for _nested in Dataset._iter_schema_streams(_stream):
yield _nested
else:
raise TypeError(f"Invalid type was found. Must be of \
{Union[DotMap, Stream]}")

def reload_streams(self, force_load: bool = False) -> None:
"""Recursively loads, from disk , all available streams in the streams' schema
Args:
Expand All @@ -97,21 +107,12 @@ def reload_streams(self,
TypeError: An error is raised if a not allowed type is passed.
"""

if schema is None:
schema = self.streams

if isinstance(schema, Stream):
for stream in self._iter_schema_streams(self.streams):
if force_load is True:
schema.load()
stream.load()
else:
if schema.autoload is True:
schema.load()
elif isinstance(schema, DotMap):
for _stream in schema.values():
self.reload_streams(_stream, force_load=force_load)
else:
raise TypeError(f"Invalid type was found. Must be of \
{Union[DotMap, Stream]}")
if stream.autoload is True:
stream.load()

@staticmethod
def import_dataset(filename: Union[str, ComplexPath]) -> Dataset:
Expand Down Expand Up @@ -240,13 +241,33 @@ def add_georeference_and_calibrate(self, plot_diagnosis=True):
else:
raise AssertionError('Dataset is already been automatically calibrated.')

@staticmethod
def _offset_data_index(data, offset):
if isinstance(data, DotMap):
for frame in data.values():
Dataset._offset_data_index(frame, offset)
else:
data.index += offset - data.index[0]

def reference_harp_to_ubx_time(self):
if self.has_calibration is False:
raise AssertionError('Dataset is not calibrated to UBX time.')

utc_offset = self.streams.UBX.positiondata['Time_UTC'][0]
Dataset._offset_data_index(self.georeference.spacetime, utc_offset)
Dataset._offset_data_index(self.georeference.time, utc_offset)
for stream in self._iter_schema_streams(self.streams):
if len(stream.data) == 0:
continue
if stream.clockreference.referenceid == ClockRefId.HARP:
Dataset._offset_data_index(stream.data, utc_offset)
stream.clockreference.referenceid = ClockRefId.GNSS

def to_geoframe(self,
sampling_dt: datetime.timedelta = datetime.timedelta(seconds=1),
rereference_to_ubx_time: bool = False):
return convert_dataset_to_geoframe(self, sampling_dt, rereference_to_ubx_time)
sampling_dt: datetime.timedelta = datetime.timedelta(seconds=1)):
return convert_dataset_to_geoframe(self, sampling_dt)

def to_geojson(self,
filename,
sampling_dt: datetime.timedelta = datetime.timedelta(seconds=1),
rereference_to_ubx_time: bool = False):
export_dataset_to_geojson(self, filename, sampling_dt, rereference_to_ubx_time)
sampling_dt: datetime.timedelta = datetime.timedelta(seconds=1)):
export_dataset_to_geojson(self, filename, sampling_dt)

0 comments on commit 0829e53

Please sign in to comment.