Example #1
0
def sigma_from_CTD(sal, temp, press, lon, lat, ref=0):
    """
    Calculates potential density from CTD parameters at various reference pressures

    Parameters
    ----------

    sal :array-like
         Salinity in PSU (PSS-78)

    temp :array_like
          In-situ temperature in deg C

    press :array_like
           Pressure in dbar

    lon :array_like
         longitude in decimal degrees

    lat :array_like
         latitute in decimal degrees

    ref :int
         reference pressure point for caluclateing sigma0 (in ref * 1000 dBar ref[0-4])

    Returns
    -------

    simga :array-like
           Potential density calculated at a reference pressure of ref * 1000 dBar

    """

    CT = gsw.CT_from_t(sal, temp, press)

    SA = gsw.SA_from_SP(sal, press, lon, lat)

    # Reference pressure in ref*1000 dBars
    if ref == 0:
        sigma = gsw.sigma0(SA, CT)
    elif ref == 1:
        sigma = gsw.sigma1(SA, CT)
    elif ref == 2:
        sigma = gsw.sigma2(SA, CT)
    elif ref == 3:
        sigma = gsw.sigma3(SA, CT)
    elif ref == 4:
        sigma = gsw.sigma4(SA, CT)

    return sigma
 def sigma2(self,pres):
     i = np.where(np.asarray(self.ipres) == int(pres))[0][0]
     return gsw.sigma2(self.isals[i],self.itemps[i])
Example #3
0
#  TRANSFORMATIONS ON DIFFERENT GRIDS (Density, Spatial auxiliary grid)
# =======================================================================================
# ---------------------------------------------------------------------------------------
# - Spatial auxiliary grid
auxgrd_name = [
    'lat395model', 'lat198model', 'lat170eq80S90N', 'lat340eq80S90N'
][0]  # choose aux grid
lat_auxgrd, zT_auxgrd, z_w_auxgrd = utils_mask.gen_auxgrd(ncdat, auxgrd_name)
lat_mgrd = ncdat.TLAT.isel(
    nlon=0)  # mean of LAT for each j #! very inappropriate
# ---------------------------------------------------------------------------------------
# - Potential density and binning
SA = ncdat.SALT[0, :, :, :].values  # absolute salinity
PT = ncdat.TEMP[0, :, :, :].values  # potential temperature
CT = gsw.CT_from_pt(SA, PT)  # conservative temperature
sig2 = gsw.sigma2(SA, CT)  # potential density anomaly referenced to 2000dbar
RHO = ncdat.RHO[
    0, :, :, :].values * 1000 - 1000  # in-situ density anomaly [SI]
PD_bins = np.linspace(27, 38, 200)  # PD_bins = np.linspace(1.004,1.036,65)
# ---------------------------------------------------------------------------------------
# - Paths
path_auxgrd = paths.get_path2var(auxgrd_name)
utils_misc.checkdir(path_auxgrd)
path_mgrd = 'vars_mgrd/'
path_dens = 'vars_dens/'
varname_binning = 'eqbins_{}to{}in{}steps'.format(int(PD_bins.min()),
                                                  int(PD_bins.max()),
                                                  int(len(PD_bins)))

# =======================================================================================
#  Variables contained in model output
Example #4
0
# =======================================================================================
#  Transformation on different grids (Density, Spatial auxiliary grid)
# =======================================================================================
# ---------------------------------------------------------------------------------------
# - Mask for Atlantic
ATLboolmask = utils_mask.get_ATLbools(ncdat.REGION_MASK.values) # boolean mask
# ---------------------------------------------------------------------------------------
# - Spatial auxiliary grid
lat_auxgrd, zT_auxgrd, z_w_auxgrd = utils_mask.gen_auxgrd(ncdat, auxgrd_name)
lat_mgrd = ncdat.TLAT.isel(nlon=0)          # mean of LAT for each j #! very inappropriate
# ---------------------------------------------------------------------------------------
# - Density grid/bins
SA = ncdat.SALT[0,:,:,:].values             # absolute salinity
PT = ncdat.TEMP[0,:,:,:].values             # potential temperature
CT = gsw.CT_from_pt(SA, PT)                 # conservative temperature
sig2 = gsw.sigma2(SA, CT)                   # potential density anomaly referenced to 2000dbar
RHO = ncdat.RHO[0,:,:,:].values*1000-1000   # in-situ density anomaly [SI]
if densChoice == 'sig2': dens = sig2
elif densChoice == 'rho': dens = RHO
# density bins (db), center-values (dbc) and thicknesses (ddb, ddbc)
db = np.concatenate((np.linspace(dbsetup[0,0],dbsetup[0,1],dbsetup[0,2]), np.linspace(dbsetup[1,0],dbsetup[1,1],dbsetup[1,2]), np.linspace(dbsetup[2,0],dbsetup[2,1],dbsetup[2,2]), np.linspace(dbsetup[3,0],dbsetup[3,1],dbsetup[3,2])))
dbc = np.array([np.mean(db[i-1:i+1]) for i in np.arange(1,len(db))]) #! center-values | reasonable for non-eq-spaced db?
ddb = utils_ana.canonical_cumsum(np.diff(db)/2, 2, axis=0, crop=True)        # layer thickness of density_bins
ddbc = np.diff(db)                                                   # layer thickness from midpoint to midpoint (#! note: it is 1 element longer than ddb)
# depth of isopycnals (i.e. of density_bins at both staggered grids)
z_t_3d = utils_conv.exp_k_to_kji(ncdat.z_t, dens.shape[-2], dens.shape[-1])
zdb = LGS(lambda: utils_conv.resample_colwise(z_t_3d, dens, db, 'lin', fill_value=np.nan, mask = ATLboolmask, mono_method='sort'), path_zdb, 'zdb', noload=boolLGSnoload)
zdbc = LGS(lambda: utils_conv.resample_colwise(z_t_3d, dens, dbc, 'lin', fill_value=np.nan, mask = ATLboolmask, mono_method='sort'), path_zdbc, 'zdbc', noload=boolLGSnoload)
#dzdb = utils_ana.canonical_cumsum(np.diff(zdb, axis=0)/2, 2, axis=0, crop=True)      # layer thickness of isopycnal depths
dzdb = np.diff(zdb, axis=0)
del PT, CT, z_t_3d, dbsetup