#compute the mean shear velocity in the BBL as theoretically it should be constant
        shear_velocity = np.zeros(number_of_profiles)
        for profile in range(number_of_profiles):
            BBL_from = int(list_of_BBL_indices[profile])
            BBL_to = int(list_of_bathymetry_indices[profile])
        
            #print(list_of_BBL_indices[profile],list_of_bathymetry_indices[profile])
            BBL_shear_velocity = np.nanmean(shear_velocity_grid[BBL_from:BBL_to])
            
            law_of_the_wall_turbulent_diffusivity = thesis.von_Karman_constant * BBL_shear_velocity * distance_from_ground_grid[profile,BBL_from:BBL_to]
            
            #replace the corresponding bins with the turbulent diffusivity from the law of the wall
            turbulent_diffusivity_Osborn_grid[profile,BBL_from:BBL_to] = law_of_the_wall_turbulent_diffusivity
            turbulent_diffusivity_Shih_grid[profile,BBL_from:BBL_to] = law_of_the_wall_turbulent_diffusivity
        
        oxygen_gradient_grid = thesis.central_differences(eps_oxygen_grid)/thesis.central_differences(eps_depth) #in units of micromol/(m*l)
        unit_conversion_grid = 86400 #to convert from m*micromol/(l*s) to mmol/(m^2*d)  ; l to m^3 and micro to milli cancel each other out (factor of 1000)
    
        oxygen_flux_Osborn_grid = - turbulent_diffusivity_Osborn_grid * oxygen_gradient_grid * unit_conversion_grid
        oxygen_flux_Shih_grid = - turbulent_diffusivity_Shih_grid * oxygen_gradient_grid * unit_conversion_grid
        #oxygen_flux_BB_grid =  - turbulent_diffusivity_BB_grid * oxygen_gradient_grid * unit_conversion_grid

        
        # check if the absolute Osborn fluxes are higher than the absolute Shih fluxes (as they should be, because Gamma_Osborn >= Gamma_Shih)
        assert np.all(np.isnan(oxygen_flux_Osborn_grid) == np.isnan(oxygen_flux_Shih_grid))
        test_Osborn = oxygen_flux_Osborn_grid[~np.isnan(oxygen_flux_Osborn_grid)]
        test_Shih = oxygen_flux_Shih_grid[~np.isnan(oxygen_flux_Shih_grid)]
        assert np.all( np.abs(test_Osborn) >= np.abs(test_Shih))
        
        
        for profile in range(number_of_profiles):
Exemple #2
0
          100 * number_of_fluxes_over_the_threshold / total_number_of_fluxes,
          "%")
    print(
        "Sum:", 100 * amount_of_missing_values / total_number_of_fluxes +
        100 * number_of_zero_flux / total_number_of_fluxes +
        100 * number_of_fluxes_over_the_threshold / total_number_of_fluxes,
        "%")

    distance_list = np.zeros(np.shape(longitude_list))
    first_point = (np.mean(lat), longitude_list[0])
    for i in range(len(longitude_list)):
        current_point = (np.mean(lat), longitude_list[i])
        distance_list[i] = geo.geodesic(first_point,
                                        current_point).km  #Distance in km

    delta_X = thesis.central_differences(distance_list)

    print("\n\n\n", cruisename, "flux sum:")
    print("Osborn rolling mean", np.nansum(rolling_mean_Osborn_flux * delta_X),
          "Osborn profiles", np.nansum(mean_Osborn_flux * delta_X))
    print("Shih rolling mean", np.nansum(rolling_mean_Shih_flux * delta_X),
          "Shih profiles", np.nansum(mean_Shih_flux * delta_X))
    print("\n\n\n")

    np.savetxt(
        "./data/" + cruisename + '_coarse_flux_results.txt',
        np.transpose([
            longitude_list, distance_list, mean_Osborn_flux,
            rolling_mean_Osborn_flux, mean_Shih_flux, rolling_mean_Shih_flux
        ]),
        header=
#conversion from pressure coordinates to depth
eps_depth = gsw.z_from_p(eps_pressure, np.mean(
    lat))  #mean lat should be sufficient, because the transect is east-west
eps_depth_grid = np.reshape(eps_depth, (1, -1)) * np.ones(np.shape(eps_grid))

#########################################
#Calculate fluxes########################
#########################################

Gamma_Osborn_eps_grid = thesis.Osborn(eps_Reynolds_bouyancy_grid)
turbulent_diffusivity_Osborn_grid = Gamma_Osborn_eps_grid * eps_grid / (
    eps_N_squared_grid)
#remove negative diffusivity
turbulent_diffusivity_Osborn_grid[
    turbulent_diffusivity_Osborn_grid < 0] = np.nan
oxygen_flux_osborn_grid = -turbulent_diffusivity_Osborn_grid[:, :] * thesis.central_differences(
    eps_oxygen_grid) / thesis.central_differences(eps_depth)
#convert from m*micromol/(kg*s) to mmol/(m^2*d)
oxygen_flux_osborn_grid = oxygen_flux_osborn_grid * 86400 * (1000 /
                                                             eps_density_grid)

Gamma_BB_eps_grid = thesis.BB(eps_Reynolds_bouyancy_grid)
turbulent_diffusivity_BB_grid = Gamma_BB_eps_grid * eps_grid / (
    eps_N_squared_grid)
#remove negative diffusivity
turbulent_diffusivity_BB_grid[turbulent_diffusivity_BB_grid < 0] = np.nan
oxygen_flux_BB_grid = -turbulent_diffusivity_BB_grid[:, :] * thesis.central_differences(
    eps_oxygen_grid) / thesis.central_differences(eps_depth)
#convert from m*micromol/(kg*s) to mmol/(m^2*d)
oxygen_flux_BB_grid = oxygen_flux_BB_grid * 86400 * (1000 / eps_density_grid)

Gamma_Skif_eps_grid = thesis.Skif(eps_Reynolds_bouyancy_grid)
Exemple #4
0
    axis3.plot(longitude,
               rolling_mean_Shih,
               "-",
               color=color,
               label=cruise_name +
               r" $\langle$Shih flux$\rangle_{\mathrm{z,lon}}$ ")
    axis3.set_title(cruise_name)
    axis3.legend(loc="lower center")
    axis3.set_xlabel("Shih Oxygen flux")

    ##########################################################################################
    distance_from_ground_bin_edges = np.arange(0, 80, 2.5)

    #sorted(list(set(transect_bathymetry)))

    diff_distance = thesis.central_differences(distance)
    #diff_distance = np.diff(distance)
    #assert np.all(diff_distance > 0)
    #print(np.round(diff_distance,3))
    #print(diff_distance >= 0)

    #integral_axis[0,cruise_index].bar(distance,raw_Osborn,alpha = 0.5, width = diff_distance, align = "edge")
    #integral_axis[0,cruise_index].plot(distance,raw_Osborn,"k-")
    #integral_axis[1,cruise_index].bar(distance,rolling_mean_Shih,alpha = 0.5, width = diff_distance, align = "edge")
    #integral_axis[1,cruise_index].plot(distance,rolling_mean_Shih,"k-")

    print(
        "-------------------------------------------------------------------------------"
    )
    print(cruise_name)
    print("For a basin with a halocline at depth", halocline_depth,
                #test if the saturation at that depth is under a certain level
                if eps_oxygen_sat_grid[profile, test_index] < 50:
                    print("Oxycline drops too fast!",
                          eps_oxygen_sat_grid[profile, test_index])
                    outlier_count += 1
                    list_of_bad_profiles.append([
                        "_".join((cruisename, transect_name, str(profile))),
                        "\t\t\toxygen_drops_too_fast"
                    ])
                    continue

                try:
                    #test if the saturation at that depth is under a certain level
                    if eps_pressure[np.nanargmin(
                            thesis.central_differences(
                                eps_oxygen_sat_grid[profile, :]))] < 50:
                        print(
                            "Oxycline is too high!", eps_pressure[np.nanargmin(
                                thesis.central_differences(
                                    eps_oxygen_sat_grid[profile, :]))])
                        outlier_count += 1
                        #list_of_bad_profiles.append(["_".join((cruisename,transect_name,str(profile))),"oxycline_is_too_shallow"])
                        #continue

                except ValueError:
                    #if np.all(np.isnan(eps_oxygen_sat_grid[profile,:])):
                    print("All NaN profile")
                    outlier_count += 1
                    list_of_bad_profiles.append([
                        "_".join((cruisename, transect_name, str(profile))),
                        "\t\t\tNaN_profile"
                          c=color,
                          cmap="viridis",
                          vmin=vmin,
                          vmax=vmax,
                          marker=",",
                          s=1.4)
 image = density_axarr[1].scatter(oxygen_flux_Skif_grid[profile, :],
                                  eps_pot_density_grid[profile, :],
                                  c=color,
                                  cmap="viridis",
                                  vmin=vmin,
                                  vmax=vmax,
                                  marker=",",
                                  s=1.4)
 oxygen_axarr[0].scatter(thesis.central_differences(
     eps_oxygen_sat_grid[profile, :] /
     thesis.central_differences(eps_depth)),
                         eps_pot_density_grid[profile, :],
                         c=color,
                         cmap="viridis",
                         vmin=vmin,
                         vmax=vmax,
                         marker=",",
                         s=1.4)
 image_oxy = oxygen_axarr[1].scatter(
     eps_pressure,
     eps_pot_density_grid[profile, :],
     c=color,
     cmap="viridis",
     vmin=vmin,
     vmax=vmax,
Exemple #7
0
#Test of different BBL conditions
exp_results = experimental_BBL(number_of_profiles,interp_pressure,density_grid,oxygen_grid,height_above_ground = 10,minimal_density_difference = 0.02)
exp_bathymetrie,exp_list_of_bathymetrie_indices = results[0]
exp_BBL,exp_list_of_BBL_indices = results[1]
exp_BBL_range,exp_list_of_BBL_range_indices = results[2]
"""

#TODO
turbulent_diffusivity_Osborn_grid = 0.2 * eps_grid / (eps_N_squared_grid)
turbulent_diffusivity_Osborn_grid[turbulent_diffusivity_Osborn_grid<0] = 0
        
eps_depth = gsw.z_from_p(eps_pressure,np.mean(lat)) #mean lat should be sufficient, because the transect is east-west
print(min(eps_depth),max(eps_depth))
#TODO: Which differention scheme should I use? 
#Here I remove the uppermost row of the diffusivity to get the same shape (diff removes one row)
oxygen_flux_osborn_grid = turbulent_diffusivity_Osborn_grid[:,:] * thesis.central_differences(eps_oxygen_grid)/thesis.central_differences(eps_depth)
#convert from m*micromol/(l*s) to mmol/(m^2*d)
oxygen_flux_osborn_grid = oxygen_flux_osborn_grid*86400/(1000**2)   

        
transect_index = -5
print("\n\n\n\n")
print("pressure\tdepth\teps\t","N^2\t","k\t","dO_2/dz\t","flux\t")
for i in range(eps_pressure.size-1):
    print(eps_pressure[i],"\t",np.round(eps_depth[i],1),"\t",'{:0.3e}'.format(eps_grid[transect_index,i]),"\t",'{:0.3e}'.format(eps_N_squared_grid[transect_index,i]),"\t",'{:0.3e}'.format(turbulent_diffusivity_Osborn_grid[transect_index,i]),"\t",'{:0.3e}'.format((np.diff(eps_oxygen_grid)/np.diff(eps_depth))[transect_index,i]),"\t",'{:0.3e}'.format(oxygen_flux_osborn_grid[transect_index,i]))
print("\n\n\n\n")
        
#append the last distance plus the last difference (for plotting all the n profiles we need a distance array of size n+1 
plotmesh_distance = np.append(distance,2*distance[-1]-distance[-2])
plotmesh_longitude = np.append(lon,2*lon[-1]-lon[-2])
        
Exemple #8
0
        BBL_from = int(list_of_BBL_indices[profile])
        BBL_to = int(list_of_bathymetry_indices[profile])

        #print(list_of_BBL_indices[profile],list_of_bathymetry_indices[profile])
        BBL_shear_velocity = np.nanmean(shear_velocity_grid[BBL_from:BBL_to])

        law_of_the_wall_turbulent_diffusivity = thesis.von_Karman_constant * BBL_shear_velocity * distance_from_ground_grid[
            profile, BBL_from:BBL_to]

        #replace the corresponding bins with the turbulent diffusivity from the law of the wall
        turbulent_diffusivity_Osborn_grid[
            profile, BBL_from:BBL_to] = law_of_the_wall_turbulent_diffusivity
        turbulent_diffusivity_Shih_grid[
            profile, BBL_from:BBL_to] = law_of_the_wall_turbulent_diffusivity

    oxygen_gradient_grid = thesis.central_differences(
        eps_oxygen_grid) / thesis.central_differences(eps_depth)
    unit_conversion_grid = 86400 * (
        1000 / eps_density_grid
    )  #to convert from m*micromol/(kg*s) to mmol/(m^2*d)

    oxygen_flux_Osborn_grid = -turbulent_diffusivity_Osborn_grid * oxygen_gradient_grid * unit_conversion_grid
    oxygen_flux_BB_grid = -turbulent_diffusivity_BB_grid * oxygen_gradient_grid * unit_conversion_grid
    oxygen_flux_Shih_grid = -turbulent_diffusivity_Shih_grid * oxygen_gradient_grid * unit_conversion_grid

    interior_Shih_flux_for_different_intervals = []
    interior_Osborn_flux_for_different_intervals = []

    edge_Shih_flux_for_different_intervals = []
    edge_Osborn_flux_for_different_intervals = []

    example_profile_index = np.argmin(abs(lon - 20.56))
Exemple #9
0
        BBL_from = int(list_of_BBL_indices[profile])
        BBL_to = int(list_of_bathymetry_indices[profile])

        #print(list_of_BBL_indices[profile],list_of_bathymetry_indices[profile])
        BBL_shear_velocity = np.nanmean(shear_velocity_grid[BBL_from:BBL_to])

        law_of_the_wall_turbulent_diffusivity = thesis.von_Karman_constant * BBL_shear_velocity * distance_from_ground_grid[
            profile, BBL_from:BBL_to]

        #replace the corresponding bins with the turbulent diffusivity from the law of the wall
        turbulent_diffusivity_Osborn_grid[
            profile, BBL_from:BBL_to] = law_of_the_wall_turbulent_diffusivity
        turbulent_diffusivity_Shih_grid[
            profile, BBL_from:BBL_to] = law_of_the_wall_turbulent_diffusivity

    oxygen_gradient_grid = thesis.central_differences(
        eps_oxygen_grid) / thesis.central_differences(
            eps_depth)  #in units of micromol/(m*l)
    unit_conversion_grid = 86400  #to convert from m*micromol/(l*s) to mmol/(m^2*d)  ; l to m^3 and micro to milli cancel each other out (factor of 1000)

    oxygen_flux_Osborn_grid = -turbulent_diffusivity_Osborn_grid * oxygen_gradient_grid * unit_conversion_grid
    oxygen_flux_Shih_grid = -turbulent_diffusivity_Shih_grid * oxygen_gradient_grid * unit_conversion_grid

    #remove negative diffusivity for the plot
    turbulent_diffusivity_Osborn_grid[turbulent_diffusivity_Osborn_grid ==
                                      0] = 1e-7

    profile_index = np.argmin(np.abs(lon - 20.57))
    print(cruise_name, transect_name, lon[profile_index])
    """   
    def make_patch_spines_invisible(ax):
        ax.set_frame_on(True)