-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile_opening.py
More file actions
98 lines (83 loc) · 3.68 KB
/
file_opening.py
File metadata and controls
98 lines (83 loc) · 3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#importing needed libraries
import os
import pandas as pd
import numpy as np
from datetime import datetime, timezone
'''
===================================================================================
@desc - Creates dataframe of given USGS data csv
@param -
{String} data_type either 'ADVM', 'SSC_Q', or 'Qall'
{S Array} ids list of strings of USGS site numbers
{Boolean} [printo = False] Prints output of dataframes
@output -
{data frame} df dataframe of csv file read
@potential future upgrades -
maybe a little less weird having to input _ADVM or _SSC_Q from interactive code
make it so you pass in a dictionary for it to add into
===================================================================================
'''
def create_USGS_dfs(data_type, ids, printo = False):
df = {} # empty dictionary to put dataframes into
current_path = os.getcwd()
for i in ids:
df[i] = pd.read_csv(current_path + r'/USGS_data/'+i+'_'+data_type+'.csv')
if printo == True:
for key in df.keys():
print("\n" +"="*40)
print(key)
print("-"*40)
print(df[key])
return df
'''
===================================================================================
@desc - Creates array of array for SNR and Amp beams
@param -
{df} dataframe to read from
{S Array} names start stop names for array of arrays (length = 2)
@output -
{array of arrays} tada [m,x] matrix of m cells with x readings
@potential future upgrades -
figure out number of beams and cell (or have inputed and index accordingly)
Put in whole data frame and have it output the number of arrays of arrays wants (e.g. 2 SNR 2 Amp each 10 cells)
pass in dictionary of df and perform them all
===================================================================================
'''
def beam_array(df, names):
a = df.columns.get_loc(names[0])
b = df.columns.get_loc(names[1])
tada = df.iloc[:,a:b+1].to_numpy().transpose()
return tada
'''
===================================================================================
@desc - Converts read in site ids from number to string (and adds 0 to begining)
@param -
{Number} x value to change
@output -
{String} USGS 8 digit site name
===================================================================================
'''
def toName(x):
return '%08d' %x
'''
===================================================================================
@desc - Converts excel serial date time to YYYY-MM-DD HH:MM:SS format and tags as UTC
##### DOESN'T AUTOMATICALLY MAKE CONVERSION TO UTC FROM WHATEVER INPUTED TIMEZONE, JUST TAGS WHATEVER CALCULATED TIME AS UTC #####
@param -
{Array of floats} excel_date: Serial date time
{int} tz_hour_offset hour timezone offset from UTC (can be + or -, e.g. EDT is -4) (default 0)
{int} tz_minute_offset: minute timezone offset from UTC (default 0)
@output -
{datetime.datetime} date time format YYYY-MM-DD HH:MM:SS
===================================================================================
'''
def serialTimeToDatetime(excel_date, tz_hour_offset = 0, tz_minute_offset = 0):
#consolidated from https://stackoverflow.com/questions/31359150/convert-date-from-excel-in-number-format-to-date-format-python
dts = np.array([])
for x in excel_date:
dt = datetime.fromordinal(datetime(1900, 1, 1).toordinal() + int(x) - 2)
hour, hourSecs = divmod(x % 1, 1)
minute, second = divmod(hourSecs * 60, 1)
dt = dt.replace(hour=int(hour) - tz_hour_offset, minute=int(minute) - tz_minute_offset, second=int(second * 60), tzinfo=timezone.utc)
dts = np.append(dts, dt)
return dts