pastastore 1.4.0__py3-none-any.whl → 1.5.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pastastore/connectors.py CHANGED
@@ -1,3 +1,5 @@
1
+ """Module containing classes for connecting to different data stores."""
2
+
1
3
  import json
2
4
  import os
3
5
  import warnings
@@ -16,11 +18,12 @@ warnings.showwarning = _custom_warning
16
18
 
17
19
 
18
20
  class ArcticConnector(BaseConnector, ConnectorUtil): # pragma: no cover
21
+ """ArcticConnector object that connects to a running MongoDB database via Arctic."""
22
+
19
23
  conn_type = "arctic"
20
24
 
21
25
  def __init__(self, name: str, connstr: str):
22
- """Create an ArcticConnector object that connects to a running MongoDB
23
- database via Arctic.
26
+ """Create an ArcticConnector object that connects to a MongoDB database.
24
27
 
25
28
  Parameters
26
29
  ----------
@@ -29,6 +32,12 @@ class ArcticConnector(BaseConnector, ConnectorUtil): # pragma: no cover
29
32
  connstr : str
30
33
  connection string (e.g. 'mongodb://localhost:27017/')
31
34
  """
35
+ warnings.warn(
36
+ "ArcticConnector is deprecated. Please use a different "
37
+ "connector, e.g. `pst.ArcticDBConnector`.",
38
+ DeprecationWarning,
39
+ stacklevel=1,
40
+ )
32
41
  try:
33
42
  import arctic
34
43
  except ModuleNotFoundError as e:
@@ -52,8 +61,7 @@ class ArcticConnector(BaseConnector, ConnectorUtil): # pragma: no cover
52
61
  self._update_all_oseries_model_links()
53
62
 
54
63
  def _initialize(self) -> None:
55
- """Internal method to initalize the libraries."""
56
-
64
+ """Initialize the libraries (internal method)."""
57
65
  for libname in self._default_library_names:
58
66
  if self._library_name(libname) not in self.arc.list_libraries():
59
67
  self.arc.initialize_library(self._library_name(libname))
@@ -66,7 +74,7 @@ class ArcticConnector(BaseConnector, ConnectorUtil): # pragma: no cover
66
74
  self.libs[libname] = self._get_library(libname)
67
75
 
68
76
  def _library_name(self, libname: str) -> str:
69
- """Internal method to get full library name according to Arctic."""
77
+ """Get full library name according to Arctic (internal method)."""
70
78
  return ".".join([self.name, libname])
71
79
 
72
80
  def _get_library(self, libname: str):
@@ -94,7 +102,7 @@ class ArcticConnector(BaseConnector, ConnectorUtil): # pragma: no cover
94
102
  metadata: Optional[Dict] = None,
95
103
  **_,
96
104
  ) -> None:
97
- """Internal method to add item to library (time series or model).
105
+ """Add item to library (time series or model) (internal method).
98
106
 
99
107
  Parameters
100
108
  ----------
@@ -111,7 +119,7 @@ class ArcticConnector(BaseConnector, ConnectorUtil): # pragma: no cover
111
119
  lib.write(name, item, metadata=metadata)
112
120
 
113
121
  def _get_item(self, libname: str, name: str) -> Union[FrameorSeriesUnion, Dict]:
114
- """Internal method to retrieve item from library.
122
+ """Retrieve item from library (internal method).
115
123
 
116
124
  Parameters
117
125
  ----------
@@ -129,7 +137,7 @@ class ArcticConnector(BaseConnector, ConnectorUtil): # pragma: no cover
129
137
  return lib.read(name).data
130
138
 
131
139
  def _del_item(self, libname: str, name: str) -> None:
132
- """Internal method to delete items (series or models).
140
+ """Delete items (series or models) (internal method).
133
141
 
134
142
  Parameters
135
143
  ----------
@@ -142,7 +150,7 @@ class ArcticConnector(BaseConnector, ConnectorUtil): # pragma: no cover
142
150
  lib.delete(name)
143
151
 
144
152
  def _get_metadata(self, libname: str, name: str) -> dict:
145
- """Internal method to retrieve metadata for an item.
153
+ """Retrieve metadata for an item (internal method).
146
154
 
147
155
  Parameters
148
156
  ----------
@@ -199,6 +207,8 @@ class ArcticConnector(BaseConnector, ConnectorUtil): # pragma: no cover
199
207
 
200
208
 
201
209
  class ArcticDBConnector(BaseConnector, ConnectorUtil):
210
+ """ArcticDBConnector object using ArcticDB to store data."""
211
+
202
212
  conn_type = "arcticdb"
203
213
 
204
214
  def __init__(self, name: str, uri: str):
@@ -228,8 +238,7 @@ class ArcticDBConnector(BaseConnector, ConnectorUtil):
228
238
  self._update_all_oseries_model_links()
229
239
 
230
240
  def _initialize(self) -> None:
231
- """Internal method to initalize the libraries."""
232
-
241
+ """Initialize the libraries (internal method)."""
233
242
  for libname in self._default_library_names:
234
243
  if self._library_name(libname) not in self.arc.list_libraries():
235
244
  self.arc.create_library(self._library_name(libname))
@@ -242,7 +251,7 @@ class ArcticDBConnector(BaseConnector, ConnectorUtil):
242
251
  self.libs[libname] = self._get_library(libname)
243
252
 
244
253
  def _library_name(self, libname: str) -> str:
245
- """Internal method to get full library name according to ArcticDB."""
254
+ """Get full library name according to ArcticDB (internal method)."""
246
255
  return ".".join([self.name, libname])
247
256
 
248
257
  def _get_library(self, libname: str):
@@ -270,7 +279,7 @@ class ArcticDBConnector(BaseConnector, ConnectorUtil):
270
279
  metadata: Optional[Dict] = None,
271
280
  **_,
272
281
  ) -> None:
273
- """Internal method to add item to library (time series or model).
282
+ """Add item to library (time series or model) (internal method).
274
283
 
275
284
  Parameters
276
285
  ----------
@@ -292,7 +301,7 @@ class ArcticDBConnector(BaseConnector, ConnectorUtil):
292
301
  lib.write(name, item, metadata=metadata)
293
302
 
294
303
  def _get_item(self, libname: str, name: str) -> Union[FrameorSeriesUnion, Dict]:
295
- """Internal method to retrieve item from library.
304
+ """Retrieve item from library (internal method).
296
305
 
297
306
  Parameters
298
307
  ----------
@@ -310,7 +319,7 @@ class ArcticDBConnector(BaseConnector, ConnectorUtil):
310
319
  return lib.read(name).data
311
320
 
312
321
  def _del_item(self, libname: str, name: str) -> None:
313
- """Internal method to delete items (series or models).
322
+ """Delete items (series or models) (internal method).
314
323
 
315
324
  Parameters
316
325
  ----------
@@ -323,7 +332,7 @@ class ArcticDBConnector(BaseConnector, ConnectorUtil):
323
332
  lib.delete(name)
324
333
 
325
334
  def _get_metadata(self, libname: str, name: str) -> dict:
326
- """Internal method to retrieve metadata for an item.
335
+ """Retrieve metadata for an item (internal method).
327
336
 
328
337
  Parameters
329
338
  ----------
@@ -380,6 +389,8 @@ class ArcticDBConnector(BaseConnector, ConnectorUtil):
380
389
 
381
390
 
382
391
  class PystoreConnector(BaseConnector, ConnectorUtil): # pragma: no cover
392
+ """PystoreConnector object using pystore as database backend."""
393
+
383
394
  conn_type = "pystore"
384
395
 
385
396
  def __init__(self, name: str, path: str):
@@ -392,6 +403,12 @@ class PystoreConnector(BaseConnector, ConnectorUtil): # pragma: no cover
392
403
  path : str
393
404
  path to the pystore directory
394
405
  """
406
+ warnings.warn(
407
+ "PystoreConnector is deprecated. Please use a different "
408
+ "connector, e.g. `pst.PasConnector`.",
409
+ DeprecationWarning,
410
+ stacklevel=1,
411
+ )
395
412
  try:
396
413
  import pystore
397
414
  except ModuleNotFoundError as e:
@@ -412,7 +429,7 @@ class PystoreConnector(BaseConnector, ConnectorUtil): # pragma: no cover
412
429
  self._update_all_oseries_model_links()
413
430
 
414
431
  def _initialize(self) -> None:
415
- """Internal method to initalize the libraries (stores)."""
432
+ """Initialize the libraries (stores) (internal method)."""
416
433
  for libname in self._default_library_names:
417
434
  if libname in self.store.list_collections():
418
435
  print(
@@ -447,7 +464,7 @@ class PystoreConnector(BaseConnector, ConnectorUtil): # pragma: no cover
447
464
  metadata: Optional[Dict] = None,
448
465
  overwrite: bool = False,
449
466
  ) -> None:
450
- """Internal method to add item to library (time series or model).
467
+ """Add item to library (time series or model) (internal method).
451
468
 
452
469
  Parameters
453
470
  ----------
@@ -489,7 +506,7 @@ class PystoreConnector(BaseConnector, ConnectorUtil): # pragma: no cover
489
506
  lib.write(name, s, metadata=metadata, overwrite=overwrite)
490
507
 
491
508
  def _get_item(self, libname: str, name: str) -> Union[FrameorSeriesUnion, Dict]:
492
- """Internal method to retrieve item from pystore library.
509
+ """Retrieve item from pystore library (internal method).
493
510
 
494
511
  Parameters
495
512
  ----------
@@ -522,7 +539,7 @@ class PystoreConnector(BaseConnector, ConnectorUtil): # pragma: no cover
522
539
  return s
523
540
 
524
541
  def _del_item(self, libname: str, name: str) -> None:
525
- """Internal method to delete data from the store.
542
+ """Delete data from the store (internal method).
526
543
 
527
544
  Parameters
528
545
  ----------
@@ -536,7 +553,7 @@ class PystoreConnector(BaseConnector, ConnectorUtil): # pragma: no cover
536
553
  self._clear_cache(libname)
537
554
 
538
555
  def _get_metadata(self, libname: str, name: str) -> dict:
539
- """Internal method to read metadata from pystore.
556
+ """Read metadata from pystore (internal method).
540
557
 
541
558
  Parameters
542
559
  ----------
@@ -600,6 +617,8 @@ class PystoreConnector(BaseConnector, ConnectorUtil): # pragma: no cover
600
617
 
601
618
 
602
619
  class DictConnector(BaseConnector, ConnectorUtil):
620
+ """DictConnector object that stores timeseries and models in dictionaries."""
621
+
603
622
  conn_type = "dict"
604
623
 
605
624
  def __init__(self, name: str = "pastas_db"):
@@ -643,7 +662,7 @@ class DictConnector(BaseConnector, ConnectorUtil):
643
662
  metadata: Optional[Dict] = None,
644
663
  **_,
645
664
  ) -> None:
646
- """Internal method to add item (time series or models).
665
+ """Add item (time series or models) (internal method).
647
666
 
648
667
  Parameters
649
668
  ----------
@@ -663,7 +682,7 @@ class DictConnector(BaseConnector, ConnectorUtil):
663
682
  lib[name] = (metadata, item)
664
683
 
665
684
  def _get_item(self, libname: str, name: str) -> Union[FrameorSeriesUnion, Dict]:
666
- """Internal method to retrieve item from pystore library.
685
+ """Retrieve item from database (internal method).
667
686
 
668
687
  Parameters
669
688
  ----------
@@ -685,7 +704,7 @@ class DictConnector(BaseConnector, ConnectorUtil):
685
704
  return item
686
705
 
687
706
  def _del_item(self, libname: str, name: str) -> None:
688
- """Internal method to delete items (series or models).
707
+ """Delete items (series or models) (internal method).
689
708
 
690
709
  Parameters
691
710
  ----------
@@ -698,7 +717,7 @@ class DictConnector(BaseConnector, ConnectorUtil):
698
717
  _ = lib.pop(name)
699
718
 
700
719
  def _get_metadata(self, libname: str, name: str) -> dict:
701
- """Internal method to read metadata.
720
+ """Read metadata (internal method).
702
721
 
703
722
  Parameters
704
723
  ----------
@@ -742,6 +761,8 @@ class DictConnector(BaseConnector, ConnectorUtil):
742
761
 
743
762
 
744
763
  class PasConnector(BaseConnector, ConnectorUtil):
764
+ """PasConnector object that stores time series and models as JSON files on disk."""
765
+
745
766
  conn_type = "pas"
746
767
 
747
768
  def __init__(self, name: str, path: str):
@@ -767,7 +788,7 @@ class PasConnector(BaseConnector, ConnectorUtil):
767
788
  self._update_all_oseries_model_links()
768
789
 
769
790
  def _initialize(self) -> None:
770
- """Internal method to initialize the libraries."""
791
+ """Initialize the libraries (internal method)."""
771
792
  for val in self._default_library_names:
772
793
  libdir = os.path.join(self.path, val)
773
794
  if not os.path.exists(libdir):
@@ -803,7 +824,7 @@ class PasConnector(BaseConnector, ConnectorUtil):
803
824
  metadata: Optional[Dict] = None,
804
825
  **_,
805
826
  ) -> None:
806
- """Internal method to add item (time series or models).
827
+ """Add item (time series or models) (internal method).
807
828
 
808
829
  Parameters
809
830
  ----------
@@ -845,7 +866,7 @@ class PasConnector(BaseConnector, ConnectorUtil):
845
866
  fm.write(jsondict)
846
867
 
847
868
  def _get_item(self, libname: str, name: str) -> Union[FrameorSeriesUnion, Dict]:
848
- """Internal method to retrieve item.
869
+ """Retrieve item (internal method).
849
870
 
850
871
  Parameters
851
872
  ----------
@@ -878,7 +899,7 @@ class PasConnector(BaseConnector, ConnectorUtil):
878
899
  return item
879
900
 
880
901
  def _del_item(self, libname: str, name: str) -> None:
881
- """Internal method to delete items (series or models).
902
+ """Delete items (series or models) (internal method).
882
903
 
883
904
  Parameters
884
905
  ----------
@@ -898,7 +919,7 @@ class PasConnector(BaseConnector, ConnectorUtil):
898
919
  pass
899
920
 
900
921
  def _get_metadata(self, libname: str, name: str) -> dict:
901
- """Internal method to read metadata.
922
+ """Read metadata (internal method).
902
923
 
903
924
  Parameters
904
925
  ----------
pastastore/datasets.py CHANGED
@@ -1,3 +1,5 @@
1
+ """Module containing example dataset."""
2
+
1
3
  import os
2
4
 
3
5
  import pandas as pd
@@ -13,7 +15,7 @@ from pastastore.base import BaseConnector
13
15
 
14
16
 
15
17
  def example_pastastore(conn="DictConnector"):
16
- """Example dataset loaded into PastaStore.
18
+ """Get example PastaStore.
17
19
 
18
20
  Parameters
19
21
  ----------
@@ -27,7 +29,6 @@ def example_pastastore(conn="DictConnector"):
27
29
  pstore : pastastore.PastaStore
28
30
  PastaStore containing example dataset
29
31
  """
30
-
31
32
  # check it test dataset is available
32
33
  datadir = os.path.join(os.path.dirname(__file__), "../tests/data")
33
34
  if not os.path.exists(datadir):
pastastore/plotting.py CHANGED
@@ -1,4 +1,4 @@
1
- """This module contains all the plotting methods for PastaStore.
1
+ """Module containing all the plotting methods for PastaStore.
2
2
 
3
3
  Pastastore comes with a number helpful plotting methods to quickly
4
4
  visualize time series or the locations of the time series contained in the
@@ -55,7 +55,7 @@ class Plots:
55
55
  legend_kwargs=None,
56
56
  **kwargs,
57
57
  ):
58
- """Internal method to plot time series from pastastore.
58
+ """Plot time series from pastastore (internal method).
59
59
 
60
60
  Parameters
61
61
  ----------
@@ -507,7 +507,6 @@ class Plots:
507
507
  ax : matplotlib Axes
508
508
  The axes in which the cumulative histogram is plotted
509
509
  """
510
-
511
510
  statsdf = self.pstore.get_statistics(
512
511
  [statistic], modelnames=modelnames, progressbar=False
513
512
  )
@@ -563,6 +562,23 @@ class Plots:
563
562
  return ax
564
563
 
565
564
  def compare_models(self, modelnames, ax=None, **kwargs):
565
+ """Compare multiple models and plot the results.
566
+
567
+ Parameters
568
+ ----------
569
+ modelnames : list
570
+ A list of model names to compare.
571
+ ax : matplotlib.axes.Axes, optional
572
+ The axes on which to plot the comparison. If not provided, a new figure
573
+ and axes will be created.
574
+ **kwargs : dict
575
+ Additional keyword arguments to pass to the plot function.
576
+
577
+ Returns
578
+ -------
579
+ cm : pastastore.CompareModels
580
+ The CompareModels object containing the comparison results.
581
+ """
566
582
  models = self.pstore.get_models(modelnames)
567
583
  names = []
568
584
  onames = [iml.oseries.name for iml in models]
@@ -644,7 +660,7 @@ class Maps:
644
660
  ax: matplotlib.Axes
645
661
  axes object
646
662
 
647
- See also
663
+ See Also
648
664
  --------
649
665
  self.add_background_map
650
666
  """
@@ -722,11 +738,10 @@ class Maps:
722
738
  ax: matplotlib.Axes
723
739
  axes object
724
740
 
725
- See also
741
+ See Also
726
742
  --------
727
743
  self.add_background_map
728
744
  """
729
-
730
745
  names = self.pstore.conn._parse_names(names, "oseries")
731
746
  if extent is not None:
732
747
  names = self.pstore.within(extent, names=names)
@@ -774,11 +789,10 @@ class Maps:
774
789
  ax: matplotlib.Axes
775
790
  axes object
776
791
 
777
- See also
792
+ See Also
778
793
  --------
779
794
  self.add_background_map
780
795
  """
781
-
782
796
  model_oseries = [
783
797
  self.pstore.get_models(m, return_dict=True)["oseries"]["name"]
784
798
  for m in self.pstore.model_names
@@ -849,7 +863,7 @@ class Maps:
849
863
  ax: matplotlib.Axes
850
864
  axes object
851
865
 
852
- See also
866
+ See Also
853
867
  --------
854
868
  self.add_background_map
855
869
  """
@@ -898,7 +912,7 @@ class Maps:
898
912
  figsize=(10, 8),
899
913
  **kwargs,
900
914
  ):
901
- """Internal method for plotting dataframe with point locations.
915
+ """Plot dataframe with point locations (internal method).
902
916
 
903
917
  Can be called directly for more control over plot characteristics.
904
918
 
@@ -932,7 +946,6 @@ class Maps:
932
946
  sc : scatter handle
933
947
  scatter plot handle, returned if ax is not None
934
948
  """
935
-
936
949
  if ax is None:
937
950
  return_scatter = False
938
951
  fig, ax = plt.subplots(figsize=figsize)
@@ -1016,7 +1029,7 @@ class Maps:
1016
1029
  ax: axes object
1017
1030
  axis handle of the resulting figure
1018
1031
 
1019
- See also
1032
+ See Also
1020
1033
  --------
1021
1034
  self.add_background_map
1022
1035
  """
@@ -1102,7 +1115,7 @@ class Maps:
1102
1115
  uniques = stresses.loc[:, ["stressmodel", "color"]].drop_duplicates(
1103
1116
  keep="first"
1104
1117
  )
1105
- for name, row in uniques.iterrows():
1118
+ for _, row in uniques.iterrows():
1106
1119
  (h,) = ax.plot(
1107
1120
  [],
1108
1121
  [],
@@ -1201,7 +1214,7 @@ class Maps:
1201
1214
  ax: axes object
1202
1215
  axis handle of the resulting figure
1203
1216
 
1204
- See also
1217
+ See Also
1205
1218
  --------
1206
1219
  self.add_background_map
1207
1220
  """