Skip to content
Merged
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
12 changes: 6 additions & 6 deletions projects/cosmology/example_1_intro.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
import matplotlib.pyplot as plt
import numpy as np
from scipy import signal
from os import path
from pathlib import Path

"""
__Plot__
Expand Down Expand Up @@ -124,12 +124,12 @@ def plot_grid(grid, title=None):
In the strong lens image and noise map below, you can see this has already been performed, with the edge regions
blank.
"""
dataset_path = path.join("projects", "cosmology", "dataset")
dataset_path = Path("projects") / "cosmology" / "dataset"

data = np.load(file=path.join(dataset_path, "data.npy"))
data = np.load(file=Path(dataset_path) / "data.npy")
plot_array(array=data, title="Image of Strong Lens SDSSJ2303+1422")

noise_map = np.load(file=path.join(dataset_path, "noise_map.npy"))
noise_map = np.load(file=Path(dataset_path) / "noise_map.npy")
plot_array(array=noise_map, title="Noise Map of Strong Lens SDSSJ2303+1422")

"""
Expand All @@ -150,7 +150,7 @@ def plot_grid(grid, title=None):
model data. This is an example of how an `Analysis` class may be extended to include additional steps in the model
fitting procedure.
"""
psf = np.load(file=path.join(dataset_path, "psf.npy"))
psf = np.load(file=Path(dataset_path) / "psf.npy")
plot_array(array=psf, title="Point Spread Function of Strong Lens SDSSJ2303+1422")


Expand All @@ -166,7 +166,7 @@ def plot_grid(grid, title=None):
This grid only contains (y,x) coordinates within the cricular mask that was applied to the data, as we only need to
perform ray-tracing within this region.
"""
grid = np.load(file=path.join(dataset_path, "grid.npy"))
grid = np.load(file=Path(dataset_path) / "grid.npy")

plot_grid(
grid=grid,
Expand Down
16 changes: 8 additions & 8 deletions projects/cosmology/example_2_multi_level_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
"""

import os
from os import path
from autoconf import conf

cwd = os.getcwd()
config_path = path.join(cwd, "projects", "cosmology", "config")
config_path = Path(cwd) / "projects" / "cosmology" / "config"
conf.instance.push(new_path=config_path)

# %matplotlib inline
Expand All @@ -34,6 +33,7 @@
import src as cosmo
import matplotlib.pyplot as plt
import numpy as np
from pathlib import Path

"""
__Plot__
Expand Down Expand Up @@ -62,18 +62,18 @@ def plot_grid(grid, title=None):

Now lets load and plot Hubble Space Telescope imaging data of the strong gravitational lens SDSSJ2303+1422.
"""
dataset_path = path.join("projects", "cosmology", "dataset")
dataset_path = Path("projects") / "cosmology" / "dataset"

data = np.load(file=path.join(dataset_path, "data.npy"))
data = np.load(file=Path(dataset_path) / "data.npy")
plot_array(array=data, title="Image of Strong Lens SDSSJ2303+1422")

noise_map = np.load(file=path.join(dataset_path, "noise_map.npy"))
noise_map = np.load(file=Path(dataset_path) / "noise_map.npy")
plot_array(array=noise_map, title="Noise Map of Strong Lens SDSSJ2303+1422")

psf = np.load(file=path.join(dataset_path, "psf.npy"))
psf = np.load(file=Path(dataset_path) / "psf.npy")
plot_array(array=psf, title="Point Spread Function of Strong Lens SDSSJ2303+1422")

grid = np.load(file=path.join(dataset_path, "grid.npy"))
grid = np.load(file=Path(dataset_path) / "grid.npy")

plot_grid(
grid=grid,
Expand Down Expand Up @@ -257,7 +257,7 @@ def plot_grid(grid, title=None):
"""

search = af.DynestyStatic(
path_prefix=path.join("projects", "cosmology"),
path_prefix=Path("projects") / "cosmology",
name="multi_level",
nlive=50,
iterations_per_full_update=2500,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@
- **Chapter Wrap Up**: Summarize the completion of Chapter 1 and its applications to real astronomy.
"""

# from autoconf import setup_notebook; setup_notebook()
# from autoconf import setup_notebook; setup_notebook()

from os import path
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal
Expand Down Expand Up @@ -109,15 +108,15 @@ def plot_grid(grid, title=None):
The noise-map has a few strange off-centre features which are an artefact of the telescope. Don't worry about these
features.
"""
dataset_path = path.join("dataset", "howtofit", "chapter_1", "astro", "simple")
dataset_path = Path("dataset") / "howtofit" / "chapter_1" / "astro" / "simple"

"""
__Dataset Auto-Simulation__

If the dataset does not already exist on your system, it will be created by running the corresponding
simulator script. This ensures that all example scripts can be run without manually simulating data first.
"""
if not path.exists(dataset_path):
if not Path(dataset_path).exists():
import subprocess
import sys

Expand All @@ -126,10 +125,10 @@ def plot_grid(grid, title=None):
check=True,
)

data = np.load(file=path.join(dataset_path, "data.npy"))
data = np.load(file=Path(dataset_path) / "data.npy")
plot_array(array=data, title="Image of Galaxy")

noise_map = np.load(file=path.join(dataset_path, "noise_map.npy"))
noise_map = np.load(file=Path(dataset_path) / "noise_map.npy")
plot_array(array=noise_map, title="Noise Map of Galaxy")

"""
Expand All @@ -143,7 +142,7 @@ def plot_grid(grid, title=None):
We load and plot the mask below to show you how it is applied to the data, and we will use it in
the `log_likelihood_function` below to ensure these regions are not fitted.
"""
mask = np.load(file=path.join(dataset_path, "mask.npy"))
mask = np.load(file=Path(dataset_path) / "mask.npy")
plot_array(array=mask, title="Mask of Galaxy")

"""
Expand All @@ -160,7 +159,7 @@ def plot_grid(grid, title=None):
When fitting the data and in the `log_likelihood_function` below, the PSF is used to create the model data. This
demonstrates how an `Analysis` class can be extended to include additional steps in the model fitting process.
"""
psf = np.load(file=path.join(dataset_path, "psf.npy"))
psf = np.load(file=Path(dataset_path) / "psf.npy")
plot_array(array=psf, title="Point Spread Function of Galaxy ?")

"""
Expand All @@ -174,7 +173,7 @@ def plot_grid(grid, title=None):
This grid includes only (y,x) coordinates within the circular mask applied to the data, as we only need to perform
calculations within this masked region.
"""
grid = np.load(file=path.join(dataset_path, "grid.npy"))
grid = np.load(file=Path(dataset_path) / "grid.npy")

plot_grid(
grid=grid,
Expand Down Expand Up @@ -779,6 +778,7 @@ def model_data_from_instance(self, instance):

This illustrates why we perform model-fitting, we can take complex data and infer simple, interpretable properties
from it which provide insight into the physical processes generating the data. This is the core goal of the scientific
from pathlib import Path
method and the use of models to explain observations.
"""
print(result.info)
Expand Down
4 changes: 2 additions & 2 deletions searches/pyswarms/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@
autofit's base classes and can be used as drop-in replacements.
"""
import numpy as np
from os import path

from autoconf import conf

# Register the config directory shipped with this repo so that
# PySwarmsGlobal/Local can find their YAML defaults.
workspace_path = path.dirname(path.dirname(path.dirname(path.abspath(__file__))))
conf.instance.push(new_path=path.join(workspace_path, "config"))
conf.instance.push(new_path=Path(workspace_path) / "config")

from searches.pyswarms.globe import PySwarmsGlobal

import autofit as af
from pathlib import Path

# --- Define a simple 1D Gaussian model ---

Expand Down
4 changes: 2 additions & 2 deletions searches/ultranest/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@
classes and can be used as a drop-in replacement.
"""
import numpy as np
from os import path

from autoconf import conf

# Register the config directory shipped with this repo so that
# UltraNest can find its YAML defaults.
workspace_path = path.dirname(path.dirname(path.dirname(path.abspath(__file__))))
conf.instance.push(new_path=path.join(workspace_path, "config"))
conf.instance.push(new_path=Path(workspace_path) / "config")

from searches.ultranest.search import UltraNest

import autofit as af
from pathlib import Path

# --- Define a simple 1D Gaussian model ---

Expand Down
2 changes: 1 addition & 1 deletion searches/ultranest/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def prior_transform(cube):
log_dir = self.paths.search_internal_path

try:
checkpoint_exists = os.path.exists(log_dir / "chains")
checkpoint_exists = Path(log_dir / "chains").exists()
except TypeError:
checkpoint_exists = False

Expand Down