Exemple #1
0
def get_args(path):
    '''
    Parse command line args & override defaults.

    Arguments:
        - path (str) Absolute filepath

    Returns:
        - (tuple) Name, email, license, project, ext, year
    '''

    defaults = get_defaults(path)
    licenses = ', '.join(os.listdir(cwd + licenses_loc))
    p = parser(description='tool for adding open source licenses to your projects. available licenses: %s' % licenses)

    _name = False if defaults.get('name') else True
    _email = False if defaults.get('email') else True
    _license = False if defaults.get('license') else True

    p.add_argument('-n', dest='name', required=_name, help='name')
    p.add_argument('-e', dest='email', required=_email, help='email')
    p.add_argument('-l', dest='license', required=_license, help='license')
    p.add_argument('-p', dest='project', required=False, help='project')
    p.add_argument('--txt', action='store_true', required=False, help='add .txt to filename')

    args = p.parse_args()

    name = args.name if args.name else defaults.get('name')
    email = args.email if args.email else defaults.get('email')
    license = get_license(args.license, licenses_loc=licenses_loc) if args.license else defaults.get('license')
    project = args.project if args.project else os.getcwd().split('/')[-1]
    ext = '.txt' if args.txt else ''
    year = str(date.today().year)

    return (name, email, license, project, ext, year)
Exemple #2
0
def init():
  global M_dm, M_disk, M_bulge, M_gas
  global N_dm, N_disk, N_bulge, N_gas
  global a_dm, a_bulge, Rd, z0
  global N_CORES, output
  global N_temp, N_range
  flags = parser(description="Description.")
  flags.add_argument('-o', help='The name of the output file.',
                     metavar="init.dat", default="init.dat")
  flags.add_argument('-cores', help='The number of cores to use.',
                     default=1)

  args = flags.parse_args()
  output = args.o
  N_CORES = int(args.cores)

  if not (path.isfile("header.txt") and path.isfile("galaxy_param.txt")):
    print "header.txt or galaxy_param.txt missing."
    exit(0)

  vars_ = process_input("galaxy_param.txt")
  M_dm, M_disk, M_bulge, M_gas = (float(i[0]) for i in vars_[0:4])
  N_dm, N_disk, N_bulge, N_gas = (int(i[0]) for i in vars_[4:8])
  a_dm, a_bulge, Rd, z0 = (float(i[0]) for i in vars_[8:12])
  N_temp = {'gas': int(1e4), 'dm': int(5e4), 'disk': int(2e4), 'bulge': int(2e4)}
  N_range = {'gas': np.linspace(N_temp['gas'], N_gas, 20), 
             'dm': np.linspace(N_temp['dm'], N_dm, 20), 
             'disk': np.linspace(N_temp['disk'], N_disk, 20), 
             'bulge': np.linspace(N_temp['bulge'], N_bulge, 20)}
Exemple #3
0
def add_license():
    p = parser(description='quickly add an open-source license to your project')
    
    p.add_argument('-l', dest='license', required=True, help='license to add')
    p.add_argument('-e', dest='email', required=True, help='your email address')
    p.add_argument('-n', dest='name', required=True, help='your name')
    p.add_argument('-p', dest='project', required=True, help='project name')
    
    args = p.parse_args()
    
    author = args.name + ' <' + args.email + '>'
    year = str(date.today().year)
    project = args.project
    
    try:
        license = licenses[args.license]
    except KeyError:
        p.exit(1, 'fatal: license %s does not exist\n' % args.license)
    
    license = re.sub(r'\[[author]+\]', author, license)
    license = re.sub(r'\[[year]+\]', year, license)
    license = re.sub(r'\[[project]+\]', project, license)
    
    with open('LICENSE.txt', 'w') as f:
        f.write(license)
Exemple #4
0
def init():
  global M_halo, M_disk, M_bulge, M_gas
  global N_halo, N_disk, N_bulge, N_gas
  global a_halo, a_bulge, Rd, z0, z0_gas
  global N_total, M_total
  global phi_grid, rho_axis, z_axis, N_rho, Nz
  global halo_core, bulge_core, N_CORES, force_yes, output, gas, factor, Z
  flags = parser(description="Generates an initial conditions file for a\
                              galaxy simulation with halo, stellar disk,\
                              gaseous disk and bulge components.")
  flags.add_argument('--nogas', help='Generates a galaxy without gas.',
                     action='store_true')
  flags.add_argument('-cores', help='The number of cores to use during the\
                                     potential canculation. Make sure this\
                                     number is a factor of N_rho*N_z.',
                     default=1)
  flags.add_argument('--force-yes', help='Don\'t ask if you want to use the\
                                          existing potential_data.txt file.\
                                          Useful for automating the execution\
                                          of the script.', action='store_true')
  flags.add_argument('-o', help='The name of the output file.',
                     metavar="init.dat", default="init.dat")
  args = flags.parse_args()
  gas = not args.nogas
  N_CORES = int(args.cores)
  force_yes = args.force_yes
  output = args.o

  if not (path.isfile("header.txt") and path.isfile("params_galaxy.txt")):
    print "header.txt or params_galaxy.txt missing."
    exit(0)

  vars_ = process_input("params_galaxy.txt")
  M_halo, M_disk, M_bulge, M_gas = (float(i[0]) for i in vars_[0:4])
  N_halo, N_disk, N_bulge, N_gas = (float(i[0]) for i in vars_[4:8])
  a_halo, a_bulge, Rd, z0, z0_gas = (float(i[0]) for i in vars_[8:13])
  halo_core, bulge_core = (i[0][:-1] == 'True' for i in vars_[13:15])
  factor = float(vars_[15][0])
  Z = float(vars_[16][0])

  z0_gas *= z0
  if not gas:
    N_gas = 0
    M_gas = 0
  M_total = M_disk + M_bulge + M_halo + M_gas
  N_total = N_disk + N_bulge + N_halo + N_gas
  N_rho = Nz = 256 # Make sure N_CORES is a factor of N_rho*Nz.
  phi_grid = np.zeros((N_rho, Nz))
  rho_max = 300 * a_halo
  # This has to go far so I can estimate the integrals below.
  z_max = 3000 * a_halo 
  rho_axis = np.logspace(-2, log10(rho_max), N_rho)
  z_axis = np.logspace(-2, log10(z_max), Nz)
Exemple #5
0
def init():
    global dm_core, gas_core
    flags = parser(description="Plots stuff.")
    flags.add_argument('--dm-core', help='Sets the density profile for the\
                       dark matter to have a core.', action='store_true')
    flags.add_argument('--gas-core', help='The same, but for the bulge.',
                       action='store_true')
    flags.add_argument('i', help='The name of the input file.',
                       metavar="file.dat")
    args = flags.parse_args()
    dm_core = args.dm_core
    gas_core = args.gas_core
    input_ = args.i
    return input_
Exemple #6
0
def init():
    global gas, dm, output
    global M_dm, a_dm, N_dm, M_gas, a_gas, N_gas, Z
    global truncation_radius, gamma_gas, gamma_dm
    flags = parser(description="Generates an initial conditions file\
                for a galaxy cluster halo simulation.")
    flags.add_argument('--no-dm',
                       help='No dark matter particles in the\
           initial conditions. The dark matter potential is\
           still used when calculating the gas temperatures.',
                       action='store_true')
    flags.add_argument('--no-gas',
                       help='Gas is completely ignored, and\
           only dark matter is included.',
                       action='store_true')
    flags.add_argument('-o',
                       help='The name of the output file.',
                       metavar="init.dat",
                       default="init.dat")
    args = flags.parse_args()
    output = args.o
    if not path.isfile("params_cluster.ini"):
        print "params_cluster.ini missing."
        exit(0)
    if args.no_dm:
        if args.no_gas:
            print "Neither gas or dark matter were selected!"
            exit(0)
        else:
            gas = True
            dm = False
    elif args.no_gas:
        gas = False
        dm = True
    else:
        gas = True
        dm = True
    config = ConfigParser()
    config.read("params_cluster.ini")
    M_dm = config.getfloat('dark_matter', 'M_dm')
    a_dm = config.getfloat('dark_matter', 'a_dm')
    N_dm = config.getint('dark_matter', 'N_dm')
    gamma_dm = config.getfloat('dark_matter', 'gamma_dm')
    if (gas):
        M_gas = config.getfloat('gas', 'M_gas')
        a_gas = config.getfloat('gas', 'a_gas')
        N_gas = config.getint('gas', 'N_gas')
        Z = config.getfloat('gas', 'Z')
        gamma_gas = config.getfloat('gas', 'gamma_gas')
    truncation_radius = config.getfloat('global', 'truncation_radius')
Exemple #7
0
def init():
  global gas, dm, output
  global M_dm, a_dm, N_dm, M_gas, a_gas, N_gas, Z
  global truncation_radius, gamma_gas, gamma_dm
  flags = parser(description="Generates an initial conditions file\
                for a galaxy cluster halo simulation.")
  flags.add_argument('--no-dm', help='No dark matter particles in the\
           initial conditions. The dark matter potential is\
           still used when calculating the gas temperatures.',
           action='store_true')
  flags.add_argument('--no-gas', help='Gas is completely ignored, and\
           only dark matter is included.',
           action='store_true')
  flags.add_argument('-o', help='The name of the output file.',
           metavar="init.dat", default="init.dat")
  args = flags.parse_args()
  output = args.o
  if not path.isfile("params_cluster.ini"):
    print "params_cluster.ini missing."
    exit(0)
  if args.no_dm:
    if args.no_gas:
      print "Neither gas or dark matter were selected!"
      exit(0)
    else:
      gas = True
      dm = False
  elif args.no_gas:
    gas = False
    dm = True
  else:
    gas = True
    dm = True
  config = ConfigParser()
  config.read("params_cluster.ini")
  M_dm = config.getfloat('dark_matter', 'M_dm')
  a_dm = config.getfloat('dark_matter', 'a_dm')
  N_dm = config.getint('dark_matter', 'N_dm')
  gamma_dm = config.getfloat('dark_matter', 'gamma_dm')
  if(gas):
    M_gas = config.getfloat('gas', 'M_gas')
    a_gas = config.getfloat('gas', 'a_gas')
    N_gas = config.getint('gas', 'N_gas')
    Z = config.getfloat('gas', 'Z')
    gamma_gas = config.getfloat('gas', 'gamma_gas')
  truncation_radius = config.getfloat('global', 'truncation_radius')
Exemple #8
0
def init():
    global dm_core, gas_core
    flags = parser(description="Plots stuff.")
    flags.add_argument('--dm-core',
                       help='Sets the density profile for the\
                       dark matter to have a core.',
                       action='store_true')
    flags.add_argument('--gas-core',
                       help='The same, but for the bulge.',
                       action='store_true')
    flags.add_argument('i',
                       help='The name of the input file.',
                       metavar="file.dat")
    args = flags.parse_args()
    dm_core = args.dm_core
    gas_core = args.gas_core
    input_ = args.i
    return input_
Exemple #9
0
def init():
    global gas, dm, gas_core, dm_core, output
    global M_dm, a_dm, N_dm, M_gas, a_gas, N_gas
    global max_radius
    flags = parser(description="Generates an initial conditions file\
                                for a galaxy cluster halo simulation.")
    flags.add_argument('--gas-core', help='Sets the density profile for the\
                       gas to have a core.', action='store_true')
    flags.add_argument('--dm-core', help='The same, but for the dark matter.',
                       action='store_true')
    flags.add_argument('--no-dm', help='No dark matter particles in the\
                       initial conditions. The dark matter potential is\
                       still used when calculating the gas temperatures.',
                       action='store_true')
    flags.add_argument('--no-gas', help='No gas, only dark matter.',
                       action='store_true')
    flags.add_argument('-o', help='The name of the output file.',
                       metavar="init.dat", default="init.dat")
    args = flags.parse_args()
    gas_core = args.gas_core
    dm_core = args.dm_core
    output = args.o
    if not (path.isfile("header.txt") and path.isfile("params_cluster.txt")):
        print "header.txt or params_cluster.txt missing."
        exit(0)
    if args.no_dm:
        if args.no_gas:
            print "Neither gas or dark matter were selected!"
            exit(0)
        else:
            gas = True
            dm = False
    elif args.no_gas:
        gas = False
        dm = True
    else:
        gas = True
        dm = True
    vars_ = process_input("params_cluster.txt")
    M_dm, a_dm, N_dm = (float(i[0]) for i in vars_[0:3])
    if(gas):
        M_gas, a_gas, N_gas = (float(i[0]) for i in vars_[3:6])
    max_radius = float(vars_[6][0])
Exemple #10
0
def init():
    global M_dm, M_disk, M_bulge, M_gas
    global N_dm, N_disk, N_bulge, N_gas
    global a_dm, a_bulge, Rd, z0
    global N_CORES, output
    global N_temp, N_range
    flags = parser(description="Description.")
    flags.add_argument('-o',
                       help='The name of the output file.',
                       metavar="init.dat",
                       default="init.dat")
    flags.add_argument('-cores', help='The number of cores to use.', default=1)

    args = flags.parse_args()
    output = args.o
    N_CORES = int(args.cores)

    if not (path.isfile("header.txt") and path.isfile("galaxy_param.txt")):
        print "header.txt or galaxy_param.txt missing."
        exit(0)

    vars_ = process_input("galaxy_param.txt")
    M_dm, M_disk, M_bulge, M_gas = (float(i[0]) for i in vars_[0:4])
    N_dm, N_disk, N_bulge, N_gas = (int(i[0]) for i in vars_[4:8])
    a_dm, a_bulge, Rd, z0 = (float(i[0]) for i in vars_[8:12])
    N_temp = {
        'gas': int(1e4),
        'dm': int(5e4),
        'disk': int(2e4),
        'bulge': int(2e4)
    }
    N_range = {
        'gas': np.linspace(N_temp['gas'], N_gas, 20),
        'dm': np.linspace(N_temp['dm'], N_dm, 20),
        'disk': np.linspace(N_temp['disk'], N_disk, 20),
        'bulge': np.linspace(N_temp['bulge'], N_bulge, 20)
    }
Exemple #11
0
def add_license():
    p = parser(description='quickly add an open-source license to your project')

    p.add_argument('-l', dest='license', required=True, help='license to add')
    p.add_argument('-e', dest='email', required=True, help='your email address')
    p.add_argument('-n', dest='name', required=True, help='your name')
    p.add_argument('-p', dest='project', required=True, help='project name')
    p.add_argument('--no', action='store_true', required=False, help='removes file extension')

    args = p.parse_args()

    author = args.name + ' <' + args.email + '>'
    year = str(date.today().year)
    project = args.project
    ext = '' if args.no else '.txt'

    try:
        license = open(os.path.join(os.path.abspath("./Licenses/"),args.license)).read()
    except KeyError:
        p.exit(1, 'fatal: license %s does not exist\n' % args.license)

    license = license.format(author=author, year=year, project=project)
    with open('LICENSE' + ext, 'w') as f:
        f.write(license)
Exemple #12
0
def get_args(path):
    '''
    Parse command line args & override defaults.

    Arguments:
        - path (str) Absolute filepath

    Returns:
        - (tuple) Name, email, license, project, ext, year
    '''

    defaults = get_defaults(path)
    licenses = ', '.join(os.listdir(cwd + licenses_loc))
    p = parser(description='tool for adding open source licenses to your projects. available licenses: %s' % licenses)

    _name = False if defaults.get('name') else True
    _email = False if defaults.get('email') else True
    _license = False if defaults.get('license') else True

    p.add_argument('-n', dest='name', required=_name, help='name')
    p.add_argument('-e', dest='email', required=_email, help='email')
    p.add_argument('-l', dest='license', required=_license, help='license')
    p.add_argument('-p', dest='project', required=False, help='project')
    p.add_argument('-v', '--version', action='version', version='%(prog)s {version}'.format(version=version))
    p.add_argument('--txt', action='store_true', required=False, help='add .txt to filename')

    args = p.parse_args()

    name = args.name if args.name else defaults.get('name')
    email = args.email if args.email else defaults.get('email')
    license = get_license(args.license) if args.license else defaults.get('license')
    project = args.project if args.project else os.getcwd().split('/')[-1]
    ext = '.txt' if args.txt else ''
    year = str(date.today().year)

    return (name, email, license, project, ext, year)
Exemple #13
0
sys.path.append('/home/beams/CCHUANG/codezoo/python/img_util/')
import img_util as imu
import tomopy
import dxchange.reader as dxreader
import dxchange.writer as dxwriter
import numpy as np
import time
import os
import cv2
from argparse import ArgumentParser as parser

if __name__ == '__main__':

    # create parser
    par = parser(description="Tomography Image Reconstruction Script")
    # define input
    par.add_argument("exp_log", help="Exp_log file")
    par.add_argument("scan_id",
                     help="ID of the scan (defined in Exp_log file)")
    par.add_argument("rec_type", help="'full' or 'sub' reconstruction")

    # define optional input
    par.add_argument("--rot-axis", type=float, help="specify rotation axis")
    par.add_argument("--rot-step", type=float, help="rotation axis step(s)")
    par.add_argument("--mblur", type=int, help="ksize of median filter")

    args = par.parse_args()  # returns data from the options specified (echo)

    # initialize parameters
    opt = imu.tomo_par_init(args.exp_log, args.scan_id)
Exemple #14
0
    try:
        log("Update stack called","INFO")
        response = client.update_stack(
            StackName = stack_name,
            TemplateBody = template_body,
            Parameters=[params]
            #TimeoutInMinutes=30,
            #Capabilities=[capabilities],
            #OnFailure='ROLLBACK',
            #EnableTerminationProtection=True
        )
    except Exception as e:
        log(e,"Error")        
        

arg = parser(description='Get additional arguments')
arg.add_argument("-op","--operation",help="operation", dest="operation", required=False)

args = arg.parse_args()
op = args.operation

config = config.ConfigParser()
config.optionxform=str

config.read("config.ini")

options = config.items("production-stack-params")

params = {}

for k,v in options:
Exemple #15
0
from sys import platform
from os import getenv, listdir, remove
from shutil import copyfile
from argparse import ArgumentParser as parser
from re import sub

if platform.startswith('linux') or platform == 'darwin':
    print("Linux and macOS aren't supported yet!")
    exit()

print('Searching for game install...')

ar_parser = parser()
ar_parser.add_argument('-u',
                       '--uninstall',
                       help='uninstall hack',
                       action='store_true',
                       default=False)
args = ar_parser.parse_args()

supported_versions = ['3.1.35', '3.1.36', '3.1.37']
appdata = getenv('APPDATA')

if not appdata:
    print(
        "I couldn't find where apps are installed on the system. Is this a modded Windows install?"
    )
    exit()

folders = listdir(appdata)
Exemple #16
0
#!/usr/bin/env python3
"""
TODO
"""
import argparse
from twitch.modules import *
from twitch import api

p = argparse.parser(description='Description')
p.parse_args()

if __name__ == '__main__':
    print('blurb')
            agent_dict["n_games"],
            agent_dict["n_episodes"],
            alpha=agent_dict["alpha"],
            gamma=agent_dict["gamma"],
            epsilon=agent_dict["epsilon"],
            lambd=agent_dict["lambd"],
            n_step=agent_dict["n_step"]
        )

    test_result = dict_result["tests_result"]
    return test_result


if __name__ == '__main__':

    parser = parser(prog='Saving_data_multiprocess', \
        description='Reinforcement learning training agent')
    parser.add_argument('-a', '--automatic', action='store_true', \
        help='Generate automatically test for agent in enviroment')
    args = parser.parse_args()

    agents_list = []
    tests_result = []
    create_custom_enviroment()


    enviroment_name = input("Insert the enviroment name: ")
    enviroment = gym.make(enviroment_name) #Creazione ambiente
    tests_moment = input("Select the test type (final, on_run, ten_perc): ")

    #Generazione automatica degli agenti
    if args.automatic:
Exemple #18
0
def init():
  global M_halo, M_disk, M_bulge, M_gas
  global N_halo, N_disk, N_bulge, N_gas
  global a_halo, a_bulge, gamma_halo, gamma_bulge, Rd, z0, z0_gas
  global halo_cut_r, halo_cut_M, bulge_cut_r, bulge_cut_M
  global disk_cut_r, disk_cut
  global N_total, M_total
  global phi_grid, rho_axis, z_axis, N_rho, Nz
  global N_CORES, force_yes, force_no, output, input_, gas, bulge, factor, Z
  global file_format

  flags = parser(description="Generates an initial conditions file for a\
                              galaxy simulation with halo, stellar disk,\
                              gaseous disk and bulge components.")
  flags.add_argument('-cores', help='The number of cores to use during the\
                                     potential canculation. Make sure this\
                                     number is a factor of N_rho*N_z. Default\
                                     is 1.',
                     default=1)
  flags.add_argument('--force-yes', help='Don\'t ask if you want to use the\
                                          existing potential_data.txt file.\
                                          Useful for automating the execution\
                                          of the script.', action='store_true')
  flags.add_argument('--force-no', help='Same as above, but with the opposite\
                                         effect.', action='store_true')
  flags.add_argument('--hdf5', help='Output initial conditions in HDF5\
                                     format.',
                     action = 'store_true')
  flags.add_argument('-o', help='The name of the output file.',
                     metavar="init.dat", default="init.dat")
  flags.add_argument('-i', help='The name of the .ini file.',
                     metavar="params_galaxy.ini", default="params_galaxy.ini")
  args = flags.parse_args()
  N_CORES = int(args.cores)
  force_yes = args.force_yes
  force_no = args.force_no
  output = args.o
  input_ = args.i
  
  if args.hdf5:
    file_format = 'hdf5'
  else:
    file_format = 'gadget2'

  if not path.isfile(input_):
    print "Input file not found:", input_
    exit(0)

  config = ConfigParser()
  config.read(input_)
  # Halo
  M_halo = config.getfloat('halo', 'M_halo')
  a_halo = config.getfloat('halo', 'a_halo')
  N_halo = config.getint('halo', 'N_halo')
  gamma_halo = config.getfloat('halo', 'gamma_halo')
  halo_cut_r = config.getfloat('halo', 'halo_cut_r')
  # Disk
  M_disk = config.getfloat('disk', 'M_disk')
  N_disk = config.getint('disk', 'N_disk')
  Rd = config.getfloat('disk', 'Rd')
  z0 = config.getfloat('disk', 'z0')
  factor = config.getfloat('disk', 'factor')
  disk_cut_r = config.getfloat('disk', 'disk_cut_r')
  # Bulge
  bulge = config.getboolean('bulge', 'include')
  M_bulge = config.getfloat('bulge', 'M_bulge')
  a_bulge = config.getfloat('bulge', 'a_bulge')
  N_bulge = config.getint('bulge', 'N_bulge')
  gamma_bulge = config.getfloat('bulge', 'gamma_bulge')
  bulge_cut_r = config.getfloat('bulge', 'bulge_cut_r')
  # Gas
  gas = config.getboolean('gas', 'include')
  M_gas = config.getfloat('gas', 'M_gas')
  N_gas = config.getint('gas', 'N_gas')
  z0_gas = config.getfloat('gas', 'z0_gas')
  Z = config.getfloat('gas', 'Z')

  z0_gas *= z0
  if not gas:
    N_gas = 0
  if not bulge:
    N_bulge = 0
  M_total = M_disk + M_bulge + M_halo + M_gas
  N_total = N_disk + N_bulge + N_halo + N_gas
  N_rho = config.getint('global', 'N_rho')
  Nz = config.getint('global', 'Nz')
  phi_grid = np.zeros((N_rho, Nz))
  rho_max = config.getfloat('global', 'rho_max')*a_halo
  z_max = config.getfloat('global', 'z_max')*a_halo
  rho_axis = np.logspace(-2, log10(rho_max), N_rho)
  z_axis = np.logspace(-2, log10(z_max), Nz)
Exemple #19
0
def init():
  global M_halo, M_disk, M_bulge, M_gas
  global N_halo, N_disk, N_bulge, N_gas
  global a_halo, a_bulge, Rd, z0, z0_gas
  global N_total, M_total
  global phi_grid, rho_axis, z_axis, N_rho, Nz
  global halo_core, bulge_core, N_CORES, force_yes, output, gas, factor, Z
  global file_format

  flags = parser(description="Generates an initial conditions file for a\
                              galaxy simulation with halo, stellar disk,\
                              gaseous disk and bulge components.")
  flags.add_argument('--nogas', help='Generates a galaxy without gas.',
                     action='store_true')
  flags.add_argument('-cores', help='The number of cores to use during the\
                                     potential canculation. Make sure this\
                                     number is a factor of N_rho*N_z. Default\
                                     is 1.',
                     default=1)
  flags.add_argument('--force-yes', help='Don\'t ask if you want to use the\
                                          existing potential_data.txt file.\
                                          Useful for automating the execution\
                                          of the script.', action='store_true')
  flags.add_argument('--hdf5', help = 'Generate HDF5 initial conditions. \
                                          Requires h5py.', 
                     action = 'store_true')
  flags.add_argument('-o', help='The name of the output file.',
                     metavar="init.dat", default="init.dat")
  args = flags.parse_args()
  gas = not args.nogas
  N_CORES = int(args.cores)
  force_yes = args.force_yes
  output = args.o
  
  if args.hdf5:
    file_format = 'hdf5'
  else:
    file_format = 'gadget2'

  if not (path.isfile("header.txt") and path.isfile("params_galaxy.ini")):
    print "header.txt or params_galaxy.ini missing."
    exit(0)

  config = ConfigParser()
  config.read("params_galaxy.ini")
  # Halo
  M_halo = config.getfloat('halo', 'M_halo')
  a_halo = config.getfloat('halo', 'a_halo')
  N_halo = config.getint('halo', 'N_halo')
  halo_core = config.getboolean('halo', 'halo_core')
  # Disk
  M_disk = config.getfloat('disk', 'M_disk')
  N_disk = config.getint('disk', 'N_disk')
  Rd = config.getfloat('disk', 'Rd')
  z0 = config.getfloat('disk', 'z0')
  factor = config.getfloat('disk', 'factor')
  # Bulge
  M_bulge = config.getfloat('bulge', 'M_bulge')
  a_bulge = config.getfloat('bulge', 'a_bulge')
  N_bulge = config.getint('bulge', 'N_bulge')
  bulge_core = config.getboolean('bulge', 'bulge_core')

  # Gas
  M_gas = config.getfloat('gas', 'M_gas')
  N_gas = config.getint('gas', 'N_gas')
  z0_gas = config.getfloat('gas', 'z0_gas')
  Z = config.getfloat('gas', 'Z')

  z0_gas *= z0
  if not gas:
    N_gas = 0
    M_gas = 0
  M_total = M_disk + M_bulge + M_halo + M_gas
  N_total = N_disk + N_bulge + N_halo + N_gas
  N_rho = config.getint('global', 'N_rho')
  Nz = config.getint('global', 'Nz')
  phi_grid = np.zeros((N_rho, Nz))
  rho_max = config.getfloat('global', 'rho_max')*a_halo
  z_max = config.getfloat('global', 'z_max')*a_halo
  rho_axis = np.logspace(-2, log10(rho_max), N_rho)
  z_axis = np.logspace(-2, log10(z_max), Nz)
Exemple #20
0
import numpy as np
import os
import pickle
import matplotlib.pyplot as plt
from argparse import ArgumentParser as parser
from skimage import io

parser = parser(description='Computer Vision 2018 Homework 2 (cnn)')
parser.add_argument('dataset_path', 
    nargs='?',
    default='./hw2-3_data', 
    help = 'where to find dataset, default: ./hw2-3_data')
args = parser.parse_args()

model_file_name = 'model.model'

data_dir = args.dataset_path + '/train'
x_train = []
y_train = []
count = 0
for i in os.listdir(data_dir):
    data_dir_n = data_dir + '/' + i
    for j in os.listdir(data_dir_n):
        data = io.imread(os.path.join(data_dir_n, j))
        x_train.append(np.array(data))
        y_train.append(np.array(int(i[6])))
        count += 1
x_train = np.array(x_train)
y_train = np.array(y_train)

data_dir = args.dataset_path + '/valid'
Exemple #21
0
    def get_arguments(self):

        parser = argparse.parser(description="get args")