Skip to content

Commit

Permalink
refactoring (#27)
Browse files Browse the repository at this point in the history
* refactoring
* error if no gas or stars were provided
  • Loading branch information
rieder authored Apr 30, 2024
1 parent 2f695cc commit 5fba70e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 18 deletions.
25 changes: 21 additions & 4 deletions bin/fresco.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
lines.
"""

import sys
import os
import argparse

Expand Down Expand Up @@ -165,16 +166,16 @@ def fresco_argument_parser(parser=None):
help=(
"PSF type. Looks for a .fits file of the given name, uses this if "
"it exists.\n"
'Otherwise, "hubble", "wfc3", "wfpc2" and "gaussian" are valid '
"options."
"Otherwise, 'hubble', 'wfc3', 'wfpc2', 'gaussian' and a local PSF file "
"are valid options."
),
)
parser.add_argument(
"--sigma",
dest="psf_sigma",
default=1.0,
type=float,
help="PSF sigma (if PSF type is gaussian)",
help="PSF sigma (only used if PSF type is gaussian)",
)
parser.add_argument(
"--fl",
Expand Down Expand Up @@ -257,7 +258,7 @@ def main():
psf_type = psf_type.lower()
if psf_type not in ["hubble", "gaussian"]:
print(f"Invalid PSF type or file does not exist: {psf_type}")
exit()
sys.exit()
psf_sigma = args.psf_sigma
age = args.age
image_width = args.width
Expand All @@ -272,6 +273,22 @@ def main():
z_offset = args.z_offset
extinction = args.calculate_extinction

# sanity check
if starsfilename is None:
nostars = True
elif not os.path.exists(starsfilename):
nostars = True
else:
nostars = False
if gasfilename is None:
nogas = True
elif not os.path.exists(gasfilename):
nogas = True
else:
nogas = False
if nostars and nogas:
raise FileNotFoundError("Need at least one of a stars or gas file")

# Derived settings

image_size = [pixels, pixels]
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

install_requires = [
"wheel>=0.32",
"amuse-framework>=2022.6.0",
"amuse-framework>=2024.4.0",
"scipy",
"matplotlib",
"astropy",
Expand Down Expand Up @@ -47,6 +47,7 @@
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Topic :: Scientific/Engineering :: Astronomy",
]

Expand All @@ -73,7 +74,7 @@
classifiers=classifiers,
url=url,
project_urls={
"Bug Tracker": "https://github.com/rieder/fresco/issues",
"Bug Tracker": "https://github.com/rieder/amuse-fresco/issues",
},
author_email=author_email,
author=author,
Expand Down
17 changes: 6 additions & 11 deletions src/amuse/plot/fresco/fieldstars.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
# -*- coding: utf-8 -*-
from __future__ import (
print_function,
division,
)
import numpy as np
from amuse.datamodel import Particles
from amuse.units import units
from amuse.ic.salpeter import new_salpeter_mass_distribution


def new_field_stars(
N,
number_of_stars,
width=10 | units.parsec,
height=10 | units.parsec,
depth=100 | units.parsec,
Expand All @@ -19,11 +14,11 @@ def new_field_stars(
seed=1701,
):
np.random.seed(seed)
stars = Particles(N)
stars.x = (np.random.random(N) - 0.5) * width
stars.y = (np.random.random(N) - 0.5) * height
stars.z = (np.random.random(N) - 0.02) * depth
stars = Particles(number_of_stars)
stars.x = (np.random.random(number_of_stars) - 0.5) * width
stars.y = (np.random.random(number_of_stars) - 0.5) * height
stars.z = (np.random.random(number_of_stars) - 0.02) * depth
if massdistribution == "salpeter":
stars.mass = new_salpeter_mass_distribution(N)
stars.mass = new_salpeter_mass_distribution(number_of_stars)

return stars
1 change: 0 additions & 1 deletion src/amuse/plot/fresco/ubvi.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ def rgb_frame(
verbose=False,
visualisation_mode="visual",
):

if gas is None:
gas = Particles()

Expand Down

0 comments on commit 5fba70e

Please sign in to comment.