-
Notifications
You must be signed in to change notification settings - Fork 20
Reference : JSON files
distpy uses configuration files to make it highly adaptable across hardware and highly flexible in terms of signal processing flows. The JSON format is human-readable text, but we would usually expect the JSON configurations to be constructed by UI rather than by hand.
Due to various "hidden" character types and different character sets, it can sometimes be the case that the JSON configuration files look correct when inspected in an editor but are nevertheless unreadable for python.
If you have this situation during testing, the following code snippet is useful for debugging your configuration files.
import json
filename = "myfileIamTesting.json"
def test(filename):
with open(filename) as f:
data = json.load(f)
print(data)
test()
The results of test() should be a printout of your JSON.
For example, the strainrate2thumbnail.json file should give:
{'document': 0, 'name': 'Standard seismic band thumbnails', 'description': 'Creates pictures of band-limited (5-200 Hz) strain-rate data.', 'command_list': [{'name': 'butter', 'uid': 1, 'in_uid': 0, 'type': 'lowpass', 'freq': 200}, {'name': 'butter', 'uid': 2, 'in_uid': 1, 'type': 'highpass', 'freq': 5}, {'name': 'thumbnail', 'uid': 3, 'in_uid': 2, 'directory_out': 'png'}]}
If the spaces in this file are replaced by tabs, however, you will get something like this:
Traceback (most recent call last):
File "<pyshell#48>", line 1, in <module>
test(filename)
File "<pyshell#47>", line 3, in test
data = json.load(f)
File "C:\Python37\lib\json\__init__.py", line 296, in load
parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
File "C:\Python37\lib\json\__init__.py", line 348, in loads
return _default_decoder.decode(s)
File "C:\Python37\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Python37\lib\json\decoder.py", line 353, in raw_decode
obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Invalid control character at: line 3 column 20 (char 38)
That final line tells us to look at line 3 column 20 (char 38) in the file. When we examine it and see that it is a tab, we can group replace all occurrences with a space.
In this way that code snippet can help you correct any issues with making a hand-crafted JSON machine-readable.
data abs angle add analytic_signal argmax approx_vlf bounded_select broaden butter clip conj convolve copy correlate count_peaks data_load deconvolve destripe diff downsample dip_filter down_wave extract fft from_gpu gather gaussian geometric_mean gradient harmonic_mean hard_threshold ifft keras kmeans kurtosis lin_transform macro median_filter mean multiply multiple_calcs peak_to_peak rms_from_fft real rescale roll running_mean sobel soft_threshold sum skewness sta_lta std_dev to_gpu unwrap up_wave velocity_map velocity_mask virtual_cmp wiener write_npy write_witsml