Skip to content

Commit b9255e9

Browse files
committed
Resolved add/add conflicts
2 parents 11d2efb + 87fe9b8 commit b9255e9

9 files changed

Lines changed: 1426 additions & 0 deletions

grb/grbs_plot.svg

Lines changed: 163 additions & 0 deletions
Loading

py/mk_grb_stats.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import os
2+
import pickle
3+
import urllib.request
4+
5+
from beautifulsoup_supply import TAIL, mk_head, get_soup
6+
from plot_supply import plot_bar, optimize_svg
7+
8+
9+
HEAD = mk_head("Статистика гамма-всплесков", style="../../compact.css", script="") + "<body>\n"
10+
GRB_URL = "https://www.mpe.mpg.de/~jcg/grbgen.html"
11+
HTML_FILENAME = os.path.join(os.pardir, 'grb', 'stats', 'index.html')
12+
13+
14+
def get_grb(soup):
15+
all_tabs = soup.findAll('table')
16+
trs = all_tabs[-1].findAll('tr')
17+
years, gnums, opts = [], [], []
18+
for tr in trs[1:-1]:
19+
tds = tr.findAll('td')
20+
opt = int(tds[3].text)
21+
years.append(int(tds[0].text))
22+
gnums.append(int(tds[1].text) - opt)
23+
opts.append(opt)
24+
return years, gnums, opts
25+
26+
soup = get_soup(GRB_URL)
27+
years, grbnums, opts = get_grb(soup)
28+
29+
labels = ('Статистика гамма-всплесков по годам', 'Год', 'Открытий за год')
30+
tmp_filename = 'grbs_plot_.svg'
31+
filename = 'grbs_plot.svg'
32+
grb_dir = os.path.join(os.pardir, 'grb')
33+
tmp_pth = os.path.join(grb_dir, tmp_filename)
34+
pth = os.path.join(grb_dir, filename)
35+
xlim = (1996.3, 2020.7)
36+
plot_bar(years, grbnums, opts, labels, tmp_pth, xlim)
37+
optimize_svg(tmp_pth, pth)
38+
os.remove(tmp_pth)
39+
40+
grbstats_txt = f"""<h2><a href="{GRB_URL}">Статистика гамма-всплесков</a></h2>
41+
<ul>
42+
"""
43+
all_grb_count, opt_count = 0, 0
44+
for i, year in enumerate(years):
45+
grbs_num = grbnums[i] + opts[i]
46+
all_grb_count += grbs_num
47+
opt_count += opts[i]
48+
grbstats_txt += f"<li>За {year} год открыто <b>{grbs_num}</b> гама-всплесков, <b>{opts[i]}</b> – послесвечений. Всего к концу года открыто <b>{all_grb_count}</b>, <b>{opt_count}</b> – послесвечений.\n"
49+
50+
grbstats_txt += f"""</ul>
51+
<br><img src="../{filename}" alt="">
52+
<h2>Ссылки</h2>
53+
<ul>
54+
<li><a href="https://heasarc.gsfc.nasa.gov/W3Browse/fermi/fermigbrst.html" target="_blank" rel="noopener noreferrer">FERMIGBRST - Fermi GBM Burst Catalog</a>
55+
<li><a href="https://gcn.gsfc.nasa.gov/gcn/gcn3_archive.html" target="_blank" rel="noopener noreferrer">GCN Circulars Archive</a>
56+
</ul>
57+
"""
58+
59+
with open(HTML_FILENAME, 'w', encoding="utf8") as handle:
60+
print(HEAD + grbstats_txt + TAIL, file=handle)

py/mk_spacesebris_stats.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
"""Python script for genererating an html page
2+
with space debris statistics. Data sources:
3+
https://www.esa.int/Safety_Security/Space_Debris/Space_debris_by_the_numbers
4+
https://sdup.esoc.esa.int/discosweb/statistics/
5+
https://www.sdo.esoc.esa.int/environment_report/Space_Environment_Report_latest.pdf
6+
"""
7+
8+
import os
9+
import urllib.request
10+
11+
from beautifulsoup_supply import TAIL, mk_head, get_soup
12+
13+
14+
SD_URL = 'https://sdup.esoc.esa.int/discosweb/statistics/embed/bythenumbers'
15+
16+
17+
def get_sd(soup):
18+
"""Parse html, get date of last page update,
19+
statistics of space debris."""
20+
months_dct = {"January": "января", "April": "апреля", "May": "мая", "July": "июля", "August": "августа", "September": "сентября"}
21+
date = soup.find("p").text.split()[4:]
22+
date[1] = months_dct[date[1]]
23+
dd = soup.find("dl").findAll("dd")
24+
stats = [dd[x].text.split()[1] for x in range(5)]
25+
stats.append(dd[5].text.split()[2])
26+
stats.append(dd[6].text.split()[2])
27+
debrs_modelled = dd[7].text.split()
28+
debrs_modelled = [debrs_modelled[0], debrs_modelled[6], debrs_modelled[16]]
29+
return " ".join(date), stats, debrs_modelled
30+
31+
32+
soup = get_soup(SD_URL)
33+
DATE, stats, DEBR_MODEL = get_sd(soup)
34+
35+
HEAD = mk_head("Космический мусор: статистика", style="stats.css", script="")
36+
BODY = f"""<body">
37+
<div id="stats" class="container show">
38+
<h1 id="header">Космический мусор: статистика от {DATE} года</h1>
39+
<div class="list">
40+
<ul>
41+
<li>Количество запусков ракет с начала космической эры: около <span class="yellow">{stats[0]}</span></li>
42+
<li>Количество запущенных ими спутников: около <span class="yellow">{stats[1]}</span></li>
43+
<li>Из них до сих пор на орбите: около <span class="yellow">{stats[2]}</span></li>
44+
<li>Из них до сих пор функционируют: около <span class="yellow">{stats[3]}</span></li>
45+
<li>Объектов отслеживается Сетью Космического Наблюдения США: около <span class="yellow">{stats[4]}</span></li>
46+
<li>Оцениваемое количество событий, приводящих к фрагментации: более <span class="yellow">{stats[5]}</span></li>
47+
<li>Полная масса космических объектов на орбите Земли: более <span class="yellow">{stats[6]}</span> тонн</li>
48+
</ul>
49+
</div>
50+
<div id="footer">
51+
<h2>Центр Астрономического и&nbsp;космического образования</h2>
52+
</div>
53+
</div>
54+
"""
55+
56+
"""
57+
<li>Количество находящихся на орбите объектов космического мусора (Оценки по статистическим моделям):
58+
<ul>
59+
<li><span class="yellow">{DEBR_MODEL[0]}</span> объектов более 10 см
60+
<li><span class="yellow">{DEBR_MODEL[1]}</span> объектов от 1 до 10 см
61+
<li><span class="yellow">{DEBR_MODEL[2]}</span> миллионов объектов от 1 мм до 1 см
62+
</ul>
63+
</li>
64+
"""
65+
with open(os.path.join(os.pardir, 'cosm', 'debris', 'index.html'), 'w', encoding="utf8") as handle:
66+
print(HEAD + BODY + TAIL, file=handle)
72.9 KB
Loading

0 commit comments

Comments
 (0)