Omnibus commited on
Commit
ff80f39
·
verified ·
1 Parent(s): b819c70

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -25
app.py CHANGED
@@ -51,8 +51,12 @@ nasa_soho_mp4=[
51
  {"name":"SDO/HMI Magnetogram", "source":"https://soho.nascom.nasa.gov/data/LATEST/current_hmi_mag-512.mp4"},
52
  ]
53
 
54
-
55
-
 
 
 
 
56
  html = """
57
  <div>
58
  PAGE_LINK
@@ -247,10 +251,8 @@ def make_nasa_soho_image_trigger():
247
 
248
  def nasa_sdo_images(obj,size,date1,date2):
249
  html_in=f"<style>{css}</style><div class='img_box_soho'>"
250
- if size=="All":
251
- size1=9999
252
- else:
253
- size1=size
254
  if int(date2[6:8])-int(date1[6:8]) >0:
255
  return ("<div style='font-size:xxx-large'>Reduce Timespan to 24 hours</div>")
256
 
@@ -261,8 +263,14 @@ def nasa_sdo_images(obj,size,date1,date2):
261
  sdo_source_format = f"https://sdo.gsfc.nasa.gov/assets/img/browse/{in_year}/{in_month}/{in_day}/"
262
  get_url=sdo_source_format
263
  print(get_url)
264
- feed1 = requests.get(get_url)
265
 
 
 
 
 
 
 
266
  link_box=[]
267
  # Parse the HTML content using BeautifulSoup
268
  soup = bs4.BeautifulSoup(feed1.content, 'html.parser')
@@ -271,18 +279,16 @@ def nasa_sdo_images(obj,size,date1,date2):
271
  for element in anchor_elements:
272
  href=element.get('href')
273
  if href.endswith('.jpg'):
274
- ls=href.split("_")
275
- print(ls[1][0:4])
276
- print(date1[8:13])
277
- if ls[1][0:4]>=date1[8:13]:
278
- src_obj=ls[3].split('.jpg')[0]
279
- if src_obj == obj or obj=="All":
280
- if int(ls[2]) == int(size1) or size=="All":
281
-
282
- #link_json={'year':ls[0][0:4],'month':ls[0][4:6],'day':ls[0][6:8],'time':ls[1],'size':ls[2],'obj':src_obj}
283
- #print(href)
284
- #link_box.append(link_json)
285
- html_in+=f'<div class="img_class_sdo"><a href="{sdo_source_format}{href}" target="_blank">{href}</a><br><img src={sdo_source_format}{href}></div>'
286
  html_in+="</div>"
287
  return html_in
288
  def run():
@@ -352,12 +358,8 @@ with gr.Blocks() as app:
352
  minute2=gr.Number(label="Minute",minimum=0,maximum=59,precision=0,value=int(timestamp[1]),min_width=10)
353
 
354
  with gr.Row():
355
- sdo_drop1=gr.Dropdown(label="Instrument", choices=["All","HMIB","HMIBC","HMIIC","HMIIF","HMID","HMII","HMI171",
356
- "0094","0131","0171","0193","0211",
357
- "0304","0335","1600","1700","4500",
358
- "211193171","211193171n","211193171rg",
359
- "094335193","304211171"], value="All")
360
- sdo_drop2=gr.Dropdown(label="Size", choices=[256,512,1024,2048,4096,"All"],value=512)
361
 
362
  sdo_btn=gr.Button("Load")
363
  sdo_html=gr.HTML()
 
51
  {"name":"SDO/HMI Magnetogram", "source":"https://soho.nascom.nasa.gov/data/LATEST/current_hmi_mag-512.mp4"},
52
  ]
53
 
54
+ sdo_obj = ["HMIB","HMIBC","HMIIC","HMIIF","HMID","HMII","HMI171",
55
+ "0094","0131","0171","0193","0211",
56
+ "0304","0335","1600","1700","4500",
57
+ "211193171","211193171n","211193171rg",
58
+ "094335193","304211171"]
59
+ sdo_size= [256,512,1024,2048,4096]
60
  html = """
61
  <div>
62
  PAGE_LINK
 
251
 
252
  def nasa_sdo_images(obj,size,date1,date2):
253
  html_in=f"<style>{css}</style><div class='img_box_soho'>"
254
+
255
+
 
 
256
  if int(date2[6:8])-int(date1[6:8]) >0:
257
  return ("<div style='font-size:xxx-large'>Reduce Timespan to 24 hours</div>")
258
 
 
263
  sdo_source_format = f"https://sdo.gsfc.nasa.gov/assets/img/browse/{in_year}/{in_month}/{in_day}/"
264
  get_url=sdo_source_format
265
  print(get_url)
266
+ feed1 = requests.get(get_url)
267
 
268
+
269
+ if "All" in size:
270
+ size = sdo_size
271
+ if "All" in obj:
272
+ obj = sdo_obj
273
+
274
  link_box=[]
275
  # Parse the HTML content using BeautifulSoup
276
  soup = bs4.BeautifulSoup(feed1.content, 'html.parser')
 
279
  for element in anchor_elements:
280
  href=element.get('href')
281
  if href.endswith('.jpg'):
282
+ for o in obj:
283
+ for s in size:
284
+ ls=href.split("_")
285
+ print(ls[1][0:4])
286
+ print(date1[8:13])
287
+ if ls[1][0:4]>=date1[8:13]:
288
+ src_obj=ls[3].split('.jpg')[0]
289
+ if src_obj == o:
290
+ if int(ls[2]) == int(size):
291
+ html_in+=f'<div class="img_class_sdo"><a href="{sdo_source_format}{href}" target="_blank">{href}</a><br><img src={sdo_source_format}{href}></div>'
 
 
292
  html_in+="</div>"
293
  return html_in
294
  def run():
 
358
  minute2=gr.Number(label="Minute",minimum=0,maximum=59,precision=0,value=int(timestamp[1]),min_width=10)
359
 
360
  with gr.Row():
361
+ sdo_drop1=gr.Dropdown(label="Instrument", multiselect=True, choices=["All"]+sdo_obj, value="0094")
362
+ sdo_drop2=gr.Dropdown(label="Size", multiselect=True, choices=["All"]+sdo_size,value=512)
 
 
 
 
363
 
364
  sdo_btn=gr.Button("Load")
365
  sdo_html=gr.HTML()