Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/source/noise_modelling/diffusion_noise_models.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
"source": [
"### Loading the Model\n",
"\n",
"We can load in the saved model from disk, just to prove it works! Here we will switch to our pre-trained model which you can get by running `synference-download`, but feel free to load in your own trained model if you have one.\n"
"We can load the model we just saved back in from disk, just to prove it works! You can load any other trained noise model the same way.\n"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
) # noqa

mwn18 = MWN18()
from synthesizer.emission_models.dust.emission import Greybody, IR_templates # noqa
from synthesizer.emission_models import Greybody # noqa
from synthesizer.emission_models.stellar.pacman_model import (
BimodalPacmanEmission,
) # noqa
Expand Down Expand Up @@ -489,7 +489,7 @@ def db_sf_convert(param, param_dict, Nparam_SFH=3):
alt_parametrizations=alt_parametrizations,
redshift_dependent_sfh=True,
params_to_ignore=sfh_params.get("params_to_ignore", []),
build_grid=False,
build_library=False,
)

combined_basis = CombinedBasis(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

import numpy as np
from astropy.cosmology import Planck18
from synthesizer.emission_models import Greybody # noqa
from synthesizer.emission_models.attenuation import (
Calzetti2000,
) # noqa
from synthesizer.emission_models.dust.emission import Greybody, IR_templates # noqa
from synthesizer.emission_models.stellar.pacman_model import (
PacmanEmission,
) # noqa
Expand Down Expand Up @@ -499,7 +499,7 @@ def db_sf_convert(param, param_dict, Nparam_SFH=3):
alt_parametrizations=alt_parametrizations,
redshift_dependent_sfh=True,
params_to_ignore=sfh_params.get("params_to_ignore", []),
build_grid=False,
build_library=False,
log_stellar_masses=all_param_dict["log_masses"],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

import numpy as np
from astropy.cosmology import Planck18
from synthesizer.emission_models import Greybody # noqa
from synthesizer.emission_models.attenuation import (
Calzetti2000,
) # noqa
from synthesizer.emission_models.dust.emission import Greybody, IR_templates # noqa
from synthesizer.emission_models.stellar.pacman_model import (
PacmanEmission,
) # noqa
Expand All @@ -33,21 +33,21 @@
from synference import (
GalaxyBasis,
calculate_beta,
calculate_burstiness,
calculate_colour,
calculate_d4000,
calculate_line_ew,
calculate_line_flux,
calculate_mass_weighted_age,
calculate_muv,
calculate_Ndot_ion,
calculate_sfh_quantile,
calculate_surviving_mass,
calculate_xi_ion0,
draw_from_hypercube,
generate_constant_R,
generate_random_DB_sfh,
generate_sfh_basis,
calculate_line_ew,
calculate_line_flux,
calculate_xi_ion0,
calculate_burstiness,
calculate_Ndot_ion,
)

# Filters
Expand Down Expand Up @@ -584,7 +584,7 @@ def db_sf_convert(param, param_dict, Nparam_SFH=3):
alt_parametrizations=alt_parametrizations,
redshift_dependent_sfh=True,
params_to_ignore=sfh_params.get("params_to_ignore", []),
build_grid=False,
build_library=False,
log_stellar_masses=all_param_dict["log_masses"],
)

Expand Down
12 changes: 7 additions & 5 deletions examples/library_generation/scripts/fixed_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

from synference import (
GalaxyBasis,
calculate_mass_weighted_age,
calculate_muv,
calculate_mwa,
draw_from_hypercube,
generate_constant_R,
generate_sfh_basis,
Expand Down Expand Up @@ -169,6 +169,8 @@


# Emission parameters
# With no dust emission model the root of this model is not labelled "total"
# (it is "attenuated" for fesc=0), so below we refer to it via emission_model.label.
emission_model = TotalEmission(
grid=grid,
dust_curve=Calzetti2000(),
Expand Down Expand Up @@ -206,7 +208,7 @@
def z_to_max_age(params, max_redshift=20):
"""Convert redshift to maximum age of the SFH at that redshift."""
z = params["redshift"]
from cosmology import Planck18 as cosmo
from astropy.cosmology import Planck18 as cosmo

age = cosmo.age(z) - cosmo.age(max_redshift)
age = age.to_value("Myr") * Myr
Expand All @@ -222,7 +224,7 @@ def z_to_max_age(params, max_redshift=20):
basis.plot_galaxy(
i,
log_stellar_mass=all_param_dict["log_masses"][i],
emission_model_keys=["total"],
emission_model_keys=[emission_model.label],
out_dir=out_dir,
)

Expand All @@ -234,11 +236,11 @@ def z_to_max_age(params, max_redshift=20):
verbose=False,
batch_size=50_000,
mUV=(calculate_muv, cosmo), # Calculate mUV for the mock catalogue.
mwa=calculate_mwa, # Calculate MWA for the mock catalogue.
mwa=calculate_mass_weighted_age, # Calculate MWA for the mock catalogue.
parameter_transforms_to_save={
"max_age": z_to_max_age
}, # Save function to calculate the maximum age of the SFH at that redshift.
emission_model_key="total",
emission_model_key=emission_model.label,
)

"""
Expand Down
5 changes: 3 additions & 2 deletions examples/library_generation/scripts/generate_agn_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
from synthesizer import Grid
from synthesizer.emission_models import (
AttenuatedEmission,
Blackbody,
DustEmission,
EmissionModel,
Greybody,
PacmanEmission,
UnifiedAGN,
)
from synthesizer.emission_models.attenuation import PowerLaw
from synthesizer.emission_models.dust.emission import Blackbody, Greybody
from synthesizer.instruments import FilterCollection, Instrument
from synthesizer.parametric import SFH, ZDist
from tqdm import tqdm
Expand Down Expand Up @@ -264,7 +265,7 @@ def torus_vdisp_from_mbh(mbh):
galaxy_params=galaxy_params,
alt_parametrizations={},
redshift_dependent_sfh=True,
build_grid=False,
build_library=False,
log_stellar_masses=all_param_dict["log_masses"],
params_to_ignore=["max_age"],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

import numpy as np
from astropy.cosmology import Planck18
from synthesizer.emission_models import PacmanEmission
from synthesizer.emission_models import Blackbody, PacmanEmission
from synthesizer.emission_models.attenuation import (
Calzetti2000,
) # noqa
from synthesizer.emission_models.dust.emission import Blackbody
from synthesizer.grid import Grid
from synthesizer.instruments import FilterCollection, Instrument
from synthesizer.parametric import SFH, ZDist
Expand Down
8 changes: 4 additions & 4 deletions examples/library_generation/scripts/generate_library_full.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

import numpy as np
from astropy.cosmology import Planck18
from synthesizer.emission_models import Greybody # noqa
from synthesizer.emission_models.attenuation import (
Calzetti2000,
) # noqa
from synthesizer.emission_models.dust.emission import Greybody, IR_templates # noqa
from synthesizer.emission_models.stellar.pacman_model import (
BimodalPacmanEmission,
) # noqa
Expand All @@ -20,8 +20,8 @@
from synference import (
CombinedBasis,
GalaxyBasis,
calculate_mass_weighted_age,
calculate_muv,
calculate_mwa,
draw_from_hypercube,
generate_constant_R,
generate_random_DB_sfh,
Expand Down Expand Up @@ -311,7 +311,7 @@ def db_sf_convert(param, param_dict):
alt_parametrizations=alt_parametrizations,
redshift_dependent_sfh=True,
params_to_ignore=[],
build_grid=False,
build_library=False,
)


Expand Down Expand Up @@ -339,7 +339,7 @@ def db_sf_convert(param, param_dict):
combined_basis.process_bases(
overwrite=True,
mUV=(calculate_muv, cosmo),
mwa=calculate_mwa,
mwa=calculate_mass_weighted_age,
n_proc=n_proc,
verbose=False,
batch_size=batch_size,
Expand Down
14 changes: 7 additions & 7 deletions examples/library_generation/scripts/generate_spectral_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

import numpy as np
from astropy.cosmology import Planck18
from synthesizer.emission_models import Greybody # noqa
from synthesizer.emission_models.attenuation import (
Calzetti2000,
) # noqa
from synthesizer.emission_models.dust.emission import Greybody, IR_templates # noqa
from synthesizer.emission_models.stellar.pacman_model import (
BimodalPacmanEmission,
) # noqa
Expand Down Expand Up @@ -96,9 +96,9 @@
# path for this file

dir_path = os.path.dirname(os.path.abspath(__file__))
from synference import grid_folder
from synference import library_folder

out_dir = grid_folder
out_dir = library_folder


def continuity_agebins(
Expand Down Expand Up @@ -223,8 +223,8 @@ def continuity_agebins(

sfh_name = str(sfh_type).split(".")[-1].split("'")[0]

name = f"BPASS_Chab_{sfh_name}_SFH_{redshift[0]}_z_{redshift[1]}_logN_{np.log10(Nmodels):.1f}_CF00_v2" # noqa: E501
if os.path.exists(f"{out_dir}/v2/spectral_library_{name}.hdf5") and not overwrite:
name = f"BPASS_Chab_{sfh_name}_SFH_z_{redshift}_logN_{np.log10(Nmodels):.1f}_CF00_v2" # noqa: E501
if os.path.exists(f"{out_dir}/spectral_library_{name}.hdf5") and not overwrite:
print(f"Grid {name} already exists, skipping.")
continue

Expand Down Expand Up @@ -414,7 +414,7 @@ def db_sf_convert(param, param_dict, Nparam_SFH=3):
alt_parametrizations=alt_parametrizations,
redshift_dependent_sfh=True,
params_to_ignore=sfh_params.get("params_to_ignore", []),
build_grid=False,
build_library=False,
)

combined_basis = CombinedBasis(
Expand Down Expand Up @@ -464,5 +464,5 @@ def db_sf_convert(param, param_dict, Nparam_SFH=3):

# Create grid - kinda overkill for a single case, but it does work.
combined_basis.create_spectral_grid(
overwrite=True, overload_out_name=f"spectral_library_{name}"
overwrite=overwrite, overload_out_name=f"spectral_library_{name}"
)
4 changes: 2 additions & 2 deletions examples/library_generation/scripts/min_example.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import os

from astropy.cosmology import Planck18
from synthesizer.emission_models import Greybody # noqa
from synthesizer.emission_models.attenuation import Calzetti2000 # noqa
from synthesizer.emission_models.dust.emission import Greybody, IR_templates # noqa
from synthesizer.emission_models.stellar.pacman_model import PacmanEmission # noqa
from synthesizer.grid import Grid
from synthesizer.instruments import FilterCollection, Instrument
Expand Down Expand Up @@ -142,7 +142,7 @@
galaxy_params=galaxy_params,
redshift_dependent_sfh=True,
params_to_ignore=[],
build_grid=False,
build_library=False,
)

# Create our mock training catalogue!
Expand Down
12 changes: 6 additions & 6 deletions examples/online/notebooks/online_learning.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,12 @@
" grid=grid,\n",
" instrument=instrument,\n",
" emission_model=emission_model,\n",
" emission_model_key=\"total\",\n",
" emission_model_key=emission_model.label,\n",
" emitter_params=emitter_params,\n",
" param_units={\"peak_age\": Myr, \"max_age\": Myr},\n",
" normalize_method=None, # calculate_muv,\n",
" output_type=\"photo_fnu\",\n",
" out_flux_unit=\"ABmag\",\n",
" out_flux_unit=\"AB\",\n",
")"
]
},
Expand Down Expand Up @@ -429,12 +429,12 @@
" grid=grid,\n",
" instrument=instrument,\n",
" emission_model=emission_model,\n",
" emission_model_key=\"total\",\n",
" emission_model_key=emission_model.label,\n",
" emitter_params=emitter_params,\n",
" param_units={\"peak_age\": Myr, \"max_age\": Myr},\n",
" normalize_method=None, # calculate_muv,\n",
" output_type=\"photo_fnu\",\n",
" out_flux_unit=\"ABmag\",\n",
" out_flux_unit=\"AB\",\n",
" fixed_params=fixed_params,\n",
")\n",
"\n",
Expand Down Expand Up @@ -530,12 +530,12 @@
" grid=grid,\n",
" instrument=instrument,\n",
" emission_model=emission_model,\n",
" emission_model_key=\"total\",\n",
" emission_model_key=emission_model.label,\n",
" emitter_params=emitter_params,\n",
" param_units={\"peak_age\": Myr, \"max_age\": Myr},\n",
" normalize_method=None, # calculate_muv,\n",
" output_type=\"photo_fnu\",\n",
" out_flux_unit=\"ABmag\",\n",
" out_flux_unit=\"AB\",\n",
" fixed_params=fixed_params,\n",
")\n",
"\n",
Expand Down
4 changes: 2 additions & 2 deletions examples/online/scripts/online_learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@
grid=grid,
instrument=instrument,
emission_model=emission_model,
emission_model_key="total",
emission_model_key=emission_model.label, # "emergent": no dust emission
emitter_params=emitter_params,
param_units={"peak_age": Myr, "max_age": Myr},
normalize_method=calculate_muv,
output_type="photo_fnu",
out_flux_unit="ABmag",
out_flux_unit="AB",
)

inputs = [
Expand Down
10 changes: 10 additions & 0 deletions src/synference/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@



try:
# Fast drop-in replacements for Synthesizer's parametric SFZH integration
# and IGM transmission (used by default in library generation).
from .fast_sfzh import make_parametric_stars
from .fast_igm import TabulatedIGM
except ImportError: # synthesizer not installed
pass

from .noise_models import (
EmpiricalUncertaintyModel, create_uncertainty_models_from_EPOCHS_cat,
DepthUncertaintyModel, UncertaintyModel, AsinhEmpiricalUncertaintyModel,
Expand Down Expand Up @@ -114,4 +122,6 @@
"create_database_universal",
"download_test_data",
"test_data_dir",
"make_parametric_stars",
"TabulatedIGM",
]
Loading
Loading