Skip to content

Conversation

@yingyue2030699
Copy link

@yingyue2030699 yingyue2030699 commented Aug 6, 2025

Time estimate or Size

xsmall

Problem

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.

Screenshot 2025-08-06 at 3 09 19 PM

Solution

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.

A new pytest for this function is included.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

Change summary:

  • Added a replacing NaN with null version of save JSON function.

Steps to Verify:

Pytest implemented at simulariumio/tests/writers/test_json_writer.py. See the file level docstring.

Screenshots (optional):

Previous save function that breaks the web interface:
Screenshot 2025-08-06 at 3 16 59 PM

New save_replacing_nan function:
Screenshot 2025-08-06 at 3 14 34 PM


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

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`.
@yingyue2030699 yingyue2030699 requested a review from a team as a code owner August 6, 2025 19:17
@yingyue2030699 yingyue2030699 requested review from meganrm and toloudis and removed request for a team August 6, 2025 19:17
@toloudis
Copy link
Contributor

toloudis commented Aug 7, 2025

Thank you for this contribution! We'll take a look!

print(f"saved to {output_path}.simularium")

@staticmethod
def save_replacing_nan(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants