8

I am trying to use the SphericalDensityPlot3D function that is defined here: Spherical Density Plot 3D. However, when I run all the contents of the mathematica package (".m") file, I get the following errors:

Get::noopen: Cannot open Utilities`FilterOptions.

Needs::nocont: Context Utilities`FilterOptions was not created when Needs was evaluated.

This happens when the following cell is evaluated:

Needs["Utilities`FilterOptions`"]

The last revision for this package is from 2001 and so I assume there are is some compatibility issue, since I am running version 11.2. So, does anyone know how I could fix this problem?

Thanks!

AG1123
  • 571
  • 2
  • 7

1 Answers1

9

The FilterOptions issue has been discussed in a number of posts, you can simply modify the line

Needs["Utilities`FilterOptions`"]

to

If[$VersionNumber >= 9,
   FilterOptions[a_,b___] := Sequence @@ FilterRules[{b}, Options[a]],
   Needs["Utilities`FilterOptions`"]]

This isn't the end. Though I can't figure out what exactly they are, the package has made use of some outdated features of Graphics3D, so to get the desired result, you need to execute

<< Version5`Graphics`

first:

enter image description here

But, since you're in v11.2, why not turn to SliceDensityPlot3D? You just need to transform the coordinate first:

expr = TransformedField[ "Spherical" -> "Cartesian", 
   Re[SphericalHarmonicY[4, 2, th, ph]], {r, th, ph} -> {x, y, z}];

SliceDensityPlot3D[expr, "CenterSphere", {x, y, z} ∈ Ball[], 
 PlotLegends -> Automatic]

Mathematica graphics

BTW, for those before v10.2, I think the solutions in this post are better alternatives compared to this package.

xzczd
  • 65,995
  • 9
  • 163
  • 468
  • +1, nice. I did not know about this method. I removed my hack answer. – Nasser May 08 '18 at 06:07
  • This is a great answer! Thanks! – AG1123 May 08 '18 at 07:45
  • 1
    @AG1123 Thanks for accepting, but actually you don't need to accept that fast, you can wait for 24 hours or even longer to see if someone will come up with a better answer :) . – xzczd May 08 '18 at 07:53
  • I will keep that in mind in the future. :-) – AG1123 May 08 '18 at 07:59
  • This fix for FilterOptions does not seem to work in version 12. Does anyone have a new fix? – Michael B. Heaney Feb 21 '20 at 20:11
  • @michael Do you mean the If[$VersionNumber >= 9, FilterOptions[a_,b___] := Sequence @@ FilterRules[{b}, Options[a]], Needs["Utilities\FilterOptions`"]]is broken, or my fix for this specific package is broken? If the former, I suggest starting a new question, because this method has been used in so many answers and its failure has a big influence; if the latter, with a mobile phone it's too hard for me to test, but the<< Version5`Graphics`` is more suspicious in my view. – xzczd Feb 22 '20 at 02:08
  • I mean the former. When it is added to a program, the program still says "Needs::nocont: Context UtilitiesFilterOptions was not created when Needs was evaluated." I will start a new question. – Michael B. Heaney Feb 22 '20 at 21:03