Skip to content

Commit

Permalink
finished removing old_div from pmagplotlib re issue PmagPy#600
Browse files Browse the repository at this point in the history
  • Loading branch information
apivarunas committed Mar 5, 2023
1 parent 3a7e6b2 commit 5cf0cd8
Showing 1 changed file with 25 additions and 32 deletions.
57 changes: 25 additions & 32 deletions pmagpy/pmagplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
import sys
import warnings

from past.utils import old_div
import numpy as np
import pandas as pd
warnings.filterwarnings("ignore") # what you don't know won't hurt you
warnings.filterwarnings("ignore") # what you don't know won't hurt you, or will it?
from distutils.version import LooseVersion

# no longer setting backend here
Expand Down Expand Up @@ -2141,7 +2140,7 @@ def plot_hdd(HDD, B, M, s):
DdeltaM.append(
abs(deltaM[k] - deltaM[k - 2]) / (Bdm[k] - Bdm[k - 2]))
for k in range(len(deltaM)):
if old_div(deltaM[k], deltaM[0]) < 0.5:
if deltaM[k] / deltaM[0] < 0.5:
Mhalf = k
break
try:
Expand Down Expand Up @@ -2280,8 +2279,8 @@ def plot_hpars(HDD, hpars, sym):
plt.figure(num=HDD['hyst'])
X, Y = [], []
X.append(0)
Y.append(old_div(float(hpars['hysteresis_mr_moment']), float(
hpars['hysteresis_ms_moment'])))
Y.append(float(hpars['hysteresis_mr_moment']) / float(
hpars['hysteresis_ms_moment']))
X.append(float(hpars['hysteresis_bc']))
Y.append(0)
plt.plot(X, Y, sym)
Expand Down Expand Up @@ -2339,20 +2338,20 @@ def plot_irm(fignum, B, M, title):
if backfield == 1:
poly = np.polyfit(X, Y, 1)
if poly[0] != 0:
bcr = (old_div(-poly[1], poly[0]))
bcr = (-poly[1] / poly[0])
else:
bcr = 0
rpars['remanence_mr_moment'] = '%8.3e' % (M[0])
rpars['remanence_bcr'] = '%8.3e' % (-bcr)
rpars['magic_method_codes'] = 'LP-BCR-BF'
if M[0] != 0:
for m in M:
Mnorm.append(old_div(m, M[0])) # normalize to unity Msat
Mnorm.append(m / M[0]) # normalize to unity Msat
title = title + ':' + '%8.3e' % (M[0])
else:
if M[-1] != 0:
for m in M:
Mnorm.append(old_div(m, M[-1])) # normalize to unity Msat
Mnorm.append(m / M[-1]) # normalize to unity Msat
title = title + ':' + '%8.3e' % (M[-1])
# do plots if desired
if fignum != 0 and M[0] != 0: # skip plot for fignum = 0
Expand Down Expand Up @@ -2706,25 +2705,19 @@ def plot_trm(fig, B, TRM, Bp, Mp, NLpars, title):
for b in Bp:
Bpnorm.append(b * 1e6)
for t in TRM:
Tnorm.append(old_div(t, Mp[-1]))
Tnorm.append(t / Mp[-1])
for t in Mp:
Mnorm.append(old_div(t, Mp[-1]))
Mnorm.append(t / Mp[-1])
plt.plot(Bnorm, Tnorm, 'go')
plt.plot(Bpnorm, Mnorm, 'g-')
if NLpars['banc'] > 0:
plt.plot([0, NLpars['best'] * 1e6],
[0, old_div(NLpars['banc_npred'], Mp[-1])], 'b--')
plt.plot([NLpars['best'] * 1e6, NLpars['banc'] * 1e6], [old_div(
NLpars['banc_npred'], Mp[-1]), old_div(NLpars['banc_npred'], Mp[-1])], 'r--')
plt.plot([NLpars['best'] * 1e6],
[old_div(NLpars['banc_npred'], Mp[-1])], 'bd')
plt.plot([NLpars['banc'] * 1e6],
[old_div(NLpars['banc_npred'], Mp[-1])], 'rs')
plt.plot([0, NLpars['best'] * 1e6],[0, NLpars['banc_npred'] / Mp[-1]], 'b--')
plt.plot([NLpars['best'] * 1e6, NLpars['banc'] * 1e6], [NLpars['banc_npred'] / Mp[-1], NLpars['banc_npred'] / Mp[-1]], 'r--')
plt.plot([NLpars['best'] * 1e6], [NLpars['banc_npred'] / Mp[-1]], 'bd')
plt.plot([NLpars['banc'] * 1e6], [NLpars['banc_npred'] / Mp[-1]], 'rs')
else:
plt.plot([0, NLpars['best'] * 1e6],
[0, old_div(NLpars['best_npred'], Mp[-1])], 'b--')
plt.plot([0, NLpars['best'] * 1e6],
[0, old_div(NLpars['best_npred'], Mp[-1])], 'bd')
plt.plot([0, NLpars['best'] * 1e6], [0, NLpars['best_npred'] / Mp[-1]], 'b--')
plt.plot([0, NLpars['best'] * 1e6], [0, NLpars['best_npred'] / Mp[-1])], 'bd')

###

Expand Down Expand Up @@ -3070,11 +3063,11 @@ def plot_map_basemap(fignum, lats, lons, Opts):
else:
g = Opts['gridspace']
latmin, lonmin = g * \
int(old_div(Opts['latmin'], g)), g * \
int(old_div(Opts['lonmin'], g))
int(Opts['latmin'] / g), g * \
int(Opts['lonmin'] / g))
latmax, lonmax = g * \
int(old_div(Opts['latmax'], g)), g * \
int(old_div(Opts['lonmax'], g))
int(Opts['latmax'] / g)), g * \
int(Opts['lonmax'] / g))
# circles=np.arange(latmin-2.*Opts['padlat'],latmax+2.*Opts['padlat'],Opts['gridspace'])
# meridians=np.arange(lonmin-2.*Opts['padlon'],lonmax+2.*Opts['padlon'],Opts['gridspace'])
meridians = np.arange(0, 360, 30)
Expand Down Expand Up @@ -3596,11 +3589,11 @@ def plot_eq_cont(fignum, DIblock, color_map='coolwarm'):
counter = counter + 1
X = pmag.dir2cart([rec[0], rec[1], 1.])
# from Collinson 1983
R = old_div(np.sqrt(1. - X[2]), (np.sqrt(X[0]**2 + X[1]**2)))
R = np.sqrt(1. - X[2]) / (np.sqrt(X[0]**2 + X[1]**2)))
XY.append([X[0] * R, X[1] * R])
# radius of the circle
radius = (old_div(3., (np.sqrt(np.pi * (9. + float(counter)))))) + 0.01
num = 2. * (old_div(1., radius)) # number of circles
radius = (3. / (np.sqrt(np.pi * (9. + float(counter))))) + 0.01
num = 2. * (1. / radius) # number of circles
# a,b are the extent of the grids over which the circles are equispaced
a1, a2 = (0. - (radius * num / 2.)), (0. + (radius * num / 2.))
b1, b2 = (0. - (radius * num / 2.)), (0. + (radius * num / 2.))
Expand Down Expand Up @@ -3635,7 +3628,7 @@ def plot_eq_cont(fignum, DIblock, color_map='coolwarm'):
beta = beta + 1.
else:
alpha = alpha + 1.
fraction.append(old_div(alpha, beta))
fraction.append(alpha / beta)
alpha, beta = 0.001, 0.001
else:
fraction.append(1.) # if the whole circle lies in the net
Expand Down Expand Up @@ -3666,9 +3659,9 @@ def plot_eq_cont(fignum, DIblock, color_map='coolwarm'):
for j in range(1, 4):
for i in range(0, 360):
x.append(np.sin((np.pi/180.) * float(i))
* (1. + (old_div(float(j), 10.))))
* (1. + (float(j) / 10.)))
y.append(np.cos((np.pi/180.) * float(i))
* (1. + (old_div(float(j), 10.))))
* (1. + (float(j) / 10.)))
plt.plot(x, y, 'w-', linewidth=26)
x, y = [], []
# the axes
Expand Down

0 comments on commit 5cf0cd8

Please sign in to comment.