sage-home / sage-model

Code for Semi-Analytic Galaxy Evolution (sage)
MIT License
6 stars 5 forks source link

Can not run `plotting/galaxy_properties.py` #37

Open manodeep opened 3 years ago

manodeep commented 3 years ago

After running sage-home/sage-model, I am trying to generate the plots and I encountered this error:

[~/research/codes/sage-home/sage-model @farnarkle2] python plotting/galaxy_properties.py 
Traceback (most recent call last):
  File "plotting/galaxy_properties.py", line 114, in <module>
    my_model = Model(model_dict)
TypeError: __init__() missing 9 required positional arguments: 'sage_output_format', 'label', 'first_file_to_analyze', 'last_file_to_analyze', 'num_sage_output_files', 'random_seed', 'IMF', 'plot_toggles', and 'plots_that_need_smf'

My changes to plotting/galaxy_properties.py are:

[~/research/codes/sage-home/sage-model @farnarkle2] git dfw plotting/
diff --git a/plotting/galaxy_properties.py b/plotting/galaxy_properties.py
index 1ce138d..4694d7b 100644
--- a/plotting/galaxy_properties.py
+++ b/plotting/galaxy_properties.py
@@ -46,11 +46,11 @@ if __name__ == "__main__":
     # We support the plotting of an arbitrary number of models. To do so, simply add the
     # extra variables specifying the path to the model directory and other variables.
     # E.g., 'model1_snapshot = ...", "model1_IMF = ...".
-    model0_snapshot = 63  # Snapshot we're plotting properties at.
+    model0_snapshot = 249 # Snapshot we're plotting properties at.
     model0_IMF = "Chabrier"  # Chabrier or Salpeter.
-    model0_label = "Mini-Millennium"  # Goes on the axis.
-    model0_sage_file = "../input/millennium.par"
-    model0_simulation = "Mini-Millennium"  # Used to set cosmology.
+    model0_label = "Genesis-L52pt5_N1080"  # Goes on the axis.
+    model0_sage_file = "/home/msinha/scratch/simulations/genesis/L52pt5_N1080/genesis_L52pt5_N1080.par" # path to sage parameter file
+    model0_simulation = "Genesis"  # Used to set cosmology.
     model0_first_file = 0  # File range we're plotting.
     model0_last_file = 0  # Closed interval, [first_file, last_file].

@@ -66,7 +66,7 @@ if __name__ == "__main__":

     # A couple of extra variables...
     plot_output_format    = "png"
-    plot_output_path = "./plots"  # Will be created if path doesn't exist.
+    plot_output_path = "/home/msinha/scratch/simulations/genesis/L52pt5_N1080/plots"  # Will be created if path doesn't exist.

     # These toggles specify which plots you want to be made.
     plot_toggles = {"SMF"             : 1,  # Stellar mass function.

@jacobseiler Do you happen to know what is going on?

jacobseiler commented 3 years ago

@manodeep Can you try using plotting/example.py rather than galaxy_properties.py? I think galaxy_properties.py hasn't been updated to support the new sage-analysis version.

manodeep commented 3 years ago

Here's what I get - though looks like the images are generated

/home/msinha/research/codes/sage-home/sage-analysis/sage_analysis/example_plots.py:123: MatplotlibDeprecationWarning: The 'nonposy' parameter of __init__() has been renamed 'nonpositive' since Matplotlib 3.3; support for the old name will be dropped two minor releases later.
  ax.set_yscale("log", nonposy="clip")
100%|████████████████████████████████████████████████████████████████████████████████████████████████| 619k/619k [00:07<00:00, 80.4kGals/s, file=Core_0]
Saved file to ./plots/1.StellarMassFunction.png
/home/msinha/research/codes/sage-home/sage-analysis/sage_analysis/example_plots.py:208: MatplotlibDeprecationWarning: The 'nonposy' parameter of __init__() has been renamed 'nonpositive' since Matplotlib 3.3; support for the old name will be dropped two minor releases later.
  ax.set_yscale("log", nonposy="clip")
Saved file to ./plots/2.BaryonicMassFunction.png
/home/msinha/research/codes/sage-home/sage-analysis/sage_analysis/example_plots.py:292: MatplotlibDeprecationWarning: The 'nonposy' parameter of __init__() has been renamed 'nonpositive' since Matplotlib 3.3; support for the old name will be dropped two minor releases later.
  ax.set_yscale("log", nonposy="clip")
Saved file to ./plots/3.GasMassFunction.png
Saved file to ./plots/4.BaryonicTullyFisher.png
Saved file to ./plots/5.SpecificStarFormationRate.png
Saved file to ./plots/6.GasFraction.png
Saved file to ./plots/7.Metallicity.png
Saved file to ./plots/8.BlackHoleBulgeRelationship.png
Saved file to ./plots/9.QuiescentFraction.png
Saved file to ./plots/10.BulgeMassFraction.png
Saved file to ./plots/11.BaryonFraction.png
Saved file to ./plots/12.MassReservoirs_Genesis_L52pt5_N1080_calibration_snapshot249.png
Saved file to ./plots/13.SpatialDistribution.png
/home/msinha/research/codes/sage-home/sage-analysis/sage_analysis/example_plots.py:1361: MatplotlibDeprecationWarning: The 'nonposy' parameter of __init__() has been renamed 'nonpositive' since Matplotlib 3.3; support for the old name will be dropped two minor releases later.
  ax.set_yscale("log", nonposy="clip")
Traceback (most recent call last):
  File "example.py", line 27, in <module>
    galaxy_analysis.generate_plots()
  File "/home/msinha/research/codes/sage-home/sage-analysis/sage_analysis/galaxy_analysis.py", line 926, in generate_plots
    fig = func(
  File "/home/msinha/research/codes/sage-home/sage-analysis/sage_analysis/example_plots.py", line 1368, in plot_SMF_history
    plot_helper.adjust_legend(ax, location="lower left", scatter_plot=0)
NameError: name 'plot_helper' is not defined

Related, how do I change where the plots are saved to?

jacobseiler commented 3 years ago

That is....very odd...I have no clue why that is not finding plot_helper as they're all running through the same method...

To change the plotting path, you can use the PlotHelper class.

from sage_analysis.plot_helper import PlotHelper
plot_helper = PlotHelper(output_path="/path/to/output/")

Then you call generate_plots with the plot_helper kwarg: generate_plots(plot_helper=plot_helper).

Can you try with the custom PlotHelper instance and see if you get the same error above for the SMF History?

physicistsam commented 3 years ago

Hi @jacobseiler and @manodeep , "plotting/example.py" giving me this following error: Traceback (most recent call last): File "example.py", line 17, in galaxy_analysis = GalaxyAnalysis( File "/home/suman/Desktop/data_area/galaxy_cross/sage-model-master/.sage_venv/lib/python3.8/site-packages/sage_analysis/galaxy_analysis.py", line 380, in init self._read_sage_file(model) File "/home/suman/Desktop/data_area/galaxy_cross/sage-model-master/.sage_venv/lib/python3.8/site-packages/sage_analysis/galaxy_analysis.py", line 580, in _read_sage_file model._volume = model.data_class.determine_volume_analyzed(model) File "/home/suman/Desktop/data_area/galaxy_cross/sage-model-master/.sage_venv/lib/python3.8/site-packages/sage_analysis/sage_hdf5.py", line 151, in determine_volume_analyzed frac_processed = model._hdf5_file[core_key]["Header"]["Runtime"].attrs["frac_volume_processed"] File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper File "/home/suman/Desktop/data_area/galaxy_cross/sage-model-master/.sage_venv/lib/python3.8/site-packages/h5py/_hl/group.py", line 305, in getitem oid = h5o.open(self.id, self._e(name), lapl=self._lapl) File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper File "h5py/h5o.pyx", line 190, in h5py.h5o.open KeyError: "Unable to open object (object 'Core_0' doesn't exist)" (.sage_venv)

Suman Chatterjee NCRA-TIFR

manodeep commented 3 years ago

@physicistsam Thanks for the report! Can you please list the keys in the main file (i.e., the hdf5 file without the "_0")?