Hey everyone!
So my code runs perfectly fine in all other parts of the data analysis but for some reason I keep getting an type error when I try to generate a light curve. Here is the full traceback:
File ~/mambaforge/envs/fermi/lib/python3.9/json/init.py:231, in dumps(obj, skipkeys, ensure_ascii, check_circular, allow_nan, cls, indent, separators, default, sort_keys, **kw)
226 # cached encoder
227 if (not skipkeys and ensure_ascii and
228 check_circular and allow_nan and
229 cls is None and indent is None and separators is None and
230 default is None and not sort_keys and not kw):
--> 231 return _default_encoder.encode(obj)
232 if cls is None:
233 cls = JSONEncoder
File ~/mambaforge/envs/fermi/lib/python3.9/json/encoder.py:199, in JSONEncoder.encode(self, o)
195 return encode_basestring(o)
196 # This doesn't pass the iterator directly to ''.join() because the
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)
File ~/mambaforge/envs/fermi/lib/python3.9/json/encoder.py:179, in JSONEncoder.default(self, o)
160 def default(self, o):
161 """Implement this method in a subclass such that it returns
162 a serializable object for o, or calls the base implementation
163 (to raise a TypeError).
(...)
177
178 """
--> 179 raise TypeError(f'Object of type {o.class.name} '
180 f'is not JSON serializable')
TypeError: Object of type int64 is not JSON serializable
It's weird because the code actually does process all of the intended bins (TS values are given for all bins in the log and the correct folders are generated), but right after it's gone through all the bins it spits out the error, which causes the whole gta.lightcurve procedure to fail so I can't plot or extract any info from the bins. Does anyone have any idea how to fix this issue?
Hey everyone! So my code runs perfectly fine in all other parts of the data analysis but for some reason I keep getting an type error when I try to generate a light curve. Here is the full traceback:
TypeError Traceback (most recent call last) Cell In[19], line 1 ----> 1 lc = gta.lightcurve('4FGL J0101.1-6422', free_params=['Prefactor'], time_bins=binsLC)
File ~/mambaforge/envs/fermi/lib/python3.9/site-packages/fermipy/lightcurve.py:298, in LightCurve.lightcurve(self, name, kwargs) 296 if config['write_fits']: 297 o['file'] = os.path.basename(filename) + '.fits' --> 298 self._make_lc_fits(o, filename + '.fits', config) 300 if config['write_npy']: 301 np.save(filename + '.npy', o)
File ~/mambaforge/envs/fermi/lib/python3.9/site-packages/fermipy/lightcurve.py:332, in LightCurve._make_lc_fits(self, lc, filename, **kwargs) 329 hdu_lc.name = 'LIGHTCURVE' 330 hdus = [fits.PrimaryHDU(), hdu_lc] 331 keywords = {'SRCNAME': lc['name'], --> 332 'CONFIG': json.dumps(lc['config'])} 333 fits_utils.write_hdus(hdus, filename, keywords=keywords)
File ~/mambaforge/envs/fermi/lib/python3.9/json/init.py:231, in dumps(obj, skipkeys, ensure_ascii, check_circular, allow_nan, cls, indent, separators, default, sort_keys, **kw) 226 # cached encoder 227 if (not skipkeys and ensure_ascii and 228 check_circular and allow_nan and 229 cls is None and indent is None and separators is None and 230 default is None and not sort_keys and not kw): --> 231 return _default_encoder.encode(obj) 232 if cls is None: 233 cls = JSONEncoder
File ~/mambaforge/envs/fermi/lib/python3.9/json/encoder.py:199, in JSONEncoder.encode(self, o) 195 return encode_basestring(o) 196 # This doesn't pass the iterator directly to ''.join() because the 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)
File ~/mambaforge/envs/fermi/lib/python3.9/json/encoder.py:257, in JSONEncoder.iterencode(self, o, _one_shot) 252 else: 253 _iterencode = _make_iterencode( 254 markers, self.default, _encoder, self.indent, floatstr, 255 self.key_separator, self.item_separator, self.sort_keys, 256 self.skipkeys, _one_shot) --> 257 return _iterencode(o, 0)
File ~/mambaforge/envs/fermi/lib/python3.9/json/encoder.py:179, in JSONEncoder.default(self, o) 160 def default(self, o): 161 """Implement this method in a subclass such that it returns 162 a serializable object for
o
, or calls the base implementation 163 (to raise aTypeError
). (...) 177 178 """ --> 179 raise TypeError(f'Object of type {o.class.name} ' 180 f'is not JSON serializable')TypeError: Object of type int64 is not JSON serializable
It's weird because the code actually does process all of the intended bins (TS values are given for all bins in the log and the correct folders are generated), but right after it's gone through all the bins it spits out the error, which causes the whole gta.lightcurve procedure to fail so I can't plot or extract any info from the bins. Does anyone have any idea how to fix this issue?
Thanks in advance!