def easy_analyse(fitspath, save=False, savepath='./'):
    import analyse
    print('make_cube: %s'%(fitspath.split('/')[-1]))
    raw_data = analyse.loadfits(fitspath)
    cw_data = analyse.makespec(raw_data)
    fitted_data, flag = analyse.basefit(cw_data)
    convolved_data = analyse.convolve(fitted_data, 2)
    fitted_data, flag = analyse.basefit(convolved_data, 'auto')

    savepath = savepath + fitspath.split('.fits')[0]
    if save:
        analyse.savefits(fitted_data, savepath+'.qlook.data.fits', clobber=True)
        analyse.savefits(flag, savepath+'.qlook.flag.fits', clobber=True)
        pass

    raw_data.data = None
    cw_data.data = None
    del(raw_data)
    del(cw_data)
    return fitted_data
def easy_analyse(fitspath, output_dir, flag=None, plot=False, save=False):
    import analyse
    print('make_cube: %s'%(fitspath.split('/')[-1]))
    raw_data = analyse.loadfits(fitspath)
    cw_data = analyse.makespec(raw_data)

    if flag is None:
        fitted_data, flag = analyse.basefit(cw_data)
    else:
        flag = analyse.loadfits(flag)
        fitted_data = analyse.basefit_flag(cw_data, None, flag)
        pass
    convolved_data = analyse.convolve(fitted_data, 2)
    fitted_data = analyse.basefit_flag(convolved_data, None, flag)

    ii = analyse.make_2d_map(fitted_data, flag)
    rms = analyse.make_2d_map(fitted_data, flag, 'rms')

    if save:
        savepath = output_dir + fitspath.split('/')[-1].split('.fits')[0]
        analyse.savefits(fitted_data, savepath+'.qlook.data.fits', clobber=True)
        analyse.savefits(flag, savepath+'.qlook.flag.fits', clobber=True)
        analyse.savefits(ii, savepath+'.qlook.ii.fits', clobber=True)
        analyse.savefits(rms, savepath+'.qlook.rms.fits', clobber=True)
        pass

    if plot:
        savepath = output_dir + fitspath.split('/')[-1].split('.fits')[0]
        isotope = fitspath.split('_')[-2]
        plot = analyse.custom_draw_map(figure=(8,8), xspacing=0.2, yspacing=0.2,
                                       tick_labels_size=12, colorber_font_size=11, show=False)
        plot(ii, title='mom0: '+isotope).save(savepath+'.qlook.ii.png')
        plot(rms, title='rms: '+isotope).save(savepath+'.qlook.rms.png')
        analyse.draw_otf_spectrum(fitted_data, figure=(12,5), title='spectra: '+isotope,
                                  show=False).savefig(savepath+'.qlook.spectrum.png')
        pass

    raw_data.data = None
    cw_data.data = None
    return fitted_data, flag