create weight file in netcdf form

  1. In Terminal, create a tmp.nc file contains necessary variables.
ncks -v nv,iint,Itime,Itime2,Times,lonc,latc,xc,yc,nprocs,partition,zeta superior_0001.nc tmp01.nc
# Variable zeta has the same dimension with variable sst (glc lake surface temperature) and sstwt (weight)
ncap2 -h -s "sst=zeta" -s "sstwt=zeta" tmp01.nc weight.nc
# Add sst and sstwt in the same dimension of zeta
ncatted -h -O -a long_name,sst,o,c,"glc lake surface temperature on fvcom grids" weight.nc
ncatted -h -O -a long_name,sstwt,o,c,"weight" weight.nc
# rename variable attribute
  1. In matlab, extent the time dimension
clc;clear;

ncload(['/Users/chuyanzhao/Desktop/FVCOM_output/Lake_Superior/2019/raw_data/LowRes/weight.nc']);

%% change variable dimension in nc file
tmp=ones(11986,365);
ncwrite('/Users/chuyanzhao/Desktop/FVCOM_output/Lake_Superior/2019/raw_data/LowRes/weight.nc','sstwt',tmp);
ncwrite('/Users/chuyanzhao/Desktop/FVCOM_output/Lake_Superior/2019/raw_data/LowRes/weight.nc','sst',tmp);
  1. In matlab, modify the time relevant variables
%% modify iint

for i=1:365
    iint(i)=iint(1)+(i-1)*8640;
end

ncwrite('/Users/chuyanzhao/Desktop/FVCOM_output/Lake_Superior/2019/raw_data/LowRes/weight.nc','iint',iint);

%% modify time and date
start_date='2019-01-01 00:00:00';
reference_date='1858-11-17 00:00:00';

num_start_date=datenum(start_date);
num_reference_date=datenum(reference_date);
day_string=strings(1,365);
fvcom_day=strings(1,365);


for i=1:365
    day(i)=num_start_date+(i-1);
    day_reference(i)=day(i)-num_reference_date;
    day_string{i}=datestr(day(i)+0.5,31);
    fvcom_day(i)=append(day_string{i}(1:10),'T',day_string{i}(12:19),'.000000');
    tmp_times(i,:)=convertStringsToChars(fvcom_day(i));
    tmp_itime2(i)=(i-1)*0;


end
% notice that the dimension is reverse in netcdf file
tmp_times=tmp_times';
day_reference=day_reference';
tmp_times=tmp_itime2';

ncwrite('/Users/chuyanzhao/Desktop/FVCOM_output/Lake_Superior/2019/raw_data/LowRes/weight.nc','Times',tmp_times);
ncwrite('/Users/chuyanzhao/Desktop/FVCOM_output/Lake_Superior/2019/raw_data/LowRes/weight.nc','time',day_reference);
ncwrite('/Users/chuyanzhao/Desktop/FVCOM_output/Lake_Superior/2019/raw_data/LowRes/weight.nc','Itime',day_reference);
ncwrite('/Users/chuyanzhao/Desktop/FVCOM_output/Lake_Superior/2019/raw_data/LowRes/weight.nc','Itime2',tmp_itime2);

  1. In matlab, define weight of fvcom results on each node in terms of the distance to boundary
load("min_node2bound.mat",'min_node2bound');
threshold3=15;
[m,n]=size(min_node2bound);
for i=1:n
if (min_node2bound(i)<threshold3)
weight_mod(i)=(-1/threshold3)*min_node2bound(i)+1;
else
    weight_mod(i)=0.0;
end
end

weight_mod=weight_mod';

for i=1:365
    tmp_sstw(:,i)=weight_mod;
end

ncwrite('/Users/chuyanzhao/Desktop/FVCOM_output/Lake_Superior/2019/raw_data/LowRes/weight.nc','sstwt',tmp_sstw);

  1. In matlab, define sst in netcdf file
    Here, the ‘interpolated_obs_LowRes.mat’ is generated from ‘plot_sst_monthly.m’.
%% define glc sst on FVCOM grids

filename=('interpolated_obs_LowRes.mat');
load(filename,'temp_obs');
temp_obs=temp_obs';
ncwrite('/Users/chuyanzhao/Desktop/FVCOM_output/Lake_Superior/2019/raw_data/LowRes/weight.nc','sst',temp_obs);

  1. Reload the weight.nc in matlab, to ensure every variable is defined correctly.
ncload(['/Users/chuyanzhao/Desktop/FVCOM_output/Lake_Superior/2019/raw_data/LowRes/weight.nc']);

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值