Commit 7ba77577 authored by Clément Haëck's avatar Clément Haëck
Browse files

Add grid_file as default argument

Gather grid_file generation to class method
parent 56c32529
......@@ -18,9 +18,9 @@ def add_args(parser):
def main():
args = lib.get_args(['region'], add_args=add_args)
outfile = path.join(lib.root_data, args['region'],
'boxgrid_{:.1f}_{:.1f}.txt'.format(
args['size_lon'], args['size_lat']))
args['grid_file'] = 'boxgrid_{:.1f}_{:.1f}.txt'.format(
args['size_lon'], args['size_lat'])
grid_file = lib.box.IndexBox.GetGridFile(args)
bounds = lib.box.Box(args['lon_min'], args['lon_max'],
args['lat_min'], args['lat_max'])
......@@ -33,8 +33,8 @@ def main():
print('Grid of {:d} boxes, {:d}x{:d}'.format(
len(grid), idx_lon_max, idx_lat_max))
print("Writing to '{}'".format(outfile))
lib.box.IndexBox.WriteGridText(grid, outfile)
print("Writing to '{}'".format(grid_file))
lib.box.IndexBox.WriteGridText(grid, grid_file)
if __name__ == '__main__':
......
......@@ -60,8 +60,7 @@ def main():
variables_hi = ['analysed_sst']
variables_gc = ['CHL']
boxes = lib.box.IndexBox.ReadGridText(
path.join(lib.root_data, args['region'], args['grid_file']))
boxes = lib.box.IndexBox.ReadGridText(lib.box.IndexBox.GetGridFile(args))
for i, b in enumerate(boxes):
print(str(b) + ' | {}/{}'.format(i+1, len(boxes)))
......
......@@ -124,6 +124,7 @@ def get_args(args, description='', add_args=None):
add_arg('coef', int)
add_arg('zone', str)
add_arg('level', str)
add_arg('grid_file', str)
if 'fixes' in args:
parser.add_argument('-fix', nargs=2, type=str, action='append',
......
......@@ -3,9 +3,12 @@
A Box is a rectangular area defined by minimum and maximum latitude and
longitude.
"""
from os import path
from matplotlib.patches import Rectangle
import lib
class Box:
"""Simple box."""
......@@ -218,6 +221,14 @@ class IndexBox(Box):
boxes.append(cls(*bounds, idx=index))
return boxes
@staticmethod
def GetGridFile(args):
"""Get grid text file.
Arguments must contain 'region' and 'grid_file'.
"""
return path.join(lib.root_data, args['region'], args['grid_file'])
class Image(Box):
"""Class for Image retrieved by fortran.
......
......@@ -9,3 +9,4 @@ number: 1
coef: 0
level: L3
zone: gyre
grid_file: boxgrid_5.0_5.0.txt
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment