Implement a JSON writer replacing NaN with null#199
Open
yingyue2030699 wants to merge 3 commits intosimularium:mainfrom
Open
Implement a JSON writer replacing NaN with null#199yingyue2030699 wants to merge 3 commits intosimularium:mainfrom
yingyue2030699 wants to merge 3 commits intosimularium:mainfrom
Conversation
Add a replacing NaN with null version of save JSON function. Currently, if there is any `nan` in the input files or during calculations within `simulariumio` using `numpy`, it might break the output JSON since JSON does not support `NaN` as a valid numerical value. This new implemented `save_replacing_nan` saves the `TrajectoryData` to a `JSON` while replacing all `NaN` with `null` (which is supported by `JSON`). This should fix the error you get when uploading the `.simularium` to the simularium website converted from `NERDSS` trajectory with `simulariumio`.
Contributor
|
Thank you for this contribution! We'll take a look! |
toloudis
reviewed
Aug 11, 2025
| print(f"saved to {output_path}.simularium") | ||
|
|
||
| @staticmethod | ||
| def save_replacing_nan( |
Contributor
There was a problem hiding this comment.
I wonder if we could do this with just an additional function argument to the main save function rather than having an entirely different function?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Time estimate or Size
xsmall
Problem
Currently, if there is any
nanin the input files or during calculations withinsimulariumiousingnumpy, it might break the output JSON since JSON does not supportNaNas a valid numerical value.Solution
This new implemented
save_replacing_nansaves theTrajectoryDatato aJSONwhile replacing allNaNwithnull(which is supported byJSON). This should fix the error you get when uploading the.simulariumto the simularium website converted fromNERDSStrajectory withsimulariumio.A new pytest for this function is included.
Type of change
Please delete options that are not relevant.
Change summary:
Steps to Verify:
Pytest implemented at
simulariumio/tests/writers/test_json_writer.py. See the file level docstring.Screenshots (optional):
Previous

savefunction that breaks the web interface:New

save_replacing_nanfunction:Yue "Moon" Ying
NERDSS software development
Dr. Margaret Johnson Group, JHU