def main():
    import argparse
    parser = argparse.ArgumentParser(description=__doc__, prog=os.path.basename(sys.argv[0]))
    # parser.add_argument('module', metavar='MODULE', type=str,
    #                     help='The name of the module to download.')
    parser.add_argument('-o','--overwrite',action='store_true',dest='overwrite',
                        help="Overwrite the existing file with a new download.")
    # parser.add_argument('-v','--verbose',action='store_true',dest='verbose',
    #                     help='Print lots of extra output.')
    args = parser.parse_args()

    simname = sim_defaults.default_simname
    halo_finder = sim_defaults.default_halo_finder
    redshift = sim_defaults.default_redshift

    catman = CatalogManager()

    catman.download_processed_halo_table(simname = simname, 
        halo_finder = halo_finder, desired_redshift = redshift, 
        initial_download_script_msg = existing_fname_error_msg, overwrite=args.overwrite)
    catman.download_ptcl_table(simname = simname, 
        desired_redshift = redshift, dz_tol = 0.05, overwrite=args.overwrite)

    msg = ("\n\nYour Halotools cache directory now has two hdf5 files, \n"
        "one storing a z = %.2f %s halo catalog for the %s simulation, \n"
        "another storing a random downsampling of ~1e6 dark matter particles from the same snapshot.\n"
        "\nHalotools can load these catalogs into memory with the following syntax:\n\n"
        ">>> from halotools.sim_manager import HaloCatalog\n"
        ">>> bolshoi_z0 = HaloCatalog()\n"
        ">>> halos = bolshoi_z0.halo_table\n"
        ">>> particles = bolshoi_z0.ptcl_table\n\n")

    print(msg % (abs(redshift), halo_finder, simname))
def main(flags):
    """ args is a python list. Element 0 is the name of the module. 
    The remaining elements are the command-line arguments as strings. 
    """

    simname = sim_defaults.default_simname
    halo_finder = sim_defaults.default_halo_finder
    redshift = sim_defaults.default_redshift

    catman = CatalogManager()

    if len(flags) == 1:
        catman.download_processed_halo_table(simname = simname, 
            halo_finder = halo_finder, desired_redshift = redshift, 
            initial_download_script_msg = existing_fname_error_msg)
        catman.download_ptcl_table(simname = simname, 
            desired_redshift = redshift, dz_tol = 0.05)

    elif (len(flags) == 2) & (flags[1] == '-overwrite'):
        catman.download_processed_halo_table(simname = simname, 
            halo_finder = halo_finder, desired_redshift = redshift, 
            initial_download_script_msg = existing_fname_error_msg, 
            overwrite = True)
        catman.download_ptcl_table(simname = simname, 
            desired_redshift = redshift, dz_tol = 0.05, overwrite=True)
    else:
        raise HalotoolsError(command_line_arg_error_msg)

    msg = ("\n\nYour Halotools cache directory now has two hdf5 files, \n"
        "one storing a z = %.2f %s halo catalog for the %s simulation, \n"
        "another storing a random downsampling of ~1e6 dark matter particles from the same snapshot.\n"
        "\nHalotools can load these catalogs into memory with the following syntax:\n\n"
        ">>> from halotools.sim_manager import HaloCatalog\n"
        ">>> bolshoi_z0 = HaloCatalog()\n"
        ">>> halos = bolshoi_z0.halo_table\n"
        ">>> particles = bolshoi_z0.ptcl_table\n\n")

    print(msg % (abs(redshift), halo_finder, simname))
def main(command_line_args):
    import argparse
    parser = argparse.ArgumentParser(description=__doc__, prog=os.path.basename(sys.argv[0]))
    allowed_simname = ('bolshoi','bolplanck','multidark','consuelo')
    allowed_redshift = (0,0.5,1,2)
    allowed_halofinder = ('bdm','rockstar')
    parser.add_argument('simname', metavar='SIMNAME', type=str,
                        choices=allowed_simname,
                        help='The name of the simulation to download, allowed values: {}.'.format(allowed_simname))
    parser.add_argument('redshift', metavar='REDSHIFT', type=float,
                        choices=allowed_redshift,
                        help='The redshift of the simulation snapshot to download, allowed values: {}.'.format(allowed_redshift))
    parser.add_argument('halo_finder', metavar='HALO_FINDER', type=str, nargs='?',
                        choices=allowed_halofinder, default=None,
                        help='The name of the halo-finder to download , allowed values: {} (ignored with --particlesonly).'.format(allowed_halofinder))

    group = parser.add_mutually_exclusive_group()
    group.add_argument('--particlesonly',action='store_true',dest='particlesonly',
                        help="Only download the dark matter particles (overrides HALO_FINDER, conflicts with --halosonly).")
    group.add_argument('--halosonly',action='store_true',dest='halosonly',
                        help="Do not download the random downsamling of dark matter particles with the halo (conflicts with --particlesonly).")

    parser.add_argument('-o','--overwrite',action='store_true',dest='overwrite',
                        help="Overwrite the existing files in your cache directory.")
    # parser.add_argument('-v','--verbose',action='store_true',dest='verbose',
    #                     help='Print lots of extra output.')
    args = parser.parse_args()

    catman = CatalogManager()

    if args.halo_finder is None and not args.particlesonly:
        raise parser.error('You must specify either HALO_FINDER or --particlesonly.')
    if args.halo_finder and args.particlesonly:
        print("Ignoring halo_finder={}, and only downloading particles.".format(args.halo_finder))
        args.halo_finder = None

    msg = ("\nYour Halotools cache directory now has {number} hdf5 file(s),\n"
           "storing {fileinfo} for the {args.simname} simulation.\n"
           "The data structure stored by these hdf5 files is an Astropy Table.\n"
           "\nHalotools can load these catalogs into memory with the following syntax:\n\n"
           ">>> from halotools.sim_manager import HaloCatalog\n"
           ">>> halocat = HaloCatalog(simname='{args.simname}', redshift={args.redshift}{halo_arg})\n"
           "{python_example}\n")

    halo_str = "a z={args.redshift:0.2f} {args.halo_finder} halo catalog".format(args=args)
    particle_str = "a random downsampling of ~1e6 dark matter particles"
    halo_arg = ", halo_finder='{args.halo_finder}'".format(args=args)
    halos_example = ">>> halos = halocat.halo_table\n"
    particles_example = ">>> particles = halocat.ptcl_table\n"
    if args.halosonly:
        python_example = halos_example
        fileinfo = halo_str
        number = 1
    elif args.particlesonly:
        python_example = particles_example
        fileinfo = particle_str
        halo_arg = ""
        number = 1
    else:
        'for the {args.simname} simulation'
        python_example = halos_example + particles_example
        fileinfo = ' and '.join((halo_str,particle_str))
        number = 2

    msg = msg.format(args=args,python_example=python_example,fileinfo=fileinfo,halo_arg=halo_arg,number=number)

    if not args.particlesonly:
        catman.download_processed_halo_table(simname = args.simname,
            halo_finder = args.halo_finder, desired_redshift = args.redshift,
            initial_download_script_msg = existing_fname_error_msg,
            overwrite = args.overwrite, success_msg = msg)
    if not args.halosonly:
        catman.download_ptcl_table(simname = args.simname, 
            desired_redshift = args.redshift, dz_tol = 0.05, success_msg = msg, 
            initial_download_script_msg = existing_fname_error_msg, overwrite=args.overwrite)
def main(command_line_args):
    """ args is a python list. Element 0 is the name of the module. 
    The remaining elements are the command-line arguments as strings. 
    """

    args = [arg for arg in command_line_args if (arg[0] != '-') & (arg != 'scripts/download_alternate_halocats.py')]
    opts = [opt for opt in command_line_args if opt[0]=='-']

    if '-help' in opts:
        print(command_line_arg_error_msg)
        return 

    if '-ptclsonly' in opts:
        # for a in args:
        #     print a
        if len(args) != 2:
            msg = ("\n\nHalotoolsError: \nWhen throwing the -ptclsonly flag during a call to the "
            "download_alternate_halocat.py script, \nyou must specify a simname and redshift, "
            "and only those two quantities.\n"
            "In particular, be sure you did not also specify a halo-finder, which is unnecessary" 
            "if you only want particle data.\n"
            "Now printing the -help message for further details.\n")
            print(msg)
            print(command_line_arg_error_msg)
            return 
        else:
            try:
                simname = str(args[0])
                redshift = float(args[1])
            except ValueError:
                msg = ("\n\nHalotoolsError: \nWhen throwing the -ptclsonly flag during a call to the "
                "download_alternate_halocat.py script, \nyou must specify a simname and redshift, "
                "and only those two quantities.\n"
                "In particular, the redshift you supplied via your second command-line argument " 
                "does not appear to be convertible to a float.\n"
                "Now printing the -help message for further details.\n")
                print(msg)
                print(command_line_arg_error_msg)
                return 
            simname = str(args[0])
            redshift = float(args[1])
    else:
        msg = ("\n\nHalotoolsError: \nWhen running the "
        "download_alternate_halocat.py script, \n"
        "you must specify a simname, redshift, and halo-finder, and only those three quantities.\n"
        "Now printing the -help message for further details.\n")
        if len(args) != 3:
            print(msg)   
            print(command_line_arg_error_msg)         
            return 
        else:
            try:
                simname = str(args[0])
                redshift = float(args[1])
                halo_finder = str(args[2])
            except ValueError:
                msg = ("\n\nHalotoolsError: \nWhen running the "
                "download_alternate_halocat.py script, you must specify a simname, redshift, and halo-finder.\n"
                "Now printing the -help message for further details.\n")
                print(msg)
                print(command_line_arg_error_msg)
                return 


    if '-overwrite' in opts:
        overwrite = True
    else:
        overwrite = False

    catman = CatalogManager()

    if '-halosonly' in opts:
        msg = ("\n\nYour Halotools cache directory a new hdf5 file \n"
            "storing a z = %.2f %s halo catalog for the %s simulation. \n"
            "The data structure stored by this hdf5 file is an Astropy Table.\n"
            "\nHalotools can load this catalog into memory with the following syntax:\n\n"
            ">>> from halotools.sim_manager import HaloCatalog\n"
            ">>> halocat = HaloCatalog(simname = your_chosen_simname, redshift = your_chosen_redshift, halo_finder = your_chosen_halo_finder)\n"
            ">>> halos = halocat.halo_table\n" % (abs(redshift), halo_finder, simname))
        catman.download_processed_halo_table(simname = simname, 
            halo_finder = halo_finder, desired_redshift = redshift, 
            initial_download_script_msg = existing_fname_error_msg, 
            overwrite = overwrite, success_msg = msg)
    elif '-ptclsonly' in opts:
        msg = ("\n\nYour Halotools cache directory a new hdf5 file \n"
            "storing a z = %.2f particle catalog for the %s simulation. \n"
            "The data structure stored by this hdf5 file is an Astropy Table.\n"
            "\nHalotools can load this catalog into memory with the following syntax:\n\n"
            ">>> from halotools.sim_manager import HaloCatalog\n"
            ">>> halocat = HaloCatalog(simname = your_chosen_simname, redshift = your_chosen_redshift)\n"
            ">>> particles = halocat.ptcl_table\n" % (abs(redshift), simname))
        catman.download_ptcl_table(simname = simname, 
            desired_redshift = redshift, dz_tol = 0.05, success_msg = msg, 
            initial_download_script_msg = existing_fname_error_msg, overwrite=overwrite)
    else:
        msg = ("\n\nYour Halotools cache directory now has two hdf5 files, \n"
            "one storing a z = %.2f %s halo catalog for the %s simulation, \n"
            "another storing a random downsampling of ~1e6 dark matter particles from the same snapshot.\n"
            "The data structure stored by these hdf5 files is an Astropy Table.\n"
            "\nHalotools can load these catalogs into memory with the following syntax:\n\n"
            ">>> from halotools.sim_manager import HaloCatalog\n"
            ">>> halocat = HaloCatalog(simname = your_chosen_simname, redshift = your_chosen_redshift, halo_finder = your_chosen_halo_finder)\n"
            ">>> halos = halocat.halo_table\n"
            ">>> particles = halocat.ptcl_table\n\n" % (abs(redshift), halo_finder, simname))
        catman.download_processed_halo_table(simname = simname, 
            halo_finder = halo_finder, desired_redshift = redshift, 
            initial_download_script_msg = existing_fname_error_msg, 
            overwrite = overwrite)
        catman.download_ptcl_table(simname = simname, 
            desired_redshift = redshift, dz_tol = 0.05, 
            success_msg = msg, initial_download_script_msg = existing_fname_error_msg, 
            overwrite=overwrite)