remove imports from function body; make wiser try/except in Nansat.write_figure