def _slice_time(self, slc=":"): """ Args: slc (str, slice, list): can be a single string containing slices, slices, ints, floats, datetime objects, or a list of any of the above. Returns: list of slices (containing integers only) or ints """ # print("> slice time", slc) # print("SLC::", slc) if not isinstance(slc, (list, tuple)): slc = [slc] # expand strings that are comma separated lists of strings _slc = [] for s in slc: if isinstance(s, string_types): for _ in s.split(','): _slc.append(_) else: _slc.append(s) slc = _slc ret = [] times = np.array([child[0] for child in self.children]) for s in slc: if isinstance(s, string_types): s = self._parse_time_slice_str(s) if isinstance(s, slice): single_val = False slc_lst = [s.start, s.stop, s.step] else: single_val = True slc_lst = [s] # do translation from string/datetime/etc -> floats for i in range(min(len(slc_lst), 2)): translation = self._translate_time(slc_lst[i]) if translation != NotImplemented: # hack: convert floats to a string with a trailing f as per # the rest of viscid. we do this because _translate_time # returns a float if isinstance(translation, (float, np.floating)): translation = "{0}f".format(translation) slc_lst[i] = translation if single_val: ret.append(to_slice(times, slc_lst[0])) else: ret.append(to_slice(times, slc_lst)) # print("< time slice made:", ret) return ret
def _slice_time(self, slc=":"): """ Args: slc (str, slice, list): can be a single string containing slices, slices, ints, floats, datetime objects, or a list of any of the above. Returns: list of slices (containing integers only) or ints """ # print("SLC::", slc) if not isinstance(slc, (list, tuple)): slc = [slc] # expand strings that are comma separated lists of strings _slc = [] for s in slc: if isinstance(s, string_types): for _ in s.split(','): _slc.append(_) else: _slc.append(s) slc = _slc ret = [] times = np.array([child[0] for child in self.children]) for s in slc: if isinstance(s, string_types): s = self._parse_time_slice_str(s) if isinstance(s, slice): single_val = False slc_lst = [s.start, s.stop, s.step] else: single_val = True slc_lst = [s] # do translation from string/datetime/etc -> floats for i in range(min(len(slc_lst), 2)): t_as_s = self.as_floating_t(slc_lst[i], none_passthrough=True) if t_as_s is not None: slc_lst[i] = "{0}f".format(t_as_s) if single_val: ret.append(to_slice(times, slc_lst[0])) else: ret.append(to_slice(times, slc_lst)) return ret