@@ -578,6 +578,174 @@ def generate_detectability_plots(self):
578578 print (" - detectability_filtered.png" )
579579 print (" - detectability_grid.png" )
580580
581+ def generate_spectrum_export_plots (self ):
582+ """Generate plots for spectrum export examples with/without EBL."""
583+ # Load mock data
584+ mock_data_path = get_data_path ("mock_data/GRB_42_mock.csv" )
585+
586+ # Create source with EBL model
587+ source_with_ebl = Source (
588+ filepath = str (mock_data_path ),
589+ min_energy = 20 * u .GeV ,
590+ max_energy = 10 * u .TeV ,
591+ ebl = "franceschini" ,
592+ z = 1.0 ,
593+ )
594+ source_with_ebl .set_spectral_grid ()
595+ source_with_ebl .fit_spectral_indices ()
596+
597+ # Create source without EBL for comparison
598+ source_no_ebl = Source (
599+ filepath = str (mock_data_path ),
600+ min_energy = 20 * u .GeV ,
601+ max_energy = 10 * u .TeV ,
602+ )
603+ source_no_ebl .set_spectral_grid ()
604+ source_no_ebl .fit_spectral_indices ()
605+
606+ time = 100 * u .s
607+
608+ # Plot 1: Power law spectrum with/without EBL
609+ fig , (ax1 , ax2 ) = plt .subplots (1 , 2 , figsize = (16 , 6 ))
610+
611+ # Without EBL
612+ powerlaw_no_ebl = source_no_ebl .get_powerlaw_spectrum (time , use_ebl = False )
613+ energy_plot = np .logspace (
614+ np .log10 (source_no_ebl .min_energy .value ),
615+ np .log10 (source_no_ebl .max_energy .value ),
616+ 100
617+ ) * u .GeV
618+ flux_no_ebl = powerlaw_no_ebl (energy_plot )
619+
620+ ax1 .loglog (energy_plot .to ("TeV" ).value , flux_no_ebl .value , linewidth = 2 , label = "Without EBL" )
621+ ax1 .set_xlabel ("Energy [TeV]" , fontsize = 12 )
622+ ax1 .set_ylabel ("dN/dE [cm⁻² s⁻¹ GeV⁻¹]" , fontsize = 12 )
623+ ax1 .set_title ("Power Law Spectrum (No EBL)" , fontsize = 14 )
624+ ax1 .grid (True , alpha = 0.3 )
625+ ax1 .legend (fontsize = 11 )
626+
627+ # With EBL
628+ powerlaw_with_ebl = source_with_ebl .get_powerlaw_spectrum (time , use_ebl = True )
629+ flux_with_ebl = powerlaw_with_ebl (energy_plot )
630+
631+ ax2 .loglog (energy_plot .to ("TeV" ).value , flux_with_ebl .value , linewidth = 2 , label = "With EBL" , color = "orange" )
632+ ax2 .set_xlabel ("Energy [TeV]" , fontsize = 12 )
633+ ax2 .set_ylabel ("dN/dE [cm⁻² s⁻¹ GeV⁻¹]" , fontsize = 12 )
634+ ax2 .set_title ("Power Law Spectrum (With EBL)" , fontsize = 14 )
635+ ax2 .grid (True , alpha = 0.3 )
636+ ax2 .legend (fontsize = 11 )
637+
638+ plt .tight_layout ()
639+ plt .savefig (
640+ self .output_dir / "powerlaw_spectrum_ebl_comparison.png" ,
641+ dpi = 150 ,
642+ bbox_inches = "tight" ,
643+ )
644+ plt .close ()
645+
646+ # Plot 2: Comparison plot showing EBL effect
647+ fig , ax = plt .subplots (figsize = (10 , 6 ))
648+
649+ ax .loglog (
650+ energy_plot .to ("TeV" ).value ,
651+ flux_no_ebl .value ,
652+ linewidth = 2 ,
653+ label = "Without EBL" ,
654+ linestyle = "-" ,
655+ )
656+ ax .loglog (
657+ energy_plot .to ("TeV" ).value ,
658+ flux_with_ebl .value ,
659+ linewidth = 2 ,
660+ label = "With EBL (franceschini)" ,
661+ linestyle = "--" ,
662+ color = "orange" ,
663+ )
664+ ax .set_xlabel ("Energy [TeV]" , fontsize = 12 )
665+ ax .set_ylabel ("dN/dE [cm⁻² s⁻¹ GeV⁻¹]" , fontsize = 12 )
666+ ax .set_title ("Power Law Spectrum: EBL Absorption Effect" , fontsize = 14 )
667+ ax .grid (True , alpha = 0.3 )
668+ ax .legend (fontsize = 11 )
669+
670+ plt .tight_layout ()
671+ plt .savefig (
672+ self .output_dir / "powerlaw_spectrum_ebl_effect.png" ,
673+ dpi = 150 ,
674+ bbox_inches = "tight" ,
675+ )
676+ plt .close ()
677+
678+ # Plot 3: Template spectrum with/without EBL
679+ fig , (ax1 , ax2 ) = plt .subplots (1 , 2 , figsize = (16 , 6 ))
680+
681+ # Without EBL
682+ template_no_ebl = source_no_ebl .get_template_spectrum (time , use_ebl = False )
683+ flux_template_no_ebl = template_no_ebl (energy_plot )
684+
685+ ax1 .loglog (energy_plot .to ("TeV" ).value , flux_template_no_ebl .value , linewidth = 2 , label = "Without EBL" )
686+ ax1 .set_xlabel ("Energy [TeV]" , fontsize = 12 )
687+ ax1 .set_ylabel ("dN/dE [cm⁻² s⁻¹ GeV⁻¹]" , fontsize = 12 )
688+ ax1 .set_title ("Template Spectrum (No EBL)" , fontsize = 14 )
689+ ax1 .grid (True , alpha = 0.3 )
690+ ax1 .legend (fontsize = 11 )
691+
692+ # With EBL
693+ template_with_ebl = source_with_ebl .get_template_spectrum (time , use_ebl = True )
694+ flux_template_with_ebl = template_with_ebl (energy_plot )
695+
696+ ax2 .loglog (energy_plot .to ("TeV" ).value , flux_template_with_ebl .value , linewidth = 2 , label = "With EBL" , color = "orange" )
697+ ax2 .set_xlabel ("Energy [TeV]" , fontsize = 12 )
698+ ax2 .set_ylabel ("dN/dE [cm⁻² s⁻¹ GeV⁻¹]" , fontsize = 12 )
699+ ax2 .set_title ("Template Spectrum (With EBL)" , fontsize = 14 )
700+ ax2 .grid (True , alpha = 0.3 )
701+ ax2 .legend (fontsize = 11 )
702+
703+ plt .tight_layout ()
704+ plt .savefig (
705+ self .output_dir / "template_spectrum_ebl_comparison.png" ,
706+ dpi = 150 ,
707+ bbox_inches = "tight" ,
708+ )
709+ plt .close ()
710+
711+ # Plot 4: Template comparison showing EBL effect
712+ fig , ax = plt .subplots (figsize = (10 , 6 ))
713+
714+ ax .loglog (
715+ energy_plot .to ("TeV" ).value ,
716+ flux_template_no_ebl .value ,
717+ linewidth = 2 ,
718+ label = "Without EBL" ,
719+ linestyle = "-" ,
720+ )
721+ ax .loglog (
722+ energy_plot .to ("TeV" ).value ,
723+ flux_template_with_ebl .value ,
724+ linewidth = 2 ,
725+ label = "With EBL (franceschini)" ,
726+ linestyle = "--" ,
727+ color = "orange" ,
728+ )
729+ ax .set_xlabel ("Energy [TeV]" , fontsize = 12 )
730+ ax .set_ylabel ("dN/dE [cm⁻² s⁻¹ GeV⁻¹]" , fontsize = 12 )
731+ ax .set_title ("Template Spectrum: EBL Absorption Effect" , fontsize = 14 )
732+ ax .grid (True , alpha = 0.3 )
733+ ax .legend (fontsize = 11 )
734+
735+ plt .tight_layout ()
736+ plt .savefig (
737+ self .output_dir / "template_spectrum_ebl_effect.png" ,
738+ dpi = 150 ,
739+ bbox_inches = "tight" ,
740+ )
741+ plt .close ()
742+
743+ print ("Generated spectrum export plots:" )
744+ print (" - powerlaw_spectrum_ebl_comparison.png" )
745+ print (" - powerlaw_spectrum_ebl_effect.png" )
746+ print (" - template_spectrum_ebl_comparison.png" )
747+ print (" - template_spectrum_ebl_effect.png" )
748+
581749 def generate_all (self ):
582750 """Generate all documentation plots."""
583751 print ("Generating documentation plots..." )
@@ -587,6 +755,7 @@ def generate_all(self):
587755 self .generate_sensitivity_plots ()
588756 self .generate_direct_sensitivity_plots ()
589757 self .generate_detectability_plots ()
758+ self .generate_spectrum_export_plots ()
590759
591760 print (f"\n All plots saved to { self .output_dir } " )
592761
@@ -603,7 +772,7 @@ def main():
603772 "--plot-type" ,
604773 nargs = "?" ,
605774 default = "all" ,
606- choices = ["all" , "spectral" , "sensitivity" , "direct_sensitivity " , "detectability" ],
775+ choices = ["all" , "spectral" , "sensitivity" , "direct-sensitivity " , "detectability" , "spectrum-export " ],
607776 help = "Type of plot to generate (default: all)" ,
608777 )
609778 parser .add_argument (
@@ -624,10 +793,12 @@ def main():
624793 generator .generate_spectral_plots ()
625794 elif args .plot_type == "sensitivity" :
626795 generator .generate_sensitivity_plots ()
627- elif args .plot_type == "direct_sensitivity " :
796+ elif args .plot_type == "direct-sensitivity " :
628797 generator .generate_direct_sensitivity_plots ()
629798 elif args .plot_type == "detectability" :
630799 generator .generate_detectability_plots ()
800+ elif args .plot_type == "spectrum-export" :
801+ generator .generate_spectrum_export_plots ()
631802
632803
633804if __name__ == "__main__" :
0 commit comments