"""Make a dummy level2b attr-only dataset. For every actual level2b file, dump all global attrs out to the same filename in a different location. This will give us smaller files that we can carry around anywhere (i.e., don't need fjord access) for testing this code. """ def make_attr_only_dataset(in_path, out_path): """Actually do the work here. Input: in_path: location of actual level2b files to steal attrs from. out_path: place we'll write the dummy level2b's to. """ from level2b_utils import find_all_level2b_files, parse_filename from netCDF4 import Dataset from os.path import basename, exists import os in_files = find_all_level2b_files(in_path) for in_file in in_files: # split into dirs by sat to keep dir listing from getting ridiculous parsed = parse_filename(in_file) full_out_path = out_path+parsed['satname']+'/' if not exists(full_out_path): os.makedirs(full_out_path) out_file = full_out_path+basename(in_file) print 'writing file: %s' % basename(out_file) in_rootgrp = Dataset(in_file, 'r', format='NETCDF4') out_rootgrp = Dataset(out_file, 'w', format='NETCDF4') # not sure why we can't just do out_rootgrp.__dict__.update here :( for key in in_rootgrp.ncattrs(): setattr(out_rootgrp, key, getattr(in_rootgrp, key)) in_rootgrp.close() out_rootgrp.close() if __name__ == "__main__": """Start cranking away.""" in_path = '/Users/mhiley/data/avhrr/Satellite_Output/' out_path = '/Users/mhiley/temp/' make_attr_only_dataset(in_path, out_path)