Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use declarative setup for SnapPy #101

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions install_usermodule_r8.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,9 @@ install_snappy() {
)

(
export VERSION="$SNAPPY_VERSION"
# Pip install messes up shebang: https://github.com/pypa/setuptools/issues/494
# pip install ./utils/SnapPy/
cd utils/SnapPy || exit 2
python3 setup.py install
pip install ./utils/SnapPy
)
}

Expand All @@ -70,14 +68,8 @@ install_bsnap() {
main() {
if [ -z "$1" ]; then
MODULE_VERSION="TEST"
SNAPPY_VERSION="0.0.0.dev0"
else
MODULE_VERSION="$1"
if [ -z "$2" ]; then
SNAPPY_VERSION="$MODULE_VERSION"
else
SNAPPY_VERSION="$2"
fi
fi

MODULE_PREFIX=/modules/rhel8/user-apps/fou-modules/SnapPy/"$MODULE_VERSION"/
Expand Down
3 changes: 1 addition & 2 deletions src/naccident/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ clean: clean_links
distclean: clean
rm -f bsnap_naccident create_naccident_input create_naccident_output

install: bsnap_naccident ../../utils/SnapPy/Snappy/AddToa.py
install: bsnap_naccident
install bsnap_naccident $(BINDIR)/
install ../../utils/SnapPy/Snappy/AddToa.py $(BINDIR)/snapAddToa


.PHONY: all clean distclean install
6 changes: 5 additions & 1 deletion utils/SnapPy/Snappy/AddToa.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def add_toa_to_nc(nc: netCDF4.Dataset):
totalVar[:] = total


if __name__ == "__main__":
def main():
import argparse

parser = argparse.ArgumentParser()
Expand All @@ -103,3 +103,7 @@ def add_toa_to_nc(nc: netCDF4.Dataset):

with netCDF4.Dataset(args.snapNc, "a") as nc:
add_toa_to_nc(nc)


if __name__ == "__main__":
main()
4 changes: 2 additions & 2 deletions utils/SnapPy/debian.bionic/control
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ Source: snap-py
Maintainer: Heiko Klein <[email protected]>
Section: python
Priority: optional
Build-Depends: python3-all, python3-netcdf4, debhelper (>= 7.4.3)
Build-Depends: python3-all, python3-setuptools, debhelper (>= 7.4.3)
Standards-Version: 3.9.7


Package: snap-py
Architecture: all
Depends: ${misc:Depends}, ${python3:Depends}, bsnap (>= 2.1.2), python3-pyqt5, python3-pyqt5.qtwebkit
Depends: ${misc:Depends}, ${python3:Depends}, bsnap (>= 2.1.2), python3-pyqt5, python3-pyqt5.qtwebkit, python3-netcdf4, python3-numpy
Description: SNAP GUI in python


4 changes: 2 additions & 2 deletions utils/SnapPy/debian.bionic/rules
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ override_dh_auto_build:


override_dh_auto_install:
python3 setup.py install --force --root=debian/snap-py --no-compile -O0 --install-layout=deb
python3 setup.py install --force --root=debian/snap-py --no-compile -O0 --install-layout=deb --prefix=/usr



override_dh_python2:
echo "omit: dh_python2 --no-guessing-versions"
dh_python2 --no-guessing-versions


45 changes: 45 additions & 0 deletions utils/SnapPy/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
[metadata]
name = Snappy
version = 2.3.0
description = SNAP utilities in python
url = https://gitlab.met.no/emep/snap
author = Heiko Klein
author_email = [email protected]
license = GPL-3.0-only

[options]
zip_safe = False
include_package_data = True
packages = find:
setup_requires =
setuptools
install_requires =
netCDF4
numpy

[options.package_data]
Snappy =
resources/*
Snappy.EEMEP =
resources/*

[options.entry_points]
gui_scripts =
snapPy = snapscripts.snapPy:main
console_scripts =
snap4rimsterm = snapscripts.snap4rimsterm:main
snapAddToa = snappy.AddToa:main
snapCombineInverse = snapscripts.snapCombineInverse:main
snapNc2grib = snapscripts.snapNc2grib:main
snapRunnerNpps = snapscripts.snapRunnerNpps:main
snapRunnerNpp = snapscripts.snapRunnerNpp:main
eemepModelRunner = snapscripts.eemepModelRunner:main
snapRemoteRunner = snapscripts.snapRemoteRunner:main
snapEnsPlot = snapscripts.snapEnsPlot:main


[options.extras_require]
gui =
cartopy
# PyQt5
# PyQtWebKit
48 changes: 3 additions & 45 deletions utils/SnapPy/setup.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,4 @@
#!/usr/bin/env python3
#
# SNAP: Servere Nuclear Accident Programme
# Copyright (C) 1992-2017 Norwegian Meteorological Institute
#
# This file is part of SNAP. SNAP is free software: you can
# redistribute it and/or modify it under the terms of the
# GNU General Public License as published by the
# Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
#! /usr/bin/env python3
from setuptools import setup

from distutils.core import setup
import os

version = os.getenv("VERSION", "0.5")

setup(
name="Snappy",
version=version,
description="SNAP GUI in python",
author="Heiko Klein",
author_email="[email protected]",
url="https://gitlab.met.no/emep/snap",
packages=["Snappy", "Snappy.EEMEP", "METNO"],
package_dir={"Snappy": "Snappy", "Snappy.EEMEP": "Snappy/EEMEP"},
package_data={"Snappy": ["resources/*"], "Snappy.EEMEP": ["resources/*"]},
scripts=[
"snapPy",
"snap4rimsterm",
"snapCombineInverse",
"snapNc2grib.py",
"snapRunnerNpps",
"snapRunnerNpp",
"eemepModelRunner",
"snapRemoteRunner.py",
],
)
setup()
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def __init__(self, directory, hpc, directory2, dryrun=False):



if __name__ == '__main__':
def main():
os.umask(0)
import argparse
parser = argparse.ArgumentParser(description="Search for volcano.xml/npp.xml files in the top-level directory, take the newest one and run the model on a HPC machine")
Expand All @@ -197,3 +197,7 @@ def __init__(self, directory, hpc, directory2, dryrun=False):
delete_oldfiles(args.dir, args.cleanup)
if dir2 and dirIsWritable(dir2):
delete_oldfiles(dir2, args.cleanup)


if __name__ == '__main__':
main()
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def snap4rimsterm(rimsterm, argosrequest, basedir, ident, met_model, bitmapCompr



if __name__ == "__main__":
def main():
os.umask(0) # make sure files can be deleted later
import argparse
parser = argparse.ArgumentParser(description="run snap from a rimsterm.xml file and convert to grib-files named ident_conc, ident_depo ident_wetd ident_dose ident_tofa")
Expand All @@ -261,3 +261,7 @@ def snap4rimsterm(rimsterm, argosrequest, basedir, ident, met_model, bitmapCompr
snap4rimsterm(args.rimsterm, args.argosrequest, args.dir, args.ident, args.metmodel, bitmapCompress=args.bitmapCompress)
else:
print("need rimsterm option", file=sys.stderr)


if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
Expand Up @@ -135,21 +135,25 @@ def initializeNc(ncFile, outNcFile, isotope):



parser = argparse.ArgumentParser()
parser.add_argument("-i", required=True, action="append", help="one or more snap.nc file from an inverse run to a measurement")
parser.add_argument("-n", action="append", help="zero or more snap.nc file from an inverse run to a stations without measurement")
parser.add_argument("-o", required=True, help="output nc file")
parser.add_argument("-I", default="I131", help="isotope (default: I131)")
args = parser.parse_args()

(times, out_nc, conc, prob) = initializeNc(args.i[0], args.o, args.I)
# remove first input
args.i.pop(0)
for i in args.i:
(conc, prob) = addFile(i, args.I, times, conc, prob)

if args.n:
for i in args.n:
(conc, prob) = addFile(i, args.I, times, conc, prob, False)

finishOutput(out_nc, args.I, times, conc, prob)
def main():
parser = argparse.ArgumentParser()
parser.add_argument("-i", required=True, action="append", help="one or more snap.nc file from an inverse run to a measurement")
parser.add_argument("-n", action="append", help="zero or more snap.nc file from an inverse run to a stations without measurement")
parser.add_argument("-o", required=True, help="output nc file")
parser.add_argument("-I", default="I131", help="isotope (default: I131)")
args = parser.parse_args()

(times, out_nc, conc, prob) = initializeNc(args.i[0], args.o, args.I)
# remove first input
args.i.pop(0)
for i in args.i:
(conc, prob) = addFile(i, args.I, times, conc, prob)

if args.n:
for i in args.n:
(conc, prob) = addFile(i, args.I, times, conc, prob, False)

finishOutput(out_nc, args.I, times, conc, prob)

if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@
import sys

import numpy as np
import logging

# suppress some warnings
warnings.filterwarnings("ignore", category=UserWarning,
message="Warning: 'partition' will ignore the 'mask' of the MaskedArray.")
# shapefile.py uses root logger :-( and warns a lot about GSHHS
import logging
logging.root.setLevel(logging.ERROR)



def plotMap(data, x, y, ax, title="", title_loc="center", clevs=[10,100,300,1000,3000,10000,30000,100000, 300000, 10000000], colors=None, extend='max'):
ax.add_feature(cartopy.feature.GSHHSFeature(scale='low', facecolor='none', edgecolor='whitesmoke', linewidth=.2), zorder=100)
ax.add_feature(cartopy.feature.BORDERS, edgecolor="lightgray", linewidth=.5, zorder=100)
Expand Down Expand Up @@ -266,9 +268,8 @@ def snapens(ncfiles, hour, outfile):
fig.subplots_adjust(hspace=0.12, wspace=0.01)
fig.savefig(outfile, bbox_inches='tight')



if __name__ == "__main__":
def main():
os.umask(0o002)

parser = argparse.ArgumentParser(
Expand All @@ -281,4 +282,8 @@ def snapens(ncfiles, hour, outfile):
parser.add_argument('SNAPNC', help="snap*.nc filenames", nargs='+')
args = parser.parse_args()

snapens(args.SNAPNC, args.hour, args.out)
snapens(args.SNAPNC, args.hour, args.out)


if __name__ == "main":
main()
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def getIsotopesFromFile(filename):
print(f"converting isotopes: {', '.join(isotop_names)}", file=sys.stderr)
return isotopes

if __name__ == "__main__":
def main():
parser = argparse.ArgumentParser(description="convert a snap.nc output-file to grib, should be run after snapAddToa")
parser.add_argument("--nc", help="snap.nc filename", required=True)
parser.add_argument("--ident", help="output-file identifier", required=True)
Expand All @@ -37,3 +37,6 @@ def getIsotopesFromFile(filename):
bitmapCompress= True
dirname = os.path.dirname(ncfile)
snapNc_convert_to_grib(ncfile, dirname, ident, isotopes, bitmapCompress=bitmapCompress)

if __name__ == "__main__":
main()
5 changes: 4 additions & 1 deletion utils/SnapPy/snapPy → utils/SnapPy/snapscripts/snapPy.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import Snappy.EEMEP.Resources
import Snappy.EEMEP.Controller

if __name__ == "__main__":
def main():
app = QtWidgets.QApplication(sys.argv)
tabs = QtWidgets.QTabWidget()
snap = SnapController()
Expand All @@ -42,3 +42,6 @@


sys.exit(app.exec_())

if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ def _check_and_unpack_new_files(self):
self.ssh.syscall("rm", delete_upload_files, 30)


if __name__ == "__main__":
def main():
os.umask(0o002)
import argparse

Expand Down Expand Up @@ -482,3 +482,7 @@ def _check_and_unpack_new_files(self):
delete_oldfiles(args.dir, args.cleanup)
if dir2 and dirIsWritable(dir2):
delete_oldfiles(dir2, args.cleanup)


if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ def runsnap(npp, met_model, outdir, release_dt, runtime, plot_from_file=None):



if __name__ == "__main__":
def main():
os.umask(0o002)

parser = argparse.ArgumentParser(
Expand Down Expand Up @@ -373,3 +373,7 @@ def runsnap(npp, met_model, outdir, release_dt, runtime, plot_from_file=None):
if (args.store):
os.environ["STORE"] = args.store
runsnap(outdir=args.outdir, met_model=args.metmodel, runtime=int(args.runtime), npp=args.npp, release_dt=release_dt, plot_from_file=plot_from_file)


if __name__ == "__main__":
main()
Loading