コード例 #1
0
def calculate_density(temperature, pressure, salinity, latitude, longitude):
    """Calculates density given glider practical salinity, pressure, latitude,
    and longitude using Gibbs gsw SA_from_SP and rho functions.

    Parameters:
        temperature (C), pressure (dbar), salinity (psu PSS-78),
        latitude (decimal degrees), longitude (decimal degrees)

    Returns:
        density (kg/m**3),
    """

    correct_sizes = (temperature.size == pressure.size == salinity.size ==
                     latitude.size == longitude.size)
    if correct_sizes is False:
        raise ValueError('Arguments must all be the same length')

    with warnings.catch_warnings():
        warnings.simplefilter("ignore")

        absolute_salinity = SA_from_SP(salinity, pressure, longitude, latitude)

        conservative_temperature = CT_from_t(absolute_salinity, temperature,
                                             pressure)

        density = rho(absolute_salinity, conservative_temperature, pressure)

        return density
コード例 #2
0
ファイル: ctd.py プロジェクト: nguyandy/gdm
def calculate_sound_speed(temperature, pressure, salinity, latitude,
                          longitude):
    """Calculates sound speed given glider practical in-situ temperature, pressure and salinity using Gibbs gsw
    SA_from_SP and rho functions.

    Parameters:
        temperature (C), pressure (dbar), salinity (psu PSS-78), latitude, longitude

    Returns:
        sound speed (m s-1)
    """

    absolute_salinity = SA_from_SP(salinity, pressure, longitude, latitude)

    conservative_temperature = CT_from_t(absolute_salinity, temperature,
                                         pressure)

    speed = sound_speed(absolute_salinity, conservative_temperature, pressure)

    return speed
コード例 #3
0
ファイル: ctd.py プロジェクト: nguyandy/gdm
def calculate_density(temperature, pressure, salinity, latitude, longitude):
    """Calculates density given glider practical salinity, pressure, latitude,
    and longitude using Gibbs gsw SA_from_SP and rho functions.

    Parameters:
        timestamps (UNIX epoch),
        temperature (C), pressure (dbar), salinity (psu PSS-78),
        latitude (decimal degrees), longitude (decimal degrees)

    Returns:
        density (kg/m**3),
    """

    # dBar_pressure = pressure * 10

    absolute_salinity = SA_from_SP(salinity, pressure, longitude, latitude)

    conservative_temperature = CT_from_t(absolute_salinity, temperature,
                                         pressure)

    density = rho(absolute_salinity, conservative_temperature, pressure)

    return density
コード例 #4
0
# for istat, (xs, ys) in enumerate(zip(ctd['lon'][0], ctd['lat'][0])):
#     ax.text(xs, ys, str(ctd['profilid'][0, istat])[-3:], transform=ccrs.PlateCarree())
# ax.scatter(ctd['lon'][0, transects[nts]], ctd['lat'][0, transects[nts]], transform=ccrs.PlateCarree(), zorder=4, facecolors='yellow')
# if savefig:
#     fig.savefig(os.path.join(pathsave, 'map_transect%s.png' %nts), transparent=True)



# DYNAMIC HEIGHT and depth
nanarray = np.empty((ctd['P'].shape[0], len(transects[nts])))
nanarray[:] = np.nan
SA, CT, g, depth, pt, nprof = nanarray.copy(), nanarray.copy(), nanarray.copy(), nanarray.copy(), nanarray.copy(), nanarray.copy()
for i, profile in enumerate(transects[nts]):
    nprof[:, i] = profile
    SA[:, i] = SA_from_SP(ctd['S'][:, profile], P, ctd['lon'][0, profile], ctd['lat'][0, profile])
    CT[:, i] = CT_from_t(SA[:, i], ctd['T'][:, profile], P)
    g[:, i] = grav(ctd['lat'][0, profile], P)
    depth[:, i] = abs(z_from_p(P, ctd['lat'][0, profile]))
    pt[:, i] = pt_from_t(SA[:, i], ctd['T'][:, profile], P, p_ref)
sig0 = sigma0(SA, CT)

# for i

deltaD = geo_strf_dyn_height(SA, CT, P, p_ref=p_ref) / g
deltaD500 = np.tile(deltaD[i500], (deltaD.shape[0],1))

# g_p = grav(ctd['lat'][0, profile], P)
# SA = SA_from_SP(ctd['S'][:, profile], P, ctd['lon'][0, profile], ctd['lat'][0, profile])
# CT = CT_from_t(SA, ctd['T'][:, profile], P)
# pt = pt_from_t(SA, ctd['T'][:, profile], P, 0)
# depth = abs(z_from_p(P, ctd['lat'][0, profile]))
コード例 #5
0
                    nc.close()

                    print('Output file %s already exists, variable %s added.' %
                          (os.path.split(output_file)[-1], gsw_vars[-1]))

            else:

                # change one dimension variables to two dimensions
                p, lon, lat = nc['p'][:], nc['lon'][:, 0][:, np.newaxis], nc[
                    'lat'][:, 0][:, np.newaxis]

                # convert in-situ variables to gsw variables
                p_ref = 1494  # shallowest profile (4) except (34) which goes until 1004

                SA = SA_from_SP(nc['SP'][:], p, lon, lat)
                CT = CT_from_t(SA, nc['t'][:], p)
                pt = pt_from_t(SA, nc['t'][:], p, p_ref)

                deltaD = np.ma.masked_invalid(
                    geo_strf_dyn_height(SA.data,
                                        CT.data,
                                        p,
                                        p_ref=p_ref,
                                        axis=1))

                # transect stations
                transects = {
                    1: list(reversed(range(2, 10))),
                    2: list(range(10, 18)),
                    3: list(reversed(range(18, 27))),
                    4: list(range(26, 34)),
コード例 #6
0
        P = np.zeros(dict_ctd['P'].shape[0])
        P[:] = np.nan
        for ip, p in enumerate(dict_ctd['P']):
            P[ip] = p
        if filename[4:] == 'vars':
            dict_vars['P'] = P
            Parray = np.tile(dict_vars['P'], (dict_vars['S'].shape[1], 1)).T
        elif filename[4:] == 'stations':
            dict_stations['P'] = P

        # calculate TEOS-10 variables and store in dict
        p_ref = 1500
        if filename[4:] == 'vars':
            dict_vars['SA'] = SA_from_SP(dict_vars['S'], Parray,
                                         dict_vars['lon'], dict_vars['lat'])
            dict_vars['CT'] = CT_from_t(dict_vars['SA'], dict_vars['T'],
                                        Parray)
            dict_vars['depth'] = abs(z_from_p(Parray, dict_vars['lat']))
            dict_vars['pt'] = pt_from_t(dict_vars['SA'], dict_vars['T'],
                                        Parray, p_ref)
            dict_vars['sigma0'] = sigma0(dict_vars['SA'], dict_vars['CT'])
            dict_vars['spiciness0'] = spiciness0(dict_vars['SA'],
                                                 dict_vars['CT'])

            # save dictionary to file
            write_dict(dict_vars, path, filename)
            print('data stored in file')

        elif filename[4:] == 'stations':
            for station in dict_ctd['station'][0, :]:
                dict_stations[station]['SA'] = SA_from_SP(
                    dict_stations[station]['S'], dict_stations['P'],