2
2
Main objects for holding information relating to the autoplotter.
3
3
"""
4
4
5
- from velociraptor import VelociraptorCatalogue
5
+ from velociraptor import Catalogue
6
6
from velociraptor .autoplotter .lines import VelociraptorLine , valid_line_types
7
7
from velociraptor .autoplotter .box_size_correction import VelociraptorBoxSizeCorrection
8
8
from velociraptor .exceptions import AutoPlotterError
19
19
from pathlib import Path
20
20
21
21
from os import path , mkdir
22
- from functools import reduce
23
22
from collections import OrderedDict
24
23
25
24
valid_plot_types = [
@@ -767,13 +766,13 @@ def _add_lines_to_axes(self, ax: Axes, x: unyt_array, y: unyt_array) -> None:
767
766
return
768
767
769
768
def get_quantity_from_catalogue_with_mask (
770
- self , quantity : str , catalogue : VelociraptorCatalogue
769
+ self , quantity : str , catalogue : Catalogue
771
770
) -> unyt_array :
772
771
"""
773
772
Get a quantity from the catalogue using the mask.
774
773
"""
775
774
776
- x = reduce ( getattr , quantity . split ( "." ), catalogue )
775
+ x = catalogue . get_quantity ( quantity )
777
776
# We give each dataset a custom name, that gets ruined when masking
778
777
# in versions of unyt less than 2.6.0
779
778
name = x .name
@@ -790,9 +789,9 @@ def get_quantity_from_catalogue_with_mask(
790
789
791
790
if self .selection_mask is not None :
792
791
# 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
+ )
796
795
if self .select_structure_type is not None :
797
796
if self .select_structure_type == self .exclude_structure_type :
798
797
raise AutoPlotterError (
@@ -801,12 +800,14 @@ def get_quantity_from_catalogue_with_mask(
801
800
)
802
801
self .structure_mask = logical_and (
803
802
self .structure_mask ,
804
- catalogue .structure_type .structuretype == self .select_structure_type ,
803
+ catalogue .get_quantity ("structure_type.structuretype" )
804
+ == self .select_structure_type ,
805
805
)
806
806
if self .exclude_structure_type is not None :
807
807
self .structure_mask = logical_and (
808
808
self .structure_mask ,
809
- catalogue .structure_type .structuretype != self .exclude_structure_type ,
809
+ catalogue .get_quantity ("structure_type.structuretype" )
810
+ != self .exclude_structure_type ,
810
811
)
811
812
812
813
# combine global and structure masks
@@ -817,9 +818,7 @@ def get_quantity_from_catalogue_with_mask(
817
818
x .name = name
818
819
return x
819
820
820
- def _make_plot_scatter (
821
- self , catalogue : VelociraptorCatalogue
822
- ) -> Tuple [Figure , Axes ]:
821
+ def _make_plot_scatter (self , catalogue : Catalogue ) -> Tuple [Figure , Axes ]:
823
822
"""
824
823
Makes a scatter plot and returns the figure and axes.
825
824
"""
@@ -835,9 +834,7 @@ def _make_plot_scatter(
835
834
836
835
return fig , ax
837
836
838
- def _make_plot_2dhistogram (
839
- self , catalogue : VelociraptorCatalogue
840
- ) -> Tuple [Figure , Axes ]:
837
+ def _make_plot_2dhistogram (self , catalogue : Catalogue ) -> Tuple [Figure , Axes ]:
841
838
"""
842
839
Makes a 2d histogram plot and returns the figure and axes.
843
840
"""
@@ -855,9 +852,7 @@ def _make_plot_2dhistogram(
855
852
856
853
return fig , ax
857
854
858
- def _make_plot_massfunction (
859
- self , catalogue : VelociraptorCatalogue
860
- ) -> Tuple [Figure , Axes ]:
855
+ def _make_plot_massfunction (self , catalogue : Catalogue ) -> Tuple [Figure , Axes ]:
861
856
"""
862
857
Makes a mass function plot and returns the figure and axes.
863
858
"""
@@ -888,15 +883,15 @@ def _make_plot_massfunction(
888
883
return fig , ax
889
884
890
885
def _make_plot_adaptivemassfunction (
891
- self , catalogue : VelociraptorCatalogue
886
+ self , catalogue : Catalogue
892
887
) -> Tuple [Figure , Axes ]:
893
888
"""
894
889
Makes the _adaptive_ mass function plot. Same as mass function.
895
890
"""
896
891
return self ._make_plot_massfunction (catalogue = catalogue )
897
892
898
893
def _make_plot_luminosityfunction (
899
- self , catalogue : VelociraptorCatalogue
894
+ self , catalogue : Catalogue
900
895
) -> Tuple [Figure , Axes ]:
901
896
"""
902
897
Makes a luminosity function plot and returns the figure and axes.
@@ -927,9 +922,7 @@ def _make_plot_luminosityfunction(
927
922
928
923
return fig , ax
929
924
930
- def _make_plot_histogram (
931
- self , catalogue : VelociraptorCatalogue
932
- ) -> Tuple [Figure , Axes ]:
925
+ def _make_plot_histogram (self , catalogue : Catalogue ) -> Tuple [Figure , Axes ]:
933
926
"""
934
927
Make histogram plot and return the figure and axes.
935
928
"""
@@ -950,7 +943,7 @@ def _make_plot_histogram(
950
943
return fig , ax
951
944
952
945
def _make_plot_cumulative_histogram (
953
- self , catalogue : VelociraptorCatalogue
946
+ self , catalogue : Catalogue
954
947
) -> Tuple [Figure , Axes ]:
955
948
"""
956
949
Make cumulative histogram plot and return the figure and axes.
@@ -984,7 +977,7 @@ def _make_plot_cumulative_histogram(
984
977
985
978
def make_plot (
986
979
self ,
987
- catalogue : VelociraptorCatalogue ,
980
+ catalogue : Catalogue ,
988
981
directory : str ,
989
982
file_extension : str ,
990
983
no_plot : bool = False ,
@@ -1065,7 +1058,7 @@ class AutoPlotter(object):
1065
1058
# Forward declarations
1066
1059
filename : Union [str , List [str ]]
1067
1060
multiple_yaml_files : bool
1068
- catalogue : VelociraptorCatalogue
1061
+ catalogue : Catalogue
1069
1062
yaml : Dict [str , Union [Dict , str ]]
1070
1063
plots : List [VelociraptorPlot ]
1071
1064
# Directory containing the observational data.
@@ -1150,9 +1143,7 @@ def parse_yaml(self):
1150
1143
1151
1144
return
1152
1145
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 ]):
1156
1147
"""
1157
1148
Links a catalogue with this object so that the plots
1158
1149
can actually be created.
@@ -1161,7 +1152,7 @@ def link_catalogue(
1161
1152
self .catalogue = catalogue
1162
1153
1163
1154
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 )
1165
1156
else :
1166
1157
self .global_mask = True
1167
1158
return
@@ -1202,8 +1193,8 @@ def create_plots(
1202
1193
import sys , traceback
1203
1194
1204
1195
_ , _ , 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 )
1207
1198
except UnitConversionError as e :
1208
1199
print (
1209
1200
f"Unable to create plot { plot .filename } due to an error when "
@@ -1218,7 +1209,19 @@ def create_plots(
1218
1209
import sys , traceback
1219
1210
1220
1211
_ , _ , 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 )
1223
1226
1224
1227
return
0 commit comments