Skip to content

Commit 217a85a

Browse files
committed
last updates, docstrings and removal of extras
1 parent 5bedec5 commit 217a85a

6 files changed

Lines changed: 180 additions & 301 deletions

File tree

docs/notebooks/basics.ipynb

Lines changed: 9 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,6 @@
88
"\n"
99
]
1010
},
11-
{
12-
"cell_type": "code",
13-
"execution_count": 1,
14-
"metadata": {},
15-
"outputs": [],
16-
"source": [
17-
"import kessler"
18-
]
19-
},
2011
{
2112
"cell_type": "markdown",
2213
"metadata": {},
@@ -45,7 +36,7 @@
4536
},
4637
{
4738
"cell_type": "code",
48-
"execution_count": 2,
39+
"execution_count": 1,
4940
"metadata": {},
5041
"outputs": [],
5142
"source": [
@@ -62,92 +53,25 @@
6253
},
6354
{
6455
"cell_type": "code",
65-
"execution_count": 4,
56+
"execution_count": 2,
6657
"metadata": {},
6758
"outputs": [
6859
{
6960
"name": "stdout",
7061
"output_type": "stream",
7162
"text": [
72-
"Loading CDMS (with extension .cdm.kvn.txt) from directory: /Users/giacomoacciarini/cdm_data/cdms_kvn/\n",
73-
"Loaded 39 CDMs grouped into 4 events\n"
63+
"Loading CDMS (with extension .kvn) from directory: synthetic_cdms/\n",
64+
"Loaded 14 CDMs grouped into 2 events\n"
7465
]
7566
}
7667
],
7768
"source": [
78-
"path_to_cdms_folder='cdm_data/cdms_kvn/'\n",
69+
"path_to_cdms_folder='synthetic_cdms/'\n",
7970
"\n",
80-
"events=EventDataset(path_to_cdms_folder)\n",
71+
"events=EventDataset(path_to_cdms_folder,cdm_extension='.kvn')\n",
8172
"#A message appears confirming that the loading has happened, with the number of CDMs and events."
8273
]
8374
},
84-
{
85-
"cell_type": "markdown",
86-
"metadata": {},
87-
"source": [
88-
"## Loading CDMs from pandas ``DataFrame`` object\n",
89-
"\n",
90-
"\n",
91-
"\n"
92-
]
93-
},
94-
{
95-
"cell_type": "markdown",
96-
"metadata": {},
97-
"source": [
98-
"\n",
99-
"In this tutorial, we show how to load CDMs from pandas ``DataFrame`` object.\n",
100-
"\n",
101-
"First we perform the relevant imports:\n",
102-
" "
103-
]
104-
},
105-
{
106-
"cell_type": "code",
107-
"execution_count": 5,
108-
"metadata": {},
109-
"outputs": [],
110-
"source": [
111-
"import kessler\n",
112-
"import pandas as pd\n",
113-
"from kessler import EventDataset\n"
114-
]
115-
},
116-
{
117-
"cell_type": "markdown",
118-
"metadata": {},
119-
"source": [
120-
"Then, we create the ``EventDataset`` object, after having uploaded the pandas dataframe and created the ``DataFrame`` object:"
121-
]
122-
},
123-
{
124-
"cell_type": "code",
125-
"execution_count": 7,
126-
"metadata": {},
127-
"outputs": [
128-
{
129-
"name": "stdout",
130-
"output_type": "stream",
131-
"text": [
132-
"Dataframe with 2 rows and 231 columns\n",
133-
"Dropping columns with NaNs\n",
134-
"Dataframe with 2 rows and 104 columns\n",
135-
"Grouping by event_id\n",
136-
"Grouped into 1 event(s)\n",
137-
"Converting DataFrame to EventDataset\n",
138-
"Time spent | Time remain.| Progress | Events | Events/sec\n",
139-
"0d:00:00:00 | 0d:00:00:00 | #################### | 1/1 | 404.06 \n",
140-
"\n",
141-
"EventDataset(Events:1, number of CDMs per event: 2 (min), 2 (max), 2.00 (mean))\n"
142-
]
143-
}
144-
],
145-
"source": [
146-
"file_name='cdm_data/cdms_csv/sample.csv'\n",
147-
"df=pd.read_csv(file_name)\n",
148-
"events=EventDataset.from_pandas(df)"
149-
]
150-
},
15175
{
15276
"cell_type": "markdown",
15377
"metadata": {},
@@ -173,27 +97,10 @@
17397
},
17498
{
17599
"cell_type": "code",
176-
"execution_count": 8,
100+
"execution_count": 3,
177101
"metadata": {},
178-
"outputs": [
179-
{
180-
"name": "stdout",
181-
"output_type": "stream",
182-
"text": [
183-
"Cannot import dbm.gnu: No module named '_gdbm'\n"
184-
]
185-
},
186-
{
187-
"name": "stderr",
188-
"output_type": "stream",
189-
"text": [
190-
"/Users/giacomoacciarini/miniconda3/envs/fdl/lib/python3.7/site-packages/pyprob/util.py:327: UserWarning: Empirical distributions on disk may perform slow because GNU DBM is not available. Please install and configure gdbm library for Python for better speed.\n",
191-
" warnings.warn('Empirical distributions on disk may perform slow because GNU DBM is not available. Please install and configure gdbm library for Python for better speed.')\n"
192-
]
193-
}
194-
],
102+
"outputs": [],
195103
"source": [
196-
"import kessler\n",
197104
"from kessler.data import kelvins_to_event_dataset"
198105
]
199106
},
@@ -230,7 +137,7 @@
230137
}
231138
],
232139
"source": [
233-
"file_name='cdm_data/kelvins_data/test_data.csv'\n",
140+
"file_name='kelvins_data/test_data.csv'\n",
234141
"events=kelvins_to_event_dataset(file_name, drop_features=['c_rcs_estimate', 't_rcs_estimate'], num_events=1000)\n",
235142
"#The output will show the number of CDMs and events loaded, as they progress.\n"
236143
]

docs/notebooks/cdms_analysis_and_plotting.ipynb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
],
4242
"source": [
4343
"import kessler\n",
44-
"from kessler import EventDataset\n",
4544
"path_to_cdms_folder='synthetic_cdms'\n",
4645
"events=kessler.EventDataset(cdms_dir=path_to_cdms_folder,cdm_extension='.kvn')\n",
4746
"#events=EventDataset(path_to_cdms_folder)"

docs/notebooks/kelvins_dataset.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"outputs": [],
88
"source": [
99
"import kessler\n",
10-
"from kessler import EventDataset\n",
1110
"from kessler.nn import LSTMPredictor\n",
1211
"from kessler.data import kelvins_to_event_dataset\n",
1312
"import pandas as pd\n",
@@ -28,13 +27,14 @@
2827
{
2928
"cell_type": "code",
3029
"execution_count": null,
30+
"id": "322e9b06",
3131
"metadata": {},
3232
"outputs": [],
3333
"source": [
3434
"#As an example, we first show the case in which the data comes from the Kelvins competition.\n",
3535
"#For this, we built a specific converter that takes care of the conversion from Kelvins format\n",
3636
"#to standard CDM format (the data can be downloaded at https://kelvins.esa.int/collision-avoidance-challenge/data/):\n",
37-
"file_name = '/home/gunes/data/kelvins/train_data/train_data.csv'\n",
37+
"file_name='kelvins_data/train_data.csv'\n",
3838
"events = kelvins_to_event_dataset(file_name, drop_features=['c_rcs_estimate', 't_rcs_estimate'], num_events=1000) #we use only 200 events"
3939
]
4040
},

kessler/event.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import matplotlib as mpl
1414
import matplotlib.pyplot as plt
1515
from glob import glob
16+
from tqdm import tqdm
1617
import copy
1718
import os
1819
import re
@@ -164,7 +165,7 @@ def __len__(self):
164165

165166

166167
class EventDataset():
167-
def __init__(self, cdms_dir=None, cdm_extension='.cdm.kvn.txt', events=None):
168+
def __init__(self, cdms_dir=None, cdm_extension='.kvn', events=None):
168169
if events is None:
169170
if cdms_dir is None:
170171
self._events = []
@@ -398,10 +399,8 @@ def from_pandas(df, cdm_compatible_fields={
398399
df_events = df.groupby(group_events_by).groups
399400
print('Grouped into {} event(s)'.format(len(df_events)))
400401
events = []
401-
util.progress_bar_init('Converting DataFrame to EventDataset', len(df_events), 'Events')
402402
i = 0
403-
for k, v in df_events.items():
404-
util.progress_bar_update(i)
403+
for k, v in tqdm(df_events.items()):
405404
i += 1
406405
df_event = df.iloc[v]
407406
cdms = []
@@ -416,7 +415,6 @@ def from_pandas(df, cdm_compatible_fields={
416415
cdm[cdm_name] = value
417416
cdms.append(cdm)
418417
events.append(Event(cdms))
419-
util.progress_bar_end()
420418
event_dataset = EventDataset(events=events)
421419
print('\n{}'.format(event_dataset))
422420
return event_dataset
@@ -425,12 +423,8 @@ def to_dataframe(self):
425423
if len(self) == 0:
426424
return pd.DataFrame()
427425
event_dataframes = []
428-
429-
util.progress_bar_init('Converting EventDataset to DataFrame', len(self._events), 'Events')
430-
for i, event in enumerate(self._events):
431-
util.progress_bar_update(i)
426+
for i, event in enumerate(tqdm(self._events)):
432427
event_dataframes.append(event.to_dataframe())
433-
util.progress_bar_end()
434428
return pd.concat(event_dataframes, ignore_index=True)
435429

436430
def dates(self):

0 commit comments

Comments
 (0)