From 5fba70efe0e672a01842472f11fc520faaef8b9f Mon Sep 17 00:00:00 2001 From: Steven Rieder Date: Tue, 30 Apr 2024 16:29:12 -0400 Subject: [PATCH] refactoring (#27) * refactoring * error if no gas or stars were provided --- bin/fresco.py | 25 +++++++++++++++++++++---- setup.py | 5 +++-- src/amuse/plot/fresco/fieldstars.py | 17 ++++++----------- src/amuse/plot/fresco/ubvi.py | 1 - 4 files changed, 30 insertions(+), 18 deletions(-) diff --git a/bin/fresco.py b/bin/fresco.py index 35098a0..2190391 100755 --- a/bin/fresco.py +++ b/bin/fresco.py @@ -6,6 +6,7 @@ lines. """ +import sys import os import argparse @@ -165,8 +166,8 @@ 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( @@ -174,7 +175,7 @@ def fresco_argument_parser(parser=None): 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", @@ -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 @@ -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] diff --git a/setup.py b/setup.py index 5877171..52aa73a 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ install_requires = [ "wheel>=0.32", - "amuse-framework>=2022.6.0", + "amuse-framework>=2024.4.0", "scipy", "matplotlib", "astropy", @@ -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", ] @@ -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, diff --git a/src/amuse/plot/fresco/fieldstars.py b/src/amuse/plot/fresco/fieldstars.py index df76b95..1b7d155 100644 --- a/src/amuse/plot/fresco/fieldstars.py +++ b/src/amuse/plot/fresco/fieldstars.py @@ -1,8 +1,3 @@ -# -*- coding: utf-8 -*- -from __future__ import ( - print_function, - division, -) import numpy as np from amuse.datamodel import Particles from amuse.units import units @@ -10,7 +5,7 @@ def new_field_stars( - N, + number_of_stars, width=10 | units.parsec, height=10 | units.parsec, depth=100 | units.parsec, @@ -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 diff --git a/src/amuse/plot/fresco/ubvi.py b/src/amuse/plot/fresco/ubvi.py index 3a057fd..f3916c7 100644 --- a/src/amuse/plot/fresco/ubvi.py +++ b/src/amuse/plot/fresco/ubvi.py @@ -135,7 +135,6 @@ def rgb_frame( verbose=False, visualisation_mode="visual", ): - if gas is None: gas = Particles()