This page was generated from /home/docs/checkouts/readthedocs.org/user_builds/blm/checkouts/latest/docs/tasks/task1.ipynb.
Interactive online version:
Slideshow:
1.1. Understanding Surface Parameters (1): Albedo¶
1.1.1. Objectives¶
Review Python programming.
Prepare plots of surface radiation and energy balance using assigned AmeriFlux observations under two scenarios: one clear day and one cloudy day.
Tips:
Check the fluxes make sense.
Think about the time of day.
Calculate the albedo through the day for both days.
How does the albedo vary through the day?
How do your site values compare to the literature?
How does the albedo vary through the year?
If you had to use one albedo value to model the site, what would it be?
For scientific background see Albedo and Reading List
1.1.2. Tasks¶
1.1.2.1. load necessary packages¶
[1]:
# These packages are necessary later on. Load all the packages in one place for consistency
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from pathlib import Path
1.1.2.2. load data¶
[2]:
#The path of the directory where all AMF data are
#path_dir = Path.cwd()/'data'/'AMF-clean'
path_dir = Path.cwd()/'data'/'1'
[3]:
name_of_site = 'CA-Obs_clean.csv.gz'
path_data = path_dir/name_of_site
path_data.resolve()
[3]:
PosixPath('/Users/sunt05/Dropbox/6.Repos/BLM/data/1/CA-Obs_clean.csv.gz')
[4]:
df_data = pd.read_csv(path_data, index_col='time',parse_dates=['time'])
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
<ipython-input-4-010038206d98> in <module>
----> 1 df_data = pd.read_csv(path_data, index_col='time',parse_dates=['time'])
/anaconda3/lib/python3.7/site-packages/pandas/io/parsers.py in parser_f(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, skipfooter, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, cache_dates, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, doublequote, escapechar, comment, encoding, dialect, error_bad_lines, warn_bad_lines, delim_whitespace, low_memory, memory_map, float_precision)
683 )
684
--> 685 return _read(filepath_or_buffer, kwds)
686
687 parser_f.__name__ = name
/anaconda3/lib/python3.7/site-packages/pandas/io/parsers.py in _read(filepath_or_buffer, kwds)
455
456 # Create the parser.
--> 457 parser = TextFileReader(fp_or_buf, **kwds)
458
459 if chunksize or iterator:
/anaconda3/lib/python3.7/site-packages/pandas/io/parsers.py in __init__(self, f, engine, **kwds)
893 self.options["has_index_names"] = kwds["has_index_names"]
894
--> 895 self._make_engine(self.engine)
896
897 def close(self):
/anaconda3/lib/python3.7/site-packages/pandas/io/parsers.py in _make_engine(self, engine)
1133 def _make_engine(self, engine="c"):
1134 if engine == "c":
-> 1135 self._engine = CParserWrapper(self.f, **self.options)
1136 else:
1137 if engine == "python":
/anaconda3/lib/python3.7/site-packages/pandas/io/parsers.py in __init__(self, src, **kwds)
1915 kwds["usecols"] = self.usecols
1916
-> 1917 self._reader = parsers.TextReader(src, **kwds)
1918 self.unnamed_cols = self._reader.unnamed_cols
1919
pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader.__cinit__()
pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader._setup_parser_source()
/anaconda3/lib/python3.7/gzip.py in __init__(self, filename, mode, compresslevel, fileobj, mtime)
161 mode += 'b'
162 if fileobj is None:
--> 163 fileobj = self.myfileobj = builtins.open(filename, mode or 'rb')
164 if filename is None:
165 filename = getattr(fileobj, 'name', '')
FileNotFoundError: [Errno 2] No such file or directory: '/Users/sunt05/Dropbox/6.Repos/BLM/data/1/CA-Obs_clean.csv.gz'
1.1.2.3. Let’s look at the site info¶
[ ]:
all_sites_info = pd.read_csv('data/site_info.csv')
site_info=all_sites_info[all_sites_info['Site Id'] == name_of_site.split('_clean')[0]]
site_info
1.1.2.4. examine data¶
1.1.2.4.1. Loading the first 5 rows of the dataframe¶
[ ]:
df_data.head(5)
1.1.2.4.2. Let’s print some statistics of the data¶
For names used by AmeriFlux for variables see AmeriFlux Key variables for analysis
[ ]:
df_data.describe()
[ ]:
df_data.loc[:,['SWIN','LWIN','SWOUT','LWOUT']].plot(figsize=(15,4))
[ ]:
df_data.loc[:,['LE','H']].plot(figsize=(15,4))
[ ]:
df_data.loc[:,['TA']].plot(figsize=(15,4))
df_data.loc[:,['P']].plot(figsize=(15,4))
df_data.loc[:,['WS']].plot(figsize=(15,4))
df_data.loc[:,['RH']].plot(figsize=(15,4))
df_data.loc[:,['PA']].plot(figsize=(15,4))
1.1.2.5. plot data¶
1.1.2.5.1. radiation balance¶
[ ]:
date = '2001 10 21'
df_data.loc[:,['SWIN','LWIN','SWOUT','LWOUT']].dropna().loc[date].plot()
1.1.2.5.2. examining if NETRAD == (SWIN-SWOUT)+(LWIN-LWOUT)¶
[ ]:
NetSW = df_data.loc[date,'SWIN']-df_data.loc[date,'SWOUT']
NetLW = df_data.loc[date,'LWIN']-df_data.loc[date,'LWOUT']
Netrad_calc=NetSW+NetLW
df_data.loc[date,'NETRAD'].plot(color='r',label='NETRAD from data')
Netrad_calc.plot(color='b',marker='o',label='NETRAD calculated')
plt.legend()
1.1.2.5.3. surface energy balance¶
[ ]:
df_data.loc[:,['NETRAD','H','LE']].dropna().loc[date].plot()
1.1.2.6. calculate albedo¶
1.1.2.6.1. surface albedo¶
[ ]:
ser_alb=df_data['SWOUT']/df_data['SWIN']
[ ]:
ser_alb[ser_alb.between(0,1)&(df_data['SWIN']>5)].loc[date].plot(marker='o')
[ ]: