Giter Site home page Giter Site logo

Comments (3)

TobyWallage avatar TobyWallage commented on June 16, 2024

So originally I thought XSpec was failing due to the spectra generated by SAS, turns out it was actually failing due to the issue fixed in #942 (which was why I switched from the release version to the current github version) and me not properly removing my xga_output files and xga just reusing the old XSpec scripts.

This caused the model fits to fail and the Spectrum.view() method to fall-back to show_model_fits=False behaviour. Just nuking every xga_ouput file I could find on my system was enough to fix the code I was using to produce the expected output.

However, I still think there may be a problem with the Spectrum.view() method as manually disabling the model fits with

sp.view(show_model_fits=False)

Still causes a negative xerr value for the errorbar plot.
I still wonder if this may be due to my SAS version but need someone else to test this...

from xga.

DavidT3 avatar DavidT3 commented on June 16, 2024

Thanks for writing this out so nicely Toby, and I'm sorry for the slow response, I've been very busy recently. I'm also coming across what sounds like the same problem in one of my spectral plots:

ValueError Traceback (most recent call last)
Cell In[4], line 5
3 for sp in src.get_spectra(src.r500):
4 print(sp.obs_id, sp.instrument)
----> 5 sp.view()
6 print('\n\n\n')

File /mnt/ufs18/home-218/turne540/code/XGA/xga/products/spec.py:1662, in Spectrum.view(self, figsize, lo_lim, hi_lim, back_sub, energy, src_colour, bck_colour, grouped, xscale, yscale, fontsize, show_model_fits, save_path)
1658 if not show_model_fits:
1659 # Plotting the data, accounting for the different combinations of x-axis and y-axis
1660 if back_sub:
1661 # If we're going for background subtracted data, then that is all we plot
-> 1662 plt.errorbar(x_dat, src_sub_bck_rate.value[:, 0] / per_x, xerr=x_wid,
1663 yerr=src_sub_bck_rate.value[:, 1] / per_x, fmt="+", color=src_colour,
1664 label="Background subtracted source data", zorder=1)
1665 else:
1666 # But if we're not wanting background subtracted, we need to plot the source and background spectra
1667 plt.errorbar(x_dat, src_rate.value[:, 0] / per_x, xerr=x_wid, yerr=src_rate.value[:, 1] / per_x, fmt="+",
1668 color=src_colour, label="Source data", zorder=1)

File ~/software/anaconda3/envs/xga_dev/lib/python3.9/site-packages/matplotlib/pyplot.py:2564, in errorbar(x, y, yerr, xerr, fmt, ecolor, elinewidth, capsize, barsabove, lolims, uplims, xlolims, xuplims, errorevery, capthick, data, **kwargs)
2558 @_copy_docstring_and_deprecators(Axes.errorbar)
2559 def errorbar(
2560 x, y, yerr=None, xerr=None, fmt='', ecolor=None,
2561 elinewidth=None, capsize=None, barsabove=False, lolims=False,
2562 uplims=False, xlolims=False, xuplims=False, errorevery=1,
2563 capthick=None, *, data=None, **kwargs):
-> 2564 return gca().errorbar(
2565 x, y, yerr=yerr, xerr=xerr, fmt=fmt, ecolor=ecolor,
2566 elinewidth=elinewidth, capsize=capsize, barsabove=barsabove,
2567 lolims=lolims, uplims=uplims, xlolims=xlolims,
2568 xuplims=xuplims, errorevery=errorevery, capthick=capthick,
2569 **({"data": data} if data is not None else {}), **kwargs)

File ~/software/anaconda3/envs/xga_dev/lib/python3.9/site-packages/matplotlib/init.py:1442, in _preprocess_data..inner(ax, data, *args, **kwargs)
1439 @functools.wraps(func)
1440 def inner(ax, *args, data=None, **kwargs):
1441 if data is None:
-> 1442 return func(ax, *map(sanitize_sequence, args), **kwargs)
1444 bound = new_sig.bind(ax, *args, **kwargs)
1445 auto_label = (bound.arguments.get(label_namer)
1446 or bound.kwargs.get(label_namer))

File ~/software/anaconda3/envs/xga_dev/lib/python3.9/site-packages/matplotlib/axes/_axes.py:3642, in Axes.errorbar(self, x, y, yerr, xerr, fmt, ecolor, elinewidth, capsize, barsabove, lolims, uplims, xlolims, xuplims, errorevery, capthick, **kwargs)
3639 res = np.zeros(err.shape, dtype=bool) # Default in case of nan
3640 if np.any(np.less(err, -err, out=res, where=(err == err))):
3641 # like err<0, but also works for timedelta and nan.
-> 3642 raise ValueError(
3643 f"'{dep_axis}err' must not contain negative values")
3644 # This is like
3645 # elow, ehigh = np.broadcast_to(...)
3646 # return dep - elow * ~lolims, dep + ehigh * ~uplims
3647 # except that broadcast_to would strip units.
3648 low, high = dep + np.row_stack([-(1 - lolims), 1 - uplims]) * err

ValueError: 'xerr' must not contain negative values

Disabling the model fits actually triggers an entirely separate plotting mechanism, which is why you see the error there and not when you've fit the model. It shouldn't be to do with your SAS version, and I'll try to sort it out today.

from xga.

DavidT3 avatar DavidT3 commented on June 16, 2024

This issue should now be corrected, and the fix has been merged into master.

from xga.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.