openghg / openghg_inversions

University of Bristol Atmospheric Chemistry Research Group RHIME Inversion code (with openghg dependency)
MIT License
5 stars 0 forks source link

`get_country_object` causes tests to fail with latest version of dependencies #46

Closed brendan-m-murphy closed 8 months ago

brendan-m-murphy commented 8 months ago

I'm not sure which dependency update is causing this error, but test_full_inversion, which previously worked, now fails with this error:

      def __init__(self, domain, country_file=None):

            if country_file is None:
                if not os.path.exists(os.path.join(openghginv_path, 'countries/')):
                    os.makedirs(os.path.join(openghginv_path, 'countries/'))
                    raise FileNotFoundError ("Country definition file not found."
                                             f" Please add to {openghginv_path}/countries/")
                else:
                    country_directory = os.path.join(openghginv_path, 'countries/')

                filename=glob.glob(os.path.join(country_directory, f"country_{domain}.nc"))
                f = xr.open_dataset(filename[0])
            else:
                filename = country_file
                f = xr.open_dataset(filename)

            lon = f.variables['lon'][:].values
            lat = f.variables['lat'][:].values

            #Get country indices and names
            if "country" in f.variables:
                country = f.variables['country'][:, :]
            elif "region" in f.variables:
                country = f.variables['region'][:, :]

    #         if (ukmo is True) or (uk_split is True):
    #             name_temp = f.variables['name'][:]
    #             f.close()
    #             name=np.asarray(name_temp)

    #         else:
            name_temp = f.variables['name'].values
            f.close()

            name_temp = np.ma.filled(name_temp,fill_value=None)

            name=[]
            for ii in range(len(name_temp)):
                if type(name_temp[ii]) is not str:
                    #name.append(''.os.path.join(name_temp[ii].decode("utf-8")))
>                   name.append(os.path.join(name_temp[ii].decode("utf-8")))
E                   AttributeError: 'numpy.str_' object has no attribute 'decode'. Did you mean: 'encode'?
brendan-m-murphy commented 8 months ago

This is already fixed in #28