From 5c0286475dad31c51498c5778a0751b9d6aba954 Mon Sep 17 00:00:00 2001 From: C-PROOF Date: Wed, 22 Jun 2022 15:36:38 -0700 Subject: [PATCH] Add ticket to website.py Adding in Julia's function to make the ticker for glider distance travelled to website.py --- cproofutils/website.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/cproofutils/website.py b/cproofutils/website.py index f91cb0e..9a94a39 100644 --- a/cproofutils/website.py +++ b/cproofutils/website.py @@ -68,6 +68,41 @@ _log = logging.getLogger(__name__) +def ticker(dir): + +#jpnote: +# Function to calculate distance traveled by gliders +# For every mission directory where L0-timeseries exists, +# extract distance_over_ground and sum +# Written into html file, and put directly into cproofwesbite/_includes/ +# directory, and then added using jekyll {% include %} + + sump = 0 # set variable to 0 + subdirs = glob.glob(dir + '/dfo-*') + # atts = [] + for d in subdirs: + if os.path.isdir(d): #define subdirs so that only go into directories that start with 'dfo-*' + if 1: + _log.info(d) + nc = sorted(glob.glob(d+'/*/L0-timeseries/*.nc'), key=os.path.getmtime) + with xr.open_dataset(nc[-1]) as ds: #open most recent of sorted netcdf files (last, [-1]) + + sump += ds.variables['distance_over_ground'].data[-1] # Add last element of dataset to final sum + list_ = np.where(ds.variables['distance_over_ground'].data==0) # Locate where in distance over ground there is a 0, + flattened = [val for sublist in list_ for val in sublist] # List comprhension to allow traversal through list + + for i in flattened: + sump += ds.variables['distance_over_ground'].data[i-1] # add number before every 0 appearance to final sum + + # print('final sum', "{:.f}".format(sump)) #final sum print check + # print('final sum', int(sump)) #final sum print check + + with open('/Users/cproof/cproofwebsite/_includes/inputfile.html', 'w') as output_file: #output to html file in website directory + output_file.write(str(int(sump))) + +####### + + def index_deployments(dir, templatedir='./.templates/'): """ Get useful info from deployments under "dir" and add to an