Skip to content

Commit c290b74

Browse files
committed
Reformat modules
1 parent 1adb86b commit c290b74

4 files changed

Lines changed: 38 additions & 287 deletions

File tree

src/xrisalis/analysis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def inverse_fourier(
133133
# calculate the frequency grid onto which the real sampled frequencies are mapped
134134
fft_freqs = np.fft.fftfreq(n, d)
135135
if verbose:
136-
print("Fourier frequencies calculated.")
136+
print(f"Fourier frequencies calculated.")
137137

138138
# find closest frequency grid point in numpy.fft.fftfreq of the real sampled frequencies,
139139
# dividing by frequency bin width: Delta f = 1 / (n * d)

src/xrisalis/images.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
from PIL import Image
2+
import gc
23
import numpy as np
34
import scipy.constants as spc
45
import pandas as pd
6+
from astropy.io import fits
7+
from astropy.wcs import WCS
8+
9+
# for testing
10+
import matplotlib.pyplot as plt
511

612

713
class image:
@@ -106,7 +112,7 @@ def double_point_source(size, alpha, beta, energy, spectrum=None):
106112

107113
elif energy is None:
108114
# define either spectrum or energy
109-
raise ValueError("ERROR: define either spectrum or energy")
115+
raise Exception("ERROR: define either spectrum or energy")
110116

111117
for i in range(0, size):
112118
source = np.random.randint(0, 2)
@@ -146,7 +152,7 @@ def m_point_sources(size, m, alpha, beta, energy, spectrum=None):
146152

147153
elif energy is None:
148154
# define either spectrum or energy
149-
raise ValueError("ERROR: define either spectrum or energy")
155+
raise Exception("ERROR: define either spectrum or energy")
150156

151157
for i in range(0, size):
152158
source = np.random.randint(0, m)
@@ -185,7 +191,7 @@ def point_source_multichromatic_range(size, alpha, beta, energy, spectrum=None):
185191

186192
elif energy is None:
187193
# define either spectrum or energy
188-
raise ValueError("ERROR: define either spectrum or energy")
194+
raise Exception("ERROR: define either spectrum or energy")
189195

190196
for i in range(0, size):
191197
im.energies[i] = (
@@ -211,6 +217,8 @@ def point_source_multichromatic_gauss(size, alpha, beta, energy, energy_spread):
211217
"""
212218
im = image(size)
213219

220+
spectrum = None
221+
214222
im.energies = np.random.normal(energy, energy_spread, size) * spc.eV * 1e3
215223
for i in range(0, size):
216224
im.loc[i] = np.array([alpha, beta]) * 2 * np.pi / (3600 * 360)
@@ -249,7 +257,7 @@ def disc(size, alpha, beta, energy, radius, energy_spread=0.0, spectrum=None):
249257

250258
elif energy is None:
251259
# define either spectrum or energy
252-
raise ValueError("ERROR: define either spectrum or energy")
260+
raise Exception("ERROR: define either spectrum or energy")
253261

254262
for i in range(0, size):
255263
im.energies[i] = energy * spc.eV * 1e3
@@ -275,7 +283,7 @@ def generate_from_image(
275283
img_scale,
276284
energy,
277285
energy_spread=0.0,
278-
offset=None,
286+
offset=[0, 0],
279287
spectrum=None,
280288
bkg_phot=None,
281289
bkg_spect=None,
@@ -308,7 +316,7 @@ def generate_from_image(
308316

309317
# ensuring sufficient array lengths for source and bkg counts
310318
if bkg_phot is not None:
311-
if isinstance(bkg_phot, float):
319+
if type(bkg_phot) is float:
312320
bkg_phot = int(np.around(bkg_phot * no_photons))
313321

314322
# create image instance
@@ -331,7 +339,7 @@ def generate_from_image(
331339

332340
elif energy is None:
333341
# define either spectrum or energy
334-
raise ValueError("ERROR: define either spectrum or energy")
342+
raise Exception("ERROR: define either spectrum or energy")
335343

336344
# Load the image and convert it to grayscale
337345
img = Image.open(image_path).convert("L")
@@ -346,18 +354,16 @@ def generate_from_image(
346354

347355
# Draw N samples from the probability mass function
348356
source_counts = np.random.choice(
349-
np.arange(img_array.size),
350-
size=no_photons,
351-
p=pmf.flatten(),
357+
np.arange(img_array.size), size=no_photons, p=pmf.flatten()
352358
)
353-
pixel_locations = None
359+
354360
# generate bkg photons
355361
if bkg_phot is not None:
356362
# random point of origin within the input image (not based on FoV)
357363
bkg_counts = np.random.choice(np.arange(img_array.size), size=bkg_phot)
358364

359365
# random bkg vs based on flux
360-
if bkg_spect is None:
366+
if bkg_spect == None:
361367
# rondomize photon TOA, while keeping the respective orders of both source and bkg photons (not based on relative fluxes)
362368
indices = np.arange(bkg_phot + no_photons)
363369
pixel_locations = np.concatenate(
@@ -385,7 +391,7 @@ def generate_from_image(
385391

386392
else:
387393
# save spectrum when given
388-
# TODO: sample the spectrum in process.py
394+
"""TODO: sample the spectrum in process.py"""
389395
# load file containing spectrum or copy the spectrum
390396
if isinstance(bkg_spect, str):
391397
photon_img.bkg_spect = np.loadtxt(bkg_spect)

0 commit comments

Comments
 (0)