def setupTaperedMasks(myParams, grounded, floating): ''' Smooth or copy floating and grounded masks for tapering near gl ''' # global floatingSmooth, groundedSmooth if myParams['GLTaper'] < 1: floatingSmooth = floating.copy(deepcopy=True) groundedSmooth = grounded.copy(deepcopy=True) else: groundedSmooth = mf.firedrakeSmooth(grounded, alpha=myParams['GLTaper']) floatingSmooth = mf.firedrakeSmooth(floating, alpha=myParams['GLTaper']) return groundedSmooth, floatingSmooth
def thetaInit(Ainit, Q, Q1, grounded, floating, inversionParams): """Compute intitial theta on the ice shelf (not grounded). Parameters ---------- Ainit : firedrake function A Glens flow law A Q : firedrake function space scalar function space Q1 : firedrake function space 1 deg scalar function space used with 'initWithDeg1' grounded : firedrake function Mask with 1s for grounded 0 for floating. floating : firedrake function Mask with 1s for floating 0 for grounded. Returns ------- theta : firedrake function theta for floating ice """ # Get initial file if there is one to init inversion checkFile = inversionParams['initFile'] Quse = Q # Use degree 1 solution if prompted if inversionParams['initWithDeg1']: checkFile = f'{inversionParams["inversionResult"]}.deg1' Quse = Q1 # Now check if there is a file specificed, and if so, init with that if checkFile is not None: Print(f'Init. with theta: {checkFile}') thetaTemp = mf.getCheckPointVars(checkFile, 'thetaInv', Quse)['thetaInv'] thetaInit = icepack.interpolate(thetaTemp, Q) return thetaInit # No initial theta, so use initial A to init inversion Atheta = mf.firedrakeSmooth(Ainit, alpha=1000) theta = firedrake.ln(Atheta) theta = firedrake.interpolate(theta, Q) return theta
def flotationMask(s, zF, Q, rhoI=rhoI, rhoW=rhoW): """Using flotation height, create masks for floating and grounded ice. Parameters ---------- zF firedrake interp function Flotation height (m) Q : firedrake function space function space rhoI : [type], optional [description], by default rhoI rhoW : [type], optional [description], by default rhoW Returns ------- floating firedrake interp function ice shelf mask 1 floating, 0 grounded grounded firedrake interp function Grounded mask 1 grounded, 0 floating """ zAbove = firedrakeSmooth(icepack.interpolate(s - zF, Q), alpha=100) floating = icepack.interpolate(zAbove < 0, Q) grounded = icepack.interpolate(zAbove > 0, Q) return floating, grounded
def getModelGeometry(geometryFile, Q, smooth=False, alpha=2e3, zFirn=0., rhoI=rhoI, rhoW=rhoW): """Load geometry data for model and create firedrake interpolators Parameters ---------- geometryFile : str Path to a yaml file with bed, surface, thickness, and floatMask Q : firedrake function space function space smooth: bool, optional apply firedrakeSmooth to the result alpha : float, optional parameter that controls the amount of smoothing, which is approximately the smoothing lengthscale in m, by default 2e3 zFirn : float, optional Correct elevation for firn thickness (m), by default 14 m rhoI : [type], optional [description], by default rhoI rhoW : [type], optional [description], by default rhoW Returns ------- zb firedrake interp function bed elevation (m) s firedrake interp function surface elevation (m) h firedrake interp function ice thickness (m) floatMask firedrake interp function mask with 1 for floating 0 for grounded """ # load geometry files try: with open(geometryFile) as fp: geom = yaml.load(fp, Loader=yaml.FullLoader) except Exception: myerror(f'Could not open geomtery file: {geometryFile}') # Load and convert to firedrake fd = {'bed': None, 'surface': None, 'thickness': None, 'floatMask': None} # Read and process data for myVar in geom: print(myVar, geom[myVar]) fd[myVar] = getModelVarFromTiff(geom[myVar], Q) if smooth and alpha > 1 and myVar != 'floatMask': fd[myVar] = firedrakeSmooth(fd[myVar], alpha=alpha) if myVar == 'surface': fd[myVar] = icepack.interpolate(fd[myVar] - zFirn, Q) # If data are smoothed, regenerate a new mask from smoothed results. if smooth and alpha > 1: zF = flotationHeight(fd['bed'], Q, rhoI=rhoI, rhoW=rhoW) fd['floatMask'], g = flotationMask(fd['surface'], zF, Q, rhoI=rhoI, rhoW=rhoW) else: g = icepack.interpolate(fd['floatMask'] < 1, Q) # Don't allow negative values for myVar in ['surface', 'thickness']: fd[myVar] = icepack.interpolate(firedrake.max_value(10, fd[myVar]), Q) for myVar in geom: print(f'{myVar} min/max {fd[myVar].dat.data_ro.min():10.2f} ' f'{fd[myVar].dat.data_ro.max():10.2f}') return fd['bed'], fd['surface'], fd['thickness'], fd['floatMask'], g