SetDirectory[NotebookDirectory[]]

dipoleArrow[{p_, s_}] := Arrow[{s, s + .5p}]

dipoleArrows[dipoles_] := Map[dipoleArrow, dipoles]

badDipole = Normal[badDataClean[[1]][<|"pd" -> ToExpression[StringReplace[#["actual_dipole_moment"], {"(" -> "{", ")" -> "}"}]] , "sd" -> ToExpression[StringReplace[#["actual_dipole_position"], {"(" -> "{", ")" -> "}"}]] |> &]];
goodDipole = Normal[badDataClean[[1]][<|"pd" -> ToExpression[StringReplace[#["actual_dipole_moment"], {"(" -> "{", ")" -> "}"}]] , "sd" -> ToExpression[StringReplace[#["actual_dipole_position"], {"(" -> "{", ")" -> "}"}]] |> &]];

goodDataClean= goodData[All,# ~Join~ <|"bounds_px" -> ToExpression[StringReplace[#["bounds_px"], {"(" -> "{", ")" -> "}"}]], "bounds_py" -> ToExpression[StringReplace[#["bounds_py"], {"(" -> "{", ")" -> "}"}]], "bounds_pz" -> ToExpression[StringReplace[#["bounds_pz"], {"(" -> "{", ")" -> "}"}]], "bounds_sx" -> ToExpression[StringReplace[#["bounds_sx"], {"(" -> "{", ")" -> "}"}]], "bounds_sy" -> ToExpression[StringReplace[#["bounds_sy"], {"(" -> "{", ")" -> "}"}]], "bounds_sz" -> ToExpression[StringReplace[#["bounds_sz"], {"(" -> "{", ")" -> "}"}]] |> &];
badDataClean= badData[All,# ~Join~ <|"bounds_px" -> ToExpression[StringReplace[#["bounds_px"], {"(" -> "{", ")" -> "}"}]], "bounds_py" -> ToExpression[StringReplace[#["bounds_py"], {"(" -> "{", ")" -> "}"}]], "bounds_pz" -> ToExpression[StringReplace[#["bounds_pz"], {"(" -> "{", ")" -> "}"}]], "bounds_sx" -> ToExpression[StringReplace[#["bounds_sx"], {"(" -> "{", ")" -> "}"}]], "bounds_sy" -> ToExpression[StringReplace[#["bounds_sy"], {"(" -> "{", ")" -> "}"}]], "bounds_sz" -> ToExpression[StringReplace[#["bounds_sz"], {"(" -> "{", ")" -> "}"}]] |> &];

goodData = Import["z-band-middle-all-dots-narrowsquare-diagnosis1-good.csv","Dataset", HeaderLines -> 1];

badData = Import["z-band-middle-all-dots-narrowsquare-diagnosis1-bad.csv","Dataset", HeaderLines -> 1]

badGroup = badDataClean[Select[#["success"] == "True" &]][GroupBy[{#["bounds_sx"], #["bounds_sy"], #["bounds_sz"]} &], Length];
goodGroup = goodDataClean[Select[#["success"] == "True" &]][GroupBy[{#["bounds_sx"], #["bounds_sy"], #["bounds_sz"]} &], Length];

dotsWide = Map[Point[{#[[1]], #[[2]], 0}] &, {{-2, 2}, {2, 2}, {
-2, -2}, {2, -2}}];

dotsOriginal = Map[Point[{#[[1]], #[[2]], 0}] &, {{1, 2}, {2, 2}, {
1, 1}, {2, 1}}];

dots = Map[Point[{#[[1]], #[[2]], 0}] &, {{-.25, .25}, {.25, .25}, {-.25, -.25}, {.25, -.25}}]

cuboidFromBounds[{{x1_, x2_}, {y1_, y2_}, {z1_, z2_}}] := Cuboid[{x1, y1, z1}, {x2, y2, z2}]

Graphics3D[{ { Opacity[0.2], Red,  Cuboid[{-10, -10, 3.5}, {10, 10, 4.5}]}, { Opacity[0.1], Blue, FaceForm[Green, Opacity[0]], Cuboid[{-10, -10, 2.5}, {10, 10, 3.5}]}, { Opacity[0.1], Blue, FaceForm[White, Opacity[.5]], Cuboid[{-10, -10, 4.5}, {10, 10, 5.5}]}, {Blue, PointSize[.02], dotsOriginal}}, AxesOrigin->{0, 0, 0}, PlotRange->{{-13, 13}, {-13, 13}, {-.5, 8}}, ImageSize->800]

Graphics3D[{ { Opacity[0.2], Red,  Cuboid[{-10, -10, 3.5}, {10, 10, 4.5}]}, { Opacity[0.1], Blue, FaceForm[Green, Opacity[0]], Cuboid[{-10, -10, 2.5}, {10, 10, 3.5}]}, { Opacity[0.1], Blue, FaceForm[White, Opacity[.5]], Cuboid[{-10, -10, 4.5}, {10, 10, 5.5}]}, {Blue, PointSize[.02], dots}}, AxesOrigin->{0, 0, 0}, PlotRange->{{-13, 13}, {-13, 13}, {-.5, 8}}, ImageSize->800]

Graphics3D[{ { Opacity[0.2], Red,  Cuboid[{-10, -10, 3.5}, {10, 10, 4.5}]}, { Opacity[0.1], Blue, FaceForm[Green, Opacity[0]], Cuboid[{-10, -10, 2.5}, {10, 10, 3.5}]}, { Opacity[0.1], Blue, FaceForm[White, Opacity[.5]], Cuboid[{-10, -10, 4.5}, {10, 10, 5.5}]}, {Blue, PointSize[.02], dotsWide}}, AxesOrigin->{0, 0, 0}, PlotRange->{{-13, 13}, {-13, 13}, {-.5, 8}}, ImageSize->800]

Graphics3D[{KeyValueMap[{EdgeForm[None], Opacity[#2 / 50], ColorData[{"AvocadoColors", "Reverse"}][#2 / 50],cuboidFromBounds[#1]}  &, Normal@badGroup], {White, Opacity[0.1], FaceForm[White, Opacity[0]], EdgeForm[{Thick, Dashed}], Cuboid[{-10, -10, 3.5}, {10, 10, 4.5}]}, dipoleArrow[{badDipole["pd"], badDipole["sd"]}], {Blue, PointSize[.02], dots}}, AxesOrigin->{0, 0, 0}, PlotRange->{{-13, 13}, {-13, 13}, {-.5, 8}}, ImageSize->1000]

Graphics3D[{KeyValueMap[{EdgeForm[None], Opacity[#2 / 50], ColorData[{"AvocadoColors", "Reverse"}][#2 / 50],cuboidFromBounds[#1]}  &, Normal@goodGroup], {White, Opacity[0], FaceForm[White, Opacity[.2]], EdgeForm[{Thick, Dashed}], Cuboid[{-10, -10, 3.5}, {10, 10, 4.5}]}, {Blue, PointSize[.02], dots}, dipoleArrow[{goodDipole["pd"], goodDipole["sd"]}]}, AxesOrigin->{0, 0, 0}, PlotRange->{{-13, 13}, {-13, 13}, {-.5, 8}}, ImageSize->1000]