EXTRACTING NETCDF DATA BASED ON TIME

조회 수: 26 (최근 30일)
NATHAN MURRY
NATHAN MURRY 2017년 7월 5일
댓글: Mehak S 2024년 4월 8일
Good afternoon:
I am operating on a NetCDF file that contains data for 20 variables over a period of 8 months. This is too much data, so I am trying to extract data based on the time of day. That is, to extract data for all variables from 11pm to 4am for each day in the data file. I have been able to pull out the date / time in the format "dd-mmm-yyyy hh:mm:ss". I can extract and work on ranges of time, but not a range of time per day, for many days.
I can see in my head how to do this, but I am unsure of an efficient way to code it. Experimenting with different time functions, (datenum,hours, datetime, datevec) with other structure and NetCDF tools have been unsucessful. I could use a shove in the right direction. Thank you.

채택된 답변

Walter Roberson
Walter Roberson 2017년 7월 5일
See https://www.mathworks.com/matlabcentral/answers/312198-how-to-extract-data-from-nc-file-based-on-latitude-longitude-time-and-wind#comment_464820 and note that in my sample "expanding the selection" code that you could code hours and minutes into the from date and to date strings.
  댓글 수: 21
NATHAN MURRY
NATHAN MURRY 2017년 7월 25일
There is a copy of it in the web directory I listed above. However, I do not believe you will find anything in it critical to solving the issue at hand.
NATHAN MURRY
NATHAN MURRY 2017년 8월 1일
Hi Walter: So I see I had the correct two statements, but I didn't try to join them together in a larger logical statement as you showed. With some further experimentation and additions, the function works great.
Thank you again for all of your help. I learned quite a bit in wrestling through this problem. Take care.
--NMM

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Tanziha Mahjabin
Tanziha Mahjabin 2020년 1월 29일
편집: Walter Roberson 2020년 1월 29일
Hi,
I want to cut some time from a bid data, using ncread(source,varname,start,count).
for your information,
UCUR_sd
Size: 69x69x45588
Dimensions: J,I,TIME
Datatype: single
Attributes:
long_name = 'Standard deviation of sea water velocity U component values in 1 hour.'
units = 'm s-1'
valid_min = -10
valid_max = 10
cell_methods = 'TIME: standard_deviation'
coordinates = 'TIME LATITUDE LONGITUDE'
_FillValue = 999999
ancillary_variables = 'NOBS1 NOBS2 UCUR_quality_control'
Now if i write,
u=ncread(ncfile,'UCUR',[1 1 1],[Inf Inf 44931]);
it takes the command as the start time is from the start.
But what should i write if i want cut the time from somewhere middle?
I tried to define index,
ind=find(time>=datenum(2017,02,16,0,0,0)&time<=datenum(2017,02,17,0,0,0))
u=ncread(ncfile,'UCUR',[1 1 ind],[Inf Inf 44931]);
But it is not working. Any helpful suggestion please.
  댓글 수: 1
Walter Roberson
Walter Roberson 2020년 1월 29일
netcdf times are never in MATLAB serial datenum . Instead they are in some time units relative to a particular epoch that is defined in the attributes, such as "seconds since Jul 1, 1983 00:00:00 UTC" . You need to examine the attributes for the TIME coordinate and do the conversion.

댓글을 달려면 로그인하십시오.


Tanziha Mahjabin
Tanziha Mahjabin 2020년 1월 30일
Hi Walter,
Thanks for the comment. I did the conversion.
ncfile='IMOS_aggregation_20200124T074252Z.nc';
rtime=ncread(ncfile,'TIME');
time=datenum(rtime+datenum(1950,1,1,0,0,0));
When i write something like this, ru=ncread(ncfile,'UCUR',[1 1 1],[Inf Inf 931]); it works as the time starts from the beginning.
But i want to start the time from somewhere else as i mentioned in my question. So i defined index and try to start according to that.
ind=find(time>=datenum(2017,02,16,0,0,0)&time<=datenum(2017,02,17,0,0,0))
u=ncread(ncfile,'UCUR',[1 1 ind],[Inf Inf 44931]);
It didn't work.
  댓글 수: 8
Walter Roberson
Walter Roberson 2020년 1월 30일
I don't think you want that read inside a for loop??
Mehak S
Mehak S 2024년 4월 8일
Why 't0-1' and not t0 while reading the file?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by