22Main objects for holding information relating to the autoplotter.
33"""
44
5- from velociraptor import VelociraptorCatalogue
5+ from velociraptor import Catalogue
66from velociraptor .autoplotter .lines import VelociraptorLine , valid_line_types
77from velociraptor .autoplotter .box_size_correction import VelociraptorBoxSizeCorrection
88from velociraptor .exceptions import AutoPlotterError
1919from pathlib import Path
2020
2121from os import path , mkdir
22- from functools import reduce
2322from collections import OrderedDict
2423
2524valid_plot_types = [
@@ -767,13 +766,13 @@ def _add_lines_to_axes(self, ax: Axes, x: unyt_array, y: unyt_array) -> None:
767766 return
768767
769768 def get_quantity_from_catalogue_with_mask (
770- self , quantity : str , catalogue : VelociraptorCatalogue
769+ self , quantity : str , catalogue : Catalogue
771770 ) -> unyt_array :
772771 """
773772 Get a quantity from the catalogue using the mask.
774773 """
775774
776- x = reduce ( getattr , quantity . split ( "." ), catalogue )
775+ x = catalogue . get_quantity ( quantity )
777776 # We give each dataset a custom name, that gets ruined when masking
778777 # in versions of unyt less than 2.6.0
779778 name = x .name
@@ -790,9 +789,9 @@ def get_quantity_from_catalogue_with_mask(
790789
791790 if self .selection_mask is not None :
792791 # Create mask
793- self .structure_mask = reduce (
794- getattr , self . selection_mask . split ( "." ), catalogue
795- ). astype ( bool )
792+ self .structure_mask = catalogue . get_quantity ( self . selection_mask ). astype (
793+ bool
794+ )
796795 if self .select_structure_type is not None :
797796 if self .select_structure_type == self .exclude_structure_type :
798797 raise AutoPlotterError (
@@ -801,12 +800,14 @@ def get_quantity_from_catalogue_with_mask(
801800 )
802801 self .structure_mask = logical_and (
803802 self .structure_mask ,
804- catalogue .structure_type .structuretype == self .select_structure_type ,
803+ catalogue .get_quantity ("structure_type.structuretype" )
804+ == self .select_structure_type ,
805805 )
806806 if self .exclude_structure_type is not None :
807807 self .structure_mask = logical_and (
808808 self .structure_mask ,
809- catalogue .structure_type .structuretype != self .exclude_structure_type ,
809+ catalogue .get_quantity ("structure_type.structuretype" )
810+ != self .exclude_structure_type ,
810811 )
811812
812813 # combine global and structure masks
@@ -817,9 +818,7 @@ def get_quantity_from_catalogue_with_mask(
817818 x .name = name
818819 return x
819820
820- def _make_plot_scatter (
821- self , catalogue : VelociraptorCatalogue
822- ) -> Tuple [Figure , Axes ]:
821+ def _make_plot_scatter (self , catalogue : Catalogue ) -> Tuple [Figure , Axes ]:
823822 """
824823 Makes a scatter plot and returns the figure and axes.
825824 """
@@ -835,9 +834,7 @@ def _make_plot_scatter(
835834
836835 return fig , ax
837836
838- def _make_plot_2dhistogram (
839- self , catalogue : VelociraptorCatalogue
840- ) -> Tuple [Figure , Axes ]:
837+ def _make_plot_2dhistogram (self , catalogue : Catalogue ) -> Tuple [Figure , Axes ]:
841838 """
842839 Makes a 2d histogram plot and returns the figure and axes.
843840 """
@@ -855,9 +852,7 @@ def _make_plot_2dhistogram(
855852
856853 return fig , ax
857854
858- def _make_plot_massfunction (
859- self , catalogue : VelociraptorCatalogue
860- ) -> Tuple [Figure , Axes ]:
855+ def _make_plot_massfunction (self , catalogue : Catalogue ) -> Tuple [Figure , Axes ]:
861856 """
862857 Makes a mass function plot and returns the figure and axes.
863858 """
@@ -888,15 +883,15 @@ def _make_plot_massfunction(
888883 return fig , ax
889884
890885 def _make_plot_adaptivemassfunction (
891- self , catalogue : VelociraptorCatalogue
886+ self , catalogue : Catalogue
892887 ) -> Tuple [Figure , Axes ]:
893888 """
894889 Makes the _adaptive_ mass function plot. Same as mass function.
895890 """
896891 return self ._make_plot_massfunction (catalogue = catalogue )
897892
898893 def _make_plot_luminosityfunction (
899- self , catalogue : VelociraptorCatalogue
894+ self , catalogue : Catalogue
900895 ) -> Tuple [Figure , Axes ]:
901896 """
902897 Makes a luminosity function plot and returns the figure and axes.
@@ -927,9 +922,7 @@ def _make_plot_luminosityfunction(
927922
928923 return fig , ax
929924
930- def _make_plot_histogram (
931- self , catalogue : VelociraptorCatalogue
932- ) -> Tuple [Figure , Axes ]:
925+ def _make_plot_histogram (self , catalogue : Catalogue ) -> Tuple [Figure , Axes ]:
933926 """
934927 Make histogram plot and return the figure and axes.
935928 """
@@ -950,7 +943,7 @@ def _make_plot_histogram(
950943 return fig , ax
951944
952945 def _make_plot_cumulative_histogram (
953- self , catalogue : VelociraptorCatalogue
946+ self , catalogue : Catalogue
954947 ) -> Tuple [Figure , Axes ]:
955948 """
956949 Make cumulative histogram plot and return the figure and axes.
@@ -984,7 +977,7 @@ def _make_plot_cumulative_histogram(
984977
985978 def make_plot (
986979 self ,
987- catalogue : VelociraptorCatalogue ,
980+ catalogue : Catalogue ,
988981 directory : str ,
989982 file_extension : str ,
990983 no_plot : bool = False ,
@@ -1065,7 +1058,7 @@ class AutoPlotter(object):
10651058 # Forward declarations
10661059 filename : Union [str , List [str ]]
10671060 multiple_yaml_files : bool
1068- catalogue : VelociraptorCatalogue
1061+ catalogue : Catalogue
10691062 yaml : Dict [str , Union [Dict , str ]]
10701063 plots : List [VelociraptorPlot ]
10711064 # Directory containing the observational data.
@@ -1150,9 +1143,7 @@ def parse_yaml(self):
11501143
11511144 return
11521145
1153- def link_catalogue (
1154- self , catalogue : VelociraptorCatalogue , global_mask_tag : Union [None , str ]
1155- ):
1146+ def link_catalogue (self , catalogue : Catalogue , global_mask_tag : Union [None , str ]):
11561147 """
11571148 Links a catalogue with this object so that the plots
11581149 can actually be created.
@@ -1161,7 +1152,7 @@ def link_catalogue(
11611152 self .catalogue = catalogue
11621153
11631154 if global_mask_tag is not None :
1164- self .global_mask = reduce ( getattr , global_mask_tag . split ( "." ), catalogue )
1155+ self .global_mask = catalogue . get_quantity ( global_mask_tag )
11651156 else :
11661157 self .global_mask = True
11671158 return
@@ -1202,8 +1193,8 @@ def create_plots(
12021193 import sys , traceback
12031194
12041195 _ , _ , exc_traceback = sys .exc_info ()
1205- print ("Traceback:" )
1206- traceback .print_tb (exc_traceback , limit = 10 , file = sys .stdout )
1196+ print ("Traceback:" , file = sys . stderr )
1197+ traceback .print_tb (exc_traceback , limit = 10 , file = sys .stderr )
12071198 except UnitConversionError as e :
12081199 print (
12091200 f"Unable to create plot { plot .filename } due to an error when "
@@ -1218,7 +1209,19 @@ def create_plots(
12181209 import sys , traceback
12191210
12201211 _ , _ , exc_traceback = sys .exc_info ()
1221- print ("Traceback:" )
1222- traceback .print_tb (exc_traceback , limit = 10 , file = sys .stdout )
1212+ print ("Traceback:" , file = sys .stderr )
1213+ traceback .print_tb (exc_traceback , limit = 10 , file = sys .stderr )
1214+ except Exception as e :
1215+ print (
1216+ f"Unable to create plot { plot .filename } due to an unkown error: { e } !" ,
1217+ file = sys .stderr ,
1218+ )
1219+ self .created_successfully .append (False )
1220+ if debug :
1221+ import sys , traceback
1222+
1223+ _ , _ , exc_traceback = sys .exc_info ()
1224+ print ("Traceback:" , file = sys .stderr )
1225+ traceback .print_tb (exc_traceback , limit = 10 , file = sys .stderr )
12231226
12241227 return
0 commit comments