Skip to content

Commit 72d40f0

Browse files
committed
move geographic area and mean orientation functions to utils.py
1 parent 0799796 commit 72d40f0

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

pycurrents_ADCP_processing/utils.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import json
33
import numpy as np
44
import xarray as xr
5+
import os
56

67

78
# general utility functions common to multiple classes
@@ -75,6 +76,15 @@ def find_geographic_area(poly_dict, point):
7576
return name_str
7677

7778

79+
def find_geographic_area_attr(lon: float, lat: float):
80+
# Geojson definitions for IOS
81+
json_file = 'ios_polygons.geojson'
82+
json_file = os.path.join(os.path.abspath(os.path.dirname(__file__)), json_file)
83+
# json_file = os.path.realpath(json_file)
84+
polygons_dict = read_geojson(json_file)
85+
return find_geographic_area(polygons_dict, Point(lon, lat))
86+
87+
7888
def parse_processing_history(processing_history: str):
7989
"""
8090
Get number of leading and trailing ensembles cut from an ADCP dataset
@@ -174,3 +184,14 @@ def calculate_depths(dataset: xr.Dataset):
174184
return dataset.instrument_depth.data - dataset.distance.data
175185
else:
176186
return dataset.instrument_depth.data + dataset.distance.data
187+
188+
189+
def mean_orientation(o: list):
190+
# orientation, o, is a list of bools with True=up and False=down
191+
if sum(o) > len(o) / 2:
192+
return 'up'
193+
elif sum(o) < len(o) / 2:
194+
return 'down'
195+
else:
196+
ValueError('Number of \"up\" orientations equals number of \"down\" '
197+
'orientations in data subset')

0 commit comments

Comments
 (0)