Save netCDF file to grib file

41 views Asked by At

I am trying to save a netCDF file to a grib file, but I get several error with trying different things.

First when I load the netcdf file in Iris I get the FutureWarning: Ignoring a datum in netCDF load for consistency with existing behaviour. In a future version of Iris, this datum will be applied. To apply the datum when loading, use the iris.FUTURE.datum_support flag. cubes = iris.load(data_path + file) error

It does load the cube, so blindly ignorant I continue and try to save the file with iris.save or iris_grib.save_grib2:

import iris
import iris.plot as iplt
import iris.quickplot as qplt
import iris_grib
import xarray as xr
import cfgrib
import xarray as xr
from datetime import datetime, timedelta
import pandas as pd
import numpy as np

cubes = iris.load(data_path + file)

iris_grib.save_grib2(cubes[0], data_path+'test.grib2')

or

iris.save(cubes[0],data_path+'test.grib2')

But I get the error: TranslationError: time coord not found

I have tried downloading the file in xarray, then converting it to a cube and then save it as grib. But this gives the error: 'TranslationError: CoordSystem not present'

cubie = ds.z.to_iris()

iris_grib.save_grib2(cubie, data_path+'test.grib2')

I have tried, making a netcdf of my data, and downloading the file in xarray and then converting it to a cube, but this gives the error ValueError: substring not found

DS = xr.Dataset({
'SIC' : xr.DataArray(
data = [ds.z.values],
dims = ['time','projection_y_coordinate','projection_x_coordinate'],
coords = {'time':times,'projection_x_coordinate':ds.x.values,'projection_y_coordinate':ds.y.values},
attrs = { 'units':'%','author':ds.author,'GMT_version':ds.GMT_version,\
         'history':ds.history,'info':ds.info,'title':ds.title,'GDAL':ds.GDAL}),})

DS.SIC.to_iris()

I then tried to just add the time coordinate to my original cube:


Time= iris.coords.DimCoord(times, long_name='time')
cubes.add_dim_coord(Time, 0) 

but this does not work because: CannotAddError: A dim_coord is already associated with dimension 1. so I tried with dim = 0, and dim = 2, but that does not work because CannotAddError: The cube does not have the specified dimension (2)

I feel I have run out of options and would love to have your help!

you can freely download the data: Remote sensing Antarctica Bremen

0

There are 0 answers