# Copyright 2020 Alexander Lavrukhin <lavrukhin@physics.msu.ru>, David Parunakian <rumith@srd.sinp.msu.ru>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#############################################################
# Short script to plot MESSENGER magnetic field and bow shock
# and magnetopause crossings along an orbit
import pandas as pd
import numpy as np
import plotly.graph_objs as go
import plotly.express as px
from plotly.subplots import make_subplots
# ENTER NUMBER OF ORBIT # (EXCLUDING 0025, 0026) #
orbit = '0027'
#_______________________#________________________#
# Reading orbit file from FTP
df = pd.read_csv('ftp://epn2024.sinp.msu.ru/messenger/messenger-' + orbit + '.csv', sep = ',')
df["B_tot"] = (df["BX_MSO"]**2 + df["BY_MSO"]**2 + df["BZ_MSO"]**2)**0.5
# Reading crossings file from FTP
# BS - bow shock; MP - magnetopause
df_cross = pd.read_csv('ftp://epn2024.sinp.msu.ru/messenger/Mercury_BS_and_MP_crossings.csv', sep = ',')
print(df_cross.head())
# plotting total magnetic field magnitude B along the orbit
fig = go.Figure()
fig.add_trace(go.Scatter(x = df['DATE'], y = df['B_tot'], name = 'B_total'))
# BS MP crossings times
orb_num = int(orbit) - 1
for i in range(1,9):
fig.add_trace(go.Scatter(x = [df_cross.iloc[orb_num][i], df_cross.iloc[orb_num][i]], y = [0, 450], mode='lines', name = df_cross.columns[i], line_color = 'black'))
fig.show()
# Plotting components of the magnetic field B_x, B_y, B_z in MSO coordinates
fig = go.Figure()
fig.add_trace(go.Scatter(x = df['DATE'], y = df['BX_MSO'], name = 'B_x'))
fig.add_trace(go.Scatter(x = df['DATE'], y = df['BY_MSO'], name = 'B_y'))
fig.add_trace(go.Scatter(x = df['DATE'], y = df['BZ_MSO'], name = 'B_z'))
# BS MP crossings times
orb_num = int(orbit) - 1
for i in range(1,9):
fig.add_trace(go.Scatter(x = [df_cross.iloc[orb_num][i], df_cross.iloc[orb_num][i]], y = [-450, 450], mode='lines', name = df_cross.columns[i], line_color = 'black'))
fig.show()