|
26 | 26 |
|
27 | 27 | UPDATE HISTORY: |
28 | 28 | Updated 07/2026: add dunder (magic) methods for mathematical operations |
| 29 | + add HTML representation of harmonics class |
29 | 30 | Updated 06/2024: use wrapper to importlib for optional dependencies |
30 | 31 | Updated 05/2024: make subscriptable and allow item assignment |
31 | 32 | Updated 10/2023: place time and month variables in try/except block |
|
110 | 111 | from gravity_toolkit.destripe_harmonics import destripe_harmonics |
111 | 112 | from gravity_toolkit.read_gfc_harmonics import read_gfc_harmonics |
112 | 113 | from gravity_toolkit.read_GRACE_harmonics import read_GRACE_harmonics |
113 | | -from gravity_toolkit.utilities import import_dependency, reify |
| 114 | +from gravity_toolkit.utilities import import_dependency, reify, html_repr |
114 | 115 |
|
115 | 116 | # attempt imports |
116 | 117 | geoidtk = import_dependency('geoid_toolkit') |
@@ -1976,11 +1977,28 @@ def __str__(self): |
1976 | 1977 | properties.append(f' max_degree: {self.lmax}') |
1977 | 1978 | if self.mmax and (self.mmax != self.lmax): |
1978 | 1979 | properties.append(f' max_order: {self.mmax}') |
1979 | | - if self.month: |
1980 | | - properties.append(f' start_month: {min(self.month)}') |
1981 | | - properties.append(f' end_month: {max(self.month)}') |
| 1980 | + if np.any(self.month): |
| 1981 | + properties.append(f' start_month: {np.min(self.month)}') |
| 1982 | + properties.append(f' end_month: {np.max(self.month)}') |
1982 | 1983 | return '\n'.join(properties) |
1983 | 1984 |
|
| 1985 | + def __repr__(self): |
| 1986 | + """Representation of the ``harmonics`` object""" |
| 1987 | + return self.__str__() |
| 1988 | + |
| 1989 | + def _repr_html_(self): |
| 1990 | + """HTML representation of the ``harmonics`` object""" |
| 1991 | + header = 'gravity_toolkit.harmonics' |
| 1992 | + properties = {} |
| 1993 | + properties['max_degree'] = self.lmax |
| 1994 | + if self.mmax and (self.mmax != self.lmax): |
| 1995 | + properties['max_order'] = self.mmax |
| 1996 | + if np.any(self.month): |
| 1997 | + properties['start_month'] = np.min(self.month) |
| 1998 | + properties['end_month'] = np.max(self.month) |
| 1999 | + properties['slices'] = self.__len__() |
| 2000 | + return html_repr(header, properties) |
| 2001 | + |
1984 | 2002 | def __add__(self, other): |
1985 | 2003 | """Add values to a ``harmonics`` object""" |
1986 | 2004 | temp = self.copy() |
@@ -2048,7 +2066,7 @@ def __truediv__(self, other): |
2048 | 2066 |
|
2049 | 2067 | def __len__(self): |
2050 | 2068 | """Number of months""" |
2051 | | - return len(self.month) if np.any(self.month) else 0 |
| 2069 | + return len(np.atleast_1d(self.month)) if np.any(self.month) else 0 |
2052 | 2070 |
|
2053 | 2071 | def __iter__(self): |
2054 | 2072 | """Iterate over GRACE/GRACE-FO months""" |
|
0 commit comments