-
Notifications
You must be signed in to change notification settings - Fork 35
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
Improve print(mesh)
#142
Comments
Related, to some extent, to #21. |
I think that would be great! But I think @lheagy and @rowanc1 and probably others of SimPEG have to chime in with their opinion, as it is their brainchild. A few points:
|
That is interesting. I never figured out, how to distinguish between a Notebook kernel and an IPython/Qt kernel. If you do the same in an IPython terminal, what will happen? |
(The discussion around this problem is here: simpeg/simpeg#698). |
As a developer, you don't have to do anything besides implement a method called |
@prisae - if you want an HTML representation in notebooks and a plain text representation in IPython/Qt then simpll make class object for your versions info that implements the two |
What happens if you call |
Also here's something to test: class Information(object):
@property
def n_cells(self):
return 6
@property
def bounds(self):
return (-1,1, -1,1, -1,1)
def _get_attrs(self):
"""An internal helper for the representation methods"""
attrs = []
attrs.append(("N Cells", self.n_cells, "{}"))
bds = self.bounds
attrs.append(("X Bounds", (bds[0], bds[1]), "{:.3e}, {:.3e}"))
attrs.append(("Y Bounds", (bds[2], bds[3]), "{:.3e}, {:.3e}"))
attrs.append(("Z Bounds", (bds[4], bds[5]), "{:.3e}, {:.3e}"))
return attrs
def __repr__(self):
fmt = "{} ({})\n".format(type(self).__name__, hex(id(self)))
# now make a call on the object to get its attributes as a list of len 2 tuples
row = " {}:\t{}\n"
for attr in self._get_attrs():
try:
fmt += row.format(attr[0], attr[2].format(*attr[1]))
except:
fmt += row.format(attr[0], attr[2].format(attr[1]))
return fmt
def _repr_html_(self):
fmt = ""
# HTML version
fmt += "\n"
fmt += "<table>\n"
fmt += "<tr><th>{}</th><th>Information</th></tr>\n".format(type(self).__name__)
row = "<tr><td>{}</td><td>{}</td></tr>\n"
# now make a call on the object to get its attributes as a list of len 2 tuples
for attr in self._get_attrs():
try:
fmt += row.format(attr[0], attr[2].format(*attr[1]))
except:
fmt += row.format(attr[0], attr[2].format(attr[1]))
fmt += "</table>\n"
fmt += "\n"
return fmt
Information() |
That's a bug on my part in |
This is looking good and would be a great contribution! Just a couple questions at this early stage:
|
I think that it would be absolutely awesome to improve this print out. Starting down the road of useful (albeit at the start) static widgets is a really cool avenue to explore. The print function was originally done by @dwfmarchant, back in 2014 or so! Probably in the first versions of the python implementation - lots of room for improvement. :) |
This was fixed in #143 . |
I think the current print-utility of meshes was made with small meshes in mind. It sort of explodes for big, stretched meshes:
I think something along these lines would be preferable (maybe as a rendered table in notebooks):
The text was updated successfully, but these errors were encountered: