2

As the title indicates, I want to extract a time period e.g january for a variable, wind_speed, from a .nc file that consists of wind speeds with 3-hourly resolution during one year. I would like to do this in nco if possible.

I tried the following method: ncrcat -O -F -d time,1,248 -v wind_speed sfcWind.nc out.nc and it works. For this method I need to calculate the time span during the chosen month. Is there any other method in nco where one can specify the month and get the corresponding data?

Another thing is that if one wants data for dec, jan, feb then this method cannot be used, or at least to my knowledge. Any suggestions here?

Best Smail

David Halley
  • 417
  • 3
  • 6
  • 18
  • I suggest creating a simple script that generates specified start/end indices (for instance across DJF) and then builds an `ncks` (or other function) command to be executed based on those start/end indices. If you share the netcdf file in question, I can provide more guidance. – N1B4 Jan 16 '17 at 20:09
  • Dear N1B4, Thank you for your response. I would like to chare the netcdf file but it is around 2GB which is too large. – David Halley Jan 17 '17 at 08:31
  • Could you then provide some more details on its contents, perhaps using `ncdump -h yourfile.nc`? – N1B4 Jan 17 '17 at 14:34
  • I managed to upload a file on this my hotmail onedrive. Its size is less than 1 GB. You can find it via this link: https://1drv.ms/f/s!AlJG9g1WlnmlhDC1WfgR1ljtI67E I'm sorry for the misunderstanding but the variable is named sfcWind (the same as the file). My goal is learn how to extract the wind speeds for dec, jan, feb and keep them in one file. – David Halley Jan 18 '17 at 07:45
  • I used the method as Charlie Zender proposed below and it worked. Thanks – David Halley Jan 18 '17 at 10:37

2 Answers2

2

NCO supports multislabs, i.e., multiple time hyperslabs in one command. With this you can group together arbitrary months, and the --msa switch will keep them in order. The manual is your friend.

Charlie Zender
  • 5,929
  • 14
  • 19
  • Dear Charlie, I used the method you proposed and it worked. I would like to know if there exists any method of choosing data from a specific month. For example, if I write some certain command and then "3" afterwards, then I will get all data contained in March? – David Halley Jan 18 '17 at 10:37
  • You can extract data based either on the hyperslab subscript or the hyperslab value. The value can be a date, assuming the time variable has a "units" attribute in UDUnits format. If I understand your question, that may be what you want. This is explained in the manual in the "hyperslabs" section. – Charlie Zender Jan 18 '17 at 13:46
  • Yes, and that is what I used. I just had an imagination of that among all of the fine operations there exist one which operates on months such that "1" represents January, "2" represents February and so forth. – David Halley Jan 18 '17 at 15:04
  • If I answered your question, please mark the question as answered. – Charlie Zender Jan 23 '17 at 23:27
  • cdo allows you to do this specifying the month as you desire, e.g. 1=January etc, see below. – ClimateUnboxed Apr 06 '17 at 20:13
0

cdo can do the trick, set the index to the month of your choice.

cdo selmon,1 sfcWind.nc sfcWind_jan.nc

If you want to select several months as you mention, you can just provide a comma separated list (of course if you have a single year of data, then your december will not be "adjacent" to the Jan, Feb).

ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86