Skip to content
Snippets Groups Projects
Commit c0496b50 authored by Diego Gomes's avatar Diego Gomes
Browse files

Remove Old Files

parent dce5d27f
Branches master
No related tags found
No related merge requests found
%% Cell type:code id:dd9cf71b-e692-4c35-864a-428259e8bf7b tags:
``` python
from datetime import datetime
from matplotlib.dates import DateFormatter, MonthLocator
import matplotlib.pyplot as plt
class ProjectDataProcessor:
"""Process data for latent heat flux comparison between FLUXNET and MODIS dataset"""
def __init__(self, FLUXNET_file_path, MODIS_file_path):
self.FLUXNET_file_path = FLUXNET_file_path
self.MODIS_file_path = MODIS_file_path
self.data_FLUXNET = {}
self.data_MODIS = {}
self._load_FLUXNET_data()
self._load_MODIS_data()
def _load_FLUXNET_data(self):
"""Load latent heat flux data from FLUXNET dataset"""
date_list = []
value_list = []
with open(self.FLUXNET_file_path, 'r', encoding='utf-8') as f:
first_line = f.readline().split(',')
ts_index = first_line.index('TIMESTAMP')
le_index = first_line.index('LE_F_MDS')
for line in f:
line = line.split(',')
date = datetime.strptime(line[ts_index], '%Y%m%d')
value = line[le_index]
date_list.append(date)
value_list.append(float(value))
for year in range(min(date_list).year, max(date_list).year + 1):
self.data_FLUXNET[year] = {'dates':[], 'values':[]}
for date, value in zip(date_list, value_list):
self.data_FLUXNET[date.year]['dates'].append(date)
self.data_FLUXNET[date.year]['values'].append(value)
def _load_MODIS_data(self):
"""Load latent heat flux data from MODIS dataset"""
date_list = []
value_list = []
with open(self.MODIS_file_path, 'r', encoding='utf-8') as f:
for line in f:
line = line.split(',')
date = datetime.strptime(line[2], 'A%Y%j')
value = line[5:][144]
if value != 'F':
date_list.append(date)
value_list.append(float(value)/ (24*60*60))
for year in range(min(date_list).year, max(date_list).year + 1):
self.data_MODIS[year] = {'dates':[], 'values':[]}
for date, value in zip(date_list, value_list):
self.data_MODIS[date.year]['dates'].append(date)
self.data_MODIS[date.year]['values'].append(value)
def plot(self, *years):
"""Plot latent heat flux data from FLUXNET and MODIS given any number of available years"""
for year in years:
if year not in self.data_FLUXNET.keys() or year not in self.data_MODIS.keys():
raise ValueError('Make sure all specified years are available in both datasets')
fig, axs = plt.subplots(len(years), 1, figsize=(10, 5*len(years)))
for count, year in enumerate(years):
x_f = self.data_FLUXNET[year]['dates']
y_f = self.data_FLUXNET[year]['values']
x_m = self.data_MODIS[year]['dates']
y_m = self.data_MODIS[year]['values']
if len(years) > 1:
axs[count].plot(x_f, y_f, label='FLUXNET ' + str(year))
axs[count].plot(x_m, y_m, label='MODIS ' + str(year))
axs[count].set_xlim([datetime.strptime('1.1.'+str(year), '%d.%m.%Y'),
datetime.strptime('31.12.'+str(year), '%d.%m.%Y')])
axs[count].set_ylabel('Latent Heat Flux [W m-2]')
axs[count].xaxis.set_major_locator(MonthLocator())
axs[count].xaxis.set_major_formatter(DateFormatter('%b'))
axs[count].set_title(year)
axs[count].legend()
else:
axs.plot(x_f, y_f, label='FLUXNET ' + str(year))
axs.plot(x_m, y_m, label='MODIS ' + str(year))
axs.set_xlim([datetime.strptime('1.1.'+str(year), '%d.%m.%Y'),
datetime.strptime('31.12.'+str(year), '%d.%m.%Y')])
axs.set_ylabel('Latent Heat Flux [W m-2]')
axs.xaxis.set_major_locator(MonthLocator())
axs.xaxis.set_major_formatter(DateFormatter('%b'))
axs.set_title(year)
axs.legend()
plt.show()
```
%% Cell type:code id:b5ff9ec5-2ccf-408f-98b5-1df96f2d5d26 tags:
``` python
FLUXNET_file_path = 'data/Oensingen_FLUXNET/FLX_CH-Oe2_FLUXNET2015_FULLSET_DD_2004-2014_1-4.csv'
MODIS_file_path = 'data/Oensingen_MODIS/LE_500m_filtered_scaled.csv'
oensingen = ProjectDataProcessor(FLUXNET_file_path, MODIS_file_path)
print(f'FLUXNET years available: {oensingen.data_FLUXNET.keys()}')
print(f'MODIS years available: {oensingen.data_MODIS.keys()}')
```
%% Cell type:code id:2ccfe8b7-b77c-4d27-abf8-af0f7c0db240 tags:
``` python
# Call the plot functions with the years to be plotted
oensingen.plot(2010,2011,2012)
```
%% Cell type:code id:b61f160b-1cdb-4131-8c8a-11d2c4b27b88 tags:
``` python
```
This diff is collapsed.
This diff is collapsed.
Source diff could not be displayed: it is too large. Options to address this: view the blob.
Source diff could not be displayed: it is too large. Options to address this: view the blob.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment