Scraping Solar Demon
Retrieve a list of flares from Solar Demon as a CSV file.
What is it?
Solar Demon is a tool to detect flares, dimmings, and EUV waves in SDO/AIA images.
The associated paper is ‘Solar Demon - an approach to detecting flares, dimmings, and EUV waves on SDO AIA images’ by Kraaikamp and Verbeeck(2015).
Scraping the data
I wanted a way of converting all the data to a Pandas dataframe to export as a CSV. Here’s the code:
import pandas as pd
from bs4 import BeautifulSoup
import requests
from dateutil.parser import parse as parse_datetime_str
def find_month_breaks(rows):
breaks = []
for i, row in enumerate():
if i >= 1:
first_td = row.("td")
if first_td and first_td.("colspan"):
breaks.()
return breaks
def parse_row(rows, index):
return [e.text for e in[].("td")]
if __name__ == "__main__":
url = "https://www.sidc.be/solardemon/science/flares.php?min_seq=1&min_flux_est=0.000000001&days=0&science=1"
page = requests.() # this takes a few minutes to run
soup =(., 'html.parser')
rows = soup.("tr")
column_headers = ["day of month",
"est. class",
"start",
"peak",
"end",
"#",
"lat",
"lon",
"dist. R☉",
"AR" ,
"est. flux",
"GOES flux",
"GOES peak time",
"extra time",
"COMESEP",
"# det.",
"dimming"]
month_frames = []
month_breaks =() + [len()]
for i in range(len()-1):
month_yr_str =[[]].text
this_month_frame = pd.([(,) for in range([]+1,[+1])], columns=)
['month'] = month_yr_str.(",")[0]
['year'] = int(.(",")[1])
month_frames.()
df = pd.(, ignore_index=True)
# convert the month, day of month, and year columns into one date column
['date'] = (['month'] + " " +['day of month'] + ", " +['year'].(str)).(lambda r:(.(" ", "")))
df = df.(columns=["month", "day of month", "year"]) # drop the old columns
new_columns = ['date', 'est. class', 'start', 'peak', 'end', '#', 'lat', 'lon', 'dist. R☉',
'AR', 'est. flux', 'GOES flux', 'GOES peak time', 'extra time',
'COMESEP', '# det.', 'dimming']
df =[] # reorder the columns
# do whatever you want with the pandas dataframe now, e.g. write it to CSV
df.("solar_demon_data.csv")
Enjoy!