Skip to content

Commit 54bcd00

Browse files
Merge pull request #265 from Autostronomy/getcaskade
Major update: convert to caksade parameter management system
2 parents 664c06a + 626290f commit 54bcd00

190 files changed

Lines changed: 11630 additions & 22553 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/coverage.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
python -m pip install pytest-github-actions-annotate-failures
4545
- name: Install AstroPhot
4646
run: |
47-
pip install -e .
47+
pip install -e ".[dev]"
4848
pip show ${{ env.PROJECT_NAME }}
4949
shell: bash
5050
- name: Test with pytest

.github/workflows/testing.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
runs-on: ${{matrix.os}}
1616
strategy:
1717
matrix:
18-
python-version: ["3.9", "3.10"]
18+
python-version: ["3.10", "3.11", "3.12"]
1919
os: [ubuntu-latest, windows-latest, macOS-latest]
2020
steps:
2121
- uses: actions/checkout@master
@@ -40,7 +40,7 @@ jobs:
4040
- name: Install AstroPhot
4141
run: |
4242
cd $GITHUB_WORKSPACE/
43-
pip install .
43+
pip install .[dev]
4444
pip show astrophot
4545
shell: bash
4646
- name: Test with pytest

.readthedocs.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ build:
2323
python: "3.9"
2424
apt_packages:
2525
- pandoc # Specify pandoc to be installed via apt-get
26+
- graphviz
2627
jobs:
2728
pre_build:
2829
# Generate the Sphinx configuration for this Jupyter Book so it builds.

astrophot/__init__.py

Lines changed: 88 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
11
import argparse
22
import requests
33
import torch
4-
from .parse_config import galfit_config, basic_config
5-
from . import models, image, plots, utils, fit, param, AP_config
4+
from . import config, models, plots, utils, fit
5+
from .param import forward, Param, Module
6+
7+
from .image import (
8+
Image,
9+
ImageList,
10+
TargetImage,
11+
TargetImageList,
12+
SIPTargetImage,
13+
JacobianImage,
14+
JacobianImageList,
15+
PSFImage,
16+
ModelImage,
17+
ModelImageList,
18+
Window,
19+
WindowList,
20+
)
21+
from .models import Model
622

723
try:
824
from ._version import version as VERSION # noqa
@@ -21,32 +37,10 @@
2137

2238
def run_from_terminal() -> None:
2339
"""
24-
Execute AstroPhot from the command line with various options.
25-
26-
This function uses the `argparse` module to parse command line arguments and execute the appropriate functionality.
27-
It accepts the following arguments:
28-
29-
- `filename`: the path to the configuration file. Or just 'tutorial' to download tutorials.
30-
- `--config`: the type of configuration file being provided. One of: astrophot, galfit.
31-
- `-v`, `--version`: print the current AstroPhot version to screen.
32-
- `--log`: set the log file name for AstroPhot. Use 'none' to suppress the log file.
33-
- `-q`: quiet flag to stop command line output, only print to log file.
34-
- `--dtype`: set the float point precision. Must be one of: float64, float32.
35-
- `--device`: set the device for AstroPhot to use for computations. Must be one of: cpu, gpu.
36-
37-
If the `filename` argument is not provided, it raises a `RuntimeError`.
38-
If the `filename` argument is `tutorial` or `tutorials`,
39-
it downloads tutorials from various URLs and saves them locally.
40-
41-
This function logs messages using the `AP_config` module,
42-
which sets the logging output based on the `--log` and `-q` arguments.
43-
The `dtype` and `device` of AstroPhot can also be set using the `--dtype` and `--device` arguments, respectively.
44-
45-
Returns:
46-
None
40+
Running from terminal no longer supported. This is only used for convenience to download the tutorials.
4741
4842
"""
49-
AP_config.ap_logger.debug("running from the terminal, not sure if it will catch me.")
43+
config.logger.debug("running from the terminal, not sure if it will catch me.")
5044
parser = argparse.ArgumentParser(
5145
prog="astrophot",
5246
description="Fast and flexible astronomical image photometry package. For the documentation go to: https://astrophot.readthedocs.io",
@@ -58,60 +52,60 @@ def run_from_terminal() -> None:
5852
metavar="configfile",
5953
help="the path to the configuration file. Or just 'tutorial' to download tutorials.",
6054
)
61-
parser.add_argument(
62-
"--config",
63-
type=str,
64-
default="astrophot",
65-
choices=["astrophot", "galfit"],
66-
metavar="format",
67-
help="The type of configuration file being being provided. One of: astrophot, galfit.",
68-
)
55+
# parser.add_argument(
56+
# "--config",
57+
# type=str,
58+
# default="astrophot",
59+
# choices=["astrophot", "galfit"],
60+
# metavar="format",
61+
# help="The type of configuration file being being provided. One of: astrophot, galfit.",
62+
# )
6963
parser.add_argument(
7064
"-v",
7165
"--version",
7266
action="version",
7367
version=f"%(prog)s {__version__}",
7468
help="print the current AstroPhot version to screen",
7569
)
76-
parser.add_argument(
77-
"--log",
78-
type=str,
79-
metavar="logfile.log",
80-
help="set the log file name for AstroPhot. use 'none' to suppress the log file.",
81-
)
82-
parser.add_argument(
83-
"-q",
84-
action="store_true",
85-
help="quiet flag to stop command line output, only print to log file",
86-
)
87-
parser.add_argument(
88-
"--dtype",
89-
type=str,
90-
choices=["float64", "float32"],
91-
metavar="datatype",
92-
help="set the float point precision. Must be one of: float64, float32",
93-
)
94-
parser.add_argument(
95-
"--device",
96-
type=str,
97-
choices=["cpu", "gpu"],
98-
metavar="device",
99-
help="set the device for AstroPhot to use for computations. Must be one of: cpu, gpu",
100-
)
70+
# parser.add_argument(
71+
# "--log",
72+
# type=str,
73+
# metavar="logfile.log",
74+
# help="set the log file name for AstroPhot. use 'none' to suppress the log file.",
75+
# )
76+
# parser.add_argument(
77+
# "-q",
78+
# action="store_true",
79+
# help="quiet flag to stop command line output, only print to log file",
80+
# )
81+
# parser.add_argument(
82+
# "--dtype",
83+
# type=str,
84+
# choices=["float64", "float32"],
85+
# metavar="datatype",
86+
# help="set the float point precision. Must be one of: float64, float32",
87+
# )
88+
# parser.add_argument(
89+
# "--device",
90+
# type=str,
91+
# choices=["cpu", "gpu"],
92+
# metavar="device",
93+
# help="set the device for AstroPhot to use for computations. Must be one of: cpu, gpu",
94+
# )
10195

10296
args = parser.parse_args()
10397

10498
if args.log is not None:
105-
AP_config.set_logging_output(
99+
config.set_logging_output(
106100
stdout=not args.q, filename=None if args.log == "none" else args.log
107101
)
108102
elif args.q:
109-
AP_config.set_logging_output(stdout=not args.q, filename="AstroPhot.log")
103+
config.set_logging_output(stdout=not args.q, filename="AstroPhot.log")
110104

111105
if args.dtype is not None:
112-
AP_config.dtype = torch.float64 if args.dtype == "float64" else torch.float32
106+
config.DTYPE = torch.float64 if args.dtype == "float64" else torch.float32
113107
if args.device is not None:
114-
AP_config.device = "cpu" if args.device == "cpu" else "cuda:0"
108+
config.DEVICE = "cpu" if args.device == "cpu" else "cuda:0"
115109

116110
if args.filename is None:
117111
raise RuntimeError(
@@ -128,7 +122,6 @@ def run_from_terminal() -> None:
128122
"https://raw.github.com/Autostronomy/AstroPhot/main/docs/source/tutorials/BasicPSFModels.ipynb",
129123
"https://raw.github.com/Autostronomy/AstroPhot/main/docs/source/tutorials/AdvancedPSFModels.ipynb",
130124
"https://raw.github.com/Autostronomy/AstroPhot/main/docs/source/tutorials/ConstrainedModels.ipynb",
131-
"https://raw.github.com/Autostronomy/AstroPhot-tutorials/main/docs/tutorials/simple_config.py",
132125
]
133126
for url in tutorials:
134127
try:
@@ -140,12 +133,35 @@ def run_from_terminal() -> None:
140133
f"WARNING: couldn't find tutorial: {url[url.rfind('/')+1:]} check internet connection"
141134
)
142135

143-
AP_config.ap_logger.info("collected the tutorials")
144-
elif args.config == "astrophot":
145-
basic_config(args.filename)
146-
elif args.config == "galfit":
147-
galfit_config(args.filename)
136+
config.logger.info("collected the tutorials")
148137
else:
149-
raise ValueError(
150-
f"Unrecognized configuration file format {args.config}. Should be one of: astrophot, galfit"
151-
)
138+
raise ValueError(f"Unrecognized request")
139+
140+
141+
__all__ = (
142+
"models",
143+
"Model",
144+
"Image",
145+
"ImageList",
146+
"TargetImage",
147+
"TargetImageList",
148+
"SIPTargetImage",
149+
"JacobianImage",
150+
"JacobianImageList",
151+
"PSFImage",
152+
"ModelImage",
153+
"ModelImageList",
154+
"Window",
155+
"WindowList",
156+
"plots",
157+
"utils",
158+
"fit",
159+
"forward",
160+
"Param",
161+
"Module",
162+
"config",
163+
"run_from_terminal",
164+
"__version__",
165+
"__author__",
166+
"__email__",
167+
)
Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,28 @@
22
import logging
33
import torch
44

5-
__all__ = ["ap_dtype", "ap_device", "ap_logger", "set_logging_output"]
5+
__all__ = ["DTYPE", "DEVICE", "logger", "set_logging_output"]
66

7-
ap_dtype = torch.float64
8-
ap_device = "cuda:0" if torch.cuda.is_available() else "cpu"
9-
ap_verbose = 0
7+
DTYPE = torch.float64
8+
DEVICE = "cuda:0" if torch.cuda.is_available() else "cpu"
109

1110
logging.basicConfig(
1211
filename="AstroPhot.log",
1312
level=logging.INFO,
1413
format="%(asctime)s:%(levelname)s: %(message)s",
1514
)
16-
ap_logger = logging.getLogger()
15+
logger = logging.getLogger()
1716
out_handler = logging.StreamHandler(sys.stdout)
1817
out_handler.setLevel(logging.INFO)
1918
out_handler.setFormatter(logging.Formatter("%(message)s"))
20-
ap_logger.addHandler(out_handler)
19+
logger.addHandler(out_handler)
2120

2221

2322
def set_logging_output(stdout=True, filename=None, **kwargs):
2423
"""
2524
Change the logging system for AstroPhot.
2625
Here you can set whether output prints to screen or to a logging file.
27-
This function will remove all handlers from the current logger in ap_logger,
26+
This function will remove all handlers from the current logger in logger,
2827
then add new handlers based on the input to the function.
2928
3029
Parameters:
@@ -39,20 +38,20 @@ def set_logging_output(stdout=True, filename=None, **kwargs):
3938
4039
"""
4140
hi = 0
42-
while hi < len(ap_logger.handlers):
43-
if isinstance(ap_logger.handlers[hi], logging.StreamHandler):
44-
ap_logger.removeHandler(ap_logger.handlers[hi])
45-
elif isinstance(ap_logger.handlers[hi], logging.FileHandler):
46-
ap_logger.removeHandler(ap_logger.handlers[hi])
41+
while hi < len(logger.handlers):
42+
if isinstance(logger.handlers[hi], logging.StreamHandler):
43+
logger.removeHandler(logger.handlers[hi])
44+
elif isinstance(logger.handlers[hi], logging.FileHandler):
45+
logger.removeHandler(logger.handlers[hi])
4746
else:
4847
hi += 1
4948

5049
if stdout:
5150
out_handler = logging.StreamHandler(sys.stdout)
5251
out_handler.setLevel(kwargs.get("stdout_level", logging.INFO))
5352
out_handler.setFormatter(kwargs.get("stdout_formatter", logging.Formatter("%(message)s")))
54-
ap_logger.addHandler(out_handler)
55-
ap_logger.debug("logging now going to stdout")
53+
logger.addHandler(out_handler)
54+
logger.debug("logging now going to stdout")
5655
if filename is not None:
5756
out_handler = logging.FileHandler(filename)
5857
out_handler.setLevel(kwargs.get("filename_level", logging.INFO))
@@ -62,5 +61,5 @@ def set_logging_output(stdout=True, filename=None, **kwargs):
6261
logging.Formatter("%(asctime)s:%(levelname)s: %(message)s"),
6362
)
6463
)
65-
ap_logger.addHandler(out_handler)
66-
ap_logger.debug("logging now going to %s" % filename)
64+
logger.addHandler(out_handler)
65+
logger.debug("logging now going to %s" % filename)

astrophot/errors/fit.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
from .base import AstroPhotError
22

3-
__all__ = ("OptimizeStop",)
3+
__all__ = ("OptimizeStopFail", "OptimizeStopSuccess")
44

55

6-
class OptimizeStop(AstroPhotError):
6+
class OptimizeStopFail(AstroPhotError):
77
"""
8-
Raised at any point to stop optimization process.
8+
Raised at any point to stop optimization process due to failure.
9+
"""
10+
11+
pass
12+
13+
14+
class OptimizeStopSuccess(AstroPhotError):
15+
"""
16+
Raised at any point to stop optimization process due to success condition.
917
"""
1018

1119
pass

astrophot/fit/__init__.py

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,9 @@
1-
from .base import *
2-
from .lm import *
3-
from .oldlm import *
4-
from .gradient import *
5-
from .iterative import *
6-
from .minifit import *
7-
8-
try:
9-
from .hmc import *
10-
from .nuts import *
11-
except AssertionError as e:
12-
print("Could not load HMC or NUTS due to:", str(e))
13-
from .mhmcmc import *
14-
15-
"""
16-
base: This module defines the base class BaseOptimizer,
17-
which is used as the parent class for all optimization algorithms in AstroPhot.
18-
This module contains helper functions used across multiple optimization algorithms,
19-
such as computing gradients and making copies of models.
20-
21-
LM: This module defines the class LM,
22-
which uses the Levenberg-Marquardt algorithm to perform optimization.
23-
This algorithm adjusts the learning rate at each step to find the optimal value.
24-
25-
Grad: This module defines the class Gradient-Optimizer,
26-
which uses a simple gradient descent algorithm to perform optimization.
27-
This algorithm adjusts the learning rate at each step to find the optimal value.
28-
29-
Iterative: This module defines the class Iter,
30-
which uses an iterative algorithm to perform Optimization.
31-
This algorithm repeatedly fits each model individually until they all converge.
32-
33-
"""
1+
from .lm import LM
2+
from .gradient import Grad
3+
from .iterative import Iter
4+
from .scipy_fit import ScipyFit
5+
from .minifit import MiniFit
6+
from .hmc import HMC
7+
from .mhmcmc import MHMCMC
8+
9+
__all__ = ["LM", "Grad", "Iter", "ScipyFit", "MiniFit", "HMC", "MHMCMC"]

0 commit comments

Comments
 (0)