def load_AWS(): '''Load AWS observations from case study.''' print('\nimporting AWS observations...') # Load AWS data AWS_srs = np.genfromtxt( '/data/clivarm/wip/ellgil82/AWS/iWS18_SEB_hourly_untilnov17.txt', names=True) AWS_srs = pd.DataFrame( AWS_srs ) # Convert to pandas DataFrame this way because it loads in incorrectly using pd.from_csv # Calculate date, given list of years and day of year date_list = compose_date(AWS_srs['year'], days=AWS_srs['day']) AWS_srs['Date'] = date_list # Set date as index AWS_srs.index = AWS_srs['Date'] # Calculate actual time from decimal DOY (seriously, what even IS that format?) AWS_srs['time'] = 24 * (AWS_srs['Time'] - AWS_srs['day']) # Trim to case study print('\nsubsetting for Case Study...') case = AWS_srs.loc[case_start:case_end] print('\nconverting times...') # Convert times so that they can be plotted time_list = [] for i in case['time']: hrs = int(i) # will now be 1 (hour) mins = int((i - hrs) * 60) # will now be 4 minutes secs = int(0 - hrs * 60 * 60 + mins * 60) # will now be 30 j = datetime.time(hour=hrs, minute=mins) time_list.append(j) case['Time'] = time_list case['datetime'] = case.apply( lambda r: pd.datetime.combine(r['Date'], r['Time']), 1) case['E'] = case['LWnet_corr'] + case['SWnet_corr'] + case['Hlat'] + case[ 'Hsen'] - case['Gs'] return case
def load_AWS(station): ## --------------------------------------------- SET UP VARIABLES ------------------------------------------------## ## Load data from AWS 14 and AWS 15 for January 2011 print('\nDayum grrrl, you got a sweet AWS...') if host == 'jasmin': os.chdir(filepath) for file in os.listdir(filepath): if fnmatch.fnmatch(file, '%(station)s*' % locals()): AWS_srs = pd.read_csv(str(file), na_values=-9999, header=0) elif host == 'bsl': os.chdir('/data/clivarm/wip/ellgil82/AWS/') for file in os.listdir('/data/clivarm/wip/ellgil82/AWS/'): if fnmatch.fnmatch(file, '%(station)s*' % locals()): AWS_srs = pd.read_csv(str(file), na_values = -9999, header = 0) # Calculate date, given list of years and day of year date_list = compose_date(AWS_srs['year'], days=AWS_srs['day']) AWS_srs['Date'] = date_list # Set date as index AWS_srs.index = AWS_srs['Date'] # Calculate actual time from decimal DOY (seriously, what even IS that format?) try: AWS_srs['time'] = 24.*(AWS_srs['Time'] - AWS_srs['day']) time_list = [] for i in AWS_srs['time']: hrs = int(i) # will now be 1 (hour) mins = int((i-hrs)*60) # will now be 4 minutes secs = int(0 - hrs*60*60 + mins*60) # will now be 30 j = datetime.time(hour = hrs, minute=mins) time_list.append(j) AWS_srs['Time'] = time_list except TypeError: print('Got time already m9') AWS_srs['Time'] = pd.to_datetime(AWS_srs['Time'], format='%H:%M:%S').dt.time print '\nconverting times...' # Convert times so that they can be plotted AWS_srs['datetime'] = AWS_srs.apply(lambda r : pd.datetime.combine(r['Date'],r['Time']),1) try: AWS_srs['E'] = AWS_srs['LWnet_corr'].values + AWS_srs['SWnet_corr'].values + AWS_srs['Hlat'].values + AWS_srs['Hsen'].values - AWS_srs['Gs'].values except: print('No full SEB \'ere pal...') AWS_srs['WD'][AWS_srs['WD'] < 0.] = np.nan AWS_srs['FF_10m'][AWS_srs['FF_10m'] < 0.] = np.nan AWS_srs['WD'] = AWS_srs['WD'].interpolate() # interpolate missing values AWS_srs['FF_10m'] = AWS_srs['FF_10m'].interpolate() AWS_srs['WD'][AWS_srs['WD'] == 0.] = np.nan if station == 'AWS14_SEB_2009-2017_norp': AWS_srs = AWS_srs.tail(1).append(AWS_srs.iloc[:-1]) # Calculate months months = [g for n, g in AWS_srs.groupby(pd.TimeGrouper('M'))] DJF = pd.concat((months[11], months[0], months[1]), axis=0) MAM = pd.concat((months[2], months[3], months[4]), axis=0) JJA = pd.concat((months[5], months[6], months[7]), axis=0) SON = pd.concat((months[8], months[9], months[10]), axis=0) if host == 'jasmin': os.chdir('/gws/nopw/j04/bas_climate/users/ellgil82/hindcast/output/alloutput/') elif host == 'bsl': os.chdir('/data/mac/ellgil82/hindcast/output/') return AWS_srs, DJF, MAM, JJA, SON
def load_AWS(station, year): ## --------------------------------------------- SET UP VARIABLES ------------------------------------------------## ## Load data from AWS 14 and AWS 15 for January 2011 print('\nDayum grrrl, you got a sweet AWS...') if host == 'jasmin': os.chdir(filepath) for file in os.listdir(filepath): if fnmatch.fnmatch(file, '%(station)s*' % locals()): AWS_srs = pd.read_csv(str(file), na_values=-9999, header=0) elif host == 'bsl': os.chdir('/data/clivarm/wip/ellgil82/AWS/') for file in os.listdir('/data/clivarm/wip/ellgil82/AWS/'): if fnmatch.fnmatch(file, '%(station)s*' % locals()): AWS_srs = pd.read_csv(str(file), na_values=-9999, header=0) # Calculate date, given list of years and day of year date_list = compose_date(AWS_srs['year'], days=AWS_srs['day']) AWS_srs['Date'] = date_list # Set date as index AWS_srs.index = AWS_srs['Date'] # Calculate actual time from decimal DOY (seriously, what even IS that format?) try: AWS_srs['time'] = 24. * (AWS_srs['Time'] - AWS_srs['day']) time_list = [] case = AWS_srs.loc[year + '-01-01':year + '-12-31'] # '2015-01-01':'2015-12-31' for i in case['time']: hrs = int(i) # will now be 1 (hour) mins = int((i - hrs) * 60) # will now be 4 minutes secs = int(0 - hrs * 60 * 60 + mins * 60) # will now be 30 j = datetime.time(hour=hrs, minute=mins) time_list.append(j) case['Time'] = time_list except TypeError: print('Got time already m9') AWS_srs['Time'] = pd.to_datetime(AWS_srs['Time'], format='%H:%M:%S').dt.time case = AWS_srs.loc[year + '-01-01':year + '-12-31'] #'2015-01-01':'2015-12-31' print '\nconverting times...' # Convert times so that they can be plotted case['datetime'] = case.apply( lambda r: pd.datetime.combine(r['Date'], r['Time']), 1) try: case['E'] = case['LWnet_corr'].values + case[ 'SWnet_corr'].values + case['Hlat'].values + case[ 'Hsen'].values - case['Gs'].values except: print('No full SEB \'ere pal...') case['WD'][case['WD'] < 0.] = np.nan case['FF_10m'][case['FF_10m'] < 0.] = np.nan case['WD'] = case['WD'].interpolate() # interpolate missing values case['FF_10m'] = case['FF_10m'].interpolate() if station == 'AWS14_SEB_2009-2017_norp': case = case.tail(1).append(case.iloc[:-1])