Skip to content

Commit

Permalink
updating interface, starting packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
heikoklein committed Jan 17, 2025
1 parent f0b9159 commit 9415b2d
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 30 deletions.
71 changes: 50 additions & 21 deletions utils/SnapPy/Snappy/EEMEP/Controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
@author: heikok
"""

import subprocess
from PyQt5 import QtWidgets
from collections import deque
import datetime
Expand Down Expand Up @@ -78,6 +79,28 @@ def run(self):
traceback.print_exc()


class SnapVolcanoWorker(QThread):
finished = pyqtSignal()

def __init__(self, outputdir, volcanofile):
super().__init__()
self.outputdir = outputdir
self.volcanofile = volcanofile

def run(self):
"""Run the snapVolcano as subprocess command."""

with open(os.path.join(self.outputdir, "snapVolcano.log"), "w") as fh:
process = subprocess.run(
["snapVolcano", self.volcanofile],
stdout=fh,
stderr=fh,
cwd=self.outputdir,
)
process.wait()
self.finished.emit()


class Controller:
"""
Controller for EEMEP Widget. Starts the browserwidget as self.main and connects it to the form handler
Expand Down Expand Up @@ -402,7 +425,7 @@ def run_eemep_query(self, qDict):
cheight = eemep_cheight_max

eruptions = []
eruption = '<eruption start="{start}Z" end="{end}Z" bottom="{bottom:.0f}" top="{top:.0f}" rate="{rate:.0f}" m63="{m63:.2f}"/>'
eruption = '<eruption start="{start}Z" end="{end}Z" bottom="{bottom:.0f}" top="{top:.0f}" rate="{rate:.0f}" m63="{m63:.2f}"/>\n'
eruptions.append(
eruption.format(
start=startDT.isoformat(),
Expand All @@ -421,35 +444,36 @@ def run_eemep_query(self, qDict):
self.lastOutputDir, ModelRunner.VOLCANO_FILENAME
)
self.lastQDict = qDict
sourceTerm = """<?xml version="1.0" encoding="UTF-8"?>
<volcanic_eruption_run run_time_hours="{runTime}" output_directory="{outdir}">
ecModelRun = qDict["ecmodelrun"]
if not ecModelRun == "best":
ecModelRun += "Z"
snapMetModel = qDict["snap_metmodel"]
snapModelRun = qDict["snap_modelrun"]
if snapMetModel == "":
snapsetup = ""
else:
snapsetup = f"""
<!-- optional snap setup -->
<snap_model_setup>
<weather_forecast reference_date="{snapModelRun}" model="{snapMetModel}" />
</snap_model_setup>
"""

self.lastSourceTerm = f"""<?xml version="1.0" encoding="UTF-8"?>
<volcanic_eruption_run run_time_hours="{runTime}" output_directory="{self.lastOutputDir}">
<model_setup use_restart_file="{restart}">
<!-- reference_date might also be best_estimate, e.g. mix latest forecasts -->
<weather_forecast reference_date="{model_run}" model_start_time="{model_start_time}Z"/>
<weather_forecast reference_date="{ecModelRun}" model_start_time="{modelStartDT.isoformat()}Z"/>
</model_setup>
<volcano name="{volcano}" lat="{lat}" lon="{lon}" altitude="{alt:.0f}" />
{snapsetup}
<volcano name="{volcano}" lat="{latf:.3f}" lon="{lonf:.3f}" altitude="{altf:.0f}" />
<eruptions>
<!-- bottom and top of ash-cloud in m above ground -->
<!-- rate in kg/s -->
{eruptions}
{"".join(eruptions)}
</eruptions>
</volcanic_eruption_run>"""
ecModelRun = qDict["ecmodelrun"]
if not ecModelRun == "best":
ecModelRun += "Z"
self.lastSourceTerm = sourceTerm.format(
lat=latf,
lon=lonf,
volcano=volcano,
alt=altf,
outdir=self.lastOutputDir,
restart=restart,
model_run=ecModelRun,
model_start_time=modelStartDT.isoformat(),
eruptions="\n".join(eruptions),
runTime=runTime,
)
debug("output directory: {}".format(self.lastOutputDir))
os.makedirs(self.lastOutputDir, exist_ok=True)

Expand Down Expand Up @@ -483,6 +507,11 @@ def run_eemep_query(self, qDict):
self.model_update.update_log_signal.connect(self.update_log)
self.model_update.start(QThread.LowPriority)

if snapsetup != "":
# start a background snap run on volcano.xml
self.snap_thread = SnapVolcanoWorker(self.lastOutputDir, self.volcano_file)
self.snap_thread.start()


if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
Expand Down
2 changes: 0 additions & 2 deletions utils/SnapPy/Snappy/EEMEP/ModelRunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,6 @@ def __init__(self, path, hpcMachine, npp=False):
self.volcano = NppRun(volcano_path)
else:
self.volcano = VolcanoRun(volcano_path)
if self.volcano.snap_model_setup is not None:
SnapAshRunner(volcano_path)

self.runtag = "eemep_{}".format(os.path.basename(self.volcano.outputDir))
self.hpc_outdir = os.path.join(self.rundir, self.runtag)
Expand Down
2 changes: 2 additions & 0 deletions utils/SnapPy/Snappy/EEMEP/SnapVolcanoTranslator.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,15 @@ def run(self) -> int:
fail due to missing meteo, but still give a good beginning.
"""
with open(os.path.join(self.volcano.outputdir, "snap.outlog"), "w") as fh:
logger.info("Starting bsnap_naccident snap.input")
proc = subprocess.run(
["bsnap_naccident", "snap.input"],
cwd=self.volcano.outputdir,
stderr=fh,
stdout=fh,
)
with open(os.path.join(self.volcano.outputdir, "snapAddToa.outlog"), "w") as fh:
logger.info("Starting snapAddToa snap.nc")
proc = subprocess.run(
["snapAddToa", "snap.nc"],
cwd=self.volcano.outputdir,
Expand Down
26 changes: 21 additions & 5 deletions utils/SnapPy/Snappy/EEMEP/resources/startScreenVolc.html
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ <h2>EEMEP Log</h2>

<br clear="both" style="clear:both;"/>
<label>MET-MODEL:</label>
<div style="float:right;">
<select name="metmodel">
<option selected="selected" value="nrpa_ec_0p1">EC 0.1, NRPA-domain</option>
</select>
</div>
<div style="float:right;">
<select name="metmodel">
<option selected="selected" value="nrpa_ec_0p1">EC 0.1, NRPA-domain</option>
</select>
</div>


<br clear="both" style="clear:both;"/>
Expand All @@ -142,6 +142,22 @@ <h2>EEMEP Log</h2>
</select>
</div>

<br clear="both" style="clear:both;"/>
<label>SNAP-MET-MODEL:</label>
<div style="float:right;">
<select name="snap_metmodel">
<option value="">Off</option>
<option selected="selected" value="nrpa_ec_0p1">EC 0.1, NRPA-domain</option>
</select>
</div>
<br clear="both" style="clear:both;"/>
<label>EC-Model Runtime:</label>
<div style="float:right;">
<select name="snap_modelrun">
<option selected="selected" value="best">Best mixed</option>
</select>
</div>

</div>
</fieldset>

Expand Down
1 change: 1 addition & 0 deletions utils/SnapPy/Snappy/resources/snap.input_nrpa_ec_0p1.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ WET.DEPOSITION.VERSION = 2

*** particles distributed on components according to mass
MAX.TOTALPARTICLES= 20000000
MAX.PARTICLES.PER.RELEASE=5000


REMOVE.RELATIVE.MASS.LIMIT= 0.
Expand Down
4 changes: 2 additions & 2 deletions utils/SnapPy/debpkg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ if [ ! -f "Snappy/resources/1-s2.0-S0146645313000110-mmc1.zip" ]; then
fi

HOST=$(lsb_release --codename --short)
export VERSION=2.4.3
CHANGELOG="fixing non-continuous releases; adding column-output"
export VERSION=2.4.7
CHANGELOG="automatic snapash runs"
export DEBEMAIL=${USER}@met.no
rm --force debian
ln --symbolic debian.$HOST debian
Expand Down

0 comments on commit 9415b2d

Please sign in to comment.