From b3a7b516669721ddf52389925c486f6fa72db64f Mon Sep 17 00:00:00 2001 From: shaunbell Date: Thu, 30 Jan 2020 12:52:57 -0800 Subject: [PATCH] clean --- Summary/EPICkey_summary.py | 86 -------------------- Summary/SQLCTD_summary.py | 92 ---------------------- Summary/__init__.py | 0 Summary/scripts/EPICKey_summary_ecoraid.sh | 17 ---- Summary/utilities/ConfigParserLocal.py | 47 ----------- Summary/utilities/__init__.py | 0 6 files changed, 242 deletions(-) delete mode 100755 Summary/EPICkey_summary.py delete mode 100755 Summary/SQLCTD_summary.py delete mode 100755 Summary/__init__.py delete mode 100755 Summary/scripts/EPICKey_summary_ecoraid.sh delete mode 100755 Summary/utilities/ConfigParserLocal.py delete mode 100755 Summary/utilities/__init__.py diff --git a/Summary/EPICkey_summary.py b/Summary/EPICkey_summary.py deleted file mode 100755 index 3fc6438..0000000 --- a/Summary/EPICkey_summary.py +++ /dev/null @@ -1,86 +0,0 @@ -#!/usr/bin/env - -""" - SQL2meta_ctd.py - - Retrieve specific characteristics from CTD cruise database (CTD_MetaInformation) - - Using Anaconda packaged Python -""" - -# System Stack -import datetime -import os -import argparse - -# Science Stack -from netCDF4 import Dataset - - -__author__ = 'Shaun Bell' -__email__ = 'shaun.bell@noaa.gov' -__created__ = datetime.datetime(2015, 12, 10) -__modified__ = datetime.datetime(2015, 12, 10) -__version__ = "0.1.0" -__status__ = "Development" -__keywords__ = 'CTD', 'MetaInformation', 'Cruise', 'MySQL' - -"""--------------------------------netcdf Routines---------------------------------------""" - - -def get_global_atts(nchandle): - - g_atts = {} - att_names = nchandle.ncattrs() - - for name in att_names: - g_atts[name] = nchandle.getncattr(name) - - return g_atts - -def get_vars(nchandle): - return nchandle.variables - -def ncreadfile_dic(nchandle, params): - data = {} - for j, v in enumerate(params): - if v in nchandle.variables.keys(): #check for nc variable - data[v] = nchandle.variables[v][:] - - else: #if parameter doesn't exist fill the array with zeros - data[v] = None - return (data) - -def repl_var(nchandle, var_name, val): - nchandle.variables[var_name][:] = val[:] - return - - - -"""------------------------ Main Modules ----------------------------------------""" - -parser = argparse.ArgumentParser(description='Epic Key Variable Cruise Summary') -parser.add_argument('DataPath', metavar='DataPath', type=str, help='Full DataPath to CTD files to be analyzed') -parser.add_argument('CruiseID', metavar='CruiseID', type=str, help='CruiseID') - -args = parser.parse_args() - -### get all .nc files from chosen directory -full_path = [args.DataPath + x for x in os.listdir(args.DataPath) if x.endswith('.nc')] - -#cumulative dictionary - epickey:count -sum_dic = {} - -for ncfile in full_path: - nchandle = Dataset(ncfile,'a') - vars_dic = get_vars(nchandle) - nchandle.close() - - for keys,vals in enumerate(vars_dic): - if vals not in sum_dic: - sum_dic[vals] = 1 - else: - sum_dic[vals] = sum_dic[vals]+1 - -for keys,vals in enumerate(sum_dic): - print "{0}, {1}, {2}".format(args.CruiseID, vals, sum_dic[vals]) \ No newline at end of file diff --git a/Summary/SQLCTD_summary.py b/Summary/SQLCTD_summary.py deleted file mode 100755 index 2b49b7a..0000000 --- a/Summary/SQLCTD_summary.py +++ /dev/null @@ -1,92 +0,0 @@ -#!/usr/bin/env - -""" - SQL2meta_ctd.py - - Retrieve specific characteristics from CTD cruise database (CTD_MetaInformation) - - Using Anaconda packaged Python -""" - -# System Stack -import datetime -import pymysql -import argparse - -# Science Stack -import numpy as np - -# User Stack -import utilities.ConfigParserLocal as ConfigParserLocal - -__author__ = 'Shaun Bell' -__email__ = 'shaun.bell@noaa.gov' -__created__ = datetime.datetime(2015, 12, 10) -__modified__ = datetime.datetime(2015, 12, 10) -__version__ = "0.1.0" -__status__ = "Development" -__keywords__ = 'CTD', 'MetaInformation', 'Cruise', 'MySQL' - -"""--------------------------------SQL Init----------------------------------------""" - -"""--------------------------------SQL Init----------------------------------------""" - -def connect_to_DB(host, user, password, database): - # Open database connection - try: - db = pymysql.connect(host, user, password, database) - except: - print "db error" - - # prepare a cursor object using cursor() method - cursor = db.cursor(pymysql.cursors.DictCursor) - return(db,cursor) - - - -def count_cruise(db, cursor, table, year, month, day): - sql = ("SELECT count(*) from `{0}` as castnum WHERE `GMTYear` = '{1}' AND `GMTMonth` = '{2}' AND `GMTDay` = '{3}'" ).format(table, year, month, day) - - result_dic = {} - try: - # Execute the SQL command - cursor.execute(sql) - # Get column names - rowid = {} - counter = 0 - for i in cursor.description: - rowid[i[0]] = counter - counter = counter +1 - #print rowid - # Fetch all the rows in a list of lists. - results = cursor.fetchall() - for row in results: - result_dic['value'] ={keys: row[keys] for val, keys in enumerate(row.keys())} - return (result_dic) - except: - print "Error: unable to fecth data" - -"""------------------------ Main Modules ----------------------------------------""" - -parser = argparse.ArgumentParser(description='MySql Cruise Summary') -parser.add_argument('table', metavar='table', type=str, help='database tablename') -parser.add_argument('year', metavar='year', type=int, help='year to run') -parser.add_argument('nyear', metavar='nyear', type=int, help='number of years to run') - -args = parser.parse_args() - -db_config = ConfigParserLocal.get_config('db_config_cruise_data.pyini') - -(db,cursor) = connect_to_DB(db_config['host'], db_config['user'], db_config['password'], db_config['database']) - -startday = datetime.datetime(args.year,1,1,0,0,0) -num_days = 365 * args.nyear -print "date, castnum\n" -for day in startday + np.arange(num_days) * datetime.timedelta(1): - - data = count_cruise(db, cursor, args.table, str(day.year), day.strftime('%b') , str(day.day) ) - print ("{0}, {1}").format(day, int(data.values()[0].values()[0]) ) - - -db.close() - diff --git a/Summary/__init__.py b/Summary/__init__.py deleted file mode 100755 index e69de29..0000000 diff --git a/Summary/scripts/EPICKey_summary_ecoraid.sh b/Summary/scripts/EPICKey_summary_ecoraid.sh deleted file mode 100755 index 77d89ee..0000000 --- a/Summary/scripts/EPICKey_summary_ecoraid.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -# Purpose: -# Script to run CTDnc2odv.py for all .nc files in a directory - -# older data streams -> 2011 or so -data_dir="/Users/bell/Data_Local/FOCI/CTD_orig/*/*/" -# ecoraid newer archive format -#data_dir="/Users/bell/ecoraid/*/CTDCasts/*/final_data/*/" -prog_dir="/Users/bell/Programs/Python/AtSeaPrograms/Summary/" - -for files in $data_dir -do - cruiseID=(${files//\// }) - #echo "processing file: ${cruiseID[${#cruiseID[@]}-1]}" - python ${prog_dir}EPICkey_summary.py $files ${cruiseID[${#cruiseID[@]}-1]} -done diff --git a/Summary/utilities/ConfigParserLocal.py b/Summary/utilities/ConfigParserLocal.py deleted file mode 100755 index cfe6a3f..0000000 --- a/Summary/utilities/ConfigParserLocal.py +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env - -""" -ConfigParser.py - - Parse .pyini files (custom generated user ini files) - - These files are JSON created and are flat files which can be edited by any text reader - -Using Anaconda packaged Python -""" - -#System Stack -import json -import sys - -def get_config(infile): - """ Input - full path to config file - - Output - dictionary of file config parameters - """ - infile = str(infile) - - try: - d = json.load(open(infile)) - except: - print "Invalid or unfound config file \n Exitting without changes" - sys.exit() - - return d - -def write_config(infile, d): - """ Input - full path to config file - Dictionary of parameters to write - - Output - None - """ - infile = str(infile) - - try: - d = json.dump(d, open(infile,'w'), sort_keys=True, indent=4) - except: - print "Invalid or unfound config file \n Exitting without changes" - sys.exit() - - - diff --git a/Summary/utilities/__init__.py b/Summary/utilities/__init__.py deleted file mode 100755 index e69de29..0000000