# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# The data from Maven here is from 01/01/2015 to 03/01/2015, at the beginning of the mission. This was the first attempt at filtering the data, without using the quality data from the SPDF website.

import numpy as np
import pandas as pd
import datetime
posFrame = pd.read_csv('csv files/MavenPosition2.csv')
windFrame = pd.read_csv('csv files/MavenSolarWind2.csv')
windFrame = windFrame.loc[:, ~windFrame.columns.str.contains('^Unnamed')]
posFrame = posFrame.loc[:, ~posFrame.columns.str.contains('^Unnamed')]
windFrame['EPOCH__yyyy-mm-ddThh:mm:ss.sssZ'] = pd.to_datetime(windFrame['EPOCH__yyyy-mm-ddThh:mm:ss.sssZ'])
windFrame['date'] = pd.to_datetime(windFrame['EPOCH__yyyy-mm-ddThh:mm:ss.sssZ']).dt.date
posFrame['EPOCH_yyyy-mm-ddThh:mm:ss.sssZ'] = pd.to_datetime(posFrame['EPOCH_yyyy-mm-ddThh:mm:ss.sssZ'])
posFrame['date'] = pd.to_datetime(posFrame['EPOCH_yyyy-mm-ddThh:mm:ss.sssZ']).dt.date
mergedFrame = pd.merge(windFrame, posFrame, on='date')
mergedFrame = mergedFrame.drop(['date', 'EPOCH_yyyy-mm-ddThh:mm:ss.sssZ'], axis=1)
mergedFrame = mergedFrame[mergedFrame.IonDensityN_CC != -1.0E+31]
mergedFrame = mergedFrame[mergedFrame.IonVelocityXKM_S != -1.0E+31]
mergedFrame = mergedFrame[mergedFrame.IonVelocityYKM_S != -1.0E+31]
mergedFrame = mergedFrame[mergedFrame.IonVelocityZKM_S != -1.0E+31]
mergedFrame.to_csv(r'csv files/MavenMerged2.csv')
mergedFrame.describe()

# +
import numpy as np
import pandas as pd
import datetime
import matplotlib.pyplot as plt

fig = plt.figure()
fig.suptitle("Maven velocity and position data")

df = pd.read_csv('csv files/MavenMerged2.csv')
df['EPOCH__yyyy-mm-ddThh:mm:ss.sssZ'] = pd.to_datetime(df['EPOCH__yyyy-mm-ddThh:mm:ss.sssZ'])
df = df.loc[:, ~df.columns.str.contains('^Unnamed')]

df['IonSpeedKM_S'] = np.linalg.norm(df[['IonVelocityXKM_S','IonVelocityYKM_S','IonVelocityZKM_S']].values,axis=1)

df = df.resample('H', on = 'EPOCH__yyyy-mm-ddThh:mm:ss.sssZ').mean().reset_index()

df.plot(kind='line', x='EPOCH__yyyy-mm-ddThh:mm:ss.sssZ', y='IonDensityN_CC')
df.plot(kind='line', x='EPOCH__yyyy-mm-ddThh:mm:ss.sssZ', y='IonSpeedKM_S')
df.plot(kind='line', x='EPOCH__yyyy-mm-ddThh:mm:ss.sssZ', y='MarsGeoXKM')
df.plot(kind='line', x='EPOCH__yyyy-mm-ddThh:mm:ss.sssZ', y='MarsGeoYKM')
df.plot(kind='line', x='EPOCH__yyyy-mm-ddThh:mm:ss.sssZ', y='MarsGeoZKM')

plt.show()

# +
import numpy as np
import pandas as pd
import datetime
import matplotlib.pyplot as plt

plt.rcParams['figure.figsize'] = [5, 5]

fig, axes = plt.subplots(nrows = 5, ncols=1)
fig.suptitle("Maven velocity and position data")

df = pd.read_csv('csv files/MavenMerged2.csv')
df['EPOCH__yyyy-mm-ddThh:mm:ss.sssZ'] = pd.to_datetime(df['EPOCH__yyyy-mm-ddThh:mm:ss.sssZ'])
df['IonSpeedKM_S'] = np.linalg.norm(df[['IonVelocityXKM_S','IonVelocityYKM_S','IonVelocityZKM_S']].values,axis=1)

df = df.resample('H', on = 'EPOCH__yyyy-mm-ddThh:mm:ss.sssZ').mean().reset_index()

df2 = pd.read_csv('csv files/Omni4Maven2.csv')
df2['EPOCH_TIME_yyyy-mm-ddThh:mm:ss.sssZ'] = pd.to_datetime(df2['EPOCH_TIME_yyyy-mm-ddThh:mm:ss.sssZ'])
df2 = df2[df2['ION_DENSITY_N/cm3'] != -1.0E+31]
df2 = df2.resample('H', on = 'EPOCH_TIME_yyyy-mm-ddThh:mm:ss.sssZ').mean().reset_index()

#ax = plt.gca()
df.plot(kind='line', x='EPOCH__yyyy-mm-ddThh:mm:ss.sssZ', y='IonSpeedKM_S', ax=axes[1])
df2.plot(kind='line', x='EPOCH_TIME_yyyy-mm-ddThh:mm:ss.sssZ', y='BULK_FLOW_SPEED_km/s',color='red', ax=axes[0])

df.plot(kind='line', x='EPOCH__yyyy-mm-ddThh:mm:ss.sssZ', y='MarsGeoXKM', ax=axes[2])
df.plot(kind='line', x='EPOCH__yyyy-mm-ddThh:mm:ss.sssZ', y='MarsGeoYKM', ax=axes[3])
df.plot(kind='line', x='EPOCH__yyyy-mm-ddThh:mm:ss.sssZ', y='MarsGeoZKM', ax=axes[4])
#df.plot(kind='line', x='EPOCH__yyyy-mm-ddThh:mm:ss.sssZ', y='IonDensityN_CC', color='red', ax=ay)
#df2.plot(kind='line', x='EPOCH_TIME_yyyy-mm-ddThh:mm:ss.sssZ', y='ION_DENSITY_N/cm3',  ax=ay)
for ax in axes:
    ax.set_xlim([datetime.date(2015, 1, 2), datetime.date(2015, 1, 3)])

plt.show()

# +
import numpy as np
import pandas as pd
import datetime
import matplotlib.pyplot as plt

fig = plt.figure()
fig.suptitle("Maven filtered speed")


df = pd.read_csv('csv files/MavenMerged2.csv')
df['EPOCH__yyyy-mm-ddThh:mm:ss.sssZ'] = pd.to_datetime(df['EPOCH__yyyy-mm-ddThh:mm:ss.sssZ'])
#df = df[df['MarsGeoXKM'] >= -0]
#df = df[df['MarsGeoYKM'] >= 0]
#df = df[df['MarsGeoZKM'] >= 0]
df['IonSpeedKM_S'] = np.linalg.norm(df[['IonVelocityXKM_S','IonVelocityYKM_S','IonVelocityZKM_S']].values,axis=1)
df = df.resample('H', on = 'EPOCH__yyyy-mm-ddThh:mm:ss.sssZ').mean().reset_index()

df1 = pd.read_csv('csv files/Omni4Maven2.csv')
df1['EPOCH_TIME_yyyy-mm-ddThh:mm:ss.sssZ'] = pd.to_datetime(df1['EPOCH_TIME_yyyy-mm-ddThh:mm:ss.sssZ'])

#df.plot(kind='line', x='EPOCH__yyyy-mm-ddThh:mm:ss.sssZ', y='IonSpeedKM_S')

ax = plt.gca()
ay = plt.gca()
df.plot(kind='line', x='EPOCH__yyyy-mm-ddThh:mm:ss.sssZ', y='IonSpeedKM_S', color='red', ax=ax)
df1.plot(kind='line', x='EPOCH_TIME_yyyy-mm-ddThh:mm:ss.sssZ', y='BULK_FLOW_SPEED_km/s', ax=ax)

ax.set_xlim([datetime.date(2015, 1, 2), datetime.date(2015, 1, 5)])

plt.show()
# -



StarcoderdataJupyterScriptsDedupFiltered