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

PPS 2021 refactor #60

Merged
merged 45 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
0895e0a
Removed get_outputfiles, filter4oldfiles, get_xml_outputfiles, filter…
Jan 16, 2024
a0593c2
remove old runner
Jan 16, 2024
3f5e8f8
Refactoring
Jan 16, 2024
b0c5bad
Refactoring
Jan 16, 2024
e5a06d5
Update tests
Jan 16, 2024
14ecd8f
Remove old pps runner
Jan 16, 2024
a950ad8
Remove old functions
Jan 16, 2024
a89cd52
Adapt to use always l1c
Jan 16, 2024
744f818
Use level1c file as identifier
Jan 17, 2024
020c5d0
Added test
Jan 17, 2024
024e4d7
flake8
Jan 17, 2024
2c4fa7d
Merge branch 'main' into pps2021_refactor
Jan 24, 2024
509319f
Fixing two bugs
Jan 26, 2024
a78d2f8
Moved code for checking host to function
Jan 26, 2024
62c1440
Rename runner
Mar 27, 2024
40f1a39
Remove non used config options
Mar 27, 2024
f989714
Extract nwp preparation to seperate script
Apr 2, 2024
642e49b
Config template files
Apr 2, 2024
ab3facf
flake8 and tests
Apr 2, 2024
458a652
remove unused file
Apr 2, 2024
8e85405
Add level1c4pps dependency
Apr 2, 2024
4834af2
Update to newer versions of testing (pytest?)
Apr 2, 2024
59c584e
refactoring configuration
Apr 3, 2024
85ab48a
flake8
Apr 3, 2024
130bf2e
Add possibility to run update_nwp every hour
Apr 4, 2024
c926143
More subfunctions in nwp-prepare code
Apr 5, 2024
5354d27
Add publisher
Apr 5, 2024
2d2bb56
Added and refactored some tests
Apr 8, 2024
fe4f759
flake8
Apr 9, 2024
94c040d
Added possibility to run with patched subscriber
Apr 9, 2024
c048243
Remove six
Apr 12, 2024
45da179
Check for NWP files one day back as before
Apr 12, 2024
f863d70
Do not use pkg_resoruses to find version
Apr 12, 2024
4070de4
One more usage of six
Apr 12, 2024
1b1e4d4
Use shell=False with Popen
Apr 12, 2024
5bc5720
Fixed name of env variable
Apr 12, 2024
f68f7af
Use timeout for the reciever
Apr 12, 2024
29df5ec
flake8
Apr 12, 2024
1bde12c
Update bin/level1c_runner.py
ninahakansson Apr 15, 2024
f520c0e
Ute timezone aware objects
Apr 15, 2024
a1bd874
isort
Apr 15, 2024
1f6f8ba
flake8
Apr 15, 2024
c22870c
flake8 docstrings
Apr 15, 2024
13bb3d2
fix tests after flake8
Apr 15, 2024
c977117
Remove unused duplicate function
Apr 15, 2024
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
45 changes: 38 additions & 7 deletions bin/pps_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"""Posttroll runner for the NWCSAF/PPS version >= v2018.
"""

import argparse
import logging
import os
import sys
Expand Down Expand Up @@ -125,7 +126,7 @@
LOG.debug("...from config file = " + str(options['pps_outdir']))

LOG.debug("Run command: " + str(cmd_str))
try:

Check failure on line 129 in bin/pps_runner.py

View check run for this annotation

codefactor.io / CodeFactor

bin/pps_runner.py#L129

subprocess call with shell=True identified, security issue. (B602)
pps_all_proc = Popen(cmd_str, shell=True, stderr=PIPE, stdout=PIPE)
except PpsRunError:
LOG.exception("Failed in PPS...")
Expand All @@ -149,7 +150,7 @@
cmdl = create_pps_call_command(py_exec, pps_script, scene)

LOG.debug("Run command: " + str(cmdl))
try:

Check failure on line 153 in bin/pps_runner.py

View check run for this annotation

codefactor.io / CodeFactor

bin/pps_runner.py#L153

subprocess call with shell=True identified, security issue. (B602)
pps_cmaprob_proc = Popen(cmdl, shell=True, stderr=PIPE, stdout=PIPE)
except PpsRunError:
LOG.exception("Failed when trying to run the PPS Cma-prob")
Expand Down Expand Up @@ -283,14 +284,34 @@
listen_thread.stop()


def get_arguments():
"""Get command line arguments."""
parser = argparse.ArgumentParser()
parser.add_argument('--test_with_l1c_file',
type=str,
help="To test for l1c file with patched subscriber",
required=False)
parser.add_argument('-c', '--config_file',
type=str,
dest='config_file',
default='l1c_config.yaml',
help="The file containing " +
"configuration parameters e.g. product_filter_config.yaml, \n" +
"default = ./l1c_config.yaml",
required=True)

args = parser.parse_args()
return args


if __name__ == "__main__":

from logging import handlers

CONFIG_PATH = os.environ.get('PPSRUNNER_CONFIG_DIR', './')
CONFIG_FILE = os.environ.get('PPSRUNNER_CONFIG_FILE', 'pps_config.yaml')

OPTIONS = get_config(os.path.join(CONFIG_PATH, CONFIG_FILE), add_defaults=True)
args = get_arguments()
config_file = args.config_file

OPTIONS = get_config(config_file, add_defaults=True)

_PPS_LOG_FILE = OPTIONS.get('pps_log_file',
os.environ.get('PPSRUNNER_LOG_FILE', False))
Expand Down Expand Up @@ -318,7 +339,17 @@
logging.getLogger('posttroll').setLevel(logging.INFO)

LOG = logging.getLogger('pps_runner')
LOG.debug("Path to PPS-runner config file = " + CONFIG_PATH)
LOG.debug("PPS-runner config file = " + CONFIG_FILE)

LOG.debug("Path to PPS-runner config file = {:s}".format(args.config_file))

if args.test_with_l1c_file:
from posttroll.message import Message
from posttroll.testing import patched_subscriber_recv
some_files = [args.test_with_l1c_file]
messages = [Message("some_topic", "file", data={"uri": f, "orbit_number": 00000, "sensor": "avhrr",
'platform_name': "EOS-Aqua",
"start_time": datetime(2024, 4, 9, 8, 3)})
for f in some_files]
subscriber_settings = dict(nameserver=False, addresses=["ipc://bla"])
with patched_subscriber_recv(messages):
pps(OPTIONS)
pps(OPTIONS)
10 changes: 7 additions & 3 deletions bin/run_nwp_preparation.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,19 @@

# datetime.datetime.utcnow => datetime.datetime.now(datetime.UTC) ~python 3.12
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this working in 3.12?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the datetime.datetime.now(datetime.UTC) is working in python 3.12 but in 3.9 I get AttributeError: module 'datetime' has no attribute 'UTC'. The datetime.datetime.now(datetime.UTC) will also need some changes in other parts of the code as it is not expecting timezone-aware objects. Currently I get a warning in 3.12: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).



def prepare_and_publish(pub, options, flens):
config_file_name = options.config_file
starttime = datetime.utcnow() - timedelta(days=8)
ninahakansson marked this conversation as resolved.
Show resolved Hide resolved
ok_files, publish_topic = update_nwp(starttime, flens, config_file_name)
if "publish_topic" is not None:
if publish_topic is not None:
for filename in ok_files:
publish_msg = prepare_nwp_message(filename, publish_topic)
LOG.debug("Will publish")
LOG.debug("publish_msg")
publish_l1c(pub, publish_msg, publish_topic)



def _run_subscribe_publisher(pub, options, flens):
"""Prepare NWP data for pps."""
every_hour_minute = options.run_every_hour_at_minute
Expand All @@ -71,12 +73,14 @@ def _run_subscribe_publisher(pub, options, flens):
raise
LOG.info("Ready with nwp preparation for pps, waiting 45 minutes")
time.sleep(45 * 60)



def prepare_nwp4pps_runner(options, flens):
"""Start runner for nwp data preparations."""
with Publish("pps-nwp-preparation-runner", 0) as pub:
_run_subscribe_publisher(pub, options, flens)


def get_arguments():
"""Get command line arguments."""
parser = argparse.ArgumentParser()
Expand Down
2 changes: 1 addition & 1 deletion nwcsafpps_runner/publish_and_listen.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def run(self):
LOG.debug("Subscribe topics = %s", str(self.subscribe_topics))
with posttroll.subscriber.Subscribe("", self.subscribe_topics, True) as subscr:

for msg in subscr.recv(timeout=90):
for msg in subscr.recv():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why we had a timeout of 90 seconds before, but is it safe to change this? Why was this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed it because the patched subscriber did not have the timeout keyword. I am not sure if it is safe to remove.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The timeout is needed I think when the thread is shut down. Maybe something we need in the patched_subscriber then.

if not self.loop:
break

Expand Down
Loading