meshplot
meshplot copied to clipboard
Jupyter plot error
Hi,
I was trying to use the Jupyter Notebook tutorial you provide in the examples folder.
The data.npz
file is correctly loaded, but the execution of the mp.ploy(v,f)
command end with the following error ValueError: Out of range float values are not JSON compliant, raised when the OrbitControls
are created by the Viewer.
I also report the whole stack trace below.
How can this error be solved?
Thank you in advance!
ValueError Traceback (most recent call last) ~\AppData\Local\Temp/ipykernel_6436/3157376963.py in
----> 1 mp.plot(v, f) ~\miniconda3\envs\meshplot\lib\site-packages\meshplot\plot.py in plot(v, f, c, uv, n, shading, plot, return_plot, filename, texture_data) 79 def plot(v, f=None, c=None, uv=None, n=None, shading={}, plot=None, return_plot=True, filename="", texture_data=None):#, return_id=False): 80 if not plot: ---> 81 view = Viewer(shading) 82 else: 83 view = plot ~\miniconda3\envs\meshplot\lib\site-packages\meshplot\Viewer.py in init(self, settings) 16 self._cam = p3s.PerspectiveCamera(position=[0, 0, 1], lookAt=[0, 0, 0], fov=self.__s["fov"], 17 aspect=self.__s["width"]/self.__s["height"], children=[self._light]) ---> 18 self._orbit = p3s.OrbitControls(controlling=self._cam) 19 self._scene = p3s.Scene(children=[self._cam, self._light2], background=self.__s["background"])#"#4c4c80" 20 self._renderer = p3s.Renderer(camera=self._cam, scene = self._scene, controls=[self._orbit], ~\miniconda3\envs\meshplot\lib\site-packages\pythreejs\controls\OrbitControls_autogen.py in init(self, controlling, **kwargs) 27 def init(self, controlling=None, **kwargs): 28 kwargs['controlling'] = controlling ---> 29 super(OrbitControls, self).init(**kwargs) 30 31 _model_name = Unicode('OrbitControlsModel').tag(sync=True) ~\miniconda3\envs\meshplot\lib\site-packages\pythreejs\controls\Controls_autogen.py in init(self, **kwargs) 28 29 def init(self, **kwargs): ---> 30 super(Controls, self).init(**kwargs) 31 32 _model_name = Unicode('ControlsModel').tag(sync=True) ~\miniconda3\envs\meshplot\lib\site-packages\pythreejs_base\Three.py in init(self, **kwargs) 15 16 def init(self, **kwargs): ---> 17 super(ThreeWidget, self).init(**kwargs) 18 self.on_msg(self._on_potential_ret_val) 19 ~\miniconda3\envs\meshplot\lib\site-packages\ipywidgets\widgets\widget.py in init(self, **kwargs) 413 414 Widget._call_widget_constructed(self) --> 415 self.open() 416 417 def del(self): ~\miniconda3\envs\meshplot\lib\site-packages\ipywidgets\widgets\widget.py in open(self) 436 args['comm_id'] = self._model_id 437 --> 438 self.comm = Comm(**args) 439 440 @observe('comm') ~\miniconda3\envs\meshplot\lib\site-packages\ipykernel\comm\comm.py in init(self, target_name, data, metadata, buffers, **kwargs) 55 if self.primary: 56 # I am primary, open my peer. ---> 57 self.open(data=data, metadata=metadata, buffers=buffers) 58 else: 59 self._closed = False ~\miniconda3\envs\meshplot\lib\site-packages\ipykernel\comm\comm.py in open(self, data, metadata, buffers) 89 comm_manager.register_comm(self) 90 try: ---> 91 self._publish_msg('comm_open', 92 data=data, metadata=metadata, buffers=buffers, 93 target_name=self.target_name, ~\miniconda3\envs\meshplot\lib\site-packages\ipykernel\comm\comm.py in publish_msg(self, msg_type, data, metadata, buffers, **keys) 64 metadata = {} if metadata is None else metadata 65 content = json_clean(dict(data=data, comm_id=self.comm_id, **keys)) ---> 66 self.kernel.session.send(self.kernel.iopub_socket, msg_type, 67 content, 68 metadata=json_clean(metadata), ~\miniconda3\envs\meshplot\lib\site-packages\jupyter_client\session.py in send(self, stream, msg_or_type, content, parent, ident, buffers, track, header, metadata) 828 if self.adapt_version: 829 msg = adapt(msg, self.adapt_version) --> 830 to_send = self.serialize(msg, ident) 831 to_send.extend(buffers) 832 longest = max([len(s) for s in to_send]) ~\miniconda3\envs\meshplot\lib\site-packages\jupyter_client\session.py in serialize(self, msg, ident) 702 content = self.none 703 elif isinstance(content, dict): --> 704 content = self.pack(content) 705 elif isinstance(content, bytes): 706 # content is already packed, as in a relayed message ~\miniconda3\envs\meshplot\lib\site-packages\jupyter_client\session.py in json_packer(obj) 93 94 def json_packer(obj): ---> 95 return jsonapi.dumps( 96 obj, 97 default=json_default, ~\miniconda3\envs\meshplot\lib\site-packages\zmq\utils\jsonapi.py in dumps(o, **kwargs) 23 Keyword arguments are passed along to :py:func: json.dumps
. 24 """ ---> 25 return json.dumps(o, **kwargs).encode("utf8") 26 27 ~\miniconda3\envs\meshplot\lib\json_init.py in dumps(obj, skipkeys, ensure_ascii, check_circular, allow_nan, cls, indent, separators, default, sort_keys, **kw) 232 if cls is None: 233 cls = JSONEncoder --> 234 return cls( 235 skipkeys=skipkeys, ensure_ascii=ensure_ascii, 236 check_circular=check_circular, allow_nan=allow_nan, indent=indent, ~\miniconda3\envs\meshplot\lib\json\encoder.py in encode(self, o) 197 # exceptions aren't as detailed. The list call should be roughly 198 # equivalent to the PySequence_Fast that ''.join() would do. --> 199 chunks = self.iterencode(o, _one_shot=True) 200 if not isinstance(chunks, (list, tuple)): 201 chunks = list(chunks) ~\miniconda3\envs\meshplot\lib\json\encoder.py in iterencode(self, o, _one_shot) 255 self.key_separator, self.item_separator, self.sort_keys, 256 self.skipkeys, _one_shot) --> 257 return _iterencode(o, 0) 258 259 def _make_iterencode(markers, _default, _encoder, _indent, _floatstr, ValueError: Out of range float values are not JSON compliant
I am experiencing the same problem. I think this is the same issue as discussed here
I'm not sure if this is related, but since the error is similar, I thought I would add to this issue rather than create a new one.
I'm also unable to visualize meshplot.Viewer in a jupyter notebook. (Using the meshplot example from libigl). I've upgraded jupyter_client
to 7.0.6 which supposedly includes the commit that was suppose to fix at least a version of this issue, but to no avail.
from meshplot import plot, subplot, interact
V = np.array([
[0., 0, 0],
[1, 0, 0],
[1, 1, 1],
[2, 1, 0]
])
F = np.array([
[0, 1, 2],
[1, 3, 2]
])
plot(V, F)
I get the following
Out of range float values are not JSON compliant
Supporting this message is deprecated in jupyter-client 7, please make sure your message is JSON-compliant
content = self.pack(content)
(adding meshplot.jupyter()
does not change the result.)
jupyter_client.__version__
>> '7.0.6'
import pythreejs
pythreejs.version_info
>> (2, 3, 0, 'final')
For a temporary workaround, you can downgrade it.
I have been able to make it work with
conda install -c conda-forge ipykernel=6.3
and downgrade jupyter_client to < 7 should work as well.
I am using the JupyterLab App v3.3.4-2 and installed the latest version of everything and I got the error: "... UserWarning: Message serialization failed with: Out of range float values are not JSON compliant ..."
So I found this post and downgraded ipykernel to 6.3.1 and jupyter_client to 6.1.7 and now I get this message instead: "Renderer(camera=PerspectiveCamera(children=(DirectionalLight(color='white', intensity=0.6, position=(-0.016842… <meshplot.Viewer.Viewer at 0x12240f89cd0>"
What am I missing?
Now I did some more testing. Running the same notebook in the VS Code environment the mesh is visualized correctly :-) Why doesn't this work in the JupyterLab App?
@richardstardust It might be the plugin is not correctly set up. Could you try this? https://github.com/jupyter-widgets/pythreejs#jupyterlab
Thanks for the tip! I ran: conda install -c conda-forge 'nodejs>=12' and now it works :-)
A temporary monkey patch to kill the message can be done like this:
At line 100 of the jupyter_client/session.py file, you perform the json_clean(obj)
first instead of letting it fail in the try
block. For my particular case, it was jupyter_client==7.3.4 with python==3.8.10
This file is located in your <python venv>/Lib/site-packages/jupyter_client/session.py
...
def json_packer(obj):
try:
return json.dumps(
# obj, # --> original
json_clean(obj), # --> hack to clean first
default=json_default,
ensure_ascii=False,
allow_nan=False,
).encode("utf8", errors="surrogateescape")
except (TypeError, ValueError) as e:
# Fallback to trying to clean the json before serializing
packed = json.dumps(
json_clean(obj), # --> would have been cleaned anyway here
default=json_default,
ensure_ascii=False,
allow_nan=False,
).encode("utf8", errors="surrogateescape")
...