Ejemplo n.º 1
0
def parse_args(argv):
    ''' Parse an array of command-line options into a argparse.Namespace '''
    parser = argparse.ArgumentParser(
        description='Simulating small waves on the surface of a small planet.',
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('-n',
                        type=int,
                        default=200,
                        help='Size of simulation grid; an n x n grid')
    parser.add_argument('--decay',
                        default='1 week',
                        help='The half-life of a wave')
    parser.add_argument('--gravity',
                        type=float,
                        default=9.8e-4,
                        help='The planet\'s gravity, in metres per second')
    parser.add_argument('--width',
                        default='100km',
                        help=('Circumference of the planet, travelling '
                              'east-west'))
    parser.add_argument('--height',
                        default='100km',
                        help=('Circumference of the planet, travelling '
                              'north-south'))
    parser.add_argument('--depth',
                        default='4km',
                        help='Average depth of the planet\'s ocean')
    parser.add_argument('--time-per-frame',
                        default='1 hour',
                        help=('How much planetary time should pass in each '
                              'frame of animation'))
    parser.add_argument('--frames-per-drop',
                        type=int,
                        default=100,
                        help=('On average, how many frames before a new drop '
                              'of water is created'))
    parser.add_argument('--maximum-speed',
                        type=float,
                        default=0.003,
                        help=('For colouring the visualisation: the speed '
                              'that should correspond to the lightest colour'))
    parser.add_argument('-v',
                        '--debug',
                        action='store_true',
                        help='Verbose logging')
    args = parser.parse_args(argv[1:])

    # parse human-readable unts
    args.seconds_per_frame = parse_timespan(args.time_per_frame)
    args.h_background = parse_length(args.depth)
    width = parse_length(args.width)
    height = parse_length(args.height)
    args.drag = 1 / parse_timespan(args.decay)

    # set dx and dy
    args.dx = width / args.n
    args.dy = height / args.n

    return args
Ejemplo n.º 2
0
 def test_parse_length(self):
     self.assertEqual(0, humanfriendly.parse_length('0m'))
     self.assertEqual(42, humanfriendly.parse_length('42'))
     self.assertEqual(42, humanfriendly.parse_length('42m'))
     self.assertEqual(1000, humanfriendly.parse_length('1km'))
     self.assertEqual(0.153, humanfriendly.parse_length('15.3 cm'))
     self.assertEqual(1e-02, humanfriendly.parse_length('1cm'))
     self.assertEqual(1e-03, humanfriendly.parse_length('1mm'))
     self.assertEqual(1e-09, humanfriendly.parse_length('1nm'))
     self.assertRaises(humanfriendly.InvalidLength, humanfriendly.parse_length, '1z')
     self.assertRaises(humanfriendly.InvalidLength, humanfriendly.parse_length, 'a')
Ejemplo n.º 3
0
 def test_parse_length(self):
     """Test :func:`humanfriendly.parse_length()`."""
     self.assertEqual(0, humanfriendly.parse_length('0m'))
     self.assertEqual(42, humanfriendly.parse_length('42'))
     self.assertEqual(42, humanfriendly.parse_length('42m'))
     self.assertEqual(1000, humanfriendly.parse_length('1km'))
     self.assertEqual(0.153, humanfriendly.parse_length('15.3 cm'))
     self.assertEqual(1e-02, humanfriendly.parse_length('1cm'))
     self.assertEqual(1e-03, humanfriendly.parse_length('1mm'))
     self.assertEqual(1e-09, humanfriendly.parse_length('1nm'))
     self.assertRaises(humanfriendly.InvalidLength, humanfriendly.parse_length, '1z')
     self.assertRaises(humanfriendly.InvalidLength, humanfriendly.parse_length, 'a')
Ejemplo n.º 4
0
def print_parsed_length(value):
    """Parse a human readable length and print the number of metres."""
    output(parse_length(value))
Ejemplo n.º 5
0
def print_parsed_length(value):
    """Parse a human readable length and print the number of metres."""
    print(parse_length(value))