ClimateUnboxed
ClimateUnboxed

Reputation: 8087

Scale a specific field in a netcdf file keeping metadata

I would like to scale a specific field in a netcdf file by a constant.

Using CDO I know how to scale all fields by a constant $c:

cdo mulc,$c in.nc out.nc

but to apply this to a specific field I would have to cut out the variable, apply the scaling, and then delete the entry from the original file and merge the files, a solution which is cumbersome, slow and not very elegant:

cdo merge -mulc,$c -selvar,$var in.nc -delvar,$var in.nc out.nc

I tried to do it in nco

ncap -s  "ACSWTTEN=10*ACSWTTEN" in.nc out.nc

which works but it strips all the metadata from the field, as nco seems to create a new variable in this way. Again, I can manually redefine all the metadata, but this does not seem an elegant approach.

So, is there a way of scaling a single specific field in a netcdf file that contains many fields, but without destroying the metadata?

Upvotes: 0

Views: 503

Answers (2)

ClimateUnboxed
ClimateUnboxed

Reputation: 8087

It is possible to do this with cdo in fact using aexpr

cdo aexpr,"ACSWTTEN=10*ACSWTTEN" in.nc out.nc

Upvotes: 0

Charlie Zender
Charlie Zender

Reputation: 6352

Yes, in fact your NCO command above is exactly right except you need to use ncap2 not ncap, its predecessor:

ncap2 -s  "ACSWTTEN=10*ACSWTTEN" in.nc out.nc

We will deprecate ncap soon because the situation is confusing :)

Upvotes: 1

Related Questions