Closed joriswitstok closed 1 year ago
Hi Joris,
Hmm, sorry, not entirely sure what's going on with that. I mostly see the plotting codes as a best-effort basis addition for basic visualisation of results, they're unfortunately far from universal. I have trouble with them and modify things for specific projects on a pretty regular basis. Did you check for nans, negative errors or other weird behaviour in your data array?
Cheers, Adam
Makes sense, just thought I'd raise the issue in case it comes up again! I've extensively checked the data and it turns out there was a problem with unit conversion (I am plotting the results of someone else's fits), meaning that in the correct units the fitted spectrum was accidentally a factor 10^2 higher than the data. In this (hopefully rare) case, the error is somehow caused by the y_scale
parameter being an integer, as mentioned – if it is a float instead of an int, the code runs without errors and importantly, the plots are produced fine so you can see there's an offset (though of course the y-axis label reads 10^-20.0 as opposed to 10^-20)...
Excellent, glad you managed to figure it out! To be honest, the adaptive y axis limits for the plots have been a headache from the beginning. Maybe they were a mistake.
Hi Adam,
After having some trouble when using the default plotting functions in
bagpipes
(see full traceback below), I dug into the code to see what was causing the issue.I found that if I change the
y_scale
parameter in theadd_spectrum
function to become a float (i.e. replace line 26 inbagpipes/plotting/plot_spectrum.py
toy_scale = float(int(np.log10(ymax))-1)
), the error goes away. For some reason, the multiplication of afloat64
array with an integer (in lines 46 and 47) produced anobject
array, which then causes an error when used together with the wavelength array (spectrum[:, 0]
, which is stillfloat64
) infill_between
(line 52).I am not entirely sure why this is producing an error for me specifically (and apparently not for others, maybe it has something to do with the numpy version I have installed?), but I thought I'd flag it in case anyone else runs into the same problem.
Cheers, Joris
Traceback (most recent call last): File "specz_R100_irr_dust.py", line 82, in <module> fig = gal.plot() File "/Users/Joris/anaconda3/envs/SED3/lib/python3.7/site-packages/bagpipes/input/galaxy.py", line 230, in plot y_scale_spec=y_scale_spec) File "/Users/Joris/anaconda3/envs/SED3/lib/python3.7/site-packages/bagpipes/plotting/plot_galaxy.py", line 35, in plot_galaxy y_scale=y_scale_spec) File "/Users/Joris/anaconda3/envs/SED3/lib/python3.7/site-packages/bagpipes/plotting/plot_spectrum.py", line 53, in add_spectrum zorder=zorder-1, alpha=0.75, linewidth=0) File "/Users/Joris/anaconda3/envs/SED3/lib/python3.7/site-packages/matplotlib/__init__.py", line 1414, in inner return func(ax, *map(sanitize_sequence, args), **kwargs) File "/Users/Joris/anaconda3/envs/SED3/lib/python3.7/site-packages/matplotlib/axes/_axes.py", line 5253, in fill_between where=where, interpolate=interpolate, step=step, **kwargs) File "/Users/Joris/anaconda3/envs/SED3/lib/python3.7/site-packages/matplotlib/axes/_axes.py", line 5158, in _fill_between_x_or_y [(ind_dir, ind), (dep_dir, dep1), (dep_dir, dep2)], kwargs)) File "/Users/Joris/anaconda3/envs/SED3/lib/python3.7/site-packages/numpy/ma/core.py", line 2369, in masked_invalid condition = ~(np.isfinite(a)) TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''