From d10ac848c4b10cb6024efd8ae22cb3398af2de5e Mon Sep 17 00:00:00 2001 From: Steven Rieder Date: Tue, 30 Apr 2024 15:56:44 -0400 Subject: [PATCH 1/2] refactoring --- setup.py | 43 ++++++++++++++--------------- src/amuse/plot/fresco/fieldstars.py | 31 +++++++++------------ src/amuse/plot/fresco/ubvi.py | 1 - 3 files changed, 34 insertions(+), 41 deletions(-) diff --git a/setup.py b/setup.py index 8bd2c4c..52aa73a 100644 --- a/setup.py +++ b/setup.py @@ -2,22 +2,22 @@ from setuptools import setup -name = 'amuse-fresco' -author = 'Steven Rieder and Inti Pelupessy' -author_email = 'steven+fresco@rieder.nl' +name = "amuse-fresco" +author = "Steven Rieder and Inti Pelupessy" +author_email = "steven+fresco@rieder.nl" license_ = "Apache License 2.0" -url = 'https://github.com/rieder/fresco' +url = "https://github.com/rieder/fresco" install_requires = [ - 'wheel>=0.32', - 'amuse-framework>=2022.6.0', - 'scipy', - 'matplotlib', - 'astropy', + "wheel>=0.32", + "amuse-framework>=2024.4.0", + "scipy", + "matplotlib", + "astropy", ] setup_requires = [] -description = 'Make a realistic visualisation of a star cluster' +description = "Make a realistic visualisation of a star cluster" with open("README.md", "r", encoding="utf-8") as fh: long_description = fh.read() long_description_content_type = "text/markdown" @@ -26,16 +26,11 @@ all_data_files = [] -packages = [ - 'amuse.plot.fresco' -] +packages = ["amuse.plot.fresco"] -package_dir = { - 'amuse.plot.fresco': 'src/amuse/plot/fresco' -} +package_dir = {"amuse.plot.fresco": "src/amuse/plot/fresco"} -package_data = { -} +package_data = {} classifiers = [ # Maturity of amuse-fresco @@ -52,15 +47,19 @@ "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", - 'Topic :: Scientific/Engineering :: Astronomy', + "Programming Language :: Python :: 3.11", + "Topic :: Scientific/Engineering :: Astronomy", ] try: from src.amuse.plot.fresco.version import version + use_scm_version = False except ImportError: version = False - setup_requires += ['setuptools_scm',] + setup_requires += [ + "setuptools_scm", + ] use_scm_version = { "root": ".", "relative_to": __file__, @@ -75,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, @@ -90,6 +89,6 @@ package_data=package_data, data_files=all_data_files, include_package_data=True, - python_requires='>=3.7, <4', + python_requires=">=3.7, <4", scripts=["bin/fresco.py"], ) diff --git a/src/amuse/plot/fresco/fieldstars.py b/src/amuse/plot/fresco/fieldstars.py index a7dbc31..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,20 +5,20 @@ def new_field_stars( - N, - width=10 | units.parsec, - height=10 | units.parsec, - depth=100 | units.parsec, - massdistribution="salpeter", - agespread=3 | units.Gyr, - seed=1701, - ): + number_of_stars, + width=10 | units.parsec, + height=10 | units.parsec, + depth=100 | units.parsec, + massdistribution="salpeter", + agespread=3 | units.Gyr, + 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() From 955f3ff48b73a9d9e0d306fa663ffb0bb31231b9 Mon Sep 17 00:00:00 2001 From: Steven Rieder Date: Tue, 30 Apr 2024 16:26:37 -0400 Subject: [PATCH 2/2] error if no gas or stars were provided --- bin/fresco.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 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]