-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
1,431 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright (c) 2022 Adam.Dybbroe | ||
|
||
# Author(s): | ||
|
||
# Adam.Dybbroe <a000680@c21856.ad.smhi.se> | ||
|
||
# This program 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 <http://www.gnu.org/licenses/>. | ||
|
||
"""Post geojson formatted Alarms to a ReST-API | ||
""" | ||
|
||
|
||
def post_alarm(geojson_data, url): | ||
"""Post an Alarm to a rest-api stored as a geojson file.""" | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright (c) 2022 Adam Dybbroe | ||
|
||
# Author(s): | ||
|
||
# Adam Dybbroe <Firstname.Lastname at smhi.se> | ||
|
||
# This program 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 <http://www.gnu.org/licenses/>. | ||
|
||
"""Handling the yaml configurations. | ||
""" | ||
|
||
import yaml | ||
from yaml import UnsafeLoader | ||
|
||
|
||
def read_config(config_filepath): | ||
"""Read and extract config information.""" | ||
with open(config_filepath, 'r') as fp_: | ||
config = yaml.load(fp_, Loader=UnsafeLoader) | ||
|
||
return config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright (c) 2022 Adam Dybbroe | ||
|
||
# Author(s): | ||
|
||
# Adam Dybbroe <Firstname.Lastname@smhi.se> | ||
|
||
# This program 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 <http://www.gnu.org/licenses/>. | ||
|
||
"""Geojson utilities. | ||
""" | ||
|
||
import os | ||
import geojson | ||
import json | ||
import logging | ||
from trollsift import Parser, globify | ||
import pytz | ||
from datetime import datetime, timedelta | ||
import numpy as np | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
def read_geojson_data(filename): | ||
"""Read Geo json data from file.""" | ||
if str(filename).endswith('.geojson') and filename.exists(): | ||
# Read the file: | ||
try: | ||
with open(filename, "r") as fpt: | ||
return geojson.load(fpt) | ||
except json.decoder.JSONDecodeError: | ||
LOG.exception("Geojson file invalid and cannot be read: %s", str(filename)) | ||
else: | ||
LOG.error("No valid filename to read: %s", str(filename)) | ||
|
||
|
||
def get_recent_geojson_files(path, pattern, time_interval): | ||
"""Get all geojson files with filtered active fire detections (=triggered alarms) since *dtime*.""" | ||
dtime_start = time_interval[0] | ||
dtime_end = time_interval[1] | ||
if not dtime_end: | ||
dtime_end = datetime.utcnow() | ||
|
||
p__ = Parser(pattern) | ||
files = path.glob(globify(pattern)) | ||
dtimes = [] | ||
fnames = [] | ||
for gjson_file in files: | ||
fname = gjson_file.name | ||
res = p__.parse(fname) | ||
if res['start_time'] > dtime_start and res['start_time'] < dtime_end: | ||
#print("File: %s" % fname) | ||
dtimes.append(res['start_time']) | ||
fnames.append(fname) | ||
|
||
dtimes = np.array(dtimes) | ||
fnames = np.array(fnames) | ||
|
||
idx = dtimes.argsort() | ||
files = np.take(fnames, idx) | ||
return files.tolist() | ||
|
||
|
||
def store_geojson_alarm(fires_alarms_dir, file_parser, idx, alarm): | ||
"""Store the fire alarm to a geojson file.""" | ||
utc = pytz.timezone('utc') | ||
start_time = datetime.fromisoformat(alarm["features"]["properties"]["observation_time"]) | ||
platform_name = alarm["features"]["properties"]["platform_name"] | ||
start_time = start_time.astimezone(utc).replace(tzinfo=None) | ||
fname = file_parser.compose({'start_time': start_time, 'id': idx, | ||
'platform_name': platform_name}) | ||
output_filename = fires_alarms_dir / fname | ||
with open(output_filename, 'w') as fpt: | ||
geojson.dump(alarm, fpt) | ||
|
||
return output_filename |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.