Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add print representation of Lookup object #30

Merged
merged 2 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ setup_requires =
matplotlib
psf_utils
tqdm
prettytable
install_requires =
numpy
scipy
matplotlib
psf_utils
tqdm
prettytable

[options.packages.find]
where = src
where = src
21 changes: 21 additions & 0 deletions src/pygmid/Lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import scipy.io
from scipy.interpolate import interpn
import pickle
import prettytable

from .constants import *
from .numerical import interp1
Expand Down Expand Up @@ -413,3 +414,23 @@ def fco(self, **kwargs):
dimensions
"""
return self.look_up('SFL_STH', **kwargs)

def __str__(self):

tab = prettytable.PrettyTable()
tab.field_names = ['Variable', 'Size', 'Min', 'Max']

for k, v in self.__DATA.items():

is_numeric = np.issubdtype(v.dtype, np.number)

if is_numeric:
size = str(v.shape).replace('(', '').replace(')', '').\
replace(', ', 'x').replace(',', '')

tab.add_row([ k
, size if size else '1'
, f'{v.min():.2e}' if is_numeric else 'N/A'
, f'{v.max():.2e}' if is_numeric else 'N/A'])

return tab.get_string()