Skip to content

Commit

Permalink
Merge pull request #5 from emotional-cities/re-load-schema
Browse files Browse the repository at this point in the history
Add method to reload dataset schema
  • Loading branch information
bruno-f-cruz authored Nov 22, 2022
2 parents edc09f4 + 5e88caa commit 5ad7394
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
35 changes: 34 additions & 1 deletion pluma/schema/dataset.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import pickle
import os

from dotmap import DotMap
from typing import Union

from pluma.schema.outdoor import build_schema
from pluma.sync.ubx2harp import get_clockcalibration_ubx_to_harp_clock
from pluma.stream import StreamType
from pluma.stream import StreamType, Stream

from pluma.plotting import maps

Expand Down Expand Up @@ -64,6 +67,36 @@ def add_ubx_georeference(self,
if strip is True:
self.georeference.strip()


def reload_streams(self,
schema: Union[DotMap, Stream, None] = None,
force_load: bool = False) -> None:
"""Recursively loads, from disk , all available streams in the streams' schema
Args:
schema (Union[DotMap, Stream, None]): Target schema to reload. \
If None it will default to the Dataset.streams schema. Defaults to None.
force_load (bool, optional): If True, it will attempt to load any stream found,\
ignoring the stream.autoload value. Defaults to False.
Raises:
TypeError: An error is raised if a not allowed type is passed.
"""
if schema is None:
schema = self.streams

if isinstance(schema, Stream):
if force_load is True:
schema.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]}")


def export_streams(self, filename: str = None):
"""Serializes and exports the dataset as a pickle object.
Expand Down
3 changes: 3 additions & 0 deletions pluma/stream/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ def __init__(self, device : str, streamlabel : str, root = '', data : any = None
self.autoload = autoload
self.streamtype = StreamType.NONE

def load(self):
raise NotImplementedError("load() method is not implemented for the Stream base class.")

def plot(self, col = None , **kwargs):
if self.data.empty:
raise ValueError("Input dataframe is empty.")
Expand Down
10 changes: 7 additions & 3 deletions pluma/stream/ubx.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ def __init__(self,
self.positiondata = None
self.clock_calib_model = None # Store the model here
self.streamtype = StreamType.UBX
self.autoload_messages = autoload_messages
if self.autoload:
self.load_event_list(autoload_messages)
self.load_event_list(self.autoload_messages)

def load(self, event: _UBX_MSGIDS):
def load(self):
self.load_event_list(self.autoload_messages)

def load_event(self, event: _UBX_MSGIDS):
self._update_dotmap(event,
load_ubx_event_stream(
event,
Expand All @@ -35,7 +39,7 @@ def has_event(self, event: _UBX_MSGIDS):

def load_event_list(self, events: list):
for event in events:
self.load(event)
self.load_event(event)

def parseposition(self,
event: _UBX_MSGIDS = _UBX_MSGIDS.NAV_HPPOSLLH,
Expand Down

0 comments on commit 5ad7394

Please sign in to comment.