Esempio n. 1
0
def test_clean():
    """Test clean task."""
    ctx = Context()
    ctx.run = MagicMock()
    assert type(clean) == Task
    clean(ctx)
    ctx.run.assert_called_once()
Esempio n. 2
0
def main():
    validate_environment()

    # Initialize the global context.
    os_family = platform.system()
    Context.set_triplet_os(os_family)
    args, cmake_args = parser.parse_args(sys.argv[1:], os_family)
    add_args_to_context(args)
    # Pass around Context instead of using the global one to facilitate testing.
    context = Context

    check_venv(args)

    # Execute the minimum amount of code possible to run self tests to minimize
    # untestable code (i.e. code that runs the self-test).
    if args.subcommand == "self-test":
        run_self_test()

    toolchain_downloader = ToolchainDownloader(os_family, args.linux_distro)
    if not toolchain_downloader.fetch_and_install():
        sys.exit(1)
    toolchain_dir = toolchain_downloader.result_dir
    compile_env = context.get_compile_environment(toolchain_dir)

    curator_downloader = CuratorDownloader(os_family, args.linux_distro)
    if not curator_downloader.fetch_and_install():
        sys.exit(1)
    curator_path = curator_downloader.result_dir

    if not args.subcommand:
        logging.info(
            "No subcommand specified; running cmake, compile and install")
        tasks.cmake(context,
                    toolchain_dir=toolchain_dir,
                    env=compile_env,
                    cmdline_cmake_args=cmake_args)
        tasks.compile_all(context, compile_env)
        tasks.install(context, compile_env)
    elif args.subcommand == "clean":
        tasks.clean(context, compile_env)
    else:
        tasks.compile_all(context, compile_env)
        if args.subcommand == "install":
            tasks.install(context, compile_env)
        elif args.subcommand == "cmake-test":
            tasks.run_tests.cmake_test(compile_env)
        elif args.subcommand == "benchmark-test":
            tasks.run_tests.benchmark_test(compile_env)
        elif args.subcommand == "resmoke-test":
            tasks.run_tests.resmoke_test(
                compile_env,
                suites=args.resmoke_suites,
                mongo_dir=args.resmoke_mongo_dir,
                is_cnats=args.resmoke_cnats,
            )
        else:
            raise ValueError("Unknown subcommand: ", args.subcommand)
Esempio n. 3
0
    def test_cleans_clone_dir_by_default(self, monkeypatch, patch_clone_dir):
        ctx = MockContext()

        def mock_rmtree(which, ignore_errors=False):
            assert str(which) == str(patch_clone_dir)

        monkeypatch.setattr(shutil, 'rmtree', mock_rmtree)
        tasks.clean(ctx)
        # clear the patch so that the temp patch_clone_dir
        # will also be properly deleted upon exit
        monkeypatch.undo()
Esempio n. 4
0
    def test_cleans_specified_dir(self, monkeypatch):
        ctx = MockContext()

        def mock_rmtree(which, ignore_errors=False):
            assert str(which) == '/whatever'

        monkeypatch.setattr(shutil, 'rmtree', mock_rmtree)
        tasks.clean(ctx, which='/whatever')

        # clear the patch so that the temp patch_clone_dir
        # will also be properly deleted upon exit
        monkeypatch.undo()
Esempio n. 5
0
def main():
    # Check Python version
    if not sys.version_info >= (3, 7):
        logging.error('Please run this script with Python 3.7 or newer')
        sys.exit(1)

    # Initialize the global context.
    os_family = platform.system()
    Context.set_triplet_os(os_family)
    args, cmake_args = parser.parse_args(sys.argv[1:], os_family)
    add_args_to_context(args)
    # Pass around Context instead of using the global one to facilitate testing.
    context = Context

    # Execute the minimum amount of code possible to run self tests to minimize
    # untestable code (i.e. code that runs the self-test).
    if args.subcommand == 'self-test':
        run_self_test()

    url = get_toolchain_url(os_family, args.linux_distro)
    toolchain_dir = fetch_and_install_toolchain(url, Context.TOOLCHAIN_ROOT)
    compile_env = context.get_compile_environment(toolchain_dir)

    if not args.subcommand:
        logging.info(
            'No subcommand specified; running cmake, compile and install')
        tasks.cmake(context,
                    toolchain_dir=toolchain_dir,
                    env=compile_env,
                    cmdline_cmake_args=cmake_args)
        tasks.compile_all(context, compile_env)
        tasks.install(context, compile_env)
    elif args.subcommand == 'clean':
        tasks.clean(context, compile_env)
    else:
        tasks.compile_all(context, compile_env)

        if args.subcommand == 'install':
            tasks.install(context, compile_env)
        elif args.subcommand == 'cmake-test':
            tasks.run_tests.cmake_test(compile_env)
        elif args.subcommand == 'benchmark-test':
            tasks.run_tests.benchmark_test(compile_env)
        elif args.subcommand == 'resmoke-test':
            tasks.run_tests.resmoke_test(compile_env,
                                         suites=args.resmoke_suites,
                                         mongo_dir=args.resmoke_mongo_dir,
                                         is_cnats=args.resmoke_cnats)
        else:
            raise ValueError('Unknown subcommand: ', args.subcommand)
        start_chan = int(center_chan - width // 2)

        imagename = "test_images/{0}.{1}.spw_{2}".format(ms_active[:-3], source, spw_num)

        # Remove old image products
        rmtables(imagename + "*")

        clean(
            vis=ms_active,
            imagename=imagename,
            field="*" + source + "*",
            spw=str(spw_num),
            mode="channel",
            niter=0,
            imagermode=imagermode,
            cell=cellsize,
            imsize=imagesize,
            start=start_chan,
            width=width,
            nchan=1,
            weighting=weighting,
            pbcor=False,
            minpb=0.1,
            phasecenter=phasecenter,
        )

        remove_products(imagename)


logprint("Finished EVLA_pipe_testimage_lines.py", logfileout="logs/testimage_lines.log")

pipeline_save()
Esempio n. 7
0
    # Check that the concatenated MS exists
    if not os.path.exists(concat_ms):
        raise IOError("Concatenated MS does not exist in the given directory.")

    if not os.path.exists(dirty_image_direc):
        os.mkdir(dirty_image_direc)

    out_image = os.path.join(dirty_image_direc,
                             line_name + "_" + project_name + "_dirty_nocontsub")

    rmtables(out_image + ".*")

    clean(vis=concat_ms, imagename=out_image, niter=0, imsize=imsize,
          cell=cell, mode=mode, nchan=nchan, width=width, start=start,
          threshold=threshold, field=field, phasecenter=phasecenter, spw=spw,
          imagermode=imagermode, multiscale=multiscale, outframe=outframe,
          veltype=veltype, minpb=0.3, weighting=weighting, robust=robust,
          restfreq=restfreq, usescratch=usescratch,
          interpolation=interpolation, pbcor=True)

if contsub:
    # Check that the concatenated MS exists
    if not os.path.exists(concat_ms):
        raise IOError("Concatenated MS does not exist in the given directory.")

    if os.path.exists(contsub_ms) and delete_old:
        rmtables(contsub_ms)

    uvcontsub(vis=concat_ms, fitspw=fitspw, excludechans=excludechans,
              fitorder=0, want_cont=False)
        cellsize = set_cellsize(ms_active, spw_num, sample_factor=6.)
        imagesize = set_imagesize(ms_active, spw_num, source, sample_factor=6.,
                                  pblevel=minpb, max_size=max_size)

        if imagermode == "mosaic":
            # XXX Set this to centre of M33 for now.
            phasecenter = 'J2000 01h33m50.904 +30d39m35.79'
        else:
            phasecenter = ''

        imagename = \
            'test_images/{0}.{1}.spw_{2}'.format(ms_active[:-3],
                                                 source,
                                                 spw_num)
        # Remove old image products
        rmtables(imagename + "*")

        clean(vis=ms_active,
              imagename=imagename,
              field= '*' + source + '*', spw=str(spw_num), mode='mfs', niter=0,
              imagermode=imagermode, cell=cellsize, imsize=imagesize,
              weighting=weighting, pbcor=False, minpb=0.1,
              phasecenter=phasecenter)

        remove_products(imagename)

logprint("Finished EVLA_pipe_testimage_cont.py",
         logfileout='logs/testimage_cont.log')

pipeline_save()
    stats_dict = ia.statistics()
    ia.close()
    # If there's nothing there, max == min
    max_val = stats_dict["max"]
    if max_val == 0:
        casalog.post("No valid region in the given mask. Skipping clean.")
        valid_mask = False
    else:
        casalog.post("Mask contains valid region. Proceeding with clean.")

if valid_mask:
    clean(vis=vis, imagename=out_root + '.clean', field='M33*',
          restfreq='1420.40575177MHz',
          mode='channel', width=1, nchan=1, start=1,
          cell='1.5arcsec', multiscale=[0, 4, 8, 20, 40, 80],
          threshold='2.2mJy/beam', imagermode='mosaic', gain=0.1,
          imsize=[4096, 4096], weighting='natural', robust=0.0, niter=200000,
          pbcor=True, minpb=0.2, interpolation='linear', usescratch=False,
          phasecenter='J2000 01h33m50.904 +30d39m35.79', veltype='radio',
          modelimage=model, mask=mask)

    # Only run if the image was actually produces
    if os.path.exists(out_root + ".clean.image") and model is not None:
        feather(imagename=out_root + ".clean.image.feathered",
                highres=out_root + ".clean.image",
                lowres=model)

    # If something went awry, and the image wasn't produced, remove the
    # remnants.
    if not os.path.exists(out_root + ".clean.image"):
        rmtables(out_root + ".clean.*")
Esempio n. 10
0
    def testCleanup(self):
        RandomNumberProfile.objects.create(range_start=10, range_end=25, create_date=timezone.now()-datetime.timedelta(days=2))
        clean()

        self.assertEquals(RandomNumberProfile.objects.all().count(), 0)