Beispiel #1
0
    def __init__(self, configName):
        '''
        Sets up the initial spatial grid, time grid, accumulation rate, age, density, mass, stress, and temperature of the model run
        :param configName: name of json config file containing model configurations
        '''

        # load in json config file and parses the user inputs to a dictionary
        with open(configName, "r") as f:
            jsonString = f.read()
            self.c = json.loads(jsonString)

        # create directory to store results
        if os.path.exists(self.c['resultsFolder']):
            rmtree(self.c['resultsFolder'])
        os.makedirs(self.c['resultsFolder'])

        # read in initial temperatures and accumulation rates
        input_temp, input_year_temp = read_temp(self.c['InputFileNameTemp'])
        input_bdot, input_year_bdot = read_bdot(self.c['InputFileNamebdot'])

        # load in model parameters
        self.bdot0 = input_bdot[0]
        self.temp0 = input_temp[0]
        gridLen, dx, dt, t, stp, Ts, T_mean, bdotSec, rhos0 = self.define_parameters()

        # set up model grid
        gridheight = np.linspace(c['H'], c['HbaseSpin'], gridLen)
        self.z  = self.c['H'] - gridHeight
        self.dz = np.diff(self.z)
        self.dz = np.append(self.dz, self.dz[-1])

        # set up the initial age and density of the firn column using herron & langway analytic
        THL = input_temp[0]
        AHL = input_bdot[0]
        self.age, self.rho = hl_analytic(self.c['rhos0'], self.z, THL, AHL)

        # set up initial mass, stress, and mean accumulation rate
        self.mass  = self.rho * self.dz
        self.sigma = self.mass * dx * GRAVITY
        self.sigma = self.sigma.cumsum(axis = 0)
        self.mass_sum = self.mass.cumsum(axis = 0)
        self.bdot_mean = np.concatenate(([self.mass_sum[0] / (RHO_I * S_PER_YEAR)], self.mass_sum[1:] / (self.age[1:] * RHO_I / t)))

        # set up initial temperature grid as well as a class to handle heat/isotope diffusion
        init_Tz = input_temp[0] * np.ones(gridLen)
        self.diffu = Diffusion(self.z, stp, gridLen, init_Tz)

        # set up initial grain growth (if specified in config file)
        if self.c['physGrain']:
            if self.c['calcGrainSize']:
                r02 = -2.42e-9 * (self.c['Ts0']) + 9.46e-7
                self.r2 = r02 * np.ones(gridLen)
            else:
                self.r2 = np.linspace(self.c['r2s0'], (6 * self.c['r2s0']), gridLen)
Beispiel #2
0
    def define_parameters(self):
        '''
        Return the parameters used in the model, for the initialization as well as the time evolution

        :returns gridLen: size of grid used in the model run
                         (unit: number of boxes, type: int)
        :returns dx: vector of width of each box, used for stress calculations
                    (unit: ???, type: array of ints)
        :returns dt: number of seconds per time step
                    (unit: seconds, type: float)
        :returns t: number of years per time step
                   (unit: years, type: float)
        :returns modeltime: linearly spaced time vector from indicated start year to indicated end year
                           (unit: years, type: array of floats)
        :returns years: total number of years in the model run
                       (unit: years, type: float)
        :returns stp: total number of steps in the model run
                     (unit: number of steps, type: int)
        :returns T_mean: interpolated temperature vector based on the model time and the initial user temperature data
                        (unit: ???, type: array of floats)
        :returns Ts: interpolated temperature vector based on the model time & the initial user temperature data
                    may have a seasonal signal imposed depending on number of years per time step (< 1)
                    (unit: ???, type: array of floats)
        :returns bdot: bdot is meters of ice equivalent/year. multiply by 0.917 for W.E. or 917.0 for kg/year
                      (unit: ???, type: )
        :returns bdotSec: accumulation rate vector at each time step
                         (unit: ???, type: array of floats)
        :returns rhos0: surface accumulate rate vector
                       (unit: ???, type: array of floats)
        :returns D_surf: diffusivity tracker
                        (unit: ???, type: array of floats)
        '''

        gridLen = np.size(self.z)
        dx = np.ones(gridLen)

        input_temp, input_year_temp = read_temp(self.c['InputFileNameTemp'])
        input_bdot, input_year_bdot = read_bdot(self.c['InputFileNamebdot'])

        yr_start  = max(input_year_temp[0], input_year_bdot[0])
        yr_end    = min(input_year_temp[-1], input_year_bdot[-1])
        modeltime = np.linspace(yr_start, yr_end, stp + 1)
        years     = (yr_end - yr_start) * 1.0
        stp       = int(years * self.c['stpsPerYear'])

        dt = years * S_PER_YEAR / stp
        t  = 1.0 / self.c['stpsPerYear']

        TPeriod = years
        Ts = np.interp(modeltime, input_year_temp, input_temp)
        T_mean = Ts
        if t < 1.0:
            Ts = Ts + self.c['TAmp'] * (np.cos(2 * np.pi * np.linspace(0, TPeriod, stp + 1)) + 0.3 * np.cos(4 * np.pi * np.linspace(0, TPeriod, stp + 1)))

        bdot = np.interp(modeltime, input_year_bdot, input_bdot)
        bdotSec = bdot / S_PER_YEAR / (stp / years)

        rhos0 = self.c['rhos0'] * np.ones(stp)
        D_surf = self.c['D_surf'] * np.ones(stp)

        return gridLen, dx, dt, t, modeltime, years, stp, Ts, T_mean, bdot, bdotSec, rhos0, D_surf