diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..29f4721 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,53 @@ +[build-system] +requires = ["setuptools", "setuptools-scm"] +build-backend = "setuptools.build_meta" + +[project] +description = "pyrcel: 0D adiabatic cloud parcel model" +name = "pyrcel" +authors = [ + { name = "Daniel Rothenberg", email = "daniel@danielrothenberg.com" }, +] +readme = "README.md" +requires-python = ">=3.8" +license = { file = "LICENSE.md" } +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Environment :: Console", + "Intended Audience :: Science/Research", + "License :: OSI Approved :: BSD License", + "Natural Language :: English", + "Operating System :: Unix", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Topic :: Scientific/Engineering :: Atmospheric Science", +] +dependencies = [ + "numba", + "numpy", + "pandas", + "pyyaml", + "scipy", + "setuptools", + "setuptools-scm", + "xarray", +] +dynamic = ["version"] + +[project.urls] +Documentation = "https://pyrcel.readthedocs.io/en/latest/" +Repository = "https://github.com/darothen/pyrcel" + +[tools.setuptools] +packages = ["pyrcel"] + +[tool.setuptools.packages] +find = {namespaces = false} + +[project.scripts] +run_parcel = "pyrcel.scripts.run_parcel:run_parcel" + +[tool.setuptools_scm] +version_file = "pyrcel/version.py" \ No newline at end of file diff --git a/pyrcel/__init__.py b/pyrcel/__init__.py index 87d739c..03357bd 100644 --- a/pyrcel/__init__.py +++ b/pyrcel/__init__.py @@ -9,8 +9,9 @@ """ from importlib.metadata import version as _version + try: - __version__ = _version('pyrcel') + __version__ = _version("pyrcel") except Exception: # This is a local copy, or a copy that was not installed via setuptools __version__ = "local" diff --git a/pyrcel/scripts/__init__.py b/pyrcel/scripts/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/scripts/run_parcel b/pyrcel/scripts/run_parcel.py similarity index 50% rename from scripts/run_parcel rename to pyrcel/scripts/run_parcel.py index 48bd85f..4cde8f6 100755 --- a/scripts/run_parcel +++ b/pyrcel/scripts/run_parcel.py @@ -12,17 +12,22 @@ import pyrcel as pm import pyrcel.util -parser = ArgumentParser(description=__doc__, - formatter_class=RawDescriptionHelpFormatter) -parser.add_argument("namelist", type=str, metavar="config.yml", - help="YAML namelist controlling simulation configuration") +parser = ArgumentParser( + description=__doc__, formatter_class=RawDescriptionHelpFormatter +) +parser.add_argument( + "namelist", + type=str, + metavar="config.yml", + help="YAML namelist controlling simulation configuration", +) DIST_MAP = { - 'lognormal': pm.Lognorm, + "lognormal": pm.Lognorm, } -if __name__ == "__main__": +def run_parcel(): # Read command-line arguments args = parser.parse_args() @@ -38,56 +43,60 @@ # Create the aerosol aerosol_modes = [] print("Constructing aerosol modes") - for i, aerosol_params in enumerate(y['initial_aerosol'], start=1): + for i, aerosol_params in enumerate(y["initial_aerosol"], start=1): ap = aerosol_params - dist = DIST_MAP[ap['distribution']](**ap['distribution_args']) + dist = DIST_MAP[ap["distribution"]](**ap["distribution_args"]) - aer = pm.AerosolSpecies(ap['name'], dist, - kappa=ap['kappa'], bins=ap['bins']) + aer = pm.AerosolSpecies(ap["name"], dist, kappa=ap["kappa"], bins=ap["bins"]) print(" {:2d})".format(i), aer) aerosol_modes.append(aer) # Set up the model - ic = y['initial_conditions'] + ic = y["initial_conditions"] print("Initializing model") try: - model = pm.ParcelModel(aerosol_modes, - V=ic['updraft_speed'], - T0=ic['temperature'], - S0=-1.*(1.0 - ic['relative_humidity']), - P0=ic['pressure'], - console=True, - truncate_aerosols=True) + model = pm.ParcelModel( + aerosol_modes, + V=ic["updraft_speed"], + T0=ic["temperature"], + S0=-1.0 * (1.0 - ic["relative_humidity"]), + P0=ic["pressure"], + console=True, + truncate_aerosols=True, + ) except pyrcel.util.ParcelModelError: print("Something went wrong setting up the model") sys.exit(0) # Run the model - mc = y['model_control'] + mc = y["model_control"] print("Beginning simulation") try: - par_out, aer_out = model.run(max_steps=2000, solver='cvode', - output_fmt='dataframes', - # terminate=True, - # terminate_depth=10., - **mc) + par_out, aer_out = model.run( + max_steps=2000, + solver="cvode", + output_fmt="dataframes", + # terminate=True, + # terminate_depth=10., + **mc, + ) except pyrcel.util.ParcelModelError: print("Something went wrong during model run") sys.exit(0) # Output - ec = y['experiment_control'] + ec = y["experiment_control"] - Smax = par_out['S'].max() - T_fin = par_out['T'].iloc[-1] + Smax = par_out["S"].max() + T_fin = par_out["T"].iloc[-1] # Make output directory if it doesn't exist - if not os.path.exists(ec['output_dir']): - os.makedirs(ec['output_dir']) + if not os.path.exists(ec["output_dir"]): + os.makedirs(ec["output_dir"]) - out_file = os.path.join(ec['output_dir'], ec['name']) + ".nc" + out_file = os.path.join(ec["output_dir"], ec["name"]) + ".nc" try: print("Trying to save output to {}".format(out_file)) pm.output.write_parcel_output(out_file, parcel=model) @@ -96,4 +105,8 @@ sys.exit(0) # Succesful completion - print("Done!") \ No newline at end of file + print("Done!") + + +if __name__ == "__main__": + run_parcel() diff --git a/setup.py b/setup.py index f2f6507..1b5f5a9 100644 --- a/setup.py +++ b/setup.py @@ -41,51 +41,51 @@ def _write_version_file(): # Write version and install -_write_version_file() +# _write_version_file() setup( - name="pyrcel", - author="Daniel Rothenberg", - author_email="daniel@danielrothenberg.com", - maintainer="Daniel Rothenberg", - maintainer_email="daniel@danielrothenberg.com", - description="pyrcel: 0D adiabatic cloud parcel model", - long_description=""" - This code implements a relatively simple, adiabatic cloud parcel model for studying aerosol - activation. It allows the user to peform and iterate parcel model experiments in a simple - fashion through the use of an object-oriented implementation. Furthermore, interfaces for - several numerical solvers are built into the model so that users can choose whatever scheme - they would like to run with the model. - """, - license="New BSD (3-clause)", - url="https://github.com/darothen/pyrcel", - version=VERSION, - download_url="https://github.com/darothen/pyrcel", - # TODO: Update install requirements and corresponding documentation - install_requires=[ - "numba", - "numpy", - "pandas", - "pyyaml", - "scipy", - "setuptools", - "xarray", - ], - packages=["pyrcel"], - package_data={"pyrcel": ["data/std_atm.csv"]}, - scripts=["scripts/run_parcel"], - ext_modules=extensions, - classifiers=[ - "Development Status :: 5 - Production/Stable", - "Environment :: Console", - "Intended Audience :: Science/Research", - "License :: OSI Approved :: BSD License", - "Natural Language :: English", - "Operating System :: Unix", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", - "Topic :: Scientific/Engineering :: Atmospheric Science", - ], +# name="pyrcel", +# author="Daniel Rothenberg", +# author_email="daniel@danielrothenberg.com", +# maintainer="Daniel Rothenberg", +# maintainer_email="daniel@danielrothenberg.com", +# description="pyrcel: 0D adiabatic cloud parcel model", +# long_description=""" +# This code implements a relatively simple, adiabatic cloud parcel model for studying aerosol +# activation. It allows the user to peform and iterate parcel model experiments in a simple +# fashion through the use of an object-oriented implementation. Furthermore, interfaces for +# several numerical solvers are built into the model so that users can choose whatever scheme +# they would like to run with the model. +# """, +# license="New BSD (3-clause)", +# url="https://github.com/darothen/pyrcel", +# version=VERSION, +# download_url="https://github.com/darothen/pyrcel", +# # TODO: Update install requirements and corresponding documentation +# install_requires=[ +# "numba", +# "numpy", +# "pandas", +# "pyyaml", +# "scipy", +# "setuptools", +# "xarray", +# ], +# packages=["pyrcel"], +# package_data={"pyrcel": ["data/std_atm.csv"]}, +# scripts=["scripts/run_parcel"], +# ext_modules=extensions, +# classifiers=[ +# "Development Status :: 5 - Production/Stable", +# "Environment :: Console", +# "Intended Audience :: Science/Research", +# "License :: OSI Approved :: BSD License", +# "Natural Language :: English", +# "Operating System :: Unix", +# "Programming Language :: Python :: 3.8", +# "Programming Language :: Python :: 3.9", +# "Programming Language :: Python :: 3.10", +# "Programming Language :: Python :: 3.11", +# "Topic :: Scientific/Engineering :: Atmospheric Science", +# ], )