Skip to content

Commit

Permalink
improved active dict handling as in bgc.sprof()
Browse files Browse the repository at this point in the history
  • Loading branch information
cgrdn committed Mar 13, 2024
1 parent c04b259 commit 60d8579
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion bgcArgoDMQC/core/prof.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def __init__(self, wmo, cycle, kind='C', keep_fillvalue=False, rcheck=True, verb

self.__floatdict__, self.__prof__, self.__fillvalue__ = load_profile(io.Path.ARGO_PATH, wmo, cycle, kind=kind)
self.__rawfloatdict__ = self.__floatdict__
self._dict = 'raw'

# local path info
self.argo_path = io.Path.ARGO_PATH
Expand Down Expand Up @@ -63,6 +64,7 @@ def rm_fillvalue(self):
'''
self.__nofillvaluefloatdict__ = dict_fillvalue_clean(self.__rawfloatdict__)
self.__floatdict__ = copy.deepcopy(self.__nofillvaluefloatdict__)
self._dict = 'nofill'
self.to_dataframe()

def clean(self, bad_flags=None):
Expand All @@ -73,6 +75,7 @@ def clean(self, bad_flags=None):
'''
self.__cleanfloatdict__ = dict_clean(self.__floatdict__, bad_flags=bad_flags)
self.__floatdict__ = copy.deepcopy(self.__cleanfloatdict__)
self._dict = 'clean'
self.to_dataframe()

def reset(self):
Expand All @@ -81,7 +84,22 @@ def reset(self):
clean(), rm_fillvalue(), check_range().
'''
self.__floatdict__ = copy.deepcopy(self.__rawfloatdict__)
self._dict = 'raw'
self.to_dataframe()

def set_dict(self, name):
'''
Call on the proper dict function given a dictionary name
'''

if name == 'raw':
self.reset()
elif name == 'nofill':
self.rm_fillvalue()
elif name == 'clean':
self.clean()
else:
raise ValueError('Unregognized dict type name, should be one of "clean", "nofill", "raw"')

def check_range(self, key, verbose=False):
'''
Expand Down Expand Up @@ -141,10 +159,13 @@ def to_dataframe(self):

def update_field(self, field, value, where=None):

current_float_dict = copy.deepcopy(self._dict)
self.reset()

where = slice(None) if where is None else where
self.__floatdict__[field][where] = value

self.assign(self.__floatdict__)
self.set_dict(current_float_dict)
self.to_dataframe()

def set_fillvalue(self, field, where=None):
Expand Down

0 comments on commit 60d8579

Please sign in to comment.