Skip to content
This repository was archived by the owner on May 11, 2026. It is now read-only.
Merged

Dev #52

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
22 changes: 11 additions & 11 deletions docs/tutorials/applying_corrections.ipynb

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions docs/tutorials/backgrounds.ipynb

Large diffs are not rendered by default.

213 changes: 162 additions & 51 deletions docs/tutorials/finders.ipynb

Large diffs are not rendered by default.

296 changes: 154 additions & 142 deletions docs/tutorials/local_backgrounds.ipynb

Large diffs are not rendered by default.

36 changes: 18 additions & 18 deletions docs/tutorials/reduction.ipynb

Large diffs are not rendered by default.

624 changes: 624 additions & 0 deletions docs/tutorials/timing_methods.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion opticam_new/align.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def align_batch(
output_shape=reference_image_shape,
order=3,
mode='constant',
cval=float(np.nanmedian(data)),
cval=0.,
clip=True,
preserve_range=True,
)
Expand Down
26 changes: 16 additions & 10 deletions opticam_new/analysis/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,11 @@ def compute_power_spectra(

lc = self._convert_lc_time_to_seconds(self.light_curves[fltr])

dt = np.diff(lc.time)
if not np.allclose(dt, dt[0]):
print(f'[OPTICAM] Unable to compute periodogram for {fltr} light curve due to gaps. Consider using either the compute_lomb_scargle_periodograms() or compute_averaged_power_spectra() methods instead.')
continue

ps = Powerspectrum.from_lightcurve(
lc,
norm=norm,
Expand All @@ -494,7 +499,7 @@ def compute_power_spectra(

results[fltr] = ps

if self.show_plots:
if self.show_plots and len(results) > 0:
fig = _plot(results, scale)
fig.savefig(f'{self.out_directory}/plots/{self.prefix}_{self.phot_label}_periodograms.png')
plt.show()
Expand Down Expand Up @@ -645,22 +650,18 @@ def compute_averaged_crossspectra(
of filter names and the values are the cross-spectra.
"""

segment_size = segment_size.to(u.day).value # convert from given units to days
segment_size = segment_size.to_value(u.s) # convert from given units to seconds

results = {}

for fltr1, lc1 in self.light_curves.items():
for fltr2, lc2 in self.light_curves.items():
if fltr1 == fltr2:
if fltr1 == fltr2 or (fltr1, fltr2) in results or (fltr2, fltr1) in results:
continue

# convert light curves from days to seconds
lc1 = self._convert_lc_time_to_seconds(lc1)
lc2 = self._convert_lc_time_to_seconds(lc2)

cs = AveragedCrossspectrum.from_lightcurve(
lc1,
lc2,
self._convert_lc_time_to_seconds(lc1),
self._convert_lc_time_to_seconds(lc2),
segment_size=segment_size,
norm=norm,
silent=True,
Expand Down Expand Up @@ -852,10 +853,15 @@ def _plot(
x_label = 'Time lag [s]'
y_label = 'Correlation'

if key in colors:
color = colors[key]
else:
color = 'k'

axes[i].step(
x,
y,
color='k',
color=color,
lw=1,
where='mid',
)
Expand Down
7 changes: 3 additions & 4 deletions opticam_new/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(
finder: None | Callable = None,
threshold: float = 5,
aperture_selector: Callable = np.median,
remove_cosmic_rays: bool = True,
remove_cosmic_rays: bool = False,
number_of_processors: int = cpu_count() // 2,
show_plots: bool = True,
verbose: bool = True
Expand Down Expand Up @@ -95,9 +95,9 @@ def __init__(
photometry. If a callable is provided, it should take a list of source sizes (`List[float]`) as input and
return a single value.
remove_cosmic_rays: bool, optional
Whether to remove cosmic rays from images, by default True. Cosmic rays are removed using the LACosmic
Whether to remove cosmic rays from images, by default False. Cosmic rays are removed using the LACosmic
algorithm as implemented in `astroscrappy`. Note: this can be computationally expensive, particularly for
large images (i.e., low binning factors).
large images.
number_of_processors: int, optional
The number of processors to use for parallel processing, by default half the number of available processors.
show_plots: bool, optional
Expand Down Expand Up @@ -398,7 +398,6 @@ def create_catalogs(
reference_coords = self.get_source_coords_from_image(
reference_image,
background=self.background,
away_from_edge=True,
n_sources=n_alignment_sources,
)
except Exception as e:
Expand Down
9 changes: 0 additions & 9 deletions opticam_new/finders.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ def get_source_coords_from_image(
finder: DefaultFinder,
threshold: float | int,
bkg: Background2D | None = None,
away_from_edge: bool | None = False,
n_sources: int | None = None,
background: BaseBackground | None = None,
) -> NDArray:
Expand All @@ -64,8 +63,6 @@ def get_source_coords_from_image(
The **non-background-subtracted** image from which to extract source coordinates.
bkg : Background2D, optional
The background of the image, by default None. If None, the background is estimated from the image.
away_from_edge : bool, optional
Whether to exclude sources near the edge of the image, by default False.
n_sources : int, optional
The number of source coordinates to return, by default `None` (all sources will be returned).

Expand All @@ -88,12 +85,6 @@ def get_source_coords_from_image(

coords = np.array([tbl["xcentroid"], tbl["ycentroid"]]).T

if away_from_edge:
edge = background.box_size
for coord in coords:
if coord[0] < edge or coord[0] > image.shape[1] - edge or coord[1] < edge or coord[1] > image.shape[0] - edge:
coords = np.delete(coords, np.where(np.all(coords == coord, axis=1)), axis=0)

if n_sources is not None:
coords = coords[:n_sources]

Expand Down
2 changes: 1 addition & 1 deletion opticam_new/utils/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ def generate_gappy_observations(

# randomly skip some images to create gaps
if rng.random() < gap_probability:
# if an image is skipped, increase the probability of skipping the next one to creaate larger gaps
# if an image is skipped, increase the probability of skipping the next one to create larger gaps
gap_probability = .95
continue
else:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "opticam_new"
version = "0.2.1"
version = "0.2.2"
description = "A Python package for reducing OPTICAM data."
readme = "README.md"
authors = [
Expand Down