I'll just leave this here, in case someone ever needs it; finding the solution is far from obvious.
Because I cannot (yet) access some Python packages to post-process my data, I use NCO instead. However, dealing with time in WRF NetCDF format quickly becomes complicated. Nevertheless, the people on the NCO forum have been very helpful in guiding me to use their tool to shift time in WRF output while maintaining the WRF date-time format.
For example, I have to shift from UTC to UTC-10 ; you'll find the basic Bash script below :
And below is the before / after :
I hope this will be helpful.
Link to the original NCO thread and answer from Henry Butowsky
Because I cannot (yet) access some Python packages to post-process my data, I use NCO instead. However, dealing with time in WRF NetCDF format quickly becomes complicated. Nevertheless, the people on the NCO forum have been very helpful in guiding me to use their tool to shift time in WRF output while maintaining the WRF date-time format.
For example, I have to shift from UTC to UTC-10 ; you'll find the basic Bash script below :
Code:
#!/bin/bash
# Input and output file names
input_file="RAINNC.nc"
output_file="processed_RAINNC.nc"
# Start time counter
start_time=$(date +%s)
# NCO script content
nco_script=$(cat << 'END_SCRIPT'
t2=array(0.0,1.0,$Time);
t2@units="hours since 2013-09-30 14:00:00";
sz=$Time.size;
for(idx=0;idx<sz;idx++)
Times(idx,:)=sprint(strftime(t2(idx),"%Y-%m-%d_%H:%M:%S"));
END_SCRIPT
)
# Execute NCO script with ncap2
ncap2 -O -h -s "$nco_script" "$input_file" "$output_file"
# End time counter
end_time=$(date +%s)
runtime=$((end_time - start_time))
echo "Processing completed in $runtime seconds. Output saved to: $output_file"
And below is the before / after :
Code:
nctime RAINNC.nc |tms |head -n 5
"2013-10-01_00:00:00",
"2013-10-01_01:00:00",
"2013-10-01_02:00:00",
"2013-10-01_03:00:00",
"2013-10-01_04:00:00",
./process_rainnc.sh
ncap2: WARNING assign(): Var being read and written in ASSIGN Times
Processing completed in 7 seconds. Output saved to: processed_RAINNC.nc
nctime processed_RAINNC.nc |tms |head -n 5
"2013-09-30_14:00:00",
"2013-09-30_15:00:00",
"2013-09-30_16:00:00",
"2013-09-30_17:00:00",
"2013-09-30_18:00:00",
I hope this will be helpful.
Link to the original NCO thread and answer from Henry Butowsky