Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions scripts/realtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
# Numerical
import numpy as np
import pandas as pd
from pySECS import SECS
from pysecs import SECS
import bezpy

# Plotting libraries
Expand Down Expand Up @@ -124,13 +124,13 @@ def __init__(self, name='BOU'):
self.update_data()

def _update_times(self):
self.end_time = datetime.datetime.utcnow()
self.end_time = datetime.datetime.now(datetime.UTC)
self.start_time = self.end_time - self.dt

def update_data(self):
self._update_times()

url = ("{server_url}/ws/edge/?format=json".format(server_url=SERVER_URL) +
url = ("{server_url}/ws/data/?format=json".format(server_url=SERVER_URL) +
"&id={name}".format(name=self.name) +
"&type={loc_code}".format(loc_code=self.loc_code) +
"&starttime={starttime}".format(starttime=self.start_time.strftime("%Y-%m-%dT%H:%M:%SZ")) +
Expand All @@ -145,9 +145,10 @@ def update_data(self):
data={'X': data['values'][0]['values'],
'Y': data['values'][1]['values'],
'Z': data['values'][2]['values']},
dtype=np.float).dropna()
dtype=float).dropna()

self.df['Direction'] = np.rad2deg(np.arctan2(self.df['X'], self.df['Y']))
print(f"Succesfully updated {self.name}")
except:
print(f"Failed to update {self.name}")

Expand Down Expand Up @@ -216,9 +217,9 @@ def update_data(self):
obs_lat_lon_r[:,1] = good_xy[:,0]
obs_lat_lon_r[:,2] = R_earth

obs_var = np.ones(obs_lat_lon_r.shape)
obs_var = np.ones(B_obs.shape)
# Don't include Z component in fits for now
obs_var[:,2] = np.inf
obs_var[:,:,2] = np.inf

gridded_lat_lon_r = np.zeros((len(gridded_xy), 3))
gridded_lat_lon_r[:,0] = gridded_xy[:,1]
Expand All @@ -238,7 +239,7 @@ def update_data(self):
#--------------
secs = SECS(sec_df_loc=secs_lat_lon_r)
secs.fit(obs_loc=obs_lat_lon_r, obs_B=B_obs,
obs_var=obs_var, epsilon=0.05)
obs_std=obs_var, epsilon=0.05)

B_gridded = secs.predict_B(gridded_lat_lon_r)

Expand Down
15 changes: 8 additions & 7 deletions scripts/secs_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
# Numerical
import numpy as np
import pandas as pd
from secs import SECS
from pysecs import SECS
import bezpy

#------------------
Expand Down Expand Up @@ -79,13 +79,13 @@ def __init__(self, name='BOU'):
self.update_data()

def _update_times(self):
self.end_time = datetime.datetime.utcnow()
self.end_time = datetime.datetime.now(datetime.UTC)
self.start_time = self.end_time - self.dt

def update_data(self):
self._update_times()

url = ("{server_url}/ws/edge/?format=json".format(server_url=SERVER_URL) +
url = ("{server_url}/ws/data/?format=json".format(server_url=SERVER_URL) +
"&id={name}".format(name=self.name) +
"&type={loc_code}".format(loc_code=self.loc_code) +
"&starttime={starttime}".format(starttime=self.start_time.strftime("%Y-%m-%dT%H:%M:%SZ")) +
Expand All @@ -100,9 +100,10 @@ def update_data(self):
data={'X': data['values'][0]['values'],
'Y': data['values'][1]['values'],
'Z': data['values'][2]['values']},
dtype=np.float).dropna()
dtype=float).dropna()

self.df['Direction'] = np.rad2deg(np.arctan2(self.df['X'], self.df['Y']))
print(f"Succesfully updated {self.name}")
except:
print(f"Failed to update {self.name}")

Expand Down Expand Up @@ -170,9 +171,9 @@ def update_data(self):
obs_lat_lon_r[:,1] = good_xy[:,0]
obs_lat_lon_r[:,2] = R_earth

obs_var = np.ones(obs_lat_lon_r.shape)
obs_var = np.ones(B_obs.shape)
# Don't include Z component in fits for now
obs_var[:,2] = np.inf
obs_var[:,:,2] = np.inf

gridded_lat_lon_r = np.zeros((len(gridded_xy), 3))
gridded_lat_lon_r[:,0] = gridded_xy[:,1]
Expand All @@ -192,7 +193,7 @@ def update_data(self):
#--------------
secs = SECS(sec_df_loc=secs_lat_lon_r)
secs.fit(obs_loc=obs_lat_lon_r, obs_B=B_obs,
obs_var=obs_var, epsilon=0.05)
obs_std=None, epsilon=0.05)

B_gridded = secs.predict_B(gridded_lat_lon_r)

Expand Down
6 changes: 3 additions & 3 deletions scripts/secs_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def scale_vectors(x, y, scale=np.log10):
# Load the most recent data
#---------------------------

data_load = np.load(args.infile)
data_load = np.load(args.infile, allow_pickle=True)
B_gridded = data_load['B_gridded']
B_obs = data_load['B_obs']
gridded_xy = data_load['gridded_xy']
Expand Down Expand Up @@ -162,8 +162,8 @@ def setup_map():
scale_units='inches', scale=Bscale, width=arrow_width,
alpha=1., zorder=10)

t = times[-1].astype(datetime.datetime)/1000000000
time_string = datetime.datetime.fromtimestamp(t).strftime('%Y-%m-%d %H:%M')
t = times[-1].to_pydatetime()
time_string = t.strftime('%Y-%m-%d %H:%M')
title = ax.set_title(f'SECS Magnetic Field\n{time_string}')

fig.savefig(args.outdir + '/' + args.outfile, bbox_inches='tight')
Expand Down