Skip to content

Commit

Permalink
adjust for python3
Browse files Browse the repository at this point in the history
  • Loading branch information
meihuisu committed Jul 16, 2024
1 parent fc600d8 commit 91e58d9
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 17 deletions.
14 changes: 7 additions & 7 deletions pycvm/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import struct
import getopt
import json
import pdb

# Numpy is required.
try:
Expand Down Expand Up @@ -215,10 +214,11 @@ class Plot:
# @param width The width of the plot in inches (dpi = 100).
# @param height The height of the plot in inches (dpi = 100).
def __init__(self, title = None, xlabel = None, ylabel = None, legend = None, width = 10, height = 10):
## Defines the figure and axes object to which we can add subplots.
## Defines the figure and plot object to which we can add subplots.

self.figure = plt.figure(figsize=(width, height), dpi=100)
self.plot = self.figure.add_subplot(1, 1, 1)

if ylabel != None:
plt.ylabel(ylabel, fontsize=14)

Expand All @@ -241,7 +241,7 @@ def __init__(self, title = None, xlabel = None, ylabel = None, legend = None, wi
def addsubplot(self):
self.subplotcounter += 1;
return self.plot;

##
# Shows the plot.
def show(self):
Expand Down Expand Up @@ -1017,7 +1017,7 @@ def export_np_float_array(self, floats, fname):

# export raw floats nxy ndarray to an external file
def export_binary(self, floats, fname):
# print("calling export_binary -",len(floats))
print("calling export_binary -",len(floats))
rawfile = fname
if rawfile is None :
rawfile="data.bin"
Expand Down Expand Up @@ -1052,7 +1052,7 @@ def import_metadata(self, fname):

# export ascii meta data to an external file
def export_metadata(self,meta,fname):
# print("calling export_metadata")
print("calling export_metadata")
metafile=fname
if metafile is None:
metafile = "meta.json"
Expand Down Expand Up @@ -1083,7 +1083,7 @@ def import_matprops(self, fname):

# export material properties in JSON form to an external file
def export_matprops(self,blob,fname):
# print("calling export_matprops")
print("calling export_matprops")
matpropsfile=fname
if matpropsfile is None :
matpropsfile="matprops.json"
Expand Down
11 changes: 6 additions & 5 deletions pycvm/cross_section.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
# Imports

from mpl_toolkits import basemap
#XXX from mpl_toolkits.basemap import cm
from matplotlib import cm
import math

from .common import Plot, Point, MaterialProperties, UCVM, UCVM_CVMS, \
math, pycvm_cmapDiscretize, cm, mcolors, np, plt
Expand Down Expand Up @@ -159,7 +159,7 @@ def getplotvals(self, mproperty='vs'):
## Private number of x points.
self.num_x = num_prof +1
## Private number of y points.
self.num_y = int ((int(self.todepth) - int(self.startingdepth)) / int(self.vspacing)) +1
self.num_y = math.ceil((self.todepth - self.startingdepth) / self.vspacing) +1
print("\nUsing -->"+self.datafile)
## print("expecting x "+str(self.num_x)+" y "+str(self.num_y))

Expand Down Expand Up @@ -197,10 +197,11 @@ def getplotvals(self, mproperty='vs'):
## Private number of x points.
self.num_x = num_prof + 1
## Private number of y points.
self.num_y = int((int(self.todepth) - int(self.startingdepth)) / int(self.vspacing)) + 1

self.num_y = math.ceil((self.todepth - self.startingdepth) / self.vspacing) + 1


## The 2D array of retrieved material properties.
self.materialproperties = [[MaterialProperties(-1, -1, -1) for i in range(self.num_x)] for j in range(self.num_y)]
self.materialproperties = [[MaterialProperties(-1, -1, -1) for x in range(self.num_x)] for y in range(self.num_y)]


for y in range(0, self.num_y):
Expand Down
5 changes: 4 additions & 1 deletion pycvm/depth_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
# arguments, or through Python code in the class DepthProfile.

# Imports
from .common import Plot, Point, MaterialProperties, UCVM, UCVM_CVMS, plt, math
from .common import Plot, Point, MaterialProperties, UCVM, UCVM_CVMS, plt
##from scipy.interpolate import spline, splprep, splev
##from scipy.interpolate import Rbf, InterpolatedUnivariateSpline
##import scipy.interpolate as interpolate
import math
import numpy as np
import json

Expand Down Expand Up @@ -223,6 +224,7 @@ def addtoplot(self, plot, colors = None, customlabels = None):
max_x = max(max_x, max(newvplist))
plot.addsubplot().plot(newvplist, yvals, "-", color=vpcolor, label=vplabel)


if "vs" in self.properties:
myInt=1000
newvslist=np.array(self.vslist)/myInt
Expand Down Expand Up @@ -262,6 +264,7 @@ def addtoplot(self, plot, colors = None, customlabels = None):
plt.xlim(0, math.ceil(max_x / 0.5) * 0.5)

plt.axis([0, max_x, int(self.todepth), int(self.startingdepth)])


##
# Plots a new depth profile using all the default plotting options.
Expand Down
6 changes: 3 additions & 3 deletions pycvm/elevation_cross_section.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def getplotvals(self, mproperty='vs') :
## Private number of x points.
self.num_x = num_prof +1
## Private number of y points.
self.num_y = abs((int(self.toelevation) - int(self.startelevation)) / int(self.vspacing)) +1
self.num_y = math.ceil((self.toelevation - self.startelevation) / self.vspacing) +1

print("\nUsing -->"+self.datafile)
## print("expecting x "+str(self.num_x)+" y "+str(self.num_y))
Expand Down Expand Up @@ -181,7 +181,7 @@ def getplotvals(self, mproperty='vs') :
## Private number of x points.
self.num_x = num_prof + 1
## Private number of y points.
self.num_y = abs((int(self.toelevation) - int(self.startelevation)) / int(self.vspacing)) + 1
self.num_y = math.ceil((self.toelevation - self.startelevation) / self.vspacing) + 1


## The 2D array of retrieved material properties.
Expand Down Expand Up @@ -407,7 +407,7 @@ def plot(self) :
plt.title(title)

cax = plt.axes([0.1, 0.1, 0.8, 0.02])
cbar = plt.colorbar(img, cax=cax, orientation='horizontal',ticks=TICKS,spacing='proportional')
cbar = plt.colorbar(img, cax=cax, orientation='horizontal',ticks=TICKS,spacing='regular')
if mproperty != "poisson":
if(mproperty.title() == "Density") :
cbar.set_label(mproperty.title() + " (g/cm^3)")
Expand Down
2 changes: 1 addition & 1 deletion pycvm/elevation_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# arguments, or through Python code in the class ElevationProfile.

# Imports
from .common import Plot, Point, MaterialProperties, UCVM, UCVM_CVMS, plt
from .common import Plot, Point, MaterialProperties, UCVM, UCVM_CVMS, plt, math
##from scipy.interpolate import spline, splprep, splev
##from scipy.interpolate import Rbf, InterpolatedUnivariateSpline
##import scipy.interpolate as interpolate
Expand Down

0 comments on commit 91e58d9

Please sign in to comment.