generated from erosita/uds
final
This commit is contained in:
32
scripts/00_dyear_to_date.py
Executable file
32
scripts/00_dyear_to_date.py
Executable file
@@ -0,0 +1,32 @@
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
def decimal_year_to_date(decimal_year):
|
||||
"""
|
||||
Converts a decimal year (e.g., 2024.5) to a datetime object.
|
||||
"""
|
||||
year = int(decimal_year)
|
||||
fractional_year = decimal_year - year
|
||||
|
||||
# Determine if it's a leap year to get the correct number of days
|
||||
is_leap_year = (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0)
|
||||
days_in_year = 366 if is_leap_year else 365
|
||||
|
||||
# Calculate the day of the year (1-indexed)
|
||||
day_of_year = int(fractional_year * days_in_year) + 1
|
||||
|
||||
# Create a datetime object for January 1st of the given year
|
||||
start_of_year = datetime(year, 1, 1)
|
||||
|
||||
# Add the calculated number of days to get the final date
|
||||
result_date = start_of_year + timedelta(days=day_of_year - 1)
|
||||
|
||||
return result_date
|
||||
|
||||
# Example usage:
|
||||
decimal_year_example = 2020.9181
|
||||
date_result = decimal_year_to_date(decimal_year_example)
|
||||
print(f"Decimal year {decimal_year_example} converts to: {date_result}")
|
||||
|
||||
decimal_year_example_2 = 2021.8271
|
||||
date_result_2 = decimal_year_to_date(decimal_year_example_2)
|
||||
print(f"Decimal year {decimal_year_example_2} converts to: {date_result_2}")
|
124
scripts/02_plot_zoom.py
Executable file
124
scripts/02_plot_zoom.py
Executable file
@@ -0,0 +1,124 @@
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
НАЗВАНИЕ:
|
||||
|
||||
plot.py
|
||||
|
||||
|
||||
НАЗНАЧЕНИЕ:
|
||||
|
||||
Простой скрипт для отрисовки файла, выгруженного с СРГ L2 монитора https://monitor.srg.cosmos.ru/
|
||||
|
||||
ВЫЗОВ:
|
||||
|
||||
conda activate
|
||||
./plot.py
|
||||
|
||||
|
||||
УПРАВЛЕНИЕ:
|
||||
|
||||
Название файла надо вставить внутрь скрипта (ищите default.csv)
|
||||
|
||||
ПАРАМЕТРЫ:
|
||||
|
||||
N/A
|
||||
|
||||
|
||||
ВЫВОД:
|
||||
|
||||
Файл monitor.png записывается в текущую директорию
|
||||
|
||||
|
||||
ИСТОРИЯ:
|
||||
 Роман Кривонос, ИКИ РАН, krivonos@cosmos.ru
|
||||
Декабрь 2024
|
||||
|
||||
"""
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
from matplotlib import ticker
|
||||
import pandas as pd
|
||||
import datetime
|
||||
import dateutil
|
||||
from os.path import dirname
|
||||
import inspect
|
||||
|
||||
import monitor
|
||||
from monitor.config import *
|
||||
from monitor.utils import *
|
||||
|
||||
""" find root dir """
|
||||
root_path=dirname(dirname(dirname(inspect.getfile(monitor))))
|
||||
print("Monitor root path: {}".format(root_path))
|
||||
|
||||
|
||||
products_dir=root_path+'/products/'
|
||||
data_dir=root_path+'/data/'
|
||||
|
||||
create_folder(products_dir)
|
||||
|
||||
fig, ax = plt.subplots(figsize=(9, 5), dpi=100)
|
||||
|
||||
|
||||
#ax.set(xlabel='time (s)', ylabel='voltage (mV)',
|
||||
# title='About as simple as it gets, folks')
|
||||
|
||||
ax.grid(visible=True,linestyle='dotted', )
|
||||
ax.xaxis.set_minor_locator(ticker.MultipleLocator(1/12))
|
||||
ax.yaxis.set_minor_locator(ticker.MultipleLocator(0.2))
|
||||
ax.tick_params(axis="both", width=1, labelsize=14)
|
||||
|
||||
#ax.grid()
|
||||
#plt.xlim([2020,2025])
|
||||
#plt.ylim([2,12])
|
||||
ax.xaxis.set_minor_locator(ticker.MultipleLocator(1/12))
|
||||
ax.yaxis.set_minor_locator(ticker.MultipleLocator(0.2))
|
||||
ax.tick_params(axis="both", width=1, labelsize=14)
|
||||
|
||||
for axis in ['top','bottom','left','right']:
|
||||
ax.spines[axis].set_linewidth(1)
|
||||
|
||||
cl='black'
|
||||
|
||||
input_file='flare2.csv'
|
||||
|
||||
# Сюда надо вставить название файла, скачанного с https://monitor.srg.cosmos.ru/
|
||||
df = pd.read_csv(data_dir+input_file)
|
||||
|
||||
|
||||
tm=[]
|
||||
rate=[]
|
||||
|
||||
# first flare (weak)
|
||||
#year=2020
|
||||
#tstart=2020.8365-year
|
||||
#tstop=2020.9916-year
|
||||
|
||||
# second flare (strong)
|
||||
year=2021
|
||||
tstart=2021.800-year
|
||||
tstop=2021.88-year
|
||||
|
||||
for index, row in df.iterrows():
|
||||
dt = dateutil.parser.parse(row['timestamp'])
|
||||
dyear = get_decimal_year(dt)-year
|
||||
|
||||
if(dyear < tstart or dyear > tstop):
|
||||
continue
|
||||
tm.append(dyear)
|
||||
rate.append(float(row['value_60.0-120.0']))
|
||||
|
||||
plt.plot(tm, rate, color=cl, linewidth=2, linestyle='solid')
|
||||
|
||||
#geminga_dt = datetime.date.fromisoformat('2023-04-16')
|
||||
#day_of_year = geminga_dt.timetuple().tm_yday # returns 1 for January 1st
|
||||
#geminga_tm=geminga_dt.year+(day_of_year/365)
|
||||
#plt.axvline(x = geminga_tm, color = 'b', linewidth=3 , linestyle='dashed', label = 'Geminga scan')
|
||||
|
||||
plt.ylabel('Count rate (counts s$^{-1}$)',fontsize=14, fontweight='normal')
|
||||
plt.xlabel(f'Year {year}',fontsize=14, fontweight='normal')
|
||||
|
||||
fout_png=input_file.replace(".csv",".png")
|
||||
fig.savefig(products_dir+fout_png, bbox_inches='tight')
|
||||
plt.show()
|
@@ -73,6 +73,13 @@ ax.xaxis.set_minor_locator(ticker.MultipleLocator(1/12))
|
||||
ax.yaxis.set_minor_locator(ticker.MultipleLocator(0.2))
|
||||
ax.tick_params(axis="both", width=1, labelsize=14)
|
||||
|
||||
#geminga_dt = datetime.date.fromisoformat('2023-04-16')
|
||||
#day_of_year = geminga_dt.timetuple().tm_yday # returns 1 for January 1st
|
||||
#geminga_tm=geminga_dt.year+(day_of_year/365)
|
||||
#plt.axvline(x = geminga_tm, color = 'b', linewidth=3 , linestyle='dashed', label = 'Geminga scan')
|
||||
|
||||
|
||||
|
||||
#plt.xlim([2020,2025])
|
||||
#plt.ylim([2,12])
|
||||
plt.ylabel('Count rate (counts s$^{-1}$)',fontsize=14, fontweight='normal')
|
||||
|
Reference in New Issue
Block a user