Skip to content

Commit

Permalink
Merge pull request #10 from lewismc/PEP8
Browse files Browse the repository at this point in the history
PEP8 compliant code.
  • Loading branch information
RileyWilliams authored Sep 15, 2016
2 parents 5af5b26 + 2a6d676 commit ff47f98
Show file tree
Hide file tree
Showing 10 changed files with 198 additions and 199 deletions.
28 changes: 16 additions & 12 deletions pycovjson/cli/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,40 @@


def main():
parser = argparse.ArgumentParser(description='Convert Scientific Data Formats into CovJSON.')
parser.add_argument('-i', '--input', dest='inputfile', help='Name of input file', required=True)
parser.add_argument('-o', '--output', dest='outputfile', help='Name and location of output file', default='coverage.covjson')
parser.add_argument('-t', '--tiled', action='store_true', help='Apply tiling')
parser.add_argument('-s', '--shape', nargs='+', help='Tile shape, list', type=int)
parser.add_argument('-v', dest='variable', help='Variable to populate coverage with')
parser = argparse.ArgumentParser(
description='Convert Scientific Data Formats into CovJSON.')
parser.add_argument('-i', '--input', dest='inputfile',
help='Name of input file', required=True)
parser.add_argument('-o', '--output', dest='outputfile',
help='Name and location of output file', default='coverage.covjson')
parser.add_argument(
'-t', '--tiled', action='store_true', help='Apply tiling')
parser.add_argument('-s', '--shape', nargs='+',
help='Tile shape, list', type=int)
parser.add_argument('-v', dest='variable',
help='Variable to populate coverage with')
args = parser.parse_args()
inputfile = args.inputfile
outputfile = args.outputfile
variable = args.variable
tiled = args.tiled
tile_shape = args.shape


if tiled and len(tile_shape) == 0:
reader = Reader(inputfile)
shape_list = reader.get_shape(variable)
dims = reader.get_dimensions(variable)
print(list(zip(dims, shape_list)))
tile_shape = input('Enter the shape tile shape as a list of comma separated integers')
tile_shape = input(
'Enter the shape tile shape as a list of comma separated integers')
tile_shape = tile_shape.split(',')
tile_shape = list(map(int, tile_shape))
print(tile_shape)
if outputfile == None:
outputfile = outputfile.default

Writer(outputfile, inputfile, [variable], tiled=tiled, tile_shape=tile_shape).write()
Writer(outputfile, inputfile, [variable],
tiled=tiled, tile_shape=tile_shape).write()

if __name__ == '__main__':
main()



9 changes: 4 additions & 5 deletions pycovjson/cli/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@

def main():
parser = argparse.ArgumentParser(description='View Scientific Data files.')
parser.add_argument('-i', '--input', dest='inputfile', help='Name of input file', required=True)
parser.add_argument('-i', '--input', dest='inputfile',
help='Name of input file', required=True)

parser.add_argument('-v', '--variables,', dest='variables', help='Display variables', action='store_true')
parser.add_argument('-v', '--variables,', dest='variables',
help='Display variables', action='store_true')

args = parser.parse_args()
inputfile = args.inputfile
Expand All @@ -30,6 +32,3 @@ def main():

if __name__ == '__main__':
main()



1 change: 0 additions & 1 deletion pycovjson/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,4 @@
vars = ['temperature', 'salinity']



Writer('file_name.json', coverage, vars, 'NdArray').write()
82 changes: 41 additions & 41 deletions pycovjson/model.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import numpy as np, math
import numpy as np
import math
from collections import OrderedDict


class Coverage(object):
def __init__(self,domain, ranges, params, reference):

def __init__(self, domain, ranges, params, reference):
self.domain = domain.to_dict()
self.range = ranges.to_dict()
self.parameter = params.to_dict()
Expand All @@ -21,6 +24,7 @@ def to_dict(self):


class Domain(object):

def __init__(self, domain_type, x_values=[], y_values=[], z_values=[], t_values=[]):
self.domain_type = domain_type

Expand All @@ -29,19 +33,20 @@ def __init__(self, domain_type, x_values=[], y_values=[], z_values=[], t_values=
self.z_values = z_values
self.t_values = t_values
self.referencing = []

def __str__(self):
return 'Domain Type: ' + self.domain_type + '\nAxes:'+ str(self.axes)
return 'Domain Type: ' + self.domain_type + '\nAxes:' + str(self.axes)

def to_dict(self):
domain_dict = OrderedDict()
domain_dict['domainType'] = self.domain_type
domain_dict['axes'] = {}

domain_dict['axes']['x'] = {'values' : self.x_values}
domain_dict['axes']['x'] = {'values': self.x_values}

domain_dict['axes']['y']= {'values' : self.y_values}
domain_dict['axes']['y'] = {'values': self.y_values}

domain_dict['axes']['t'] = {'values' : self.t_values}
domain_dict['axes']['t'] = {'values': self.t_values}
domain_dict['axes']['z'] = {'values': self.z_values}
if len(self.z_values) == 0:
# domain_dict['axes']['z']= {'values' : self.z_values}
Expand All @@ -55,7 +60,8 @@ def to_dict(self):


class Range(object):
def __init__(self, range_type,data_type={}, axes= [],shape=[], values=[], variable_name='', tile_sets = []):

def __init__(self, range_type, data_type={}, axes=[], shape=[], values=[], variable_name='', tile_sets=[]):
self.range_type = range_type
self.data_type = data_type
self.axis_names = axes
Expand All @@ -64,7 +70,6 @@ def __init__(self, range_type,data_type={}, axes= [],shape=[], values=[], variab
self.variable_name = variable_name
self.tile_sets = tile_sets


def to_dict(self):
range_dict = OrderedDict()
range_dict[self.variable_name] = {}
Expand All @@ -73,7 +78,7 @@ def to_dict(self):
range_dict[self.variable_name]['dataType'] = self.data_type
range_dict[self.variable_name]['axisNames'] = self.axis_names
range_dict[self.variable_name]['shape'] = self.shape
if self.range_type == 'TiledNdArray' :
if self.range_type == 'TiledNdArray':
range_dict[self.variable_name]['tileSets'] = self.tile_sets

else:
Expand All @@ -82,7 +87,7 @@ def to_dict(self):

return range_dict

def populate(self, data_type={}, axes= [],shape=[], values=[], variable_name=''):
def populate(self, data_type={}, axes=[], shape=[], values=[], variable_name=''):
"""
Function to populate Range object with values
Expand All @@ -95,40 +100,43 @@ def populate(self, data_type={}, axes= [],shape=[], values=[], variable_name='')


class Parameter(object):
def __init__(self, variable_name='', description='' , unit='', symbol='',symbol_type='',observed_property='',op_id=None, label_langtag='en' ):

def __init__(self, variable_name='', description='', unit='', symbol='', symbol_type='', observed_property='', op_id=None, label_langtag='en'):
self.variable_name = variable_name
self.param_type = 'Parameter'
self.description = description
self.unit = unit
self.unit = unit
self.label_langtag = label_langtag
self.symbol = symbol
self.symbol_type = symbol_type
self.observed_property = observed_property
self.op_id = op_id


def to_dict(self):
param_dict = OrderedDict()
param_dict[self.variable_name] = {}
param_dict[self.variable_name]['type'] = self.param_type
param_dict[self.variable_name]['description'] = self.description
param_dict[self.variable_name]['unit'] ={}
param_dict[self.variable_name]['unit']['label'] = {self.label_langtag : self.unit}
param_dict[self.variable_name]['symbol']={}
param_dict[self.variable_name]['unit'] = {}
param_dict[self.variable_name]['unit'][
'label'] = {self.label_langtag: self.unit}
param_dict[self.variable_name]['symbol'] = {}
param_dict[self.variable_name]['symbol']['value'] = self.symbol
param_dict[self.variable_name]['symbol']['type'] = self.symbol_type
param_dict[self.variable_name]['observedProperty']={}
param_dict[self.variable_name]['observedProperty'] = {}
param_dict[self.variable_name]['observedProperty']['id'] = self.op_id
param_dict[self.variable_name]['observedProperty']['label'] = {self.label_langtag : self.observed_property}
param_dict[self.variable_name]['observedProperty'][
'label'] = {self.label_langtag: self.observed_property}
return param_dict



class Reference(object):

def __init__(self, obj_list):
self.coordinates = []
self.obj_list = obj_list
print('Object list : ', self.obj_list)

def get_temporal(self, *args):
return self.TemporalReferenceSystem(*args)

Expand All @@ -148,6 +156,7 @@ def to_list(self):


class TemporalReferenceSystem(Reference):

def __init__(self, cal=None):
self.type = 'TemporalRS'
self.coordinates = ['t']
Expand All @@ -156,17 +165,18 @@ def __init__(self, cal=None):
self.cal = "Gregorian"
else:
self.cal = cal

def to_dict(self):
ref_dict = OrderedDict()
ref_dict['coordinates'] = self.coordinates
ref_dict['system'] ={}
ref_dict['system'] = {}
ref_dict['system']['type'] = self.type
ref_dict['system']['calendar'] = self.cal
return ref_dict



class SpatialReferenceSystem2d(Reference):

def __init__(self):
self.id = "http://www.opengis.net/def/crs/OGC/1.3/CRS84"
self.type = 'GeographicCRS'
Expand All @@ -181,14 +191,14 @@ def set_type(self, new_type):
def to_dict(self):
ref_dict = OrderedDict()
ref_dict['coordinates'] = self.coordinates
ref_dict['system'] ={}
ref_dict['system'] = {}
ref_dict['system']['type'] = self.type
ref_dict['system']['id'] = self.id
return ref_dict



class SpatialReferenceSystem3d(Reference):

def __init__(self):
self.id = "http://www.opengis.net/def/crs/EPSG/0/4979"
self.type = 'GeographicCRS'
Expand All @@ -203,15 +213,16 @@ def set_type(self, new_type):
def to_dict(self):
ref_dict = OrderedDict()
ref_dict['coordinates'] = self.coordinates
ref_dict['system'] ={}
ref_dict['system'] = {}
ref_dict['system']['type'] = self.type
ref_dict['system']['id'] = self.id
return ref_dict


class TileSet(object):

def __init__(self, tile_shape, url_template):
self.tile_shape = tile_shape #List containing shape
self.tile_shape = tile_shape # List containing shape
self.url_template = url_template

def create_tileset(self):
Expand All @@ -222,7 +233,6 @@ def create_tileset(self):
tileset.append(tile_dict)
return tileset


def get_url_template(self, val):
self.val = val

Expand All @@ -235,12 +245,14 @@ def generate_url_template(self, axis_names):
if len(axis_names) == 1:
url_template = '{' + axis_names[0] + '}.covjson'
elif len(axis_names) == 2:
url_template = '{' + axis_names[0] + '}-{' + axis_names[1] +'}.covjson'
url_template = '{' + axis_names[0] + \
'}-{' + axis_names[1] + '}.covjson'
elif len(axis_names) == 3:
url_template = '{' + axis_names[0] + '}-{' + axis_names[1] + '}-{' + axis_names[2] + '}.covjson'

url_template = '{' + axis_names[0] + '}-{' + \
axis_names[1] + '}-{' + axis_names[2] + '}.covjson'

return url_template

def get_tiles(self, tile_shape: object, array) -> object:
"""
Function which yields a generator which can be leveraged to return tile arrays from an input array
Expand All @@ -260,7 +272,6 @@ def step(b, dim, tile_indices):

tile_count = math.ceil(self.shape[dim] / tile_shape[dim])


for i in range(tile_count):
c = b[tile_shape[dim] * i:tile_shape[dim] * (i + 1)]
c = np.rollaxis(c, 1)
Expand All @@ -272,14 +283,3 @@ def step(b, dim, tile_indices):
def get_array_shape(self):
print(self.shape)
return self.shape











Loading

0 comments on commit ff47f98

Please sign in to comment.