#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Mon May 13 17:05:39 2024 @author: jdaniel """ import numpy as np import pandas as pd def getcheck(i,A): icheck = 20 for j in range(0,icheck): t = A.csolventemiss[i,j]+A.cinstallemiss[i,j]+A.activebank[i,j+1]+A.cactiveemiss[i,j]+A.cdecomemiss[i,j]+\ A.inactivebank[i,j+1]+A.cinactiveemiss[i,j] print("%8.3f%8.3f%8.3f%8.3f%8.3f%8.3f%8.3f%10.4f" % (A.csolventemiss[i,j],A.cinstallemiss[i,j],A.activebank[i,j+1],A.cactiveemiss[i,j],\ A.cdecomemiss[i,j],A.inactivebank[i,j+1],A.cinactiveemiss[i,j],t)) def expt(p,tau,f,t): return(np.exp(-t**p/tau**p-f*t)) def getweibullalt(i,params,emissvals): bankremain = np.zeros(params.iyears) bankemiss = np.zeros(params.iyears) p = emissvals[4] tau = emissvals[5] f = emissvals[1] r1 = np.copy(bankremain) r2 = np.copy(bankremain) for j in range(0,params.iyears): r1[j] = np.exp(-(j/tau)**p) if (f*j <= 1): r2[j] = 1-f*j else: r2[j] = 0 bankremain[j] = r1[j] * r2[j] for j in range(0,params.iyears-1): bemissmain = .5*(r1[j] + r1[j+1])*f bemissalt = bankremain[j] - bankremain[j+1] bankemiss[j] = np.min([bemissmain,bemissalt]) return(bankremain,bankemiss) def getweibull(i,params,emissvals): bankremain = np.zeros(params.iyears) bankemiss = np.zeros(params.iyears) isubtime = 100 p = emissvals[4] tau = emissvals[5] f = emissvals[1] for j in range(0,params.iyears): if (j >= 0): if ((i == 3) or (i==4) or (i==11)): fuse = 1.*f/.00781*(.0211*np.exp(-((j-1)**.5614)*.6895)+.00434) tmp = np.array([.086,.04,.03,.026,.022,.02,.02]) if (j <= 6): fuse = tmp[j] fuse = f elif (i == 5): #boardstock from Albrect 50 mm data #tmp = np.array([.07,.033,.025,.022,.019,.017,.016]) a, b, c, d = .02727443,0.7420496,0.00391957,0.51737918 a, b, c, d = 0.17394786,0.84390568,0.001,0.35983694 tmp = a*np.exp(-b*(j)**d)+c if (j <= -18): fuse = tmp else: fuse = .04 #fuse = f else: #fuse = 1.*f/.00781*(.0211*np.exp(-((j-1)**.5614)*.6895)+.00434) tmp = np.array([.086,.04,.03,.026,.022,.02,.02]) if (j <= 6): fuse = tmp[j] fuse = f else: fuse=1 fuse = f*1 if (j >= 1): bankremain[j] = bankremain[j-1]-\ (expt(p,tau,fuse,float(j-1))-expt(p,tau,fuse,float(j))) # bankremain[j] = expt(p,tau,fuse,float(j)) else: bankremain[j] = 1. sum = 0 if (j >= 1): tmp = expt(p,tau,fuse,float(j-1)) for k in range(0,isubtime): tprime = float(j)+(float(k)+.5)/float(isubtime) sum = sum + f * np.exp(-fuse*tprime-tprime**p/tau**p) bankemiss[j-1] = sum/float(isubtime) return(bankremain,bankemiss) def getSegmentation(segfile,sheet): #ratios - first index is region, second index is market fileinfo = pd.read_excel(segfile, sheet_name = sheet ) markets = fileinfo.columns[1::] nummarkets = len(markets) tmp = fileinfo.iloc[1::,1::] tmp1 = fileinfo.iloc[0,1::] vals = np.zeros(tmp.shape) ratios = np.zeros(tmp.shape) ratiosrefrig = np.zeros(tmp.shape) ratiosnorefrig = np.zeros(tmp.shape) vals = np.array(fileinfo.iloc[1::,1::]) sum = np.zeros(len(tmp1)) sumnorefrig = np.zeros(len(tmp1)) asize = tmp.shape for i in range(0,asize[1]): ratios[:,i] = vals[:,i]*tmp1[i] for i in range(0,asize[0]): sum[i] = np.sum(ratios[i,:]) sumnorefrig[i] = np.sum(ratios[i,3:-1]) ratiosrefrig[i,:] = ratios[i,:]/sum[i] print(i,sumnorefrig[i]) if (sumnorefrig[i] > 0): ratiosnorefrig[i,3:-1] = ratios[i,3:-1]/sumnorefrig[i] else: ratiosnorefrig[i,3:-1] = ratios[i,3:-1] return(ratiosrefrig,ratiosnorefrig)