source: flex_extract.git/source/python/mods/checks.py @ 97f4f4c

ctbtodev
Last change on this file since 97f4f4c was 97f4f4c, checked in by Anne Philipp <anne.philipp@…>, 5 years ago

better check on grid and arae parameter formats

  • Property mode set to 100644
File size: 2.8 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3##*******************************************************************************
4# @Author: Anne Philipp (University of Vienna)
5#
6# @Date: November 2018
7#
8# @Change History:
9#
10# @License:
11#    (C) Copyright 2014-2018.
12#
13#    This software is licensed under the terms of the Apache Licence Version 2.0
14#    which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
15#
16# @Modul Description:
17#
18#
19# @Module Content:
20
21#
22#*******************************************************************************
23
24# ------------------------------------------------------------------------------
25# MODULES
26# ------------------------------------------------------------------------------
27
28
29# ------------------------------------------------------------------------------
30# FUNCTIONS
31# ------------------------------------------------------------------------------
32
33
34def check_grid_area(grid, area, upper, lower, left , right):
35    '''
36
37
38    '''
39    # if area was provided
40    # decompose area into its 4 components
41    if area:
42        components = area.split('/')
43        upper, left, lower, right = components
44
45    if 'N' in grid:  # Gaussian output grid
46        area = 'G'
47        return grid, area
48
49    if '/' in grid:
50        gridx, gridy = grid.split('/')
51        if gridx == gridy:
52            grid = gridx
53        else:
54            raise ValueError('GRID parameter contains two values '
55                             'which are unequal %s' (grid))
56    # determine grid format
57    if float(grid) / 100. >= 0.5:
58        # grid is defined in 1/1000 degrees; old format
59        grid = '{}/{}'.format(float(grid) / 1000.,
60                              float(grid) / 1000.)
61    elif float(grid) / 100. < 0.5:
62        # grid is defined in normal degree; new format
63        grid = '{}/{}'.format(float(grid), float(grid))
64
65    # determine area format
66    if (float(upper) / 1000. >= 0.05 and
67        float(lower) / 1000. >= 0.05 and
68        float(left) / 1000. >= 0.05 and
69        float(right) / 1000. >= 0.05):
70        # area is defined in 1/1000 degrees; old format
71        area = '{}/{}/{}/{}'.format(float(upper) / 1000.,
72                                    float(left) / 1000.,
73                                    float(lower) / 1000.,
74                                    float(right) / 1000.)
75    elif (float(upper) / 1000. < 0.05 and
76          float(lower) / 1000. < 0.05 and
77          float(left) / 1000. < 0.05 and
78          float(right) / 1000. < 0.05):
79        # area is already in new format
80        area = '{}/{}/{}/{}'.format(float(upper),
81                                    float(left),
82                                    float(lower),
83                                    float(right))
84    else:
85        raise ValueError('The area components have different '
86                         'formats: %s ' (area))
87
88    return grid, area
Note: See TracBrowser for help on using the repository browser.
hosted by ZAMG