From 0df87fdea65eccc8946a5f81c8210b507afcca62 Mon Sep 17 00:00:00 2001 From: James Nightingale Date: Mon, 16 Oct 2023 20:16:38 +0100 Subject: [PATCH] remove PLane.output_to_json --- autogalaxy/analysis/analysis.py | 2 +- autogalaxy/analysis/mock/mock_result.py | 2 +- autogalaxy/plane/plane.py | 4 ---- autogalaxy/profiles/mass/__init__.py | 2 +- autogalaxy/profiles/mass/dark/__init__.py | 2 +- autogalaxy/profiles/mass/dark/abstract.py | 12 ++++++------ autogalaxy/profiles/mass/dark/mcr_util.py | 8 ++++---- .../profiles/mass/dark/nfw_virial_mass_conc.py | 12 ++++++------ docs/advanced/database.rst | 4 ++-- test_autogalaxy/aggregator/conftest.py | 1 - test_autogalaxy/analysis/test_analysis.py | 7 +++---- 11 files changed, 25 insertions(+), 31 deletions(-) diff --git a/autogalaxy/analysis/analysis.py b/autogalaxy/analysis/analysis.py index f28baf100..5e63f4d51 100644 --- a/autogalaxy/analysis/analysis.py +++ b/autogalaxy/analysis/analysis.py @@ -520,7 +520,7 @@ def save_results(self, paths: af.DirectoryPaths, result: ResultDataset): try: output_to_json( obj=result.max_log_likelihood_plane, - file_path=paths._files_path / "plane.json" + file_path=paths._files_path / "plane.json", ) except AttributeError: pass diff --git a/autogalaxy/analysis/mock/mock_result.py b/autogalaxy/analysis/mock/mock_result.py index de2739ed5..df9f4fc3d 100644 --- a/autogalaxy/analysis/mock/mock_result.py +++ b/autogalaxy/analysis/mock/mock_result.py @@ -19,7 +19,7 @@ def __init__( adapt_galaxy_image_path_dict: Dict[ag.Galaxy, ag.Array2D] = None, adapt_model_image: ag.Array2D = None, max_log_likelihood_plane: ag.Plane = None, - max_log_likelihood_tracer = None, + max_log_likelihood_tracer=None, ): super().__init__( samples=samples, diff --git a/autogalaxy/plane/plane.py b/autogalaxy/plane/plane.py index dc14ff301..b8372e996 100644 --- a/autogalaxy/plane/plane.py +++ b/autogalaxy/plane/plane.py @@ -54,10 +54,6 @@ def __init__( self.run_time_dict = run_time_dict self.run_time_dict = run_time_dict - def output_to_json(self, file_path: Union[Path, str]): - with open(file_path, "w+") as f: - json.dump(self.dict(), f, indent=4) - @property def galaxy_redshifts(self) -> List[float]: return [galaxy.redshift for galaxy in self.galaxies] diff --git a/autogalaxy/profiles/mass/__init__.py b/autogalaxy/profiles/mass/__init__.py index b77f0ae2b..5d7ef455d 100644 --- a/autogalaxy/profiles/mass/__init__.py +++ b/autogalaxy/profiles/mass/__init__.py @@ -28,7 +28,7 @@ NFWMCRScatterLudlowSph, NFWMCRLudlow, gNFWMCRLudlow, - NFWVirialMassConcSph + NFWVirialMassConcSph, ) from .stellar import ( Gaussian, diff --git a/autogalaxy/profiles/mass/dark/__init__.py b/autogalaxy/profiles/mass/dark/__init__.py index ace92041d..7a5e25bd9 100644 --- a/autogalaxy/profiles/mass/dark/__init__.py +++ b/autogalaxy/profiles/mass/dark/__init__.py @@ -6,4 +6,4 @@ from .nfw_truncated import NFWTruncatedSph from .nfw_truncated_mcr import NFWTruncatedMCRLudlowSph, NFWTruncatedMCRDuffySph from .nfw_truncated_mcr_scatter import NFWTruncatedMCRScatterLudlowSph -from .nfw_virial_mass_conc import NFWVirialMassConcSph \ No newline at end of file +from .nfw_virial_mass_conc import NFWVirialMassConcSph diff --git a/autogalaxy/profiles/mass/dark/abstract.py b/autogalaxy/profiles/mass/dark/abstract.py index 592bbd709..6b73e2edf 100644 --- a/autogalaxy/profiles/mass/dark/abstract.py +++ b/autogalaxy/profiles/mass/dark/abstract.py @@ -264,9 +264,9 @@ def concentration( redshift_of_cosmic_average_density="profile", cosmology: LensingCosmology = Planck15(), ): - ''' + """ Computes the NFW halo concentration, `c_{200m}` - ''' + """ delta_concentration = self.delta_concentration( redshift_object=redshift_profile, redshift_source=redshift_source, @@ -299,9 +299,9 @@ def radius_at_200( redshift_of_cosmic_average_density="profile", cosmology: LensingCosmology = Planck15(), ): - ''' + """ Returns `r_{200m}` for this halo in **arcseconds** - ''' + """ concentration = self.concentration( redshift_profile=redshift_object, redshift_source=redshift_source, @@ -318,9 +318,9 @@ def mass_at_200_solar_masses( redshift_of_cosmic_average_density="profile", cosmology: LensingCosmology = Planck15(), ): - ''' + """ Returns `M_{200m}` of this NFW halo, in solar masses, at the given cosmology. - ''' + """ if redshift_of_cosmic_average_density == "profile": redshift_calc = redshift_object elif redshift_of_cosmic_average_density == "local": diff --git a/autogalaxy/profiles/mass/dark/mcr_util.py b/autogalaxy/profiles/mass/dark/mcr_util.py index bcfc06f9a..f3fc01197 100644 --- a/autogalaxy/profiles/mass/dark/mcr_util.py +++ b/autogalaxy/profiles/mass/dark/mcr_util.py @@ -7,12 +7,12 @@ def kappa_s_and_scale_radius_for_duffy(mass_at_200, redshift_object, redshift_source): - ''' + """ Computes the AutoGalaxy NFW parameters (kappa_s, scale_radius) for an NFW halo of the given mass, enforcing the Duffy '08 mass-concentration relation. Interprets mass as *`M_{200c}`*, not `M_{200m}`. - ''' + """ cosmology = Planck15() cosmic_average_density = ( @@ -58,12 +58,12 @@ def kappa_s_and_scale_radius_for_duffy(mass_at_200, redshift_object, redshift_so def kappa_s_and_scale_radius_for_ludlow( mass_at_200, scatter_sigma, redshift_object, redshift_source ): - ''' + """ Computes the AutoGalaxy NFW parameters (kappa_s, scale_radius) for an NFW halo of the given mass, enforcing the Ludlow '16 mass-concentration relation. Interprets mass as *`M_{200c}`*, not `M_{200m}`. - ''' + """ from colossus.cosmology import cosmology as col_cosmology from colossus.halo.concentration import concentration as col_concentration diff --git a/autogalaxy/profiles/mass/dark/nfw_virial_mass_conc.py b/autogalaxy/profiles/mass/dark/nfw_virial_mass_conc.py index 45821be6a..ef890eead 100644 --- a/autogalaxy/profiles/mass/dark/nfw_virial_mass_conc.py +++ b/autogalaxy/profiles/mass/dark/nfw_virial_mass_conc.py @@ -10,7 +10,9 @@ from autogalaxy.cosmology.wrap import Planck15 -def kappa_s_and_scale_radius(virial_mass, concentration, virial_overdens, redshift_object, redshift_source): +def kappa_s_and_scale_radius( + virial_mass, concentration, virial_overdens, redshift_object, redshift_source +): cosmology = Planck15() cosmic_average_density = ( @@ -45,7 +47,7 @@ def kappa_s_and_scale_radius(virial_mass, concentration, virial_overdens, redshi scale_radius = scale_radius_kpc / kpc_per_arcsec # scale radius in arcsec return kappa_s, scale_radius, virial_radius - + class NFWVirialMassConcSph(NFWSph): def __init__( @@ -57,7 +59,6 @@ def __init__( redshift_object: float = 0.5, redshift_source: float = 1.0, ): - """ Spherical NFW profile initialized with the mass and concentration of the halo. @@ -75,7 +76,7 @@ def __init__( self.virial_mass = virial_mass self.concentration = concentration self.virial_overdens = virial_overdens - + ( kappa_s, scale_radius, @@ -87,6 +88,5 @@ def __init__( redshift_object=redshift_object, redshift_source=redshift_source, ) - + super().__init__(centre=centre, kappa_s=kappa_s, scale_radius=scale_radius) - \ No newline at end of file diff --git a/docs/advanced/database.rst b/docs/advanced/database.rst index 14265fee2..cb8f02b2f 100644 --- a/docs/advanced/database.rst +++ b/docs/advanced/database.rst @@ -21,7 +21,7 @@ to the non-linear search: session = af.db.open_database("database.sqlite") emcee = af.Emcee( - session=session, # This instructs the search to write to the .sqlite database. + session=session, # This can instruct the search to write to the .sqlite database. ) When a model-fit is performed, a unique identifier is generated based on the model and non-linear search. However, @@ -40,7 +40,7 @@ alongside the model and search to create the unique identifier: emcee = af.Emcee( path_prefix=path.join("features", "database"), unique_tag=dataset_name, # This makes the unique identifier use the dataset name - session=session, # This instructs the search to write to the .sqlite database. + session=session, # This can instruct the search to write to the .sqlite database. ) Lets suppose that we have performed 100 model-fits to 100 strong galaxies, and when we ran **PyAutoGalaxy** we told it diff --git a/test_autogalaxy/aggregator/conftest.py b/test_autogalaxy/aggregator/conftest.py index e5b42cd82..1fc22660d 100644 --- a/test_autogalaxy/aggregator/conftest.py +++ b/test_autogalaxy/aggregator/conftest.py @@ -36,7 +36,6 @@ def clean(database_file): value=True, ) def aggregator_from(database_file, analysis, model, samples): - result_path = path.join(conf.instance.output_path, database_file) clean(database_file=database_file) diff --git a/test_autogalaxy/analysis/test_analysis.py b/test_autogalaxy/analysis/test_analysis.py index 4b7936461..3e7b2438d 100644 --- a/test_autogalaxy/analysis/test_analysis.py +++ b/test_autogalaxy/analysis/test_analysis.py @@ -91,8 +91,8 @@ def test__modify_before_fit__kmeans_pixelization_upper_limit_ajusted_based_on_ma 9, 1.0e-4 ) -def test__save_results__plane_output_to_json(analysis_imaging_7x7): +def test__save_results__plane_output_to_json(analysis_imaging_7x7): galaxy = ag.Galaxy(redshift=0.5) model = af.Collection(galaxies=af.Collection(galaxy=galaxy)) @@ -102,12 +102,11 @@ def test__save_results__plane_output_to_json(analysis_imaging_7x7): paths = af.DirectoryPaths() analysis_imaging_7x7.save_results( - paths=paths, - result=ag.m.MockResult(max_log_likelihood_plane=plane, model=model) + paths=paths, result=ag.m.MockResult(max_log_likelihood_plane=plane, model=model) ) plane = from_json(file_path=paths._files_path / "plane.json") assert plane.galaxies[0].redshift == 0.5 - os.remove(paths._files_path / "plane.json") \ No newline at end of file + os.remove(paths._files_path / "plane.json")