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
3 changes: 1 addition & 2 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ build:

python:
install:
- requirements: requirements.txt # Path to your requirements.txt file
- requirements: docs/requirements.txt # Path to your requirements.txt file
- method: pip
path: . # Install the package itself
path: .[dev] # Install the package itself
109 changes: 1 addition & 108 deletions astrophot/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import argparse
import requests
import torch
from . import config, models, plots, utils, fit, image, errors
from .param import forward, Param, Module

Expand Down Expand Up @@ -38,110 +35,6 @@
__author__ = "Connor Stone"
__email__ = "connorstone628@gmail.com"


def run_from_terminal() -> None:
"""
Running from terminal no longer supported. This is only used for convenience to download the tutorials.

"""
config.logger.debug("running from the terminal, not sure if it will catch me.")
parser = argparse.ArgumentParser(
prog="astrophot",
description="Fast and flexible astronomical image photometry package. For the documentation go to: https://astrophot.readthedocs.io",
epilog="Please see the documentation or contact connor stone (connorstone628@gmail.com) for further assistance.",
)
parser.add_argument(
"filename",
nargs="?",
metavar="configfile",
help="the path to the configuration file. Or just 'tutorial' to download tutorials.",
)
# parser.add_argument(
# "--config",
# type=str,
# default="astrophot",
# choices=["astrophot", "galfit"],
# metavar="format",
# help="The type of configuration file being being provided. One of: astrophot, galfit.",
# )
parser.add_argument(
"-v",
"--version",
action="version",
version=f"%(prog)s {__version__}",
help="print the current AstroPhot version to screen",
)
# parser.add_argument(
# "--log",
# type=str,
# metavar="logfile.log",
# help="set the log file name for AstroPhot. use 'none' to suppress the log file.",
# )
# parser.add_argument(
# "-q",
# action="store_true",
# help="quiet flag to stop command line output, only print to log file",
# )
# parser.add_argument(
# "--dtype",
# type=str,
# choices=["float64", "float32"],
# metavar="datatype",
# help="set the float point precision. Must be one of: float64, float32",
# )
# parser.add_argument(
# "--device",
# type=str,
# choices=["cpu", "gpu"],
# metavar="device",
# help="set the device for AstroPhot to use for computations. Must be one of: cpu, gpu",
# )

args = parser.parse_args()

if args.log is not None:
config.set_logging_output(
stdout=not args.q, filename=None if args.log == "none" else args.log
)
elif args.q:
config.set_logging_output(stdout=not args.q, filename="AstroPhot.log")

if args.dtype is not None:
config.DTYPE = torch.float64 if args.dtype == "float64" else torch.float32
if args.device is not None:
config.DEVICE = "cpu" if args.device == "cpu" else "cuda:0"

if args.filename is None:
raise RuntimeError(
"Please pass a config file to astrophot. See 'astrophot --help' for more information, or go to https://astrophot.readthedocs.io"
)
if args.filename in ["tutorial", "tutorials"]:
tutorials = [
"https://raw.github.com/Autostronomy/AstroPhot/main/docs/source/tutorials/GettingStarted.ipynb",
"https://raw.github.com/Autostronomy/AstroPhot/main/docs/source/tutorials/GroupModels.ipynb",
"https://raw.github.com/Autostronomy/AstroPhot/main/docs/source/tutorials/ModelZoo.ipynb",
"https://raw.github.com/Autostronomy/AstroPhot/main/docs/source/tutorials/JointModels.ipynb",
"https://raw.github.com/Autostronomy/AstroPhot/main/docs/source/tutorials/FittingMethods.ipynb",
"https://raw.github.com/Autostronomy/AstroPhot/main/docs/source/tutorials/CustomModels.ipynb",
"https://raw.github.com/Autostronomy/AstroPhot/main/docs/source/tutorials/BasicPSFModels.ipynb",
"https://raw.github.com/Autostronomy/AstroPhot/main/docs/source/tutorials/AdvancedPSFModels.ipynb",
"https://raw.github.com/Autostronomy/AstroPhot/main/docs/source/tutorials/ConstrainedModels.ipynb",
]
for url in tutorials:
try:
R = requests.get(url)
with open(url[url.rfind("/") + 1 :], "w") as f:
f.write(R.text)
except:
print(
f"WARNING: couldn't find tutorial: {url[url.rfind('/')+1:]} check internet connection"
)

config.logger.info("collected the tutorials")
else:
raise ValueError(f"Unrecognized request")


__all__ = (
"models",
"image",
Expand Down Expand Up @@ -170,7 +63,7 @@ def run_from_terminal() -> None:
"Module",
"config",
"backend",
"run_from_terminal",
"ArrayLike",
"__version__",
"__author__",
"__email__",
Expand Down
3 changes: 2 additions & 1 deletion astrophot/fit/hmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def new_configure(self, mass_matrix_shape, adapt_mass_matrix=True, options={}):
self.inverse_mass_matrix = inverse_mass_matrix


BlockMassMatrix.configure = new_configure
if pyro is not None:
BlockMassMatrix.configure = new_configure
############################################


Expand Down
1 change: 0 additions & 1 deletion astrophot/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def __init__(self, *, name=None, target=None, window=None, mask=None, filename=N
setattr(self, key, param)

self.saveattrs.update(self.options)
self.saveattrs.add("window.extent")

kwargs.pop("model_type", None) # model_type is set by __new__
if len(kwargs) > 0:
Expand Down
8 changes: 4 additions & 4 deletions astrophot/models/mixins/ferrer.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ class iFerrerMixin:

_model_type = "ferrer"
_parameter_specs = {
"rout": {"units": "arcsec", "valid": (0.0, None), "shape": (), "dynamic": True},
"alpha": {"units": "unitless", "valid": (0, 10), "shape": (), "dynamic": True},
"beta": {"units": "unitless", "valid": (0, 2), "shape": (), "dynamic": True},
"I0": {"units": "flux/arcsec^2", "valid": (0.0, None), "shape": (), "dynamic": True},
"rout": {"units": "arcsec", "valid": (0.0, None), "dynamic": True},
"alpha": {"units": "unitless", "valid": (0, 10), "dynamic": True},
"beta": {"units": "unitless", "valid": (0, 2), "dynamic": True},
"I0": {"units": "flux/arcsec^2", "valid": (0.0, None), "dynamic": True},
}

@torch.no_grad()
Expand Down
1 change: 1 addition & 0 deletions astrophot/models/model_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def __init__(self, *args, psf=None, psf_convolve: bool = False, **kwargs):
super().__init__(*args, **kwargs)
self.psf = psf
self.psf_convolve = psf_convolve
self.saveattrs.add("window.extent")

@property
def psf(self):
Expand Down
12 changes: 6 additions & 6 deletions docs/source/tutorials/AdvancedPSFModels.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"source": [
"# Now we initialize on the image\n",
"psf_model = ap.Model(\n",
" name=\"init psf\",\n",
" name=\"init_psf\",\n",
" model_type=\"moffat psf model\",\n",
" target=psf_target,\n",
")\n",
Expand Down Expand Up @@ -134,7 +134,7 @@
" target=psf_target,\n",
")\n",
"psf_group_model = ap.Model(\n",
" name=\"psf group\",\n",
" name=\"psf_group\",\n",
" model_type=\"psf group model\",\n",
" target=psf_target,\n",
" models=[psf_model1, psf_model2],\n",
Expand Down Expand Up @@ -175,7 +175,7 @@
")\n",
"\n",
"true_psf_model = ap.Model(\n",
" name=\"true psf\",\n",
" name=\"true_psf\",\n",
" model_type=\"moffat psf model\",\n",
" target=psf_target,\n",
" n=2,\n",
Expand All @@ -190,7 +190,7 @@
")\n",
"\n",
"true_model = ap.Model(\n",
" name=\"true model\",\n",
" name=\"true_model\",\n",
" model_type=\"sersic galaxy model\",\n",
" target=target,\n",
" center=[50.0, 50.0],\n",
Expand Down Expand Up @@ -227,7 +227,7 @@
"\n",
"# Here we set up a sersic model for the galaxy\n",
"plain_galaxy_model = ap.Model(\n",
" name=\"galaxy model\",\n",
" name=\"galaxy_model\",\n",
" model_type=\"sersic galaxy model\",\n",
" target=target,\n",
")\n",
Expand Down Expand Up @@ -283,7 +283,7 @@
"\n",
"# Here we set up a sersic model for the galaxy\n",
"live_galaxy_model = ap.Model(\n",
" name=\"galaxy model\",\n",
" name=\"galaxy_model\",\n",
" model_type=\"sersic galaxy model\",\n",
" target=target,\n",
" psf_convolve=True,\n",
Expand Down
4 changes: 2 additions & 2 deletions docs/source/tutorials/ConstrainedModels.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@
" psf.Rd = allstars[0].psf.Rd\n",
" allstars.append(\n",
" ap.Model(\n",
" name=f\"star {x} {y}\",\n",
" name=f\"star_{x}_{y}\".replace(\"-\", \"n\"),\n",
" model_type=\"point model\",\n",
" center=[x, y],\n",
" flux=1,\n",
Expand All @@ -211,7 +211,7 @@
"# A group model holds all the stars together\n",
"sky = ap.Model(name=\"sky\", model_type=\"flat sky model\", I=1e-5, target=target)\n",
"MODEL = ap.Model(\n",
" name=\"spatial PSF\",\n",
" name=\"spatial_PSF\",\n",
" model_type=\"group model\",\n",
" models=[sky] + allstars,\n",
" target=target,\n",
Expand Down
4 changes: 2 additions & 2 deletions docs/source/tutorials/CustomModels.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
"outputs": [],
"source": [
"my_model = My_Sersic( # notice we are now using the custom class\n",
" name=\"wow I made a model\",\n",
" name=\"wow_I_made_a_model\",\n",
" target=target, # now the model knows what its trying to match\n",
" # note we have to give initial values for our new parameters. AstroPhot doesn't know how to auto-initialize them because they are custom\n",
" my_n=1.0,\n",
Expand Down Expand Up @@ -249,7 +249,7 @@
"outputs": [],
"source": [
"my_super_model = ap.Model(\n",
" name=\"goodness I made another one\",\n",
" name=\"goodness_I_made_another_one\",\n",
" model_type=\"super mysersic galaxy model\", # this is the type we defined above\n",
" target=target,\n",
")\n",
Expand Down
2 changes: 1 addition & 1 deletion docs/source/tutorials/FittingMethods.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
" for i, params in enumerate(sersic_params):\n",
" model_list.append(\n",
" ap.Model(\n",
" name=f\"sersic {i}\",\n",
" name=f\"sersic_{i}\",\n",
" model_type=\"sersic galaxy model\",\n",
" target=target,\n",
" center=[params[0], params[1]],\n",
Expand Down
4 changes: 2 additions & 2 deletions docs/source/tutorials/GettingStarted.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
"source": [
"# This model now has a target that it will attempt to match\n",
"model2 = ap.Model(\n",
" name=\"model with target\",\n",
" name=\"model_with_target\",\n",
" model_type=\"sersic galaxy model\",\n",
" target=target,\n",
")\n",
Expand Down Expand Up @@ -330,7 +330,7 @@
"# here we make a sersic model that can only have q and n in a narrow range\n",
"# Also, we give PA and initial value and lock that so it does not change during fitting\n",
"constrained_param_model = ap.Model(\n",
" name=\"constrained parameters\",\n",
" name=\"constrained_parameters\",\n",
" model_type=\"sersic galaxy model\",\n",
" q={\"valid\": (0.4, 0.6)},\n",
" n={\"valid\": (2, 3)},\n",
Expand Down
4 changes: 2 additions & 2 deletions docs/source/tutorials/GettingStartedJAX.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
"source": [
"# This model now has a target that it will attempt to match\n",
"model2 = ap.Model(\n",
" name=\"model with target\",\n",
" name=\"model_with_target\",\n",
" model_type=\"sersic galaxy model\",\n",
" target=target,\n",
")\n",
Expand Down Expand Up @@ -351,7 +351,7 @@
"# here we make a sersic model that can only have q and n in a narrow range\n",
"# Also, we give PA and initial value and lock that so it does not change during fitting\n",
"constrained_param_model = ap.Model(\n",
" name=\"constrained parameters\",\n",
" name=\"constrained_parameters\",\n",
" model_type=\"sersic galaxy model\",\n",
" q={\"valid\": (0.4, 0.6)},\n",
" n={\"valid\": (2, 3)},\n",
Expand Down
4 changes: 2 additions & 2 deletions docs/source/tutorials/GroupModels.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
"for win in windows:\n",
" seg_models.append(\n",
" ap.Model(\n",
" name=f\"object {win:02d}\",\n",
" name=f\"object_{win:02d}\",\n",
" window=windows[win],\n",
" model_type=\"sersic galaxy model\",\n",
" target=target,\n",
Expand All @@ -131,7 +131,7 @@
" )\n",
" )\n",
"sky = ap.Model(\n",
" name=f\"sky level\",\n",
" name=f\"sky_level\",\n",
" model_type=\"flat sky model\",\n",
" target=target,\n",
" I={\"valid\": (0, None)},\n",
Expand Down
16 changes: 8 additions & 8 deletions docs/source/tutorials/ImageAlignment.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,17 @@
"# fmt: off\n",
"# r-band model\n",
"psfr = ap.Model(name=\"psfr\", model_type=\"moffat psf model\", n=2, Rd=1.0, target=target_r.psf_image(data=np.zeros((51, 51))))\n",
"star1r = ap.Model(name=\"star1-r\", model_type=\"point model\", window=[0, 60, 80, 135], center=[12, 9], psf=psfr, target=target_r)\n",
"star2r = ap.Model(name=\"star2-r\", model_type=\"point model\", window=[40, 90, 20, 70], center=[3, -7], psf=psfr, target=target_r)\n",
"star3r = ap.Model(name=\"star3-r\", model_type=\"point model\", window=[109, 150, 40, 90], center=[-15, -3], psf=psfr, target=target_r)\n",
"modelr = ap.Model(name=\"model-r\", model_type=\"group model\", models=[star1r, star2r, star3r], target=target_r)\n",
"star1r = ap.Model(name=\"star1_r\", model_type=\"point model\", window=[0, 60, 80, 135], center=[12, 9], psf=psfr, target=target_r)\n",
"star2r = ap.Model(name=\"star2_r\", model_type=\"point model\", window=[40, 90, 20, 70], center=[3, -7], psf=psfr, target=target_r)\n",
"star3r = ap.Model(name=\"star3_r\", model_type=\"point model\", window=[109, 150, 40, 90], center=[-15, -3], psf=psfr, target=target_r)\n",
"modelr = ap.Model(name=\"model_r\", model_type=\"group model\", models=[star1r, star2r, star3r], target=target_r)\n",
"\n",
"# g-band model\n",
"psfg = ap.Model(name=\"psfg\", model_type=\"moffat psf model\", n=2, Rd=1.0, target=target_g.psf_image(data=np.zeros((51, 51))))\n",
"star1g = ap.Model(name=\"star1-g\", model_type=\"point model\", window=[0, 60, 80, 135], center=star1r.center, psf=psfg, target=target_g)\n",
"star2g = ap.Model(name=\"star2-g\", model_type=\"point model\", window=[40, 90, 20, 70], center=star2r.center, psf=psfg, target=target_g)\n",
"star3g = ap.Model(name=\"star3-g\", model_type=\"point model\", window=[109, 150, 40, 90], center=star3r.center, psf=psfg, target=target_g)\n",
"modelg = ap.Model(name=\"model-g\", model_type=\"group model\", models=[star1g, star2g, star3g], target=target_g)\n",
"star1g = ap.Model(name=\"star1_g\", model_type=\"point model\", window=[0, 60, 80, 135], center=star1r.center, psf=psfg, target=target_g)\n",
"star2g = ap.Model(name=\"star2_g\", model_type=\"point model\", window=[40, 90, 20, 70], center=star2r.center, psf=psfg, target=target_g)\n",
"star3g = ap.Model(name=\"star3_g\", model_type=\"point model\", window=[109, 150, 40, 90], center=star3r.center, psf=psfg, target=target_g)\n",
"modelg = ap.Model(name=\"model_g\", model_type=\"group model\", models=[star1g, star2g, star3g], target=target_g)\n",
"\n",
"# total model\n",
"target_full = ap.TargetImageList([target_r, target_g])\n",
Expand Down
Loading
Loading