jacscanomaly 0.3.3__tar.gz → 0.3.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. {jacscanomaly-0.3.3/src/jacscanomaly.egg-info → jacscanomaly-0.3.4}/PKG-INFO +4 -1
  2. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/README.md +3 -0
  3. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/pyproject.toml +1 -1
  4. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/src/jacscanomaly/finder.py +48 -10
  5. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4/src/jacscanomaly.egg-info}/PKG-INFO +4 -1
  6. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/src/jacscanomaly.egg-info/SOURCES.txt +1 -0
  7. jacscanomaly-0.3.4/tests/test_magnitude_input.py +75 -0
  8. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/LICENSE +0 -0
  9. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/MANIFEST.in +0 -0
  10. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/setup.cfg +0 -0
  11. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/setup.py +0 -0
  12. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/src/jacscanomaly/__init__.py +0 -0
  13. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/src/jacscanomaly/_cpp_grid.cpp +0 -0
  14. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/src/jacscanomaly/anomaly_models.py +0 -0
  15. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/src/jacscanomaly/config.py +0 -0
  16. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/src/jacscanomaly/criteria.py +0 -0
  17. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/src/jacscanomaly/data/__init__.py +0 -0
  18. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/src/jacscanomaly/data/earth_orbital_parallax_table.txt +0 -0
  19. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/src/jacscanomaly/extract.py +0 -0
  20. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/src/jacscanomaly/magnification.py +0 -0
  21. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/src/jacscanomaly/models.py +0 -0
  22. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/src/jacscanomaly/objective.py +0 -0
  23. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/src/jacscanomaly/parallax.py +0 -0
  24. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/src/jacscanomaly/photometry.py +0 -0
  25. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/src/jacscanomaly/planet_class/__init__.py +0 -0
  26. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/src/jacscanomaly/planet_class/atoms/__init__.py +0 -0
  27. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/src/jacscanomaly/planet_class/atoms/base.py +0 -0
  28. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/src/jacscanomaly/planet_class/atoms/bump.py +0 -0
  29. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/src/jacscanomaly/planet_class/atoms/central.py +0 -0
  30. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/src/jacscanomaly/planet_class/atoms/chang_refsdal.py +0 -0
  31. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/src/jacscanomaly/planet_class/atoms/cusp.py +0 -0
  32. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/src/jacscanomaly/planet_class/atoms/fold.py +0 -0
  33. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/src/jacscanomaly/planet_class/atoms/second_pspl.py +0 -0
  34. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/src/jacscanomaly/planet_class/atoms/smooth.py +0 -0
  35. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/src/jacscanomaly/planet_class/classifier.py +0 -0
  36. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/src/jacscanomaly/planet_class/features.py +0 -0
  37. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/src/jacscanomaly/planet_class/fold_kernel.py +0 -0
  38. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/src/jacscanomaly/planet_class/linear.py +0 -0
  39. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/src/jacscanomaly/planet_class/pspl.py +0 -0
  40. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/src/jacscanomaly/planet_class/seeds.py +0 -0
  41. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/src/jacscanomaly/planet_class/types.py +0 -0
  42. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/src/jacscanomaly/planet_signal.py +0 -0
  43. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/src/jacscanomaly/plot.py +0 -0
  44. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/src/jacscanomaly/runner.py +0 -0
  45. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/src/jacscanomaly/seasons.py +0 -0
  46. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/src/jacscanomaly/singlelens_fit.py +0 -0
  47. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/src/jacscanomaly/singlelens_model.py +0 -0
  48. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/src/jacscanomaly/template_free.py +0 -0
  49. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/src/jacscanomaly/trajectory.py +0 -0
  50. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/src/jacscanomaly.egg-info/dependency_links.txt +0 -0
  51. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/src/jacscanomaly.egg-info/requires.txt +0 -0
  52. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/src/jacscanomaly.egg-info/top_level.txt +0 -0
  53. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/tests/test_config.py +0 -0
  54. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/tests/test_cpp_extension.py +0 -0
  55. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/tests/test_criteria.py +0 -0
  56. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/tests/test_extract.py +0 -0
  57. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/tests/test_models.py +0 -0
  58. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/tests/test_photometry.py +0 -0
  59. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/tests/test_planet_class.py +0 -0
  60. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/tests/test_planet_signal.py +0 -0
  61. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/tests/test_refit.py +0 -0
  62. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/tests/test_seasons.py +0 -0
  63. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/tests/test_space_parallax.py +0 -0
  64. {jacscanomaly-0.3.3 → jacscanomaly-0.3.4}/tests/test_template_free.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: jacscanomaly
3
- Version: 0.3.3
3
+ Version: 0.3.4
4
4
  Summary: JAX-based scan anomaly detection for time-series residuals
5
5
  Author: Kansuke Nunota
6
6
  License: MIT
@@ -96,6 +96,9 @@ config = FinderConfig(
96
96
  finder = Finder(config)
97
97
  result = finder.run(time, flux, ferr)
98
98
 
99
+ # For magnitude data, pass mag and magerr in the same positions and select it:
100
+ # result = finder.run(time, mag, magerr, data_kind="mag")
101
+
99
102
  # You can still pass an explicit initial guess if desired:
100
103
  # p0 = np.array([10000, 10, 0.3])
101
104
  # result = finder.run(time, flux, ferr, p0)
@@ -66,6 +66,9 @@ config = FinderConfig(
66
66
  finder = Finder(config)
67
67
  result = finder.run(time, flux, ferr)
68
68
 
69
+ # For magnitude data, pass mag and magerr in the same positions and select it:
70
+ # result = finder.run(time, mag, magerr, data_kind="mag")
71
+
69
72
  # You can still pass an explicit initial guess if desired:
70
73
  # p0 = np.array([10000, 10, 0.3])
71
74
  # result = finder.run(time, flux, ferr, p0)
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "jacscanomaly"
7
- version = "0.3.3"
7
+ version = "0.3.4"
8
8
  description = "JAX-based scan anomaly detection for time-series residuals"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"
@@ -1,7 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  from dataclasses import dataclass, field, replace
4
- from typing import Optional
4
+ from typing import Literal, Optional
5
5
  import logging
6
6
 
7
7
  import numpy as np
@@ -279,6 +279,8 @@ class Finder:
279
279
  flux,
280
280
  ferr,
281
281
  x0=None,
282
+ *,
283
+ data_kind: Literal["flux", "mag"] = "flux",
282
284
  ) -> SingleLensFitResult:
283
285
  """
284
286
  Run only the single-lens fit selected by the current configuration.
@@ -286,17 +288,24 @@ class Finder:
286
288
  Parameters
287
289
  ----------
288
290
  time, flux, ferr : array-like
289
- One-dimensional light-curve arrays.
291
+ One-dimensional light-curve arrays. With ``data_kind="mag"``,
292
+ ``flux`` and ``ferr`` are interpreted as magnitude and magnitude
293
+ error, respectively, and are converted to relative flux internally.
290
294
  x0 : array-like, optional
291
295
  Initial guess for the nonlinear model parameters.
292
296
  If omitted, initial values are estimated from a scan of the light curve.
297
+ data_kind : {"flux", "mag"}, optional
298
+ Input photometry representation. The default ``"flux"`` preserves
299
+ the existing API. Magnitude inputs are converted to relative flux.
293
300
 
294
301
  Returns
295
302
  -------
296
303
  SingleLensFitResult
297
304
  Result of the single-lens fit.
298
305
  """
299
- time_j, flux_j, ferr_j, x0_j, time_np, _, _ = self._to_arrays(time, flux, ferr, x0)
306
+ time_j, flux_j, ferr_j, x0_j, time_np, _, _ = self._to_arrays(
307
+ time, flux, ferr, x0, data_kind=data_kind
308
+ )
300
309
  self._ensure_fitter(float(np.median(time_np)))
301
310
  if x0_j is None:
302
311
  return self._fit_from_auto_initial_guesses(time_j, flux_j, ferr_j, time_np)
@@ -309,6 +318,7 @@ class Finder:
309
318
  ferr,
310
319
  x0=None,
311
320
  *,
321
+ data_kind: Literal["flux", "mag"] = "flux",
312
322
  refit: bool = True,
313
323
  verbose: bool = True,
314
324
  log: Optional[logging.Logger] = None,
@@ -319,10 +329,15 @@ class Finder:
319
329
  Parameters
320
330
  ----------
321
331
  time, flux, ferr : array-like
322
- One-dimensional light-curve arrays.
332
+ One-dimensional light-curve arrays. With ``data_kind="mag"``,
333
+ pass ``mag`` and ``magerr`` in these positions; they are converted
334
+ to relative flux and flux error before fitting and scanning.
323
335
  x0 : array-like, optional
324
336
  Initial guess for the single-lens model parameters. If omitted, the
325
337
  finder estimates multiple initial values and uses the best fit.
338
+ data_kind : {"flux", "mag"}, optional
339
+ Input photometry representation. ``"mag"`` converts magnitudes to
340
+ a numerically stable relative-flux scale internally.
326
341
  refit : bool, optional
327
342
  If True, optimize the single-lens nonlinear parameters starting from
328
343
  ``x0``. If False, require ``x0`` and use it as fixed nonlinear
@@ -353,7 +368,7 @@ class Finder:
353
368
  residuals are scanned. See :doc:`workflows` for when to use this mode.
354
369
  """
355
370
  time_j, flux_j, ferr_j, x0_j, time_np, flux_np, ferr_np = self._to_arrays(
356
- time, flux, ferr, x0
371
+ time, flux, ferr, x0, data_kind=data_kind
357
372
  )
358
373
 
359
374
  self._ensure_fitter(float(np.median(time_np)))
@@ -411,6 +426,7 @@ class Finder:
411
426
  ferr,
412
427
  x0=None,
413
428
  *,
429
+ data_kind: Literal["flux", "mag"] = "flux",
414
430
  fit: Optional[SingleLensFitResult] = None,
415
431
  config: Optional[TemplateFreeSearchConfig] = None,
416
432
  ) -> TemplateFreeSearchResult:
@@ -422,10 +438,14 @@ class Finder:
422
438
  Parameters
423
439
  ----------
424
440
  time, flux, ferr : array-like
425
- One-dimensional light-curve arrays. ``ferr`` is used to normalize
426
- the residuals even when ``fit`` is supplied.
441
+ One-dimensional light-curve arrays. With ``data_kind="mag"``,
442
+ ``flux`` and ``ferr`` are interpreted as magnitude and magnitude
443
+ error. Flux errors are used to normalize residuals even when
444
+ ``fit`` is supplied.
427
445
  x0 : array-like, optional
428
446
  Nonlinear initial values used only when ``fit`` is omitted.
447
+ data_kind : {"flux", "mag"}, optional
448
+ Input photometry representation.
429
449
  fit : SingleLensFitResult, optional
430
450
  Existing baseline fit whose residuals should be searched. Passing
431
451
  this skips all single-lens fitting.
@@ -444,7 +464,7 @@ class Finder:
444
464
  ``SingleLensFitResult``, call :class:`TemplateFreeScanner` directly.
445
465
  """
446
466
  time_j, flux_j, ferr_j, x0_j, time_np, _, ferr_np = self._to_arrays(
447
- time, flux, ferr, x0
467
+ time, flux, ferr, x0, data_kind=data_kind
448
468
  )
449
469
 
450
470
  if fit is None:
@@ -463,14 +483,21 @@ class Finder:
463
483
  # ------------------------------------------------------------------
464
484
  # Internal helpers
465
485
  # ------------------------------------------------------------------
466
- def _to_arrays(self, time, flux, ferr, x0):
486
+ def _to_arrays(self, time, flux, ferr, x0, *, data_kind: Literal["flux", "mag"] = "flux"):
467
487
  """
468
- Validate inputs and convert them to both NumPy and JAX arrays.
488
+ Validate inputs and convert them to flux-space NumPy and JAX arrays.
489
+
490
+ ``data_kind="mag"`` treats ``flux`` and ``ferr`` as magnitude and
491
+ magnitude error. The conversion uses a median magnitude zero point so
492
+ that the relative flux is of order unity, avoiding numerical underflow
493
+ for the large magnitude zero points commonly used in catalogs.
469
494
  """
470
495
  time_np = np.asarray(time, dtype=float)
471
496
  flux_np = np.asarray(flux, dtype=float)
472
497
  ferr_np = np.asarray(ferr, dtype=float)
473
498
 
499
+ if data_kind not in {"flux", "mag"}:
500
+ raise ValueError("data_kind must be either 'flux' or 'mag'.")
474
501
  if time_np.ndim != 1 or flux_np.ndim != 1 or ferr_np.ndim != 1:
475
502
  raise ValueError("time/flux/ferr must be 1D arrays.")
476
503
  if not (len(time_np) == len(flux_np) == len(ferr_np)):
@@ -480,6 +507,17 @@ class Finder:
480
507
  if np.any(ferr_np <= 0):
481
508
  raise ValueError("ferr must be positive.")
482
509
 
510
+ if data_kind == "mag":
511
+ mag0 = float(np.median(flux_np))
512
+ exponent = -0.4 * np.log(10.0) * (flux_np - mag0)
513
+ float_info = np.finfo(np.float32)
514
+ exponent = np.clip(exponent, np.log(float_info.tiny), np.log(float_info.max))
515
+ flux_np = np.exp(exponent)
516
+ ferr_np = np.maximum(
517
+ (np.log(10.0) / 2.5) * flux_np * ferr_np,
518
+ float_info.tiny,
519
+ )
520
+
483
521
  time_j = jnp.asarray(time_np)
484
522
  flux_j = jnp.asarray(flux_np)
485
523
  ferr_j = jnp.asarray(ferr_np)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: jacscanomaly
3
- Version: 0.3.3
3
+ Version: 0.3.4
4
4
  Summary: JAX-based scan anomaly detection for time-series residuals
5
5
  Author: Kansuke Nunota
6
6
  License: MIT
@@ -96,6 +96,9 @@ config = FinderConfig(
96
96
  finder = Finder(config)
97
97
  result = finder.run(time, flux, ferr)
98
98
 
99
+ # For magnitude data, pass mag and magerr in the same positions and select it:
100
+ # result = finder.run(time, mag, magerr, data_kind="mag")
101
+
99
102
  # You can still pass an explicit initial guess if desired:
100
103
  # p0 = np.array([10000, 10, 0.3])
101
104
  # result = finder.run(time, flux, ferr, p0)
@@ -51,6 +51,7 @@ tests/test_config.py
51
51
  tests/test_cpp_extension.py
52
52
  tests/test_criteria.py
53
53
  tests/test_extract.py
54
+ tests/test_magnitude_input.py
54
55
  tests/test_models.py
55
56
  tests/test_photometry.py
56
57
  tests/test_planet_class.py
@@ -0,0 +1,75 @@
1
+ import numpy as np
2
+ import pytest
3
+
4
+ from jacscanomaly import CandidateCriteria, Finder, FinderConfig
5
+ from jacscanomaly.singlelens_model import A_pspl_func
6
+
7
+
8
+ def _finder():
9
+ return Finder(
10
+ FinderConfig(
11
+ grid_backend="jax",
12
+ teff_init=1.0,
13
+ teff_grid_n=1,
14
+ candidate_criteria=CandidateCriteria(min_dchi2=1.0e9),
15
+ )
16
+ )
17
+
18
+
19
+ def test_magnitude_input_is_converted_to_relative_flux_for_run():
20
+ time = np.linspace(0.0, 20.0, 60)
21
+ x0 = np.array([10.0, 5.0, 0.2])
22
+ raw_flux = 2.0 * np.asarray(A_pspl_func(x0, time)) + 0.3
23
+ raw_ferr = np.full_like(time, 0.05)
24
+ mag_zero_point = 25.0
25
+ mag = mag_zero_point - 2.5 * np.log10(raw_flux)
26
+ magerr = raw_ferr / ((np.log(10.0) / 2.5) * raw_flux)
27
+
28
+ result = _finder().run(
29
+ time,
30
+ mag,
31
+ magerr,
32
+ x0=x0,
33
+ data_kind="mag",
34
+ refit=False,
35
+ verbose=False,
36
+ )
37
+
38
+ scale = 10.0 ** ((mag_zero_point - np.median(mag)) / 2.5)
39
+ np.testing.assert_allclose(result.flux, raw_flux / scale, rtol=1e-6)
40
+ np.testing.assert_allclose(result.ferr, raw_ferr / scale, rtol=1e-6)
41
+ np.testing.assert_allclose(result.model_flux, raw_flux / scale, rtol=1e-6)
42
+ np.testing.assert_allclose(result.residual, 0.0, atol=1e-6)
43
+
44
+
45
+ def test_flux_is_the_default_input_representation():
46
+ time = np.array([1.0, 2.0])
47
+ flux = np.array([2.0, 3.0])
48
+ ferr = np.array([0.1, 0.2])
49
+
50
+ _, _, _, _, _, converted_flux, converted_ferr = _finder()._to_arrays(time, flux, ferr, None)
51
+
52
+ np.testing.assert_array_equal(converted_flux, flux)
53
+ np.testing.assert_array_equal(converted_ferr, ferr)
54
+
55
+
56
+ def test_magnitude_conversion_is_stable_for_large_zero_points():
57
+ _, flux_j, ferr_j, _, _, flux, ferr = _finder()._to_arrays(
58
+ [1.0, 2.0, 3.0],
59
+ [1000.0, 1000.5, 1001.0],
60
+ [0.1, 0.1, 0.1],
61
+ None,
62
+ data_kind="mag",
63
+ )
64
+
65
+ assert np.all(np.isfinite(flux))
66
+ assert np.all(np.isfinite(ferr))
67
+ assert np.all(flux > 0)
68
+ assert np.all(ferr > 0)
69
+ assert np.all(np.isfinite(np.asarray(flux_j)))
70
+ assert np.all(np.isfinite(np.asarray(ferr_j)))
71
+
72
+
73
+ def test_magnitude_input_rejects_unknown_data_kind():
74
+ with pytest.raises(ValueError, match="data_kind"):
75
+ _finder()._to_arrays([1.0], [20.0], [0.1], None, data_kind="counts")
File without changes
File without changes
File without changes
File without changes