Spaces:
Paused
Paused
Initial Space creation from repo-embedded image
Browse files- README.md +4 -3
- app.py +822 -0
- requirements.txt +2 -0
README.md
CHANGED
|
@@ -1,12 +1,13 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
colorFrom: yellow
|
| 5 |
colorTo: gray
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version: 5.
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
---
|
| 11 |
|
| 12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Solar
|
| 3 |
+
emoji: ⚡
|
| 4 |
colorFrom: yellow
|
| 5 |
colorTo: gray
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 5.27.1
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
---
|
| 11 |
|
| 12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
| 13 |
+
test
|
app.py
ADDED
|
@@ -0,0 +1,822 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
import json
|
| 4 |
+
import os
|
| 5 |
+
from PIL import Image
|
| 6 |
+
import moviepy.video.io.ImageSequenceClip as ic
|
| 7 |
+
#from datetime import date, timedelta
|
| 8 |
+
|
| 9 |
+
from pathlib import Path
|
| 10 |
+
import bs4
|
| 11 |
+
import datetime
|
| 12 |
+
import urllib.request
|
| 13 |
+
import uuid
|
| 14 |
+
import base64
|
| 15 |
+
import os
|
| 16 |
+
#print(os.system('pip freeze'))
|
| 17 |
+
main_directory = "https://services.swpc.noaa.gov/"
|
| 18 |
+
sdo_source = "https://sdo.gsfc.nasa.gov/assets/img/browse/"
|
| 19 |
+
sdo_source_format = "https://sdo.gsfc.nasa.gov/assets/img/browse/YEAR/MONTH/DAY/DATE_IDENT_SIZE_TOOL.jpg"
|
| 20 |
+
|
| 21 |
+
comp_list=[
|
| 22 |
+
"https://services.swpc.noaa.gov/images/geospace/geospace_1_day.png",
|
| 23 |
+
"https://services.swpc.noaa.gov/images/ace-epam-24-hour.gif",
|
| 24 |
+
"https://services.swpc.noaa.gov/images/ace-epam-e-24-hour.gif",
|
| 25 |
+
"https://services.swpc.noaa.gov/images/ace-epam-p-24-hour.gif",
|
| 26 |
+
"https://services.swpc.noaa.gov/images/ace-mag-24-hour.gif",
|
| 27 |
+
"https://services.swpc.noaa.gov/images/ace-mag-swepam-24-hour.gif",
|
| 28 |
+
"https://services.swpc.noaa.gov/images/ace-sis-24-hour.gif",
|
| 29 |
+
"https://services.swpc.noaa.gov/images/boulder-magnetometer.png",
|
| 30 |
+
"https://services.swpc.noaa.gov/images/seaesrt-time-series-270.png",
|
| 31 |
+
"https://services.swpc.noaa.gov/images/station-k-index.png",
|
| 32 |
+
#"https://services.swpc.noaa.gov/images/swx-overview-large.gif",
|
| 33 |
+
"https://services.swpc.noaa.gov/images/notifications-timeline.png",
|
| 34 |
+
]
|
| 35 |
+
|
| 36 |
+
sdo_aia_latest=[
|
| 37 |
+
{"name":"Fe18 94A", "source":"https://umbra.nascom.nasa.gov/images/latest_aia_94.gif"},
|
| 38 |
+
{"name":"Fe20 131A", "source":"https://umbra.nascom.nasa.gov/images/latest_aia_131.gif"},
|
| 39 |
+
{"name":"Fe9/10 171A", "source":"https://umbra.nascom.nasa.gov/images/latest_aia_171.gif"},
|
| 40 |
+
{"name":"Fe12 193A", "source":"https://umbra.nascom.nasa.gov/images/latest_aia_193.gif"},
|
| 41 |
+
|
| 42 |
+
{"name":"Fe14 211A", "source":"https://umbra.nascom.nasa.gov/images/latest_aia_211.gif"},
|
| 43 |
+
{"name":"He2 304A", "source":"https://umbra.nascom.nasa.gov/images/latest_aia_304.gif"},
|
| 44 |
+
{"name":"Fe16 335A", "source":"https://umbra.nascom.nasa.gov/images/latest_aia_335.gif"},
|
| 45 |
+
{"name":"cont+C4 1600A", "source":"https://umbra.nascom.nasa.gov/images/latest_aia_1600.gif"},
|
| 46 |
+
{"name":"continuum 1700A", "source":"https://umbra.nascom.nasa.gov/images/latest_aia_1700.gif"},
|
| 47 |
+
{"name":"continuum 4500A", "source":"https://umbra.nascom.nasa.gov/images/latest_aia_4500.gif"},
|
| 48 |
+
]
|
| 49 |
+
|
| 50 |
+
nasa_images=[
|
| 51 |
+
{"name":"EIT 171A", "source":"https://soho.nascom.nasa.gov/data/realtime/eit_171/512/latest.jpg"},
|
| 52 |
+
{"name":"EIT 195A", "source":"https://soho.nascom.nasa.gov/data/realtime/eit_195/512/latest.jpg"},
|
| 53 |
+
{"name":"EIT 284A", "source":"https://soho.nascom.nasa.gov/data/realtime/eit_284/512/latest.jpg"},
|
| 54 |
+
{"name":"EIT 304A", "source":"https://soho.nascom.nasa.gov/data/realtime/eit_304/512/latest.jpg"},
|
| 55 |
+
]
|
| 56 |
+
|
| 57 |
+
nasa_soho_gifs=[
|
| 58 |
+
{"name":"EIT 304A", "source":"https://soho.nascom.nasa.gov/data/LATEST/current_eit_304small.gif"},
|
| 59 |
+
{"name":"EIT 195A", "source":"https://soho.nascom.nasa.gov/data/LATEST/current_eit_195small.gif"},
|
| 60 |
+
{"name":"EIT 171A", "source":"https://soho.nascom.nasa.gov/data/LATEST/current_eit_171small.gif"},
|
| 61 |
+
{"name":"EIT 284A", "source":"https://soho.nascom.nasa.gov/data/LATEST/current_eit_284small.gif"},
|
| 62 |
+
]
|
| 63 |
+
nasa_soho_mp4=[
|
| 64 |
+
{"name":"EIT 171A", "source":"https://soho.nascom.nasa.gov/data/LATEST/current_eit_171small.mp4"},
|
| 65 |
+
{"name":"EIT 195A", "source":"https://soho.nascom.nasa.gov/data/LATEST/current_eit_195small.mp4"},
|
| 66 |
+
{"name":"EIT 284A", "source":"https://soho.nascom.nasa.gov/data/LATEST/current_eit_284small.mp4"},
|
| 67 |
+
{"name":"EIT 304A", "source":"https://soho.nascom.nasa.gov/data/LATEST/current_eit_304small.mp4"},
|
| 68 |
+
|
| 69 |
+
{"name":"LASCO C2", "source":"https://soho.nascom.nasa.gov/data/LATEST/current_c2small.mp4"},
|
| 70 |
+
{"name":"LASCO C3", "source":"https://soho.nascom.nasa.gov/data/LATEST/current_c3small.mp4"},
|
| 71 |
+
{"name":"SDO/HMI Continuum", "source":"https://soho.nascom.nasa.gov/data/LATEST/current_hmi_igr-512.mp4"},
|
| 72 |
+
{"name":"SDO/HMI Magnetogram", "source":"https://soho.nascom.nasa.gov/data/LATEST/current_hmi_mag-512.mp4"},
|
| 73 |
+
]
|
| 74 |
+
|
| 75 |
+
sdo_obj = ["HMIB","HMIBC","HMIIC","HMIIF","HMID","HMII","HMI171",
|
| 76 |
+
"0094","0131","0171","0193","0211",
|
| 77 |
+
"0304","0335","1600","1700","4500",
|
| 78 |
+
"211193171","211193171n","211193171rg",
|
| 79 |
+
"094335193","304211171"]
|
| 80 |
+
sdo_size= [256,512,1024,2048,4096]
|
| 81 |
+
month_dict={"01":31,"02":28,"03":31,"04":30,"05":31,"06":30,"07":31,"08":31,"09":30,"10":31,"11":30,"12":31}
|
| 82 |
+
html = """
|
| 83 |
+
<div>
|
| 84 |
+
PAGE_LINK
|
| 85 |
+
</div>
|
| 86 |
+
"""
|
| 87 |
+
css="""
|
| 88 |
+
.img_box{
|
| 89 |
+
display: flex;
|
| 90 |
+
flex-direction: column;
|
| 91 |
+
flex-flow: unset;
|
| 92 |
+
flex-wrap: wrap;
|
| 93 |
+
justify-content: space-around;
|
| 94 |
+
}
|
| 95 |
+
.img_class{
|
| 96 |
+
background: #ffffff;
|
| 97 |
+
max-width: 48%;
|
| 98 |
+
font-family: monospace;
|
| 99 |
+
border-top: #9300ff;
|
| 100 |
+
border-style: inset;
|
| 101 |
+
margin-top: 5px;
|
| 102 |
+
}
|
| 103 |
+
.img_class_raw{
|
| 104 |
+
background: #ffffff;
|
| 105 |
+
width: 100%;
|
| 106 |
+
font-family: monospace;
|
| 107 |
+
border-top: #9300ff;
|
| 108 |
+
border-style: inset;
|
| 109 |
+
margin-top: 5px;
|
| 110 |
+
display:flex;
|
| 111 |
+
flex-direction:column;
|
| 112 |
+
}
|
| 113 |
+
.img_box_soho{
|
| 114 |
+
display: flex;
|
| 115 |
+
flex-direction: row;
|
| 116 |
+
flex-wrap: wrap;
|
| 117 |
+
justify-content: space-between;
|
| 118 |
+
}
|
| 119 |
+
.img_class_soho{
|
| 120 |
+
background: #ffffff;
|
| 121 |
+
font-family: monospace;
|
| 122 |
+
border-top: #9300ff;
|
| 123 |
+
border-style: inset;
|
| 124 |
+
margin-top: 5px;
|
| 125 |
+
max-width: 48%;
|
| 126 |
+
}
|
| 127 |
+
.img_class_sdo{
|
| 128 |
+
background: #ffffff;
|
| 129 |
+
font-family: monospace;
|
| 130 |
+
border-top: #9300ff;
|
| 131 |
+
border-style: inset;
|
| 132 |
+
margin-top: 5px;
|
| 133 |
+
max-width: 25%;
|
| 134 |
+
font-size: small;
|
| 135 |
+
}
|
| 136 |
+
"""
|
| 137 |
+
def load_json(url1="",url2="",url3="",url4="",url5="",url6="",url7="",url8=""):
|
| 138 |
+
get_url=f'{main_directory}{url1}{url2}{url3}{url4}{url5}{url6}{url7}{url8}'
|
| 139 |
+
print(f'{get_url}')
|
| 140 |
+
get_url=get_url.split("None")[0]
|
| 141 |
+
print(f'{get_url}')
|
| 142 |
+
get_url=get_url.split("[]")[0]
|
| 143 |
+
print(f'{get_url}')
|
| 144 |
+
|
| 145 |
+
if get_url.endswith('.json'):
|
| 146 |
+
feed1 = requests.get(get_url)
|
| 147 |
+
return None, feed1.text
|
| 148 |
+
elif get_url.endswith(".png") or get_url.endswith(".gif") or get_url.endswith(".jpg"):
|
| 149 |
+
html_out=f"<style>{css}</style><div>"
|
| 150 |
+
html_out+=f'<div class="img_class_raw"><a href="{get_url}" target="_blank">{get_url}</a><br><img src={get_url}></div></div>'
|
| 151 |
+
return html_out, None
|
| 152 |
+
return None,None
|
| 153 |
+
|
| 154 |
+
def make_tree(url1="",url2="",url3="",url4="",url5="",url6="",url7="",url8=""):
|
| 155 |
+
link_box=[]
|
| 156 |
+
html_out=""
|
| 157 |
+
get_url=f'{main_directory}{url1}{url2}{url3}{url4}{url5}{url6}{url7}{url8}'
|
| 158 |
+
print(f'######### :: {get_url}')
|
| 159 |
+
if not get_url.endswith('.json'):
|
| 160 |
+
feed1 = requests.get(get_url)
|
| 161 |
+
spl = feed1.text.split("href=")
|
| 162 |
+
for line in spl:
|
| 163 |
+
spl2 = line.split(">")[0]
|
| 164 |
+
#print(spl2)
|
| 165 |
+
if spl2.endswith('/"') or spl2.endswith('.json"') or spl2.endswith('.png"') or spl2.endswith('.gif"') or spl2.endswith('.jpg"'):
|
| 166 |
+
fin=line.split(">")[0].strip('""')
|
| 167 |
+
link_box.append(fin)
|
| 168 |
+
#html_out=html_out+html.replace("PAGE_LINK",fin)
|
| 169 |
+
return gr.update(choices=[l for l in link_box],interactive=True)
|
| 170 |
+
else:
|
| 171 |
+
return None
|
| 172 |
+
|
| 173 |
+
def get_images():
|
| 174 |
+
html_out=f"<style>{css}</style><div class='img_box'>"
|
| 175 |
+
get_url=f'{main_directory}images/geospace/'
|
| 176 |
+
feed1 = requests.get(get_url)
|
| 177 |
+
spl = feed1.text.split("href=")
|
| 178 |
+
for line in spl:
|
| 179 |
+
spl2 = line.split(">")[0].strip('""')
|
| 180 |
+
if spl2.endswith(".png") or spl2.endswith(".gif") or spl2.endswith(".jpg"):
|
| 181 |
+
#print(spl2)
|
| 182 |
+
html_out+=f'<div class="img_class"><a href="{get_url}{spl2}" target="_blank">{spl2}</a><br><img src={get_url}{spl2}></div>'
|
| 183 |
+
else:
|
| 184 |
+
print(spl2)
|
| 185 |
+
get_url2=f'{main_directory}images/'
|
| 186 |
+
feed2 = requests.get(get_url2)
|
| 187 |
+
spl = feed2.text.split("href=")
|
| 188 |
+
for line2 in spl:
|
| 189 |
+
spl2 = line2.split(">")[0].strip('""')
|
| 190 |
+
if spl2.endswith(".png") or spl2.endswith(".gif") or spl2.endswith(".jpg"):
|
| 191 |
+
#print(spl2)
|
| 192 |
+
html_out+=f'<div class="img_class"><a href="{get_url2}{spl2}" target="_blank">{spl2}</a><br><img src={get_url2}{spl2}></div>'
|
| 193 |
+
else:
|
| 194 |
+
print(spl2)
|
| 195 |
+
html_out+="</div>"
|
| 196 |
+
return html_out
|
| 197 |
+
|
| 198 |
+
def make_animation():
|
| 199 |
+
get_url=f'{main_directory}images/animations/'
|
| 200 |
+
feed1 = requests.get(get_url)
|
| 201 |
+
spl = feed1.text.split("href=")
|
| 202 |
+
files_out=[]
|
| 203 |
+
for line in spl:
|
| 204 |
+
gif_box=[]
|
| 205 |
+
|
| 206 |
+
spl2 = line.split(">")[0].strip('""')
|
| 207 |
+
if spl2.endswith("/"):
|
| 208 |
+
feed2 = requests.get(f'{get_url}{spl2}')
|
| 209 |
+
spl3 = feed2.text.split("href=")
|
| 210 |
+
for line2 in spl3:
|
| 211 |
+
spl3 = line2.split(">")[0].strip('""')
|
| 212 |
+
print("$$$$$$$$$$$$$$")
|
| 213 |
+
print(spl3)
|
| 214 |
+
if spl3.endswith(".png") or spl3.endswith(".gif") or spl3.endswith(".jpg"):
|
| 215 |
+
gif_box.append(f'{get_url}{spl2}{spl3}')
|
| 216 |
+
if gif_box:
|
| 217 |
+
try:
|
| 218 |
+
#frames = [Image.open(image) for image in glob.glob(f"{frame_folder}/*.JPG")]
|
| 219 |
+
frames = []
|
| 220 |
+
for i,ea in enumerate(gif_box):
|
| 221 |
+
print("############")
|
| 222 |
+
print(ea)
|
| 223 |
+
urllib.request.urlretrieve(ea,f'tmp{i}.png')
|
| 224 |
+
frames.append(f'tmp{i}.png')
|
| 225 |
+
fps=60
|
| 226 |
+
uid=uuid.uuid4()
|
| 227 |
+
clip = ic.ImageSequenceClip(frames, fps = fps)
|
| 228 |
+
clip.to_gif(f"{uid}.gif",fps=fps)
|
| 229 |
+
files_out.append(f'{uid}.gif')
|
| 230 |
+
except Exception as e:
|
| 231 |
+
print(e)
|
| 232 |
+
return files_out
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
def make_animation_new(gif_box=[]):
|
| 236 |
+
|
| 237 |
+
if gif_box:
|
| 238 |
+
print(gif_box)
|
| 239 |
+
gif_box.sort(reverse=False)
|
| 240 |
+
print("Making GIF...")
|
| 241 |
+
try:
|
| 242 |
+
#frames = [Image.open(image) for image in glob.glob(f"{frame_folder}/*.JPG")]
|
| 243 |
+
frames = []
|
| 244 |
+
for i,ea in enumerate(gif_box):
|
| 245 |
+
print("############")
|
| 246 |
+
print(ea)
|
| 247 |
+
urllib.request.urlretrieve(ea,f'tmp{i}.png')
|
| 248 |
+
frames.append(f'tmp{i}.png')
|
| 249 |
+
fps=60
|
| 250 |
+
uid=uuid.uuid4()
|
| 251 |
+
clip = ic.ImageSequenceClip(frames, fps = fps)
|
| 252 |
+
|
| 253 |
+
|
| 254 |
+
# Save GIF to a temporary file
|
| 255 |
+
temp_gif_path = f"temp_{uid}.gif"
|
| 256 |
+
clip.write_gif(temp_gif_path, fps=fps)
|
| 257 |
+
|
| 258 |
+
# Read the GIF file into bytes
|
| 259 |
+
with open(temp_gif_path, 'rb') as gif_file:
|
| 260 |
+
gif_bytes = gif_file.read()
|
| 261 |
+
|
| 262 |
+
# Encode GIF bytes as base64 for HTML
|
| 263 |
+
gif_base64 = base64.b64encode(gif_bytes).decode('utf-8')
|
| 264 |
+
gif_data_url = f"data:image/gif;base64,{gif_base64}"
|
| 265 |
+
|
| 266 |
+
|
| 267 |
+
html_out=f"<style>{css}</style><div>"
|
| 268 |
+
html_out+=f'<div class="img_class"><img src="{gif_data_url}"></div>'
|
| 269 |
+
html_out+="</div>"
|
| 270 |
+
return html_out
|
| 271 |
+
|
| 272 |
+
except Exception as e:
|
| 273 |
+
print("ERROR HAPPENED")
|
| 274 |
+
print(e)
|
| 275 |
+
|
| 276 |
+
else:
|
| 277 |
+
print("passed")
|
| 278 |
+
|
| 279 |
+
def make_html(inp_files):
|
| 280 |
+
html_out=f"<style>{css}</style><div class='img_box'>"
|
| 281 |
+
for ea in inp_files:
|
| 282 |
+
print(ea)
|
| 283 |
+
html_out+=f'<div class="img_class"><img src="file={ea}"></div>'
|
| 284 |
+
html_out+='</div>'
|
| 285 |
+
return html_out
|
| 286 |
+
|
| 287 |
+
def make_nasa_soho_videos():
|
| 288 |
+
html_out=f"<style>{css}</style><div class='img_box_soho'>"
|
| 289 |
+
for ea in nasa_soho_mp4:
|
| 290 |
+
file_name=ea['source']
|
| 291 |
+
html_out+=f'''
|
| 292 |
+
<video width="50%" height="320" controls>
|
| 293 |
+
<source src="{file_name}" type="video/mp4">
|
| 294 |
+
Your browser does not support the video tag.
|
| 295 |
+
</video>'''
|
| 296 |
+
#html_out+=f'<div class="img_class_soho"><img src="file={file_name}"></div>'
|
| 297 |
+
html_out+='</div>'
|
| 298 |
+
return html_out
|
| 299 |
+
|
| 300 |
+
def make_nasa_soho_images(inp_src: list):
|
| 301 |
+
html_out=""
|
| 302 |
+
#html_out=f"<style>{css}</style><div class='img_box_soho'>"
|
| 303 |
+
for ea in inp_src:
|
| 304 |
+
file_name=ea['source']
|
| 305 |
+
html_out+=f'<div class="img_class_soho"><img src="{file_name}"></div>'
|
| 306 |
+
#html_out+='</div>'
|
| 307 |
+
#html_out+=html_in
|
| 308 |
+
return html_out
|
| 309 |
+
def make_nasa_soho_image_trigger():
|
| 310 |
+
html_in=f"<style>{css}</style><div class='img_box_soho'>"
|
| 311 |
+
|
| 312 |
+
html_in+= make_nasa_soho_images(nasa_images)
|
| 313 |
+
html_in+= make_nasa_soho_images(sdo_aia_latest)
|
| 314 |
+
#html_in+= make_nasa_soho_videos()
|
| 315 |
+
html_in+="</div>"
|
| 316 |
+
return html_in
|
| 317 |
+
#from datetime import date, timedelta, datetime
|
| 318 |
+
|
| 319 |
+
def generate_sdo_urls(date1_str: str, date2_str: str) -> list[str]:
|
| 320 |
+
"""
|
| 321 |
+
Generates a list of SDO browse image URLs for all days
|
| 322 |
+
inclusive of date1_str and date2_str.
|
| 323 |
+
|
| 324 |
+
The URL format is assumed to be:
|
| 325 |
+
https://sdo.gsfc.nasa.gov/assets/img/browse/YYYY/MM/DD/
|
| 326 |
+
|
| 327 |
+
Args:
|
| 328 |
+
date1_str: Start date in "YYYYMMDD" format (e.g., "20230115").
|
| 329 |
+
date2_str: End date in "YYYYMMDD" format (e.g., "20230117").
|
| 330 |
+
|
| 331 |
+
Returns:
|
| 332 |
+
A list of URL strings.
|
| 333 |
+
Returns an empty list if date1_str > date2_str or if dates are invalid.
|
| 334 |
+
"""
|
| 335 |
+
url_box = []
|
| 336 |
+
base_url = "https://sdo.gsfc.nasa.gov/assets/img/browse"
|
| 337 |
+
|
| 338 |
+
try:
|
| 339 |
+
# Convert input strings to date objects
|
| 340 |
+
# datetime.strptime creates a datetime object, .date() gets just the date part
|
| 341 |
+
start_date = datetime.datetime.strptime(date1_str[:8], "%Y%m%d").date()
|
| 342 |
+
end_date = datetime.datetime.strptime(date2_str[:8], "%Y%m%d").date()
|
| 343 |
+
except ValueError:
|
| 344 |
+
print(f"Error: Invalid date format. Please use YYYYMMDD. Received: '{date1_str}', '{date2_str}'")
|
| 345 |
+
return [] # Return empty list for invalid date format
|
| 346 |
+
|
| 347 |
+
# Handle cases where start_date is after end_date
|
| 348 |
+
if start_date > end_date:
|
| 349 |
+
print(f"Warning: Start date ({date1_str}) is after end date ({date2_str}). Returning an empty list.")
|
| 350 |
+
return []
|
| 351 |
+
|
| 352 |
+
current_date = start_date
|
| 353 |
+
while current_date <= end_date:
|
| 354 |
+
# Format year, month, and day with leading zeros if necessary
|
| 355 |
+
# .year, .month, .day are integers
|
| 356 |
+
year_str = f"{current_date.year:04}" # Ensures YYYY format (though usually not needed for year)
|
| 357 |
+
month_str = f"{current_date.month:02}" # Ensures MM format (e.g., 1 -> 01)
|
| 358 |
+
day_str = f"{current_date.day:02}" # Ensures DD format (e.g., 5 -> 05)
|
| 359 |
+
|
| 360 |
+
# Construct the URL
|
| 361 |
+
out_url = f"{base_url}/{year_str}/{month_str}/{day_str}/"
|
| 362 |
+
url_box.append(out_url)
|
| 363 |
+
|
| 364 |
+
# Move to the next day
|
| 365 |
+
current_date += datetime.timedelta(days=1)
|
| 366 |
+
|
| 367 |
+
return url_box
|
| 368 |
+
|
| 369 |
+
|
| 370 |
+
def count_days_og(date1,date2):
|
| 371 |
+
url_box=[]
|
| 372 |
+
in_year=f"{date1[0:4]}"
|
| 373 |
+
in_month=f"{date1[4:6]}"
|
| 374 |
+
in_day=f"{date1[6:8]}"
|
| 375 |
+
|
| 376 |
+
end_year=f"{date2[0:4]}"
|
| 377 |
+
end_month=f"{date2[4:6]}"
|
| 378 |
+
end_day=f"{date2[6:8]}"
|
| 379 |
+
|
| 380 |
+
years_rem,months_rem,days_rem=(0,0,0)
|
| 381 |
+
og_days_rem=days_rem
|
| 382 |
+
i_in_year,i_in_month,i_in_day,i_end_year,i_end_month,i_end_day=int(in_year),int(in_month),int(in_day),int(end_year),int(end_month),int(end_day)
|
| 383 |
+
days_json={"year": 0, "month": 0, "day": 0}
|
| 384 |
+
if i_end_year > i_in_year:
|
| 385 |
+
years_rem = i_end_year-i_in_year
|
| 386 |
+
if i_end_month > i_in_month:
|
| 387 |
+
months_rem = 12 - i_in_month
|
| 388 |
+
if i_end_day > i_in_day:
|
| 389 |
+
og_days_rem = month_dict[in_month] - i_in_day
|
| 390 |
+
|
| 391 |
+
if years_rem > 0:
|
| 392 |
+
for ii in list(range(0,years_raw)):
|
| 393 |
+
months_rem+=years_rem*12
|
| 394 |
+
out_year = in_year+ii
|
| 395 |
+
for i in list(range(0,months_rem)):
|
| 396 |
+
month_day_cnt = month_dict[str(int(in_month)+i)]
|
| 397 |
+
for io in list(range(0,month_day_cnt)):
|
| 398 |
+
days_rem += month_day_cnt
|
| 399 |
+
out_url=f"https://sdo.gsfc.nasa.gov/assets/img/browse/{out_year}/{i}/{io}/"
|
| 400 |
+
print(out_url)
|
| 401 |
+
url_box.append(out_url)
|
| 402 |
+
months_raw = 0
|
| 403 |
+
if months_rem > 0:
|
| 404 |
+
out_year = in_year
|
| 405 |
+
for i in list(range(0,months_rem)):
|
| 406 |
+
month_day_cnt = month_dict[str(int(in_month)+i)]
|
| 407 |
+
for io in list(range(0,month_day_cnt)):
|
| 408 |
+
days_rem += month_day_cnt
|
| 409 |
+
out_url=f"https://sdo.gsfc.nasa.gov/assets/img/browse/{out_year}/{i}/{io}/"
|
| 410 |
+
print(out_url)
|
| 411 |
+
url_box.append(out_url)
|
| 412 |
+
og_days_rem=0
|
| 413 |
+
if og_days_rem > 0:
|
| 414 |
+
for io in list(range(0,og_days_rem)):
|
| 415 |
+
days_rem += month_day_cnt
|
| 416 |
+
out_url=f"https://sdo.gsfc.nasa.gov/assets/img/browse/{end_year}/{end_month}/{io}/"
|
| 417 |
+
print(out_url)
|
| 418 |
+
url_box.append(out_url)
|
| 419 |
+
|
| 420 |
+
|
| 421 |
+
def nasa_sdo_images(obj,size,date1,date2):
|
| 422 |
+
url_box=[]
|
| 423 |
+
html_in=f"<style>{css}</style><div class='img_box_soho'>"
|
| 424 |
+
print(date1 + " - " + date2)
|
| 425 |
+
#if int(date2[6:8])-int(date1[6:8]) >0:
|
| 426 |
+
# return ("<div style='font-size:xxx-large'>Reduce Timespan to 24 hours</div>")
|
| 427 |
+
in_year=f"{date1[0:4]}"
|
| 428 |
+
in_month=f"{date1[4:6]}"
|
| 429 |
+
in_day=f"{date1[6:8]}"
|
| 430 |
+
|
| 431 |
+
end_year=f"{date2[0:4]}"
|
| 432 |
+
end_month=f"{date2[4:6]}"
|
| 433 |
+
end_day=f"{date2[6:8]}"
|
| 434 |
+
|
| 435 |
+
sdo_urls = generate_sdo_urls(date1,date2)
|
| 436 |
+
print(sdo_urls)
|
| 437 |
+
|
| 438 |
+
'''years_rem,months_rem,days_rem=(0,0,0)
|
| 439 |
+
og_days_rem=days_rem
|
| 440 |
+
i_in_year,i_in_month,i_in_day,i_end_year,i_end_month,i_end_day=int(in_year),int(in_month),int(in_day),int(end_year),int(end_month),int(end_day)
|
| 441 |
+
days_json={"year": 0, "month": 0, "day": 0}
|
| 442 |
+
if i_end_year > i_in_year:
|
| 443 |
+
years_rem = i_end_year-i_in_year
|
| 444 |
+
if i_end_month > i_in_month:
|
| 445 |
+
months_rem = 12 - i_in_month
|
| 446 |
+
if i_end_day > i_in_day:
|
| 447 |
+
og_days_rem = month_dict[in_month] - i_in_day
|
| 448 |
+
|
| 449 |
+
if years_rem > 0:
|
| 450 |
+
for ii in list(range(0,years_raw)):
|
| 451 |
+
months_rem+=years_rem*12
|
| 452 |
+
out_year = in_year+ii
|
| 453 |
+
for i in list(range(0,months_rem)):
|
| 454 |
+
month_day_cnt = month_dict[str(int(in_month)+i)]
|
| 455 |
+
for io in list(range(0,month_day_cnt)):
|
| 456 |
+
days_rem += month_day_cnt
|
| 457 |
+
out_url=f"https://sdo.gsfc.nasa.gov/assets/img/browse/{out_year}/{i}/{io}/"
|
| 458 |
+
print(out_url)
|
| 459 |
+
url_box.append(out_url)
|
| 460 |
+
months_raw = 0
|
| 461 |
+
if months_rem > 0:
|
| 462 |
+
out_year = in_year
|
| 463 |
+
for i in list(range(0,months_rem)):
|
| 464 |
+
month_day_cnt = month_dict[str(int(in_month)+i)]
|
| 465 |
+
for io in list(range(0,month_day_cnt)):
|
| 466 |
+
days_rem += month_day_cnt
|
| 467 |
+
out_url=f"https://sdo.gsfc.nasa.gov/assets/img/browse/{out_year}/{i}/{io}/"
|
| 468 |
+
print(out_url)
|
| 469 |
+
url_box.append(out_url)
|
| 470 |
+
og_days_rem=0
|
| 471 |
+
if og_days_rem > 0:
|
| 472 |
+
for io in list(range(0,og_days_rem)):
|
| 473 |
+
days_rem += io
|
| 474 |
+
out_url=f"https://sdo.gsfc.nasa.gov/assets/img/browse/{end_year}/{end_month}/{io}/"
|
| 475 |
+
print(out_url)
|
| 476 |
+
url_box.append(out_url)'''
|
| 477 |
+
|
| 478 |
+
file_name="DATE_TIME_SIZE_TOOL.jpg"
|
| 479 |
+
out_box=[]
|
| 480 |
+
sdo_urls.sort(reverse=True)
|
| 481 |
+
for num, link in enumerate(sdo_urls):
|
| 482 |
+
link_box=[]
|
| 483 |
+
print(link)
|
| 484 |
+
#sdo_source_format = f"https://sdo.gsfc.nasa.gov/assets/img/browse/{in_year}/{in_month}/{in_day}/"
|
| 485 |
+
sdo_source_format = link
|
| 486 |
+
#get_url=sdo_source_format
|
| 487 |
+
feed1 = requests.get(link)
|
| 488 |
+
#print(get_url)
|
| 489 |
+
if "All" in size:
|
| 490 |
+
size = sdo_size
|
| 491 |
+
if "All" in obj:
|
| 492 |
+
obj = sdo_obj
|
| 493 |
+
# Parse the HTML content using BeautifulSoup
|
| 494 |
+
soup = bs4.BeautifulSoup(feed1.content, 'html.parser')
|
| 495 |
+
#print(soup)
|
| 496 |
+
anchor_elements = soup.find_all('a')
|
| 497 |
+
for element in anchor_elements:
|
| 498 |
+
link_box.append(element.get('href'))
|
| 499 |
+
|
| 500 |
+
link_box.sort(reverse=True)
|
| 501 |
+
#for element in anchor_elements:
|
| 502 |
+
for href in link_box:
|
| 503 |
+
#print(href)
|
| 504 |
+
#href=element.get('href')
|
| 505 |
+
if href.endswith('.jpg'):
|
| 506 |
+
for o in obj:
|
| 507 |
+
for s in size:
|
| 508 |
+
ls=href.split("_")
|
| 509 |
+
#print(ls[1][0:4])
|
| 510 |
+
#print(date1[8:13])
|
| 511 |
+
if ls[1][0:4]>=date1[8:13]:
|
| 512 |
+
src_obj=ls[3].split('.jpg')[0]
|
| 513 |
+
if src_obj == o:
|
| 514 |
+
if int(ls[2]) == int(s):
|
| 515 |
+
print(f"{link}{href}")
|
| 516 |
+
out_box.append(f'{link}{href}')
|
| 517 |
+
html_in+=f'<div class="img_class_sdo"><a href="{link}{href}" target="_blank">{href}</a><br><img src={link}{href}></div>'
|
| 518 |
+
else:
|
| 519 |
+
src_obj=ls[3].split('.jpg')[0]
|
| 520 |
+
if src_obj == o:
|
| 521 |
+
if int(ls[2]) == int(s):
|
| 522 |
+
print(f"{link}{href}")
|
| 523 |
+
out_box.append(f'{link}{href}')
|
| 524 |
+
html_in+=f'<div class="img_class_sdo"><a href="{link}{href}" target="_blank">{href}</a><br><img src={link}{href}></div>'
|
| 525 |
+
|
| 526 |
+
|
| 527 |
+
return html_in, out_box
|
| 528 |
+
|
| 529 |
+
def get_concat_h_cut(in1, in2):
|
| 530 |
+
uid=uuid.uuid4()
|
| 531 |
+
im1=Image.open(in1)
|
| 532 |
+
im2=Image.open(in2)
|
| 533 |
+
dst = Image.new('RGB', (im1.width + im2.width,
|
| 534 |
+
min(im1.height, im2.height)))
|
| 535 |
+
dst.paste(im1, (0, 0))
|
| 536 |
+
dst.paste(im2, (im1.width, 0))
|
| 537 |
+
dst.save(f"h_{uid}.jpg")
|
| 538 |
+
return f"h_{uid}.jpg"
|
| 539 |
+
|
| 540 |
+
|
| 541 |
+
def get_concat_v_cut(in1, in2, theme='dark'):
|
| 542 |
+
uid=uuid.uuid4()
|
| 543 |
+
im1=Image.open(in1)
|
| 544 |
+
im2=Image.open(in2)
|
| 545 |
+
if theme=='dark':
|
| 546 |
+
color=(31,41,55)
|
| 547 |
+
if theme=='light':
|
| 548 |
+
color=(255,255,255)
|
| 549 |
+
dst = Image.new('RGB', (min(im1.width, im2.width), im1.height + im2.height),color=color)
|
| 550 |
+
dst.paste(im1, (0, 0))
|
| 551 |
+
dst.paste(im2, (0, im1.height))
|
| 552 |
+
dst.save(f"v_{uid}.jpg")
|
| 553 |
+
return f"v_{uid}.jpg"
|
| 554 |
+
|
| 555 |
+
|
| 556 |
+
|
| 557 |
+
|
| 558 |
+
def nasa_sdo_composite(obj,size,date1,date2,ret_num):
|
| 559 |
+
html_in=f"<style>{css}</style><div class='img_box_soho'>"
|
| 560 |
+
#if int(date2[6:8])-int(date1[6:8]) >0:
|
| 561 |
+
# return ("<div style='font-size:xxx-large'>Reduce Timespan to 24 hours</div>")
|
| 562 |
+
in_year=f"{date2[0:4]}"
|
| 563 |
+
in_month=f"{date2[4:6]}"
|
| 564 |
+
in_day=f"{date2[6:8]}"
|
| 565 |
+
file_name="DATE_TIME_SIZE_TOOL.jpg"
|
| 566 |
+
sdo_source_format = f"https://sdo.gsfc.nasa.gov/assets/img/browse/{in_year}/{in_month}/{in_day}/"
|
| 567 |
+
get_url=sdo_source_format
|
| 568 |
+
print(get_url)
|
| 569 |
+
feed1 = requests.get(get_url)
|
| 570 |
+
if "All" in size:
|
| 571 |
+
size = sdo_size
|
| 572 |
+
if "All" in obj:
|
| 573 |
+
obj = sdo_obj
|
| 574 |
+
link_box=[]
|
| 575 |
+
soup = bs4.BeautifulSoup(feed1.content, 'html.parser')
|
| 576 |
+
anchor_elements = soup.find_all('a')
|
| 577 |
+
#anchor_elements.sort()
|
| 578 |
+
cnt=1
|
| 579 |
+
max_cnt=ret_num
|
| 580 |
+
for element in anchor_elements:
|
| 581 |
+
href=element.get('href')
|
| 582 |
+
if href.endswith('.jpg'):
|
| 583 |
+
for o in obj:
|
| 584 |
+
for s in size:
|
| 585 |
+
ls=href.split("_")
|
| 586 |
+
#print(ls[1][0:4])
|
| 587 |
+
#print(date1[8:13])
|
| 588 |
+
if ls[1][0:4]>=date1[8:13]:
|
| 589 |
+
src_obj=ls[3].split('.jpg')[0]
|
| 590 |
+
if src_obj == o:
|
| 591 |
+
if int(ls[2]) == int(s):
|
| 592 |
+
link_box.append(href)
|
| 593 |
+
|
| 594 |
+
|
| 595 |
+
#print(link_box)
|
| 596 |
+
#print("$$$$$$$$$$$$$$$$$")
|
| 597 |
+
link_box.sort(reverse=True)
|
| 598 |
+
#print(link_box)
|
| 599 |
+
out_box=[]
|
| 600 |
+
for ea in link_box:
|
| 601 |
+
if cnt<=max_cnt:
|
| 602 |
+
out_link=f'{sdo_source_format}{ea}'
|
| 603 |
+
out_box.append(out_link)
|
| 604 |
+
cnt+=1
|
| 605 |
+
html_in+=f'<div class="img_class_sdo"><a href="{sdo_source_format}{ea}" target="_blank">{ea}</a><br><img src={sdo_source_format}{ea}></div>'
|
| 606 |
+
|
| 607 |
+
html_in+="</div>"
|
| 608 |
+
return html_in, out_box
|
| 609 |
+
|
| 610 |
+
def run():
|
| 611 |
+
out=make_tree()
|
| 612 |
+
im_html=get_images()
|
| 613 |
+
return im_html
|
| 614 |
+
def get_date(year1,month1,day1,hour1,minute1,year2,month2,day2,hour2,minute2):
|
| 615 |
+
if len(str(month1))<2: m1=0
|
| 616 |
+
else: m1=""
|
| 617 |
+
if len(str(day1))<2: d1=0
|
| 618 |
+
else: d1=""
|
| 619 |
+
if len(str(hour1))<2: h1=0
|
| 620 |
+
else: h1=""
|
| 621 |
+
if len(str(minute1))<2: mi1=0
|
| 622 |
+
else: mi1=""
|
| 623 |
+
date1=f'{year1}{m1}{month1}{d1}{day1}{h1}{hour1}{mi1}{minute1}'
|
| 624 |
+
|
| 625 |
+
if len(str(month2))<2: m2=0
|
| 626 |
+
else: m2=""
|
| 627 |
+
if len(str(day2))<2: d2=0
|
| 628 |
+
else: d2=""
|
| 629 |
+
if len(str(hour2))<2: h2=0
|
| 630 |
+
else: h2=""
|
| 631 |
+
if len(str(minute2))<2: mi2=0
|
| 632 |
+
else: mi2=""
|
| 633 |
+
date2=f'{year2}{m2}{month2}{d2}{day2}{h2}{hour2}{mi2}{minute2}'
|
| 634 |
+
print(date1)
|
| 635 |
+
print(date2)
|
| 636 |
+
return date1,date2
|
| 637 |
+
def comp_combine(inp_ims: list,comp_col,comp_row,resize=False):
|
| 638 |
+
#print(inp_ims)
|
| 639 |
+
im_box=[]
|
| 640 |
+
v_box=[]
|
| 641 |
+
rows=comp_row
|
| 642 |
+
cols=comp_col
|
| 643 |
+
if not type(inp_ims)==type([]):
|
| 644 |
+
inp_ims=eval(inp_ims)
|
| 645 |
+
for i,im in enumerate(inp_ims):
|
| 646 |
+
urllib.request.urlretrieve(im, f"tmp-{i}.jpg")
|
| 647 |
+
if resize:
|
| 648 |
+
pil_im = Image.open(f'tmp-{i}.jpg')
|
| 649 |
+
pil_im = pil_im.resize((int(resize[0]),int(resize[1])),resample=Image.Resampling.LANCZOS).convert('RGB')
|
| 650 |
+
pil_im.save(f'tmp-{i}.jpg')
|
| 651 |
+
im_box.append(f"tmp-{i}.jpg")
|
| 652 |
+
im_cnt=len(im_box)
|
| 653 |
+
cnt=1
|
| 654 |
+
for rr in range(rows):
|
| 655 |
+
|
| 656 |
+
print(rr)
|
| 657 |
+
col_start=[im_box[cnt-1]]
|
| 658 |
+
for cc in range(cols-1):
|
| 659 |
+
try:
|
| 660 |
+
print(cc)
|
| 661 |
+
col_out=get_concat_h_cut(col_start[0],im_box[cnt])
|
| 662 |
+
col_start[0]=col_out
|
| 663 |
+
cnt+=1
|
| 664 |
+
#if cnt>=im_cnt:
|
| 665 |
+
# rr=range(rows)
|
| 666 |
+
# cc=range(cols)
|
| 667 |
+
except Exception as e:
|
| 668 |
+
print(e)
|
| 669 |
+
pass
|
| 670 |
+
cnt+=1
|
| 671 |
+
v_box.append(col_out)
|
| 672 |
+
|
| 673 |
+
print(v_box)
|
| 674 |
+
v_cnt=1
|
| 675 |
+
v_box_cnt=len(v_box)
|
| 676 |
+
v_start=[v_box[0]]
|
| 677 |
+
for vv in range(v_box_cnt-1):
|
| 678 |
+
print(vv)
|
| 679 |
+
v_out=get_concat_v_cut(v_start[0],v_box[v_cnt])
|
| 680 |
+
v_start[0]=v_out
|
| 681 |
+
v_cnt+=1
|
| 682 |
+
return v_out
|
| 683 |
+
def comp_1(comp_list=comp_list,col=3,row=4,resize=[640,450]):
|
| 684 |
+
#1280x900
|
| 685 |
+
outp=comp_combine(comp_list,col,row,resize)
|
| 686 |
+
return (outp)
|
| 687 |
+
datestamp=["1","1","1"]
|
| 688 |
+
timestamp=["1","1","1"]
|
| 689 |
+
datetimestamp="1:1:1"
|
| 690 |
+
def get_time():
|
| 691 |
+
datetimestamp=str(datetime.datetime.now()).split(".")[0]
|
| 692 |
+
datestamp=datetimestamp.replace(" ","-").split("-")
|
| 693 |
+
timestamp=datestamp[3].split(":")
|
| 694 |
+
|
| 695 |
+
html_out=f"""<div style='font-size:xxx-large;'>Current: {datetimestamp} UTC</div>"""
|
| 696 |
+
year1=int(datestamp[0])
|
| 697 |
+
month1=int(datestamp[1])
|
| 698 |
+
day1=int(datestamp[2])
|
| 699 |
+
hour1=int(timestamp[0])
|
| 700 |
+
minute1=int(timestamp[1])
|
| 701 |
+
year2=int(datestamp[0])
|
| 702 |
+
month2=int(datestamp[1])
|
| 703 |
+
day2=int(datestamp[2])
|
| 704 |
+
hour2=int(timestamp[0])
|
| 705 |
+
minute2=int(timestamp[1])
|
| 706 |
+
return (gr.update(value=html_out),gr.update(value=year1),gr.update(value=month1),
|
| 707 |
+
gr.update(value=day1),gr.update(value=hour1),gr.update(value=minute1),
|
| 708 |
+
gr.update(value=year2),gr.update(value=month2),gr.update(value=day2),gr.update(value=hour2),gr.update(value=minute2))
|
| 709 |
+
|
| 710 |
+
with gr.Blocks() as app:
|
| 711 |
+
#datetimestamp=gr.Textbox()
|
| 712 |
+
#datestamp=gr.Textbox()
|
| 713 |
+
url_list=gr.State([])
|
| 714 |
+
datetimestamp=str(datetime.datetime.now()).split(".")[0]
|
| 715 |
+
datestamp=datetimestamp.replace(" ","-").split("-")
|
| 716 |
+
timestamp=datestamp[3].split(":")
|
| 717 |
+
|
| 718 |
+
time_html=gr.HTML(f"""<div style='font-size:xxx-large;'>Current: {datetimestamp} UTC</div>""")
|
| 719 |
+
with gr.Tab("NOAA"):
|
| 720 |
+
with gr.Tab("Compilation"):
|
| 721 |
+
first_comp_btn=gr.Button("Load")
|
| 722 |
+
first_comp_img=gr.Image()
|
| 723 |
+
with gr.Tab("Images"):
|
| 724 |
+
first_btn=gr.Button("Load")
|
| 725 |
+
html_im=gr.HTML()
|
| 726 |
+
with gr.Tab("Animations"):
|
| 727 |
+
anim_btn=gr.Button()
|
| 728 |
+
anim_out=gr.HTML()
|
| 729 |
+
file_out=gr.Files()
|
| 730 |
+
with gr.Tab("Raw"):
|
| 731 |
+
with gr.Row():
|
| 732 |
+
drop1=gr.Dropdown()
|
| 733 |
+
drop2=gr.Dropdown()
|
| 734 |
+
drop3=gr.Dropdown()
|
| 735 |
+
drop4=gr.Dropdown()
|
| 736 |
+
with gr.Row():
|
| 737 |
+
drop5=gr.Dropdown()
|
| 738 |
+
drop6=gr.Dropdown()
|
| 739 |
+
drop7=gr.Dropdown()
|
| 740 |
+
drop8=gr.Dropdown()
|
| 741 |
+
load_btn=gr.Button("Load")
|
| 742 |
+
html_raw=gr.HTML()
|
| 743 |
+
links=gr.JSON()
|
| 744 |
+
with gr.Tab("NASA"):
|
| 745 |
+
with gr.Tab("SDO Images"):
|
| 746 |
+
with gr.Row():
|
| 747 |
+
gr.Markdown("<h5 style='font-size:xx-large;'>From:")
|
| 748 |
+
year1=gr.Number(label="Year",minimum=2000,maximum=2025,precision=0,value=int(datestamp[0]),min_width=10)
|
| 749 |
+
month1=gr.Number(label="Month",minimum=1,maximum=12,precision=0,value=int(datestamp[1]),min_width=10)
|
| 750 |
+
day1=gr.Number(label="Day",minimum=1,maximum=31,precision=0,value=int(datestamp[2]),min_width=10)
|
| 751 |
+
hour1=gr.Number(label="Hour",minimum=0,maximum=23,precision=0,value=int(timestamp[0]),min_width=10)
|
| 752 |
+
minute1=gr.Number(label="Minute",minimum=0,maximum=59,precision=0,value=int(timestamp[1]),min_width=10)
|
| 753 |
+
gr.Markdown("<h5 style='font-size:xx-large;'>To:")
|
| 754 |
+
year2=gr.Number(label="Year",minimum=2000,maximum=2025,precision=0,value=int(datestamp[0]),min_width=10)
|
| 755 |
+
month2=gr.Number(label="Month",minimum=1,maximum=12,precision=0,value=int(datestamp[1]),min_width=10)
|
| 756 |
+
day2=gr.Number(label="Day",minimum=1,maximum=31,precision=0,value=int(datestamp[2]),min_width=10)
|
| 757 |
+
hour2=gr.Number(label="Hour",minimum=0,maximum=23,precision=0,value=int(timestamp[0]),min_width=10)
|
| 758 |
+
minute2=gr.Number(label="Minute",minimum=0,maximum=59,precision=0,value=int(timestamp[1]),min_width=10)
|
| 759 |
+
|
| 760 |
+
with gr.Row():
|
| 761 |
+
sdo_drop1=gr.Dropdown(label="Instrument", multiselect=True, choices=["All"]+sdo_obj, value="0094")
|
| 762 |
+
sdo_drop2=gr.Dropdown(label="Size", multiselect=True, choices=["All"]+sdo_size,value=512)
|
| 763 |
+
|
| 764 |
+
with gr.Tab("Composite"):
|
| 765 |
+
with gr.Row():
|
| 766 |
+
comp_num=gr.Number(label="Return",precision=0,value=4,interactive=True)
|
| 767 |
+
comp_col=gr.Number(label="Columns",precision=0,value=2,interactive=True)
|
| 768 |
+
comp_row=gr.Number(label="Rows",precision=0,value=2,interactive=True)
|
| 769 |
+
with gr.Row():
|
| 770 |
+
comp_combine_btn=gr.Button("Combine")
|
| 771 |
+
sdo_comp_btn=gr.Button("Load")
|
| 772 |
+
img_out=gr.Image()
|
| 773 |
+
comp_combine_html=gr.HTML()
|
| 774 |
+
sdo_comp_html=gr.HTML()
|
| 775 |
+
image_comp_list=gr.Textbox(visible=True)
|
| 776 |
+
with gr.Tab("Images"):
|
| 777 |
+
sdo_btn=gr.Button("Load")
|
| 778 |
+
sdo_gif=gr.Button("Make GIF")
|
| 779 |
+
sdo_gif_html=gr.HTML()
|
| 780 |
+
sdo_gif.click(make_animation_new,url_list,sdo_gif_html)
|
| 781 |
+
sdo_html=gr.HTML()
|
| 782 |
+
|
| 783 |
+
|
| 784 |
+
date1=gr.Textbox(visible=False)
|
| 785 |
+
date2=gr.Textbox(visible=False)
|
| 786 |
+
#sdo_json=gr.JSON()
|
| 787 |
+
with gr.Tab("SOHO Images"):
|
| 788 |
+
soho_btn=gr.Button("Load")
|
| 789 |
+
html_nasa=gr.HTML()
|
| 790 |
+
with gr.Tab("SOHO Video"):
|
| 791 |
+
soho_vid_btn=gr.Button("Load")
|
| 792 |
+
html_vid_nasa=gr.HTML()
|
| 793 |
+
app.load(get_time,None,[time_html,year1,month1,day1,hour1,minute1,year2,month2,day2,hour2,minute2]).then(make_tree,None,drop1)
|
| 794 |
+
|
| 795 |
+
first_comp_btn.click(comp_1,None,first_comp_img)
|
| 796 |
+
###### Composite Images ##########
|
| 797 |
+
comp_combine_btn.click(comp_combine,[image_comp_list,comp_col,comp_row],img_out)
|
| 798 |
+
sdo_comp_btn.click(get_date,[year1,month1,day1,hour1,minute1,year2,month2,day2,hour2,minute2],[date1,date2]).then(nasa_sdo_composite,[sdo_drop1,sdo_drop2,date1,date2,comp_num],[sdo_comp_html,image_comp_list])
|
| 799 |
+
|
| 800 |
+
###### NASA Images ##########
|
| 801 |
+
sdo_btn.click(get_date,[year1,month1,day1,hour1,minute1,year2,month2,day2,hour2,minute2],[date1,date2]).then(nasa_sdo_images,[sdo_drop1,sdo_drop2,date1,date2],[sdo_html,url_list])
|
| 802 |
+
soho_btn.click(make_nasa_soho_image_trigger,None,html_nasa)
|
| 803 |
+
soho_vid_btn.click(make_nasa_soho_videos,None,html_vid_nasa)
|
| 804 |
+
###### NOAA Images ##########
|
| 805 |
+
load_btn.click(load_json,[drop1,drop2,drop3,drop4,drop5,drop6,drop7,drop8],[html_raw,links])
|
| 806 |
+
anim_btn.click(make_animation,None,[file_out]).then(make_html,file_out,anim_out)
|
| 807 |
+
####### Raw ############
|
| 808 |
+
drop1.change(make_tree,drop1,[drop2])
|
| 809 |
+
drop2.change(make_tree,[drop1,drop2],[drop3])
|
| 810 |
+
drop3.change(make_tree,[drop1,drop2,drop3],[drop4])
|
| 811 |
+
drop4.change(make_tree,[drop1,drop2,drop3,drop4],[drop5])
|
| 812 |
+
drop5.change(make_tree,[drop1,drop2,drop3,drop4,drop5],[drop6])
|
| 813 |
+
drop6.change(make_tree,[drop1,drop2,drop3,drop4,drop5,drop6],[drop7])
|
| 814 |
+
drop7.change(make_tree,[drop1,drop2,drop3,drop4,drop5,drop6,drop7],[drop8])
|
| 815 |
+
|
| 816 |
+
|
| 817 |
+
######################
|
| 818 |
+
first_btn.click(run,None,[html_im])
|
| 819 |
+
#app.load(make_tree,None,drop1)
|
| 820 |
+
app.queue(default_concurrency_limit=10).launch()
|
| 821 |
+
|
| 822 |
+
#test
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
moviepy
|
| 2 |
+
beautifulsoup4
|