Commit 0a724d09 authored by markus's avatar markus

Add colorization of NOAA images

parent 9b37b64f
......@@ -7,6 +7,7 @@ verify_ssl = true
[packages]
tweepy = "*"
ffmpeg-python = "*"
[requires]
python_version = "3.7"
{
"_meta": {
"hash": {
"sha256": "7a655092435ce768e5f48b1a8c05366412580e30771c6c623bc638cc94748b47"
"sha256": "02859eb90ebc7d5cfbf1c5a9a2336ab606f1a6097691ba95830790a2c63b36e0"
},
"pipfile-spec": 6,
"requires": {
......@@ -30,6 +30,20 @@
],
"version": "==3.0.4"
},
"ffmpeg-python": {
"hashes": [
"sha256:65225db34627c578ef0e11c8b1eb528bb35e024752f6f10b78c011f6f64c4127",
"sha256:ac441a0404e053f8b6a1113a77c0f452f1cfc62f6344a769475ffdc0f56c23c5"
],
"index": "pypi",
"version": "==0.2.0"
},
"future": {
"hashes": [
"sha256:67045236dcfd6816dc439556d009594abf643e5eb48992e36beac09c2ca659b8"
],
"version": "==0.17.1"
},
"idna": {
"hashes": [
"sha256:c357b3f628cf53ae2c4c05627ecc484553142ca23264e593d327bcde5e9c3407",
......@@ -62,7 +76,8 @@
"requests-oauthlib": {
"hashes": [
"sha256:bd6533330e8748e94bf0b214775fed487d309b8b8fe823dc45641ebcd9a32f57",
"sha256:d3ed0c8f2e3bbc6b344fa63d6f933745ab394469da38db16bdddb461c7e25140"
"sha256:d3ed0c8f2e3bbc6b344fa63d6f933745ab394469da38db16bdddb461c7e25140",
"sha256:dd5a0499abfefd087c6dd96693cbd5bfd28aa009719a7f85ab3fabe3956ef19a"
],
"version": "==1.2.0"
},
......
......@@ -18,13 +18,49 @@ import satnogs_query
import twitter
twitter_client = twitter.TwitterClient()
import ffmpeg
import tempfile
import subprocess
import shutil
def generate_wav(audio):
with tempfile.NamedTemporaryFile() as tmp_ogg:
tmp_ogg.write(audio)
i = ffmpeg.input(tmp_ogg.name)
dirpath = tempfile.mkdtemp()
ffmpeg.output(i.audio, f"{dirpath}/audio.wav", ar='11025').run()
with open(f"{dirpath}/audio.wav", "rb") as tmp_wav:
wav = tmp_wav.read()
shutil.rmtree(dirpath)
return wav
def colorize_noaa_image(wav):
with tempfile.NamedTemporaryFile() as tmp_wav:
tmp_wav.write(wav)
dirpath = tempfile.mkdtemp()
subprocess.run(["wxtoimg", "-e", "HVC", tmp_wav.name, f"{dirpath}/result.png"])
with open(f"{dirpath}/result.png", "rb") as tmp_result:
result = tmp_result.read()
shutil.rmtree(dirpath)
return result
def process_observation(observation, observation_data):
waterfall_image = download_image(observation_data["waterfall_url"])
data_images = [download_image(x) for x in observation_data["data_image_urls"]]
waterfall_image = download(observation_data["waterfall_url"])
data_images = [download(x) for x in observation_data["data_image_urls"]]
audio = download(observation_data["audio_url"])
twitter_client.handle_observation(observation, observation_data, waterfall_image, data_images)
if observation_data["satellite_name"].startswith("NOAA"):
logger.info("Generating wav")
wav = generate_wav(audio)
logger.info("Done generating wav")
logger.info("Generating colorized image")
colorized_image = colorize_noaa_image(wav)
logger.info("Done colorizing image")
twitter_client.handle_observation(observation, observation_data, waterfall_image, [colorized_image])
else:
twitter_client.handle_observation(observation, observation_data, waterfall_image, data_images)
def download_image(url):
def download(url):
logger.info(f"Downloading: {url}")
with urllib.request.urlopen(url) as req:
data = req.read()
......
......@@ -43,6 +43,7 @@ def get_observation_data(satnogs_address, observation):
waterfall_image_url = re.search(f"/media/data_obs/{observation}/waterfall_{observation}_\d+-\d+-\d+T\d+-\d+-\d+.png", page).group(0)
data_image_urls = re.findall(f"src=\"(/media/data_obs/{observation}/data_{observation}_\d+-\d+-\d+T\d+-\d+-\d+.png)", page)
audio_url = re.search(f"data-audio=\"(/media/data_obs/{observation}/(.*?))\"", page).group(1)
satellite_id = re.search("<a href=\"#\" data-toggle=\"modal\" data-target=\"#SatelliteModal\" data-id=\"(\d+)\">", page).group(1)
satellite_name = re.search(f"\s+{satellite_id}\s+-\s+(.*?)</a>", page).group(1).strip()[:-2] # remove magic \n
data_timeframe_start = re.search(f"data-timeframe-start=\"(.*?)\"", page).group(1).strip()
......@@ -51,6 +52,7 @@ def get_observation_data(satnogs_address, observation):
return {
"waterfall_url": f"{satnogs_address}{str(waterfall_image_url)}",
"data_image_urls": [f"{satnogs_address}{data_image_url}" for data_image_url in data_image_urls],
"audio_url": f"{satnogs_address}{audio_url}",
"satellite_id": satellite_id,
"satellite_name": satellite_name,
"data_timeframe_start": data_timeframe_start,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment