Repository navigation
feat: export the fitbase API from diffpy.srfit - #218
Conversation
Re-export the public fitbase classes so `from diffpy.srfit import FitRecipe` works, and use the shorter import in the tests and core examples. Import pyplot lazily in plot_recipe and apply the bg-style stylesheet only to srfit's own figures, so importing srfit is faster and no longer changes the user's global matplotlib style. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #218 +/- ##
===========================================
+ Coverage 71.63% 82.73% +11.10%
===========================================
Files 25 27 +2
Lines 3437 4182 +745
===========================================
+ Hits 2462 3460 +998
+ Misses 975 722 -253
🚀 New features to boost your workflow:
|
|
@sbillinge ready for review |
|
I like this change. I think it would be good to look at putting the plotting code insde a context manager so the style changes are localized. Shall we make a n issue on this? |
|
@sbillinge This is in a context manager, no? with plt.style.context(all_styles["bg-style"]):
for name, contrib in self._contributions.items():
profile = contrib.profile
x = profile.x
yobs = profile.y
ycalc = profile.ycalc
show_fit = plot_params["show_fit"]
show_diff = plot_params["show_diff"]
if ycalc is None:
... |
yes, that's right. If all our plotting code is encapsulated like this we are not affecting people's global style files. So either everythign is encapuslated and we aren't updating global styles, or there is some leakage somewhwere and we just remove the leaks. |
|
@sbillinge Yeah, that was added in this PR so were good. no more leakage |
Claude's words:
Re-export the public fitbase classes so
from diffpy.srfit import FitRecipeworks, and use the shorter import in the tests and core examples. Import pyplot lazily in plot_recipe and apply the bg-style stylesheet only to srfit's own figures, so importing srfit is faster and no longer changes the user's global matplotlib style.Caden's words:
Three things are changed here:
FitRecipe,FitContribution, etc. can now be imported directly fromdiffpy.srfit. I did this to make srfit/cmi a bit more user friendly and cleaner. They can still be imported fromdiffpy.srfit.fitbasetoo.FitRecipewhich is not necessary and heavy. Lazy importing it makes it only imported on aplot_recipecallFitRecipeis used, the global MPL parameters are changed tobg-style. We do not want to be changing user's default plotting styles. Now, thebg-styleis only used whenplot_recipeis called and the global mpl parameters are left unchanged. This is achieved through a lazy import and a test is added for this behavior change.