Page MenuHomec4science

grid.py
No OneTemporary

File Metadata

Created
Tue, Aug 6, 03:19
###########################################################################
# #
# Copyright 2017 Andrea Cimatoribus #
# EPFL ENAC IIE ECOL #
# GR A1 435 (Batiment GR) #
# Station 2 #
# CH-1015 Lausanne #
# Andrea.Cimatoribus@epfl.ch #
# #
# Alexandre Serex #
# alexandre.serex@epfl.ch #
# #
# This file is part of ctracker #
# #
# ctracker is free software: you can redistribute it and/or modify it #
# under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# ctracker is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty #
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. #
# See the GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with ctracker. If not, see <http://www.gnu.org/licenses/>. #
# #
###########################################################################
import numpy as np
from core.parameterContainer import ParameterContainer
from tools.CFunctions import transform as c_transform
class Grid(ParameterContainer):
def __init__(self, name, data):
super(Grid, self).__init__(name, data)
# open data directory to load grid data
self.gcm_start = data.gcm_start
self.gcm_dt = data.gcm_dt
self.subiters = int(data.subiters)
self.out_dt = data.out_dt
# load metrics to compute the conversion from fractional index
# to physical coordinate
self.xG = data.xG
self.yG = data.yG
self.dX = data.dX
self.dY = data.dY
self.dxdy = data.dxdy
self.dzt = data.dzt
self.grid_shape = list(self.dzt.shape)
self.kmax, self.jmax, self.imax = self.grid_shape
zG = np.zeros((self.kmax + 1, self.jmax, self.imax))
zG[1:, ...] = np.cumsum(self.dzt[::-1], axis=0)
# tracmass has opposite Z order
zG = zG[::-1, ...]
self.Z = np.ascontiguousarray(zG).astype("float32")
self.dxyz = self.dxdy * self.dzt
self.dstep = 1.0 / self.subiters
self.dtmax = self.out_dt * self.dstep
self.dsmax = self.dtmax / self.dxyz
self.dzu = data.dzu
self.dzv = data.dzv
self.kmtb = data.kmtb
self.kmt = np.ceil(self.kmtb).astype("int8")
self.CS = data.CS
self.SN = data.SN
self.grid_zero_volume = data.grid_zero_volume
def is_config_valid(self):
if np.any(self.dxyz < 0.0):
raise ValueError("Cells with negative volume.")
if np.any((self.dxyz == 0.0) & (self.grid_zero_volume)):
raise ValueError("Zero cell volumes.")
return True
def process_input(self, data, *args, **kwargs):
pass
def process_output(self, data, *args, **kwargs):
pass
def transform(self, ii, jj, kk, stxyz):
c_transform(ii, jj, kk, stxyz, self.CS, self.SN, self.dX, self.dY, self.xG, self.yG, self.Z)

Event Timeline