def __init__(self, fileName):
        #Read the file containg probe data and store it in this object

        CompoProfile.__init__(self)
        self.pltMark = 'o'

        #open the csv file
        try:
            grtFile = open(fileName, 'r')
        except:
            print("No csv file found at location:")
            print(fileName)
            return

        grtdf = pd.read_csv(grtFile)
        self.x = list(grtdf['x (mm)'])
        for i in range(len(CMPNT)):
            self.cmpnts[i] = list(grtdf[CMPNT[i]])
Exemple #2
0
    def splitTrav(self, xPos, selectLeft):
        #Method for splitting the traverse into two halves at the inputted xPos
        #Assumes xpos will never exactly equal to an x position on the traverse
        #The two halves are CompoProfile objects with the same data of their respective halves of this Traverse object
        #They will be stored in the travSplit array so that they can be ambiguously referenced.
        #They will contain a little less info but maintain most of the core stuff

        count = 0
        #Finds the index of the datapoint to the right of the selected x
        while (self.x[count] < xPos):
            count += 1

        xRightIndex = count

        xLeftIndex = count - 1

        #initialize travSplit array to hold the two halves and the two sides of the traverse
        self.travSplit = []
        rightTrav = CompoProfile()
        leftTrav = CompoProfile()
        rightTrav.pltMark = 'o'
        leftTrav.pltMark = 'o'
        leftTrav.pltColour = 'blue'  #So it can be differentiated on the plot

        #Build the contained arrays
        #First calculate the value at 0 using linear interpolation
        #This allows for modelling from 0
        rightTrav.x.append(0)
        leftTrav.x.append(0)
        for i in range(len(GRT_CMPNT)):
            #Append the composition at 0 to both left and right traverse since they should be the same
            zeroVal = self.interpCompoAtX(xPos, GRT_CMPNT[i].cation)
            rightTrav.cmpnts[i].append(zeroVal)
            leftTrav.cmpnts[i].append(zeroVal)
        for i in range(xRightIndex, len(self.x)):

            rightTrav.x.append(self.x[i] - xPos)
            for j in range(len(GRT_CMPNT)):
                rightTrav.cmpnts[j].append(self.cmpnts[j][i])

        #Flips the left Traverse
        for i in range(xLeftIndex, -1, -1):
            leftTrav.x.append(xPos - self.x[i])
            for j in range(len(GRT_CMPNT)):
                leftTrav.cmpnts[j].append(self.cmpnts[j][i])

        #Add the two traverses to travSplit
        if len(rightTrav.x) > 0:
            self.travSplit.append(rightTrav)
            if not selectLeft:
                return rightTrav
        if len(leftTrav.x) > 0:
            self.travSplit.append(leftTrav)
            if selectLeft:
                return leftTrav
    def plotAll(self, pltIn):
        #Method to plot all components on one plot
        #Assumes that the Fe component is much higher than the rest, plots it on seperate axis
        colours = ['green', 'blue', 'orange', 'red']
        symbols = ['o', '^', 's', 'P']
        pltAlm = pltIn.twinx()

        self.travPlot = pltIn  #Saves the plot to the object

        #Loop for plotting
        for i in range(len(CMPNT)):
            self.pltColour = colours[i]
            self.pltMark = symbols[i]
            if (CMPNT[i] == "Fe"):
                CompoProfile.plotCompo(self, CMPNT[i], pltAlm, 7)
            else:
                CompoProfile.plotCompo(self, CMPNT[i], pltIn, 7)

        pltIn.set_xlabel("x (mm)")
        pltIn.set_ylabel("X (Ca,Mn,Mg)")

        #Uncomment these lines if you want everything on the same scale
        #pltIn.set_ylim(0,0.4)
        #pltAlm.set_ylim(0.45,0.85)

        pltAlm.set_ylabel("X (Fe)")
        pltIn.legend(fontsize=14, loc='upper left')
        pltAlm.legend(fontsize=14, loc='upper right')

        #This is to set up the stuff for splitting the plot in half, assuming that you input a full traverse instead of a half traverse
        self.cid = pltIn.figure.canvas.mpl_connect('button_press_event',
                                                   self.travClick)
        self.splitLine = pltIn.plot([0], [0])  #create an empty line
        self.splitTrav(
            self.x[0] - 1
        )  #Sets the baseline to leftTrav is empty and rightTrav = this. This is basically if you want to input just a half traverse, however it assumes that it is the right half
    def splitTrav(self, xPos):
        #Method for splitting the traverse into two halves at the inputted xPos
        #Assumes xpos will never exactly equal to an x position on the traverse
        #The two halves are CompoProfile objects with the same data of their respective halves of this Traverse object
        #They will be stored in the travSplit array so that they can be ambiguously referenced.
        #They will contain a little less info but maintain most of the core stuff

        count = 0
        #Finds the index of the datapoint to the right of the selected x
        while (self.x[count] < xPos):
            count += 1

        xRightIndex = count

        xLeftIndex = count - 1

        #initialize travSplit array to hold the two halves and the two sides of the traverse
        self.travSplit = []
        rightTrav = CompoProfile()
        leftTrav = CompoProfile()
        rightTrav.pltMark = 'o'
        leftTrav.pltMark = 'o'
        leftTrav.pltColour = 'blue'  #So it can be differentiated on the plot

        #Build the contained arrays
        for i in range(xRightIndex, len(self.x)):

            rightTrav.x.append(self.x[i] - xPos)
            for j in range(len(CMPNT)):
                rightTrav.cmpnts[j].append(self.cmpnts[j][i])

        #Flips the left Traverse
        for i in range(xLeftIndex, -1, -1):
            leftTrav.x.append(xPos - self.x[i])
            for j in range(len(CMPNT)):
                leftTrav.cmpnts[j].append(self.cmpnts[j][i])

        #Add the two traverses to travSplit
        if len(rightTrav.x) > 0:
            self.travSplit.append(rightTrav)
        if len(leftTrav.x) > 0:
            self.travSplit.append(leftTrav)
Exemple #5
0
    def __init__(self, dirIn, gen, trial):
        #Constructor, builds the data arrays defined in CompoProfile from the garnet_gen file
        #Also defines the PTt path from PTt-path.txt

        CompoProfile.__init__(self)
        #Plot parameters
        self.pltLine = '-'
        self.pltColour = 'red'

        self.trial = -1  #Easy way to check if initialized
        self.gen = -1  #to use for checking if the gen exists for this trial

        #self.profPlots = []

        trialDir = 'Trial-' + '{:04d}'.format(trial)
        if os.name == 'nt':  #PC
            slash = "\\"
        else:  #Mac
            slash = "/"

        #File paths for the PTt path and garnet composition
        pathDir = dirIn + slash + trialDir + slash + PATH_FILE_NAME
        grtDir = dirIn + slash + trialDir + slash + GRT_FILE_PREF + '{:03d}'.format(
            gen) + 'a.txt'

        try:
            pathFile = open(pathDir, 'r')
        except:
            print("PTt-path.txt for trial: " + str(trial) +
                  " not found at location:")
            print(pathDir)
            return

        self.trial = trial

        try:
            grtFile = open(grtDir, 'r')
        except:
            print("Garnet generation: " + str(gen) + " not found in trial: " +
                  str(trial))
            print(
                "Please select different generation if you wish to include this trial"
            )
            return

        #grtFile.close()
        self.gen = gen

        self.pressure = []
        self.temperature = []
        self.time = []

        line = pathFile.readline()  #remove header
        line = pathFile.readline()

        #Read the path file to the end
        while (len(line) > 0):
            items = [value.strip() for value in line.split()]
            self.temperature.append(float(items[TEMP_COL]))
            self.pressure.append(float(items[PRES_COL]))
            self.time.append(float(items[TIM_COL]))

            line = pathFile.readline()

        pathFile.close()

        #Read the garnet file, need to specifically take the last growth period, starts from the bottom and moves up
        #Header names are identical to output files from theriag, do not change these unless you change the theriag output as well
        grtdf = pd.read_csv(grtFile)
        rowCount = grtdf.shape[0]
        shells = grtdf['shell     ']
        xCol = grtdf['node(cm)     ']
        #Build array of arrays in correpsonding order of CMPNT
        tgCmpnt = []
        for i in range(len(CMPNT)):
            head = 'x(' + CMPNT[i] + ')     '
            tgCmpnt.append(grtdf[head])

        row = rowCount - 1

        #Will add the values from the corresponding columns then reverse them

        self.x.append(xCol[row] * 10 - H_ADJUST)

        for i in range(len(CMPNT)):
            self.cmpnts[i].append(tgCmpnt[i][row])
        row -= 1

        #loop from end of the file, counting down the shells, stops when the shell
        #number increases again, indicating an earlier stage of growth
        while (shells[row] < shells[row + 1]):
            self.x.append(xCol[row] * 10 - H_ADJUST)
            for i in range(len(CMPNT)):
                self.cmpnts[i].append(tgCmpnt[i][row])
            #print(shells[row])
            row -= 1

        self.x.reverse()
        for i in range(len(CMPNT)):
            self.cmpnts[i].reverse()
Exemple #6
0
    def plotAll(self, pltIn):
        #Method to plot all components on one plot
        #Assumes that the Fe component is much higher than the rest, plots it on seperate axis
        colours = ['green', 'blue', 'orange', 'red']
        symbols = ['o', '^', 's', 'P']
        pltAlm = pltIn.twinx()

        self.travPlot = pltIn  #Saves the plot to the object

        #Loop for plotting
        for i in range(len(GRT_CMPNT)):
            self.pltColour = colours[i]
            self.pltMark = symbols[i]
            if (GRT_CMPNT[i] == ALM):
                CompoProfile.plotCompo(self, GRT_CMPNT[i].cation, pltAlm, 7)
            else:
                CompoProfile.plotCompo(self, GRT_CMPNT[i].cation, pltIn, 7)

        pltIn.set_xlabel("Distance (mm)", fontsize=24)
        pltIn.set_ylabel("X (Ca,Mn,Mg)", fontsize=24)

        #Uncomment these lines if you want everything on the same scale
        pltIn.set_ylim(0, 0.4)
        pltAlm.set_ylim(0.4, 0.9)

        pltAlm.set_ylabel("X (Fe)", fontsize=24, rotation=-90)
        pltIn.legend(loc='upper left')
        pltAlm.legend(loc='upper right')
        pltIn.xaxis.set_tick_params(which='major',
                                    size=10,
                                    width=2,
                                    direction='in',
                                    top='on')
        pltIn.xaxis.set_tick_params(which='minor',
                                    size=7,
                                    width=2,
                                    direction='in',
                                    top='on')
        pltIn.yaxis.set_tick_params(which='major',
                                    size=10,
                                    width=2,
                                    direction='in',
                                    right=False)
        pltIn.yaxis.set_tick_params(which='minor',
                                    size=7,
                                    width=2,
                                    direction='in',
                                    right=False)

        pltAlm.xaxis.set_tick_params(which='major',
                                     size=10,
                                     width=2,
                                     direction='in',
                                     top='on')
        pltAlm.xaxis.set_tick_params(which='minor',
                                     size=7,
                                     width=2,
                                     direction='in',
                                     top='on')
        pltAlm.yaxis.set_tick_params(which='major',
                                     size=10,
                                     width=2,
                                     direction='in',
                                     right=True)
        pltAlm.yaxis.set_tick_params(which='minor',
                                     size=7,
                                     width=2,
                                     direction='in',
                                     right=True)

        pltIn.xaxis.set_major_locator(mpl.ticker.MultipleLocator(1))
        pltIn.xaxis.set_minor_locator(mpl.ticker.MultipleLocator(0.2))
        pltIn.yaxis.set_major_locator(mpl.ticker.MultipleLocator(0.1))
        pltIn.yaxis.set_minor_locator(mpl.ticker.MultipleLocator(0.02))

        pltAlm.xaxis.set_major_locator(mpl.ticker.MultipleLocator(1))
        pltAlm.xaxis.set_minor_locator(mpl.ticker.MultipleLocator(0.2))
        pltAlm.yaxis.set_major_locator(mpl.ticker.MultipleLocator(0.1))
        pltAlm.yaxis.set_minor_locator(mpl.ticker.MultipleLocator(0.02))
        #This is to set up the stuff for splitting the plot in half, assuming that you input a full traverse instead of a half traverse
        self.cid = pltIn.figure.canvas.mpl_connect('button_press_event',
                                                   self.travClick)
        self.splitLine = pltIn.plot([0], [0])  #create an empty line
        self.selectedTrav = self.splitTrav(
            self.x[0] - 1, False
        )  #Sets the baseline to leftTrav is empty and rightTrav = this. This is basically if you want to input just a half traverse, however it assumes that it is the right half