Skip to content

Commit 0360a95

Browse files
committed
Add raw data options to reduce memory footprint
1 parent 87d71c3 commit 0360a95

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/py_eddy_tracker/tracking.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,12 @@ def period(self):
142142
date_stop = datetime(1950, 1, 1) + timedelta(int(self.class_method.load_from_netcdf(self.datasets[-1]).obs['time'][0]))
143143
return date_start, date_stop
144144

145-
def swap_dataset(self, dataset):
145+
def swap_dataset(self, dataset, raw_data=False):
146146
""" Swap to next dataset
147147
"""
148148
self.previous2_obs = self.previous_obs
149149
self.previous_obs = self.current_obs
150-
self.current_obs = self.class_method.load_from_netcdf(dataset)
150+
self.current_obs = self.class_method.load_from_netcdf(dataset, raw_data=raw_data)
151151

152152
def merge_correspondance(self, other):
153153
# Verify compliance of file
@@ -515,7 +515,7 @@ def shorter_than(self, size_max):
515515
self[i]['id'] = translate[self[i]['id']]
516516
logging.debug('Select shorter than %d done', size_max)
517517

518-
def merge(self, until=-1):
518+
def merge(self, until=-1, raw_data=True):
519519
"""Merge all the correspondance in one array with all fields
520520
"""
521521
# Start loading identification again to save in the finals tracks
@@ -529,7 +529,7 @@ def merge(self, until=-1):
529529
size=self.nb_obs,
530530
track_extra_variables=self.current_obs.track_extra_variables,
531531
track_array_variables=self.current_obs.track_array_variables,
532-
array_variables=self.current_obs.array_variables)
532+
array_variables=self.current_obs.array_variables, raw_data=raw_data)
533533

534534
# All the value put at nan, necessary only for all end of track
535535
eddies['cost_association'][:] = default_fillvals['f4']
@@ -554,7 +554,7 @@ def merge(self, until=-1):
554554
break
555555
logging.debug('Merge data from %s', file_name)
556556
# Load current file (we begin with second one)
557-
self.swap_dataset(file_name)
557+
self.swap_dataset(file_name, raw_data=raw_data)
558558
# We select the list of id which are involve in the correspondance
559559
i_id = self[i]['id']
560560
# Index where we will write in the final object
@@ -603,20 +603,21 @@ def merge(self, until=-1):
603603
self.previous_obs = self.current_obs
604604
return eddies
605605

606-
def get_unused_data(self):
606+
def get_unused_data(self, raw_data=False):
607607
"""
608608
Add in track object all the observations which aren't selected
609609
Returns: Unused Eddies
610610
611611
"""
612612
self.reset_dataset_cache()
613-
self.swap_dataset(self.datasets[0])
613+
self.swap_dataset(self.datasets[0], raw_data=raw_data)
614614

615615
nb_dataset = len(self.datasets)
616616
# Get the number of obs unused
617617
nb_obs = 0
618618
list_mask= list()
619619
has_virtual = 'virtual' in self[0].dtype.names
620+
logging.debug('Count unused data ...')
620621
for i, filename in enumerate(self.datasets):
621622
last_dataset = i == (nb_dataset - 1)
622623
if has_virtual and not last_dataset:
@@ -637,15 +638,16 @@ def get_unused_data(self):
637638
m[eddies_used] = False
638639
list_mask.append(m)
639640
nb_obs += m.sum()
640-
641+
logging.debug('Count unused data OK')
641642
eddies = EddiesObservations(
642643
size=nb_obs,
643644
track_extra_variables=self.current_obs.track_extra_variables,
644645
track_array_variables=self.current_obs.track_array_variables,
645-
array_variables=self.current_obs.array_variables)
646+
array_variables=self.current_obs.array_variables, raw_data=raw_data)
646647
j = 0
647648
for i, dataset in enumerate(self.datasets):
648-
current_obs = self.class_method.load_from_netcdf(dataset)
649+
logging.debug('Loaf file : (%d) %s', i, dataset)
650+
current_obs = self.class_method.load_from_netcdf(dataset, raw_data=raw_data)
649651
if i == 0:
650652
eddies.sign_type = current_obs.sign_type
651653
unused_obs = current_obs.observations[list_mask[i]]

src/scripts/EddyFinalTracking

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ if __name__ == '__main__':
5656

5757
if CONFIG.eddies_untracked_model is None:
5858
CONFIG.eddies_untracked_model = '%(path)s/%(sign_type)s_%(prod_time)s_untracked.nc'
59-
CORRESPONDANCES.get_unused_data().write_netcdf(path=SAVE_DIR, filename=CONFIG.eddies_untracked_model)
59+
CORRESPONDANCES.get_unused_data(raw_data=True).write_netcdf(path=SAVE_DIR, filename=CONFIG.eddies_untracked_model)
6060

6161
SHORT_CORRESPONDANCES = CORRESPONDANCES._copy()
6262
SHORT_CORRESPONDANCES.shorter_than(size_max=NB_OBS_MIN)

0 commit comments

Comments
 (0)