Removing CTD downcasting values from Matrix

3 ビュー (過去 30 日間)
FRANCHI
FRANCHI 2023 年 3 月 12 日
コメント済み: FRANCHI 2023 年 4 月 29 日
Hello all,
I have a matrix of doubles from a CTD profiler with information of depth. I need to remove the values of downcasting of the instrument as the sampling is unconstant compared to the upward casting.
What lines of code (for loop I am guessing) could I use to remove the down casting values? So when the depth component is increasing.
Thank you for your help!

回答 (1 件)

Shivani
Shivani 2023 年 4 月 7 日
編集済み: Shivani 2023 年 4 月 7 日
Hi,
I am assuming that the matrix contains downward casting values first, that is when the CTD profiler moves from the surface to the bottom of the ocean followed by the upward casting values which is when the profiler moves back to the surface.
To remove the downcasting values we will have to simply extract the array containing upcast values, i.e. the second half of the matrix. We can do so by applying the max() function on the column containing the depth data. By doing so we will obtain the row index of the CTD values at maximum depth. We can use that to extract the rows from that index till the end and all the columns corresponding to these rows.
This will contain the upward casting values only because the upward casting of the CTD profiler is done only after it reaches the maximum depth.
Here’s an example with some assumed CTD data:
% columns 1,2,3 and 4 correspond to depth, temperature, salinity and pressure repectively
ctd =[100.0 10.1 35.5 1000.0; 200.0 11.5 36.2 2000.0; 300.0 12.3 36.5 3000.0; 400.0 13.2 36.8 4000.0; 500.0 14.1 3.0 5000.0; 400.0 13.5 36.7 4000.0;300.0 12.8 36.4 3000.0; 200.0 11.9 36.1 2000.0; 100.0 10.8 35.7 1000.0; 0.0 9.6 35.2 0.0]
ctd = 10×4
1.0e+03 * 0.1000 0.0101 0.0355 1.0000 0.2000 0.0115 0.0362 2.0000 0.3000 0.0123 0.0365 3.0000 0.4000 0.0132 0.0368 4.0000 0.5000 0.0141 0.0030 5.0000 0.4000 0.0135 0.0367 4.0000 0.3000 0.0128 0.0364 3.0000 0.2000 0.0119 0.0361 2.0000 0.1000 0.0108 0.0357 1.0000 0 0.0096 0.0352 0
% extracting max_depth and corresponding index from matrix
[max_depth, ind] = max(ctd(:,1))
max_depth = 500
ind = 5
%generating the required matrix with the downcasting values filtered out
ctd_filt = ctd(ind:end,:)
ctd_filt = 6×4
1.0e+03 * 0.5000 0.0141 0.0030 5.0000 0.4000 0.0135 0.0367 4.0000 0.3000 0.0128 0.0364 3.0000 0.2000 0.0119 0.0361 2.0000 0.1000 0.0108 0.0357 1.0000 0 0.0096 0.0352 0
  2 件のコメント
FRANCHI
FRANCHI 2023 年 4 月 29 日
Hi Shivani, thank you for your response. However my challenge was that the profiler goes up and down in depth over days so I have upcasting and downcasting profiles following each other. Not just one. I figured it out in the end with indexing (taking your example again). If that can help anyone :
% columns 1,2,3 and 4 correspond to depth, temperature, salinity and pressure repectively
ctd =[100.0 10.1 35.5 1000.0; 200.0 11.5 36.2 2000.0; 300.0 12.3 36.5 3000.0; 400.0 13.2 36.8 4000.0; 500.0 14.1 3.0 5000.0; 400.0 13.5 36.7 4000.0;300.0 12.8 36.4 3000.0; 200.0 11.9 36.1 2000.0; 100.0 10.8 35.7 1000.0; 0.0 9.6 35.2 0.0]
ctd = 10×4
1.0e+03 * 0.1000 0.0101 0.0355 1.0000 0.2000 0.0115 0.0362 2.0000 0.3000 0.0123 0.0365 3.0000 0.4000 0.0132 0.0368 4.0000 0.5000 0.0141 0.0030 5.0000 0.4000 0.0135 0.0367 4.0000 0.3000 0.0128 0.0364 3.0000 0.2000 0.0119 0.0361 2.0000 0.1000 0.0108 0.0357 1.0000 0 0.0096 0.0352 0
Depth = ctd(:,1); % Naming Depth for more clarity.
m = [1;diff(Depth)]; % Determinating difference in Depth from D1 to D1002384, 1 is for first value (add 1)
Ddiff = m > 0; % Determine downcasting (>0) 1 from upcasting (<0) 0
ctd_depth_diff = [Ddiff ctd]
ctd_depth_diff = 10×5
1.0e+03 * 0.0010 0.1000 0.0101 0.0355 1.0000 0.0010 0.2000 0.0115 0.0362 2.0000 0.0010 0.3000 0.0123 0.0365 3.0000 0.0010 0.4000 0.0132 0.0368 4.0000 0.0010 0.5000 0.0141 0.0030 5.0000 0 0.4000 0.0135 0.0367 4.0000 0 0.3000 0.0128 0.0364 3.0000 0 0.2000 0.0119 0.0361 2.0000 0 0.1000 0.0108 0.0357 1.0000 0 0 0.0096 0.0352 0
ctd(ctd_depth_diff(:, 1)== 1, :)= []; % Removing downcast row
FRANCHI
FRANCHI 2023 年 4 月 29 日
However, my new issue is to find an efficient way of retrieving the depth profiles (decreasing values) and seperate them into a new matrix. I have been able to index the profiles, find the length of each. But I can't figure out how to create a new matrix with a profile per column (filling smaller profiles with NaN). I can't do it manually as I have almost 1/2 million data points. Any idea ? Loop or creating cells that respect the time succession ? Here is my code so far to be clearer:
Thank you for your help!
% columns 1,2,3 and 4 correspond to depth, temperature, salinity and pressure repectively
upcast_ctd = [400 13.5 36.7 4000
300 12.8 36.4 3000
200 11.9 36.1 2000
100 10.8 35.7 1000
0 9.6 35.2 0
400 13.5 36.7 4000
300 12.8 36.4 3000];
ts = [1649959221.5 % MATLAB time
1649959234.5
1649959235.0
1649959235.5
1649959236.0
1649959236.5
1649959237.0]
ts_ctd = [ts ctd] % adding time to ctd measurements
final_t_duration = [1;diff(ts)]; % find the limits of profiles by regular time spacing
logical_profile_limits = final_t_duration > 0.5 ;
logical_diff = diff(find(logical_profile_limits==0)); % Number of repetitions
profiles_lengths_all = [(repelem(logical_diff, logical_diff));0]; % identify the length and location of profiles

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeOceanography and Hydrology についてさらに検索

タグ

製品


リリース

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by