-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathExample_FMDB_Code.py
executable file
·149 lines (124 loc) · 4.77 KB
/
Example_FMDB_Code.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
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Leaving the code as it is,it will run and run through all the basic functions.
# Alternate code is marked with a double hashtag (##) and can be uncommented to
# test.
# Libraries that need to be imported
from FMDB import FMDB
# Create database object
#
# If you do not specify a folder name in the FMDB() arguments,
# a folder named FMDB will be automoatically created. All database
# components will be stored here (i.e. stationID list, database storage,
# data files[csv])
#
db = FMDB()
#
# To specify your own folder name, just call it in the argument FMDB("fileName").
#
## db = FMDB('CA_FMDB')
# Create/update stationID list (list of all stations/their info (lat,lon,gacc,site name,etc)
# in a given state or gacc).
#
# Note: Once you have a stationID list from one of the ways listed below, that stationID list
# is permanant unless you delete it. So, if you create a stationID list for all the sites
# in California and then call one of the create/update functions (seen below) for a different
# state/gacc, those new sites will be added to the existing stationID list.
#
# There are multiple ways to create/update the stationID list.
#-------------------------------------------------------------
# To update the stationID list by a given state, use the function below.
# By changing the state argument, you change which state you are grabbing
# all of the stations from.
#
db.update_state_stations(state="CA")
#
# By default this function will grab the site data for California, so you can also
# write the function above as:
#
## db.update_state_stations()
#
# Alternatively you can use the function as seen below if you want a different state.
#
## db.update_state_stations("AZ")
#
#-------------------------------
# Or you can update the stationID list via a GACC.
#
## db.update_gacc_stations(gacc="NOCC")
#
# By default this function will grab the site data for the NOCC GACC, so you can also
# write the function above as:
#
## db.update_gacc_stations()
#
# Alternatively you can use the function as seen below.
#
## db.update_gacc_stations("EACC")
#
#--------------------------------
# Lastly, you can update all the stations in the United States by the function below.
#
## db.update_all()
# Create/update local fuel mositure database.
#
# Based on the stationID list that you created above, those sites will be grabbed from the NFMD
# and will be put onto your local database.
# By default, this function will grab data from 2000 - Present. You can change this via the arguments.
#
db.update_data()
#
# When giving a specified year range that you want:
#
## db.update_data(1990,2010)
## db.update_data(startYear=1700,endYear=1900)
#
# Where 1990 - 2010 is the range of years you want to save data from into your local database.
#
# Note: for each year you get data from, a respective pickle file will be created to hold all the
# data from that year (i.e. 1990.pkl,1991.pkl,2001.pkl,etc).
# Get data from the local fuel mositure database.
#
# Default parameters are set for the get_data function as seen below. If left unchanged, it will grab all of
# the data from the local database. If a parameter is left as None, it means all the data from that parameter
# will be grabbed (i.e. if fuelType is None, all fuels will be grabbed, or if fuelVariation is None, all variations
# will be grabbed)
#
# db.params = {'startYear': int(datetime.datetime.now().year), 'endYear': int(datetime.datetime.now().year),
# 'stationID': None, 'fuelType': None, 'fuelVariation': None,
# 'latitude1': None, 'latitude2': None, 'longitude1': None, 'longitude2': None, 'makeFile': False}
#
# To change these parameters, you can do this:
#
db.params['startYear'] = 2000
## db.params['stationID'] = 20
db.params['fuelType'] = 'Chamise'
## db.params['makeFile'] = True # This will save the data you get into a csv if you set this to True.
#
# Once you have the parameters you want, you can call the get_data function.
#
allFMDB = db.get_data()
#
# If you have the makeFile paramter as true and just want the csv:
#
## db.get_data()
# Plot the data
#
# There are a couple different plots you can create.
#
# Basic line plot for each site/fuelType/fuelVariation
#
## db.plot_lines(allFMDB)
#
# Standard deviation plot for each fuelType/fuelVariation.
# Mean line is plotted for each month along with its standard deviation for each fuelType/fuelVariation.
# i.e. lines you will have : [Chamise - Old Growth, Chamise - New Growth, Chamise - None].
#
db.plot_lines_mean(allFMDB)
#
# Bar plot that shows mean and standard devaition values for all the data each year unless monthly paramter
# is set to True.
#
## plot_bars_mean(allFMDB, monthly=False)
## plot_bars_mean(allFMDB, monthly=True)
## plot_bars_mean(allFMDB, True)