Skip to content

Commit c826774

Browse files
committed
some code cleaning
1 parent 515a652 commit c826774

File tree

3 files changed

+27
-29
lines changed

3 files changed

+27
-29
lines changed

solarmach/__init__.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
from .version import version as __version__
22

3-
# __all__ = [] # defines which functions, variables etc. will be loaded when running "from pyonset import *"
3+
# __all__ = [] # defines which functions, variables etc. will be loaded when running "from solarmach import *"
44

55
import copy
6-
# import dateutil.parser # type: ignore
7-
import math
86
import os
97

108
import astropy.constants as aconst
@@ -16,13 +14,12 @@
1614
import numpy as np
1715
import pandas as pd
1816
import scipy.constants as const
19-
from astropy.coordinates import SkyCoord
2017
from matplotlib.legend_handler import HandlerPatch
2118
from sunpy import log
2219
from sunpy.coordinates import frames, get_horizons_coord
2320
from sunpy.time import parse_time
2421

25-
from solarmach.pfss_utilities import calculate_pfss_solution, get_field_line_coords, get_gong_map, multicolorline, sphere, spheric2cartesian, vary_flines
22+
from solarmach.pfss_utilities import get_field_line_coords, multicolorline, sphere, spheric2cartesian, vary_flines
2623

2724
# pd.options.display.max_rows = None
2825
# pd.options.display.float_format = '{:.1f}'.format
@@ -463,7 +460,7 @@ def __init__(self, date, body_list, vsw_list=[], reference_long=None, reference_
463460
self.pos_E = pos_E
464461

465462
# standardize "undefined" vsw_list for further usage:
466-
if type(vsw_list)==type(None) or vsw_list is False:
463+
if type(vsw_list) is type(None) or vsw_list is False:
467464
vsw_list=[]
468465

469466
# make deep copy of vsw_list bc. otherwise it doesn't get reset in a new init:
@@ -646,7 +643,7 @@ def plot(self, plot_spirals=True,
646643
Returns the matplotlib figure and axes if return_plot_object=True (by default set to False), else nothing.
647644
"""
648645
hide_logo = False # optional later keyword to hide logo on figure
649-
AU = const.au / 1000 # km
646+
# AU = const.au / 1000 # km
650647

651648
# save inital rcParams and update some of them:
652649
initial_rcparams = plt.rcParams.copy()
@@ -924,7 +921,7 @@ def plot(self, plot_spirals=True,
924921
pfig.show()
925922

926923
if long_sector is not None:
927-
if type(long_sector) == list and np.array(long_sector).ndim==1:
924+
if type(long_sector) is list and np.array(long_sector).ndim==1:
928925
long_sector = [long_sector]
929926
long_sector_vsw = [long_sector_vsw]
930927
long_sector_color = [long_sector_color]
@@ -962,8 +959,8 @@ def plot(self, plot_spirals=True,
962959
alpha_ref1 = (delta_ref1*u.deg + backmapping_angle(self.target_solar_radius*aconst.R_sun, r_array*u.AU, long_sector_lat[0]*u.deg, t_long_sector_vsw[0]*u.km/u.s, diff_rot=self.diff_rot)).to(u.rad).value
963960
alpha_ref2 = (delta_ref2*u.deg + backmapping_angle(self.target_solar_radius*aconst.R_sun, r_array2*u.AU, long_sector_lat[1]*u.deg, t_long_sector_vsw[1]*u.km/u.s, diff_rot=self.diff_rot)).to(u.rad).value
964961

965-
# Save the last angle as a starting point for reference for the while loop
966-
alpha_init = alpha_ref2[-1]
962+
# # Save the last angle as a starting point for reference for the while loop
963+
# alpha_init = alpha_ref2[-1]
967964

968965
# Check that reference angle of the first loop is ahead
969966
if alpha_ref1[-1] > alpha_ref2[-1]:
@@ -990,7 +987,7 @@ def plot(self, plot_spirals=True,
990987
y1 = c1.get_ydata()
991988
c2 = plt.polar(alpha_ref2, r_array2 * np.cos(np.deg2rad(long_sector_lat[1])), lw=0, color=t_long_sector_color, alpha=t_long_sector_alpha)[0]
992989
x2 = c2.get_xdata()
993-
y2 = c2.get_ydata()
990+
# y2 = c2.get_ydata()
994991

995992
# Check that plotted are is between the two spirals, and do not fill after potential crossing
996993
clause1 = x1 < x2
@@ -1004,7 +1001,7 @@ def plot(self, plot_spirals=True,
10041001
plt.fill_betweenx(y1_fill, x1_fill, x2_fill, lw=0, color=t_long_sector_color, alpha=t_long_sector_alpha)
10051002

10061003
if background_spirals is not None:
1007-
if type(background_spirals) == list and len(background_spirals)>=2:
1004+
if type(background_spirals) is list and len(background_spirals)>=2:
10081005
# maybe later add option to have a non-zero latitude, so that the field lines are out of the ecliptic
10091006
background_spirals_lat = 0
10101007
# take into account solar differential rotation wrt. latitude
@@ -1658,7 +1655,7 @@ def plot_pfss(self,
16581655
y1 = c1.get_ydata()
16591656
c2 = plt.polar(alpha_ref2, r_to_plot * np.cos(np.deg2rad(long_sector_lat[1])), lw=0, color=long_sector_color, alpha=0)[0]
16601657
x2 = c2.get_xdata()
1661-
y2 = c2.get_ydata()
1658+
# y2 = c2.get_ydata()
16621659

16631660
# Check that plotted are is between the two spirals, and do not fill after potential crossing
16641661
if long_sector_vsw:
@@ -1707,7 +1704,7 @@ def legend_arrow(width, height, **_):
17071704
return mpatches.FancyArrow(0, 0.5 * height, width, 0, length_includes_head=True,
17081705
head_width=0.75 * height)
17091706

1710-
leg2 = ax.legend([ref_arr], [reference_legend_label], loc=(1.05, 0.6),
1707+
_leg2 = ax.legend([ref_arr], [reference_legend_label], loc=(1.05, 0.6),
17111708
handler_map={mpatches.FancyArrow: HandlerPatch(patch_func=legend_arrow), },
17121709
fontsize=15)
17131710
ax.add_artist(leg1)
@@ -1759,7 +1756,7 @@ def legend_arrow(width, height, **_):
17591756
ha='right', va='bottom', transform=fig.transFigure)
17601757

17611758
# Create the colorbar displaying values of the last fieldline plotted
1762-
cb = fig.colorbar(fieldline, ax=ax, location="left", anchor=(1.4, 1.2), pad=0.12, shrink=0.6, ticks=[-90, -60, -30, 0, 30, 60, 90])
1759+
_cb = fig.colorbar(fieldline, ax=ax, location="left", anchor=(1.4, 1.2), pad=0.12, shrink=0.6, ticks=[-90, -60, -30, 0, 30, 60, 90])
17631760

17641761
# Colorbar is the last object created -> it is the final index in the list of axes
17651762
cb_ax = fig.axes[-1]
@@ -1793,6 +1790,9 @@ def legend_arrow(width, height, **_):
17931790
else:
17941791
plt.show()
17951792

1793+
# restore initial rcParams that have been saved at the beginning of this function:
1794+
plt.rcParams.update(initial_rcparams)
1795+
17961796
if return_plot_object:
17971797
return fig, ax
17981798

@@ -2012,8 +2012,8 @@ def pfss_3d(self, active_area=(None, None, None, None), color_code='object', rss
20122012
r_array = np.arange(0.007, (max_dist2+0.29*const.au/R_sun.to(u.m).value)/np.cos(np.deg2rad(self.max_dist_lat)) + 3.0, 0.05)
20132013

20142014
for i, body_id in enumerate(self.body_dict):
2015-
body_lab = self.body_dict[body_id][1]
2016-
body_color = self.body_dict[body_id][2]
2015+
# body_lab = self.body_dict[body_id][1]
2016+
# body_color = self.body_dict[body_id][2]
20172017
body_vsw = self.body_dict[body_id][4]
20182018
body_pos = self.body_dict[body_id][3]
20192019

@@ -2090,7 +2090,7 @@ def pfss_3d(self, active_area=(None, None, None, None), color_code='object', rss
20902090
if body_id[:6] == 'STEREO':
20912091
str_number = f'<b>{body_id[-1]}</b>'
20922092
elif body_id == 'Europa Clipper':
2093-
str_number = f'<b>C</b>'
2093+
str_number = '<b>C</b>'
20942094
else:
20952095
str_number = f'<b>{body_id[0]}</b>'
20962096
symbol = 'circle'
@@ -2367,11 +2367,11 @@ def plot_3d(self, plot_spirals=True, plot_sun_body_line=True, plot_vertical_line
23672367
"""
23682368

23692369
import plotly.graph_objects as go
2370-
from astropy.constants import R_sun
2371-
from plotly.graph_objs.scatter3d import Line
2370+
# from astropy.constants import R_sun
2371+
# from plotly.graph_objs.scatter3d import Line
23722372

23732373
hide_logo = False # optional later keyword to hide logo on figure
2374-
AU = const.au / 1000 # km
2374+
# AU = const.au / 1000 # km
23752375
# sun_radius = aconst.R_sun.value # meters
23762376

23772377
# catch old syntax
@@ -2401,8 +2401,8 @@ def plot_3d(self, plot_spirals=True, plot_sun_body_line=True, plot_vertical_line
24012401
fig.update_layout()
24022402

24032403
for i, body_id in enumerate(self.body_dict):
2404-
body_lab = self.body_dict[body_id][1]
2405-
body_color = self.body_dict[body_id][2]
2404+
# body_lab = self.body_dict[body_id][1]
2405+
# body_color = self.body_dict[body_id][2]
24062406
body_vsw = self.body_dict[body_id][4]
24072407
body_pos = self.body_dict[body_id][3]
24082408

@@ -2478,7 +2478,7 @@ def plot_3d(self, plot_spirals=True, plot_sun_body_line=True, plot_vertical_line
24782478
if body_id[:6] == 'STEREO':
24792479
str_number = f'<b>{body_id[-1]}</b>'
24802480
elif body_id == 'Europa Clipper':
2481-
str_number = f'<b>C</b>'
2481+
str_number = '<b>C</b>'
24822482
else:
24832483
str_number = f'<b>{body_id[0]}</b>'
24842484
symbol = 'circle'
@@ -2741,7 +2741,7 @@ def sc_distance(sc1, sc2, dtime):
27412741
Absolute distance between body 1 and 2 in AU.
27422742
"""
27432743
# parse datetime:
2744-
if type(dtime) == str:
2744+
if type(dtime) is str:
27452745
try:
27462746
obstime = parse_time(dtime)
27472747
except ValueError:

solarmach/pfss_utilities.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,8 +692,7 @@ def get_gong_map(time: str, filepath: str = None, autodownload=True):
692692

693693
try:
694694
gong_map = load_gong_map(filepath=filepath)
695-
except Exception as exception:
696-
# print(exception)
695+
except Exception:
697696
if autodownload:
698697
new_filepath = download_gong_map(time, filepath=filepath)
699698
gong_map = load_gong_map(filepath=new_filepath)

solarmach/tests/test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@
1414

1515
from solarmach import (
1616
SolarMACH,
17-
calculate_pfss_solution,
18-
get_gong_map,
1917
get_sw_speed,
2018
print_body_list,
2119
sc_distance,
2220
)
21+
from solarmach.pfss_utilities import calculate_pfss_solution, get_gong_map
2322

2423

2524
def test_print_body_list():

0 commit comments

Comments
 (0)