1

I want to do something (apparently) simple, but didn't yet find the right way to do it:

I read a netcdf file (wind speed from the ERA5 reanalysis) on a grid. From this, I use the wind speed to calculate a wind capacity factor (using a given power curve). I then want to write a new netcdf file, with exactly the same structure as the input file, but just replacing the input wind speed by the new variable (wind capacity factor).

Is there a simple/fast way to do this, avoiding to redefine all the dims, vars ... with ncvar_def and ncdim_def ?

Thanks in advance for your replies!

ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86
L. Dbs
  • 11
  • 2

1 Answers1

1

Writing a netcdf file in R is not overly complicated, there is a nice example online here:

http://geog.uoregon.edu/GeogR/topics/netCDF-write-ncdf4.html

You could copy the dimensions from the input file.

However if your wind power curve is a simple analytical expression then you could perform this task in one line from the command line in bash/linux using climate data operators (cdo).

For example, if you have two variables 10u and 10v in the file (I don't recalled the reanalysis names exactly) then you could make a new variable WCF=SQRT(U2+V2) in the following way

cdo expr,'wcf=sqrt(10u**2+10v**2)' input.nc output.nc 

See an example here:

https://code.mpimet.mpg.de/boards/53/topics/1622

So if your window power function is an analytical expression you can define it this way without using R at all or worrying about dimensions etc, the new file will have an variable wcf added. You should then probably use NCO to alter the metadata (units etc) to ensure they are appropriate.

ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86
  • Good info, but I believe wind power curves are empirical rather than analytical. – Robert Davy Mar 04 '20 at 22:01
  • The OP states "I use the wind speed to calculate a wind capacity factor", so I'm assuming there is some simple relation between wind and the function... I don't think the OP is referring to empirical measurements of wind power generation. – ClimateUnboxed Mar 05 '20 at 19:02
  • OK. FYI simple wind power density estimates are available at higher resolution than ERA5 here: https://globalwindatlas.info. – Robert Davy Mar 05 '20 at 22:35
  • 1
    probably info for the OP more than I, I think that atlas is anyway an example of high resolution not necessarily meaning higher quality, it is derived anyway from ERA5 then downscaled with WRF, which has some issues with the boundary layer depending on the parameterizations used. Perhaps the operational analysis might be a better bet (8km resolution) but is not freely available and changes over time (not a long term). Interesting though. In any case, the question is more about manipulating a netcdf input x with a function F(x) and write F(x) to a file, the wind context is somewhat irrelevant. – ClimateUnboxed Mar 06 '20 at 08:30