Skip to content

Commit

Permalink
Migrates setup to use pyproject
Browse files Browse the repository at this point in the history
  • Loading branch information
darothen committed Sep 26, 2023
1 parent 7bce4d0 commit 20c63ce
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 77 deletions.
53 changes: 53 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]" },
]
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"
3 changes: 2 additions & 1 deletion pyrcel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Empty file added pyrcel/scripts/__init__.py
Empty file.
75 changes: 44 additions & 31 deletions scripts/run_parcel → pyrcel/scripts/run_parcel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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)
Expand All @@ -96,4 +105,8 @@
sys.exit(0)

# Succesful completion
print("Done!")
print("Done!")


if __name__ == "__main__":
run_parcel()
90 changes: 45 additions & 45 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="[email protected]",
maintainer="Daniel Rothenberg",
maintainer_email="[email protected]",
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="[email protected]",
# maintainer="Daniel Rothenberg",
# maintainer_email="[email protected]",
# 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",
# ],
)

0 comments on commit 20c63ce

Please sign in to comment.