Comments (5)
For whatever reason, I can't reproduce the behaviour on my own machine (I can reproduce @hfhsieh's example, but not within RM-Tools). But since a solution has been suggested, I've implemented it into the JSON-saving code in rmsynth1d, rmclean1d, and qufit. Could someone please try the updated version (47e8915) and confirm that this fixes the problem?
Thanks,
Cameron
from rm-tools.
Hi Ruolan:
Can you send me the data you were running that generated this error, and the settings you used? I'd like to recreate it so that I can better understand where it came from (so as to avoid similar problems in the future).
Thanks,
Cameron
from rm-tools.
@Cameron-Van-Eck - this has bitten me in SPICE-RACS as well. Although, in my case the JSON came from my database format, rather than writing to disk. It's strange we haven't seen this issue earlier. If it's helpful, it can be nice to use the numpy primitives to capture all float (or whatever) types. Here's an example from the SPICE-RACS pipeline:
# Ensure JSON serializable
for k, v in mDict.items():
if isinstance(v, np.float_):
mDict[k] = float(v)
elif isinstance(v, np.int_):
mDict[k] = int(v)
elif isinstance(v, np.ndarray):
mDict[k] = v.tolist()
elif isinstance(v, np.bool_):
mDict[k] = bool(v)
do_RMsynth_1D.saveOutput(mDict, aDict, prefix, rm_verbose)
P.S. This can also be handled with a custom JSON encoder - but I think the amount of work is pretty much equivalent
from rm-tools.
@Cameron-Van-Eck I think it is because the built-in json
package supports the Python basic type only, not all the numpy datatype. The example below can reproduce the this issue
import json
import numpy as np
for dtype in [np.int8, np.int16, np.int32, np.int64, np.int_]: # np.int_ == np.int64
#for dtype in [np.float16, np.float32, np.float64, np.float128, np.float_]: # np.float_ == np.float64
try:
json.dump(dtype(np.pi), open("foo", "w")) # numeric
# json.dump({"key": dtype(np.pi)}, open("foo", "w")) # dict
print("{} passed".format(dtype))
except TypeError:
print("{} failed".format(dtype))
# raise
For integer variables (and values in dict), only numpy.int64
passed for Python 2.7.16, and none for Python 3.10.8. For floating number, only numpy.float64
passed for both Python 2 and 3.
I am not sure why the recipe in the SPICE-RACS pipeline works since this issue occurs when not isinstance(v, np.int_)
and not isinstance(v, np.float_)
from rm-tools.
Can you send me the data you were running that generated this error, and the settings you used? I'd like to recreate it so that I can better understand where it came from (so as to avoid similar problems in the future).
It was just the sample data (Soucre1.dat created using 'mk_test_ascii_data.py') you provided. XD
Ruolan
from rm-tools.
Related Issues (20)
- nufft dtype error HOT 6
- 3D cube writer breaks if BUNIT doesn't exist
- Automatic PyPI publishing HOT 5
- Stokes I fitting threshold
- Stokes I renormalisation failure case
- rmsynth3d imaginary FDF files have wrong Stokes axis values HOT 2
- RMSF helper script is bugged
- do_fitIcube: tqdm.contrib.concurrent doesn't play nicely with Prefect
- rescale_I_model_3D: rescale_I_pixel uses a dictionary but util_misc.renormalize_StokesI_model expects "FitResult" class HOT 2
- Odd behaviour in peak outputs from RMsynth3d HOT 3
- Different formulas for rmtf FWHM HOT 1
- Peak fitting maps should output de-rotated Q,U
- peakfitcube tool fails with index error HOT 4
- rmtools_peakfitcube fails with all-NaN maps as output HOT 2
- error message 'ValueError: not enough values to unpack (ecpected 4, got 3)' in rmclean3d HOT 7
- QU-fitting PA uncertainty does not take angle wrapping into account HOT 5
- Release Numpy restriction? HOT 2
- Progress bar for do_fitIcube reverted to old style HOT 3
- Convert Stokes I model to same reference frequency as polarization HOT 1
- Deprecation and versioning notes HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rm-tools.