0

この質問を書くのに苦労しました。複数の CTD データ ファイル (深さのある海洋温度値を含むファイル) があります。深さによって温度がどのように変化するかを確認するために、それらを 1 つの図にプロットしました。私が今やりたいことは、平均温度 (すべてのファイルの中で) の平均プロファイル (1 行のみ) を深さでプロットすることです。つまり、複数のデータ ファイルからの各変数の行ごとの平均のようなものです。

私のデータは、温度値の列と深さ値の別の列である cnv 形式です。各データ セットの深さと温度の値の数は同じではありません (つまり、同じ行数ではありません)。

これは、各ファイルをロットするためだけに私のコードがどのように見えるかであり、それが生成する図を添付しました:

from seabird.cnv import fCNV
import numpy as np
import matplotlib.pyplot as plt
from seabird.cnv import fCNV
import glob

filenames = sorted(glob.glob('dSBE19plus*.cnv')) #load multiple files
filenames = filenames[0:8]

fig1 = plt.figure()
ax1 = fig1.add_subplot(111)
for f in filenames:
    print(f)


    data = fCNV(f)
    # Assign variable names
    depth = data['prdM']
    temp  = data['tv290C']
    salt  = data['PSAL']
    fluo  = data['flECO-AFL']
    turbidity = data['turbWETntu0']


    ax1.plot(temp,depth)

    # Draw x label
    ax1.set_xlabel('Temperature (C)')
    ax1.xaxis.set_label_position('top') # this moves the label to the top
    ax1.xaxis.set_ticks_position('top') # this moves the ticks to the top
    # Draw y label
    ax1.set_ylim([0, 100])
    ax1.set_ylabel('Depth (m)')
    ax1.set_ylim(ax1.get_ylim()[::-1]) 
    ax1.set_xlim([15, 26])

fig1.savefig('ctd_plot.png')

プロットされた各 CTD データ セットの図

私の質問が理にかなっていることを願っています。

どうもありがとう

4

1 に答える 1

0

複数のCTDデータファイルを結合し、深さ(またはあなたの場合は圧力「prDM」)に従ってビン化し、ビンでグループ化された各パラメータを平均化できます。

Python でこれを行う方法はわかりませんが、CTD データをビニングするための R 関数を次に示します。

library("tidyverse")

binCTD.mean <- function(.data, # data.frame to be binned
                        .binvar, # variable name to bin over (usually depth or pressure)
                        .breaks, # breaks as in cut() (either single value giving the number of equally distributed bins or a vector of cut points)
                        .binwidth = NA # alternatively to .breaks the binwidth can be set (overwrites .breaks)
) {
    # calculate .breaks from .binwidth if provided:
    if (!is.na(.binwidth)) { 
        .breaks <- seq(0, ## starting from the water surface makes sense?!
                       ceiling(max(.data[, .binvar])), # to highest depth (rounded up)
                       by = .binwidth) # in intervals of given binwidth
    }

    # new parameter "bins", cut according to given breaks (or binwidth)
    .data$bins <- cut(x = .data[, .binvar], breaks = .breaks)

    # return new data frame with averaged parameters, grouped by bins
    .data %>% # I LOVE the pipe operator %>% !! 
        group_by(bins) %>% # dplyr function to group data
        summarise_all(mean, na.rm = TRUE) # dplyr function to apply functions on all parameters in the data frame (actually a tibble, which is kind of the better data.frame)
}

CTD ビニングを実行するための R コードは、説明的な例とともにGitHubでも見つかります。SBE CTD .cnv ファイルを読み取るには、この R 関数 (さまざまなドイツの調査船で収集された SBE CTD .cnv ファイルでテスト済み) GitHubを使用できます。

乾杯、マルコ

于 2018-08-20T20:31:09.650 に答える