Пример #1
0
import numpy as np, matplotlib.pyplot as plt, xray, gsw
#1
woa = xray.open_dataset(
    'http://iridl.ldeo.columbia.edu/SOURCES/.NOAA/.NODC/.WOA09/'
    '.Grid-1x1/.Annual/dods')

p0 = -10.1325  #surface pressure (dbars)
pr = 0

S,T,Lat,Lon,dep = xray.broadcast_arrays\
(woa['salinity.s_an'][0],woa['temperature.t_an'][0],woa.lat*1,woa.lon*1,woa.depth*1)

p = -1 * gsw.p_from_z(dep, Lat)
SA = gsw.SA_from_SP(S, p, Lon, Lat)
TC = gsw.CT_from_t(SA, T, p)
rho = gsw.rho_CT_exact(SA, TC, pr)

rhoArr = xray.DataArray(rho,
                        dims=['depth', 'lat', 'lon'],
                        coords=[woa.depth, woa.lat, woa.lon])
rhoArr1 = rhoArr.sel(lat=slice(30, 50), lon=slice(170.5, 170.5))
rhoArr2 = rhoArr.sel(lat=slice(-72, -55), lon=slice(170.5, 170.5))

plt.figure(figsize=(7, 7))
plt.contourf(rhoArr1.lat,
             rhoArr1.depth,
             rhoArr1.squeeze(dim=None),
             cmap='ocean')
plt.title('Potential Density of Kuroshio Extension')
plt.xlabel('lat')
plt.ylabel('depth(m)')
Пример #2
0
    def derive(self,property):
        """

        Derives seawater properties as salinity, buoyancy frequency squared etc.
        Args:
            ST:
            N2:
        """

        try:
            gsw
        except:
            logger.warning('GSW toolbox missing, derive will not work, doing nothing')
            return
        
        if(property == 'ST'):
            # Poor mans check if the variables exist
            sensor_pair0 = False
            sensor_pair1 = False
            try:
                tmp1 = self.data['cond0']
                tmp1 = self.data['temp0']
                tmp1 = self.data['p']
                sensor_pair0 = True
            except:
                sensor_pair0 = False

            try:
                tmp1 = self.data['cond1']
                tmp1 = self.data['temp1']
                tmp1 = self.data['p']
                sensor_pair1 = True
            except:
                sensor_pair1 = False                
                
                
            if(sensor_pair0):
                logger.debug('Calculating PSU0/SA11/CT11/rho11')
                SP = gsw.SP_from_C(self.data['cond0'],self.data['temp0'],self.data['p'])
                self.derived['SP00'] = SP
                SA = gsw.SA_from_SP(SP,self.data['p'],self.header['lon'],self.header['lat'])
                self.derived['SA00'] = SA
                CT = gsw.CT_from_t(SA,self.data['temp0'],self.data['p'])
                self.derived['CT00'] = CT
                rho = gsw.rho_CT_exact(SA,CT,self.data['p'])
                self.derived['rho00'] = rho
            if(sensor_pair1):
                logger.debug('Calculating PSU1/SA11/CT11/rho11') 
                SP = gsw.SP_from_C(self.data['cond1'],self.data['temp1'],self.data['p'])
                self.derived['SP11'] = SP
                SA = gsw.SA_from_SP(SP,self.data['p'],self.header['lon'],self.header['lat'])
                self.derived['SA11'] = SA
                CT = gsw.CT_from_t(SA,self.data['temp1'],self.data['p'])
                self.derived['CT11'] = CT
                rho = gsw.rho_CT_exact(SA,CT,self.data['p'])
                self.derived['rho11'] = rho                
                
                
        if(property == 'N2'):
            # Poor mans check if the variables exist
            sensor_pair0 = False
            sensor_pair1 = False
            try:
                tmp1 = self.derived['SA00']
                tmp1 = self.derived['CT00']                
                tmp1 = self.data['p']
                sensor_pair0 = True
            except:
                logger.info('Did not find absolute salinities and temperature, do first a .derive("ST")')
                sensor_pair0 = False

            try:
                tmp1 = self.derived['SA11']
                tmp1 = self.derived['CT11']                
                tmp1 = self.data['p']
                sensor_pair1 = True
            except:
                logger.info('Did not find absolute salinities and temperature, do first a .derive("ST")')
                sensor_pair1 = False

            if(sensor_pair0):
                logger.debug('Calculating Nsquared00')
                [N2,p_mid] = gsw.Nsquared(self.derived['SA00'],self.derived['CT00'],self.data['p'])
                self.derived['Nsquared00'] = interp(self.data['p'],p_mid,N2)
            if(sensor_pair1):
                logger.debug('Calculating Nsquared11')                
                [N2,p_mid] = gsw.Nsquared(self.derived['SA11'],self.derived['CT11'],self.data['p'])
                self.derived['Nsquared11'] = interp(self.data['p'],p_mid,N2)
                
                
        if(property == 'alphabeta'):
            # Poor mans check if the variables exist
            sensor_pair0 = False
            sensor_pair1 = False
            try:
                tmp1 = self.derived['SA00']
                tmp1 = self.derived['CT00']                
                tmp1 = self.data['p']
                sensor_pair0 = True
            except:
                logger.info('Did not find absolute salinities and temperature, do first a .derive("ST")')
                sensor_pair0 = False

            try:
                tmp1 = self.derived['SA11']
                tmp1 = self.derived['CT11']                
                tmp1 = self.data['p']
                sensor_pair1 = True
            except:
                logger.info('Did not find absolute salinities and temperature, do first a .derive("ST")')
                sensor_pair1 = False
                

            if(sensor_pair0):
                logger.debug('Calculating Nsquared00')
                alpha = gsw.alpha(self.derived['SA00'],self.derived['CT00'],self.data['p'])
                beta = gsw.beta(self.derived['SA00'],self.derived['CT00'],self.data['p'])
                self.derived['alpha00'] = alpha
                self.derived['beta00'] = beta
            if(sensor_pair1):
                logger.debug('Calculating Nsquared11')                
                alpha = gsw.alpha(self.derived['SA11'],self.derived['CT11'],self.data['p'])
                beta = gsw.beta(self.derived['SA11'],self.derived['CT11'],self.data['p'])
                self.derived['alpha11'] = alpha
                self.derived['beta11'] = beta
Пример #3
0
# P (Pressure, dbar))
p1  = 0
p2  = 20
pr  = 0 #reference pressure at the surface


Sa1=sw.SA_from_SP(S1,p1,lon,lat)
Sa2=sw.SA_from_SP(S2,p2,lon,lat)
Tc1 = sw.CT_from_t(Sa1,T1,p1)
Tc2 = sw.CT_from_t(Sa2,T2,p2)


# Assess the stability of the water column by comparing the densities of the two 
# water masses referenced to the same pressue (i.e. use potential density). 
rho1 = sw.rho_CT_exact(Sa1,Tc1,pr)
rho2 = sw.rho_CT_exact(Sa2,Tc2,pr)

# Is the water column stably stratified in this region?
print"\n\nThe water mass from the first measurement at the surface has a density of",round(rho1,SF),\
"which is",round(rho1-rho2,SF)*(-1),"less dense than water mass below ("+str(round(rho2,SF))+")...\nCreating stable stratification."

#Now imagine that ocean circulation transports the same two water masses to pressures 
#of 4990 dbar and 5010 dbar respectively. (One is still approx 20 m deeper than the other.) 
p3 =  4990
p4 =  5010
pr2 =  5000

Sa1=sw.SA_from_SP(S1,p3,lon,lat)
Sa1=sw.SA_from_SP(S2,p4,lon,lat)
Tc1 = sw.CT_from_t(Sa1,T1,p3)
Пример #4
0
import numpy as np, matplotlib.pyplot as plt, xray, gsw
#1
woa = xray.open_dataset('http://iridl.ldeo.columbia.edu/SOURCES/.NOAA/.NODC/.WOA09/'
                        '.Grid-1x1/.Annual/dods')

p0 = -10.1325 #surface pressure (dbars)
pr =  0
                      
S,T,Lat,Lon,dep = xray.broadcast_arrays\
(woa['salinity.s_an'][0],woa['temperature.t_an'][0],woa.lat*1,woa.lon*1,woa.depth*1)

p = -1*gsw.p_from_z(dep,Lat)
SA = gsw.SA_from_SP(S,p,Lon,Lat)
TC = gsw.CT_from_t(SA,T,p)
rho= gsw.rho_CT_exact(SA,TC,pr)


rhoArr = xray.DataArray(rho,dims=['depth', 'lat','lon'],coords=[woa.depth,woa.lat,woa.lon])
rhoArr1 = rhoArr.sel(lat=slice(30, 50),lon=slice(170.5,170.5))
rhoArr2 = rhoArr.sel(lat=slice(-72, -55),lon=slice(170.5,170.5))

plt.figure(figsize=(7,7)) 
plt.contourf(rhoArr1.lat,rhoArr1.depth,rhoArr1.squeeze(dim=None),cmap='ocean')
plt.title('Potential Density of Kuroshio Extension')
plt.xlabel('lat')
plt.ylabel('depth(m)')
plt.ylim(0,3000)
cbar = plt.colorbar(orientation='vertical',fraction=0.046, pad=0.04)
cbar.ax.set_xlabel('rho  kg m^-3')
plt.show()
Пример #5
0
def GetData(PathHav, station):
    """ 
    GetData 
    aquire ocean data for each station

    GetData enters each station file, gets relevant data, 
    calculates density from the GSW package and returns 
    depth, pressure, temperature, salinity, fluorescence, oxygen and density

    The data is aguired from two files, since the oxygen data is in a separate file. 
    The relevant data is picked (num and qual are ignored). 
    
    Input:  PathHav, station
    Output: Data
    """

    # prepare variables and create paths
    StNum, lon, lat = station.name, station.Lon, station.Lat
    StPath1 = PathHav + '{}.raw'.format(StNum)
    StPath2 = PathHav + 'Ox{}.raw'.format(StNum)

    #GET DATA
    # get complicated data from txt with genfromtxt and make DataFrame
    dfDat = pd.DataFrame(
        np.genfromtxt(StPath1,
                      skip_header=9,
                      delimiter=(5, 8, 8, 8, 8, 6, 5),
                      missing_values=' ',
                      names=('depth', 'pres', 'temp', 'sal', 'flu', 'num',
                             'qual')))
    # get ox data
    dfOx = pd.DataFrame(
        np.genfromtxt(StPath2,
                      skip_header=9,
                      delimiter=(5, 8, 8, 6, 4),
                      missing_values=' ',
                      names=('depth', 'pres', 'ox', 'num', 'qual')))
    # pick out relevant data
    D = pd.concat([dfDat.loc[:, 'depth':'flu'], dfOx['ox']], axis=1)
    D = D[pd.notnull(D.depth)]  #dropping faulty rows where depth = NaN

    #CALCULATE DENSITY from gibbs sea water
    SA = gsw.SA_from_SP(D.sal, D.pres, lon,
                        lat)  # gsw.SA_from_SP(SP,p,long,lat)
    CT = gsw.CT_from_t(SA, D.temp, D.pres)  # gsw.CT_from_t(SA,t,p)
    p_ref = 0
    dens = gsw.rho_CT_exact(
        SA, CT, p_ref) - 1000  # sigma0 = rho_CT_exact(SA, CT, 0) - 1000

    # SP : salinity (PSS-78) [unitless],
    # p : pressure [dbar]
    # lon : decimal degrees east [0..+360] or [-180..+180]
    # lat : decimal degrees (+ve N, -ve S) [-90..+90]
    # SA : Absolute salinity [g/kg ]
    # t : in situ temperature degC

    GSW = pd.DataFrame({'CT': CT, 'SA': SA, 'dens': dens})

    # Create Data frame
    Data = pd.concat([D, GSW], axis=1)
    Data = Data.set_index('depth', drop=False)

    return Data