Project Data

The data required by the web app is stored in a single object defined by a class named Project.

A Project object has all the information used by the GUI to display a set of tide gates. The constructor is passed the name of a CSV file that has a list of all the barriers and the ID of one of the data sets (currently either OPM or TNC_OR). The data in the CSV file and the target descriptions returned by the make_targets function in the targets module are used to initialize the attributes of the Project object.

Attributes:
  • data

    a copy of the original data, in the form of a Pandas data frame

  • map_info

    a table containging geographical coordinates of the gates

  • regions

    a list of the unique region names in the file

  • climates

    a list of climate scenarios

  • targets

    a dictionary of restoration target attributes for each climate scenario

  • target_map

    a dictionary that associates target names with the target IDs

Source code in src/tidegates/project.py
28
29
30
31
32
33
34
35
36
37
def __init__(self, fn, ds):
    self.data = pd.read_csv(fn)
    self.targets = make_targets(ds)
    if ds == DataSet.TNC_OR:
        self.map_info = self._make_map_info()
        self.regions = self._make_region_list()
        self.totals = self._make_totals()
        self.climates = ['Current', 'Future']
        dct = self.targets['Current']
        self.target_map = { dct[x].long: x for x in dct.keys()}

_make_map_info()

Make a dataframe with attributes needed to display gates on a map. Map latitude and longitude columns in the input frame to Mercator coordinates, and copy the ID, region and barrier types so they can be displayed as tooltips.

src/tidegates/project.py
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
def _make_map_info(self):
    '''
    Make a dataframe with attributes needed to display gates on a map.
    Map latitude and longitude columns in the input frame to Mercator
    coordinates, and copy the ID, region and barrier types so they can
    be displayed as tooltips.
    '''
    df = self.data[['BARID','REGION','BarrierType']]
    R = 6378137.0
    map_info = pd.concat([
        df, 
        np.radians(self.data.POINT_X)*R, 
        np.log(np.tan(np.pi/4 + np.radians(self.data.POINT_Y)/2)) * R
    ], axis=1)
    map_info.columns = ['id', 'region', 'type', 'x', 'y']
    return map_info

_make_region_list()

Make a list of unique region names, sorted by latitude, so regions are displayed in order from north to south

src/tidegates/project.py
56
57
58
59
60
61
62
63
def _make_region_list(self):
    '''
    Make a list of unique region names, sorted by latitude, so regions
    are displayed in order from north to south
    '''
    df = self.data[['BARID','REGION','POINT_Y']]
    mf = df.groupby('REGION').mean(numeric_only=True).sort_values(by='POINT_Y',ascending=False)
    return list(mf.index)

_make_totals()

Compute the total cost to repair all barriers in each region

src/tidegates/project.py
65
66
67
68
69
70
def _make_totals(self):
    '''
    Compute the total cost to repair all barriers in each region
    '''
    tf = self.data[['BARID','REGION','COST']].groupby('REGION').sum(numeric_only=True)
    return { x: tf.COST[x] for x in tf.index }