-
Notifications
You must be signed in to change notification settings - Fork 0
/
SBSP_tools.py
131 lines (107 loc) · 4.31 KB
/
SBSP_tools.py
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import os
from datetime import datetime
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import geopandas as gpd
from shapely.geometry import Point
#import contextily as ctx
import pyproj
import xarray as xr
import datetime
import datetime as dt
import dask
# these functions process local data from SBB to be used for comparisons.
# date logic is repeated in most cases so that file-specific changes
# can be made quickily if necessary.
def H24_to_datetime(date_str):
"""
formats 24-hr times used by CSAS to datetime object
"""
if date_str[9:11] != '24':
return pd.to_datetime(date_str, format='%Y %j %H%M')
date_str = date_str[0:9] + '00' + date_str[11:]
return pd.to_datetime(date_str, format='%Y %j %H%M') + \
dt.timedelta(days=1)
def load_SBB_10year():
"""
load 10 year SBB dataset from shared_cryosphere and format datetime
returns: df
"""
df = pd.read_csv('../shared_cryosphere/dragar/SBSP/SBSP_1hr_2010-2020.csv')
df['DOY'] = df['DOY'].astype(str).apply(lambda x: x.zfill(3))
df['Hour'] = df['Hour'].astype(str).apply(lambda x: x.zfill(4))
df['datetime']=df['Year'].astype(str)+" "+df['DOY']+" "+df['Hour'].astype(str)
df.index=df['datetime'].apply(H24_to_datetime)
return df
def load_SBB_03_09():
"""
load 10 year SBB dataset from shared_cryosphere and format datetime.
returns: df
"""
df = pd.read_csv('../shared_cryosphere/dragar/SBSP/SBSP_1hr_2003-2009.csv')
df['DOY'] = df['DOY'].astype(str).apply(lambda x: x.zfill(3))
df['Hour'] = df['Hour'].astype(str).apply(lambda x: x.zfill(4))
df['datetime']=df['Year'].astype(str)+" "+df['DOY']+" "+df['Hour'].astype(str)
df.index=df['datetime'].apply(H24_to_datetime)
return df
def load_SASP_10year():
"""
load 10 year SBB dataset from shared_cryosphere and format datetime
returns: df
"""
df = pd.read_csv('../shared_cryosphere/dragar/SASP/SASP_1hr_2010-2020.csv')
# date handling
df['DOY'] = df['DOY'].astype(str).apply(lambda x: x.zfill(3))
df['Hour'] = df['Hour'].astype(str).apply(lambda x: x.zfill(4))
df['datetime']=df['Year'].astype(str)+" "+df['DOY']+" "+df['Hour'].astype(str)
df.index=df['datetime'].apply(H24_to_datetime)
return df
def load_SASP_wy2021(previous_df):
"""load wy2021 and rename headers to match the previous longer file
"""
df = pd.read_excel('../shared_cryosphere/dragar/SASP/SASP_w2021.xlsx',
sheet_name=0,
header=[7]
)
# wy2021 file has different names for headers, solved by replacing
#cols = dict(df.columns.values, previous_df.columns.values)
# upper ano is first in the xlsx file, lower is second. This matches the order in the "processed" data in the dict below.
res = {df.columns.values[i]: previous_df.columns.values[i] for i in range(len(df.columns.values))}
df = df.rename(columns=res)
# same date handling as before
df['DOY'] = df['DOY'].astype(str).apply(lambda x: x.zfill(3))
df['Hour'] = df['Hour'].astype(str).apply(lambda x: x.zfill(4))
df['datetime']=df['Year'].astype(str)+" "+df['DOY']+" "+df['Hour'].astype(str)
df.index=df['datetime'].apply(H24_to_datetime)
return df
def load_SASP_03_09():
"""load 10 year SBB dataset from shared_cryosphere and format datetime
returns: df
"""
df = pd.read_csv('../shared_cryosphere/dragar/SASP/SASP_1hr_2003-2009.csv')
df['DOY'] = df['DOY'].astype(str).apply(lambda x: x.zfill(3))
df['Hour'] = df['Hour'].astype(str).apply(lambda x: x.zfill(4))
df['datetime']=df['Year'].astype(str)+" "+df['DOY']+" "+df['Hour'].astype(str)
df.index=df['datetime'].apply(H24_to_datetime)
return df
def albedo_vis(df):
"""
process SBB 10 year dataset to visible albedo.
"""
df['up_vis'] = df['PyUp_Unfilt_W'] - df['PyUp_Filt_W']
df['down_vis'] = df['PyDwn_Unfilt_W'] - df['PyDwn_Filt_W']
df['albedo_vis'] = df['down_vis'] / df['up_vis']
return df
def albedo_broadband(df):
"""
process SBB 10 year dataset to visible albedo.
"""
df['albedo_broadband'] = df['PyDwn_Unfilt_W'] / df['PyUp_Unfilt_W']
return df
def albedo_ir(df):
"""
process SBB 10 year dataset to visible albedo.
"""
df['albedo_ir'] = df['PyDwn_Filt_W'] / df['PyUp_Filt_W']
return df