import glob
from netCDF4 import Dataset
import numpy as np
import os

ghost_version = 1.5
root_dir = '/gpfs/projects/bsc32/AC_cache/obs/ghost'

native_networks = []

for subdir, dirs, files in os.walk('{}/{}/{}/'.format(root_dir,'EBAS',ghost_version)):
    for f in sorted(files):
        print(f)
        obs_file = os.path.join(subdir, f)

        ext = obs_file[-3:]
        if ext != '.nc':
            continue

        root = Dataset(obs_file)
        assoc_nets = root['associated_networks'][:]
        for assoc_net in assoc_nets:
            native_networks.extend(assoc_net.split(':')[0].split(' '))
        root.close()   
 
print()
print(np.unique(native_networks))