Initial Commit

This commit is contained in:
Alexander Rey 2021-09-08 15:30:52 -04:00
parent db97e17285
commit 99c12cd923
54 changed files with 119432 additions and 0 deletions

8
HRRR/.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/

11
HRRR/.idea/HRRR.iml Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 3.8 (HRRR)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="PyDocumentationSettings">
<option name="renderExternalDocumentation" value="true" />
</component>
</module>

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

7
HRRR/.idea/misc.xml Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8 (HRRR)" project-jdk-type="Python SDK" />
</project>

8
HRRR/.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/HRRR.iml" filepath="$PROJECT_DIR$/.idea/HRRR.iml" />
</modules>
</component>
</project>

7
HRRR/.idea/other.xml Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PySciProjectComponent">
<option name="PY_SCI_VIEW" value="true" />
<option name="PY_SCI_VIEW_SUGGESTED" value="true" />
</component>
</project>

7
HRRR/AWS_Download.py Normal file
View File

@ -0,0 +1,7 @@
from osgeo import gdal
import numpy as np
hrrrPath = 'https://noaa-hrrr-bdp-pds.s3.amazonaws.com/hrrr.20201117/conus/hrrr.t00z.wrfsfcf00.grib2'
ds = gdal.Open('/vsicurl/' + hrrrPath)

8
LAVegMOD_DM/.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 2.7 (LAVegMOD_DM)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="PyDocumentationSettings">
<option name="renderExternalDocumentation" value="true" />
</component>
</module>

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 2.7 (LAVegMOD_DM)" project-jdk-type="Python SDK" />
</project>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/LAVegMOD_DM.iml" filepath="$PROJECT_DIR$/.idea/LAVegMOD_DM.iml" />
</modules>
</component>
</project>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PySciProjectComponent">
<option name="PY_SCI_VIEW" value="true" />
<option name="PY_SCI_VIEW_SUGGESTED" value="true" />
</component>
</project>

Binary file not shown.

Binary file not shown.

70
LAVegMOD_DM/config.py Normal file
View File

@ -0,0 +1,70 @@
#!/usr/bin/env python
##\file
# This file defines the Config class. The config class
# is used to read data from the model configuration
# file and present the information in a format that
# that is easy to use.
# STD Python modules
import exceptions
import re
import sys
class Config(dict):
def __init__(self):
dict.__init__(self)
def config(self, argv):
filename = ''
if type(argv) == str:
filename = argv
elif type(argv) == list:
if len(argv) != 2:
errorString = 'Config: Error: There should be exactly one commandline argument, the name of the config file.'
raise exceptions.RuntimeError(errorString)
filename = argv[1]
else:
errorString = 'Config: Error: unknown type passed to Config.'
raise exceptions.RuntimeError(errorString)
try:
strm = open(filename, 'r')
except exceptions.IOError as error:
errorString = 'Config: Error: could not open configuration file named ' + filename
raise exceptions.RuntimeError(errorString)
for line in strm:
line = re.sub(r'//.*', '', line )
line = re.sub(r'\n' , '', line )
while re.search(r'\\\\$', line) != None:
contLine = strm.readline()
contLine = re.sub(r'//.*', contLine)
line = re.sub(r'\\\\$', contLine, line)
line = re.sub(r'\t', '', line)
line = re.sub(r' ', '', line)
if len(line) == 0:
continue
key, value = line.split('=')
dict.__setitem__(self, key, value)
strm.close()
if dict.has_key(self, 'XFile'):
print 'Params: Msg: XFile requested. You don\'t have clearance.'
return
def __str__(self):
ret = ''
for (key,value) in self.iteritems():
ret += str(key) + ' = ' + str(value) + '\n'
return ret

103
LAVegMOD_DM/event.py Normal file
View File

@ -0,0 +1,103 @@
#!/usr/bin/env python
##\file
# This file defined the base Event class and the EventQueue class.
# These classes form the basis of the model update process
import copy
import heapq
import signal
import sys
class Time(object):
def __init__(self, time, priority):
self.time = copy.copy(time)
self.priority = copy.copy(priority)
def __lt__(self, other):
return self.time < other.time or ( self.time == other.time and self.priority < other.priority )
def __str__(self):
return str(self.time) + '(' + str(self.priority) + ')'
class Event(object):
def __init__(self, time, name = 'Event' ):
self.time = copy.copy(time)
self.name = copy.copy(name)
def __lt__(self, other):
return self.time < other.time
def __str__(self):
return str(self.time) + ' : ' + self.name
def act(self):
print self.__str__()
class GenericEvent(Event):
def __init__(self, time, name = 'GenericEvent', callable=None):
Event.__init__(self, time, name)
self.callable = callable
def act(self):
self.callable.act()
class PauseEvent(Event):
def __init__(self, time, name='PauseEvent'):
Event.__init__(self, time, name)
def act(self):
pass
class MsgEvent(Event):
def __init__(self, time, name = 'MsgEvent', stream=sys.stdout, msg = 'None'):
Event.__init__(self, time, name)
self.stream = stream
self.msg = copy.copy(msg)
def __str__(self):
return self.msg
def act(self):
print >> self.stream, self.__str__()
#class ReadCSVEvent(Event):
# def __init__(self, time, name = 'ReadCSVEvent', file=0):
# Event.__init__(self, time, name)
# self.file = copy.copy(file)
#
# def __str__(self):
# return Event.__str__(self)
#
# def read(self, file):
# pass
#
# def act(self):
# pass
class EventQueue(object):
def __init__(self):
self.queue = list()
def run(self, while_condition=(lambda arg: True)):
elt = Event(Time(0,0))
while len(self.queue) != 0 and while_condition(elt):
elt = heapq.heappop(self.queue)
elt.act()
def add_event(self, event):
heapq.heappush(self.queue, event)
def clear(self):
del self.queue
self.queue = list()
def __str__(self):
ret = ''
for elt in self.queue:
ret += str(elt) + '\n'
return ret

205
LAVegMOD_DM/function.py Normal file
View File

@ -0,0 +1,205 @@
#!/usr/bin/env python
##\file
# This file defined the base Function class.
# This class is used to provide a piece-wise
# linear function for use in the model. The
# primary use of this these classes is presenting
# the information from the species establishment
# and senescenes tables.
#
# Standard Python Modules
import exceptions
import numpy
import random
import scipy
import scipy.interpolate as interp
import xlrd
# Third Party Modules
import matplotlib as mpl
import matplotlib.pylab as plt
import mpl_toolkits.mplot3d.axes3d as Axes3D
import pandas
class Function(object):
xValue = list()
yValue = list()
def __init__(self, xValue, yValue):
if len(xValue) != len(yValue):
msg = 'Function: Error: Number of elements in xValue an yValue must match'
msg += ' len(xValue) = ' + str(len(xValue)) + ' len(yValue) = ' + str(len(yValue))
raise exceptions.RuntimeError(msg)
self.xValue = xValue
self.yValue = yValue
def toIndex(self, x, vec):
if ( x < vec[0] or vec[-1] < x ):
msg = 'Function: Error: x out of range\n'
msg += 'x = ' + str(x) + '\n'
msg += 'vec[0] = ' + str(vec[0]) + '\n'
msg += 'vec[-1] = ' + str(vec[-1]) + '\n'
raise exceptions.RuntimeError(msg)
b = 0 # b = the "bottom" index
t = len(vec)-1 # t = the "top" index
m = int(scipy.ceil((b+t)/2.0)) # m = the middle index
if ( x == vec[t] ):
b = t-1
scale = 1.0
return b,scale
while ( vec[b+1] <= x ):
if ( vec[b] <= x and x < vec[m] ):
t = m
else:
b = m
m = int(scipy.ceil((b+t)/2.0))
scale = (x - vec[b])/(vec[b+1] - vec[b])
return b,scale
def __getitem__(self, x):
b,scale = self.toIndex(x, self.xValue)
return self.yValue[b]*(1.0 - scale) + self.yValue[b+1]*scale
class ReadVegTable1D(object):
def __init__(self):
pass
def read(self, filename, modelType, species):
try:
data = pandas.read_excel(filename, modelType, index_col=None )
xValue = list( data.ix[:,0] )
yValue = list( data[species] )
return {'elvValue':xValue, 'rate':yValue}
except exceptions.IOError as error:
errorMessage = 'ReadVegTable1D: Error: Could not open file for reading : ' + filename + '\n'
errorMessage += 'ReadVegTable1D: Error: Addition error info : ' + str(error) + '\n'
raise exceptions.RuntimeError(errorMessage)
except xlrd.biffh.XLRDError as error:
errorMessage = 'ReadVegTable1D: Error: Could not find sheet named ' + modelType + ' in file ' + filename + '\n'
errorMessage += 'ReadVegTable1D: Error: Additional error info : ' + str(error) + '\n'
raise exceptions.RuntimeError(errorMessage)
except exceptions.KeyError as error:
errorMessage = 'ReadVegTable1D: Error: Could not find species named ' + species + ' in sheet ' + modelType + ' in file ' + filename +'\n'
errorMessage += 'ReadVegTable1D: Error: Additional error info : ' + str(error) + '\n'
raise exceptions.RuntimeError(errorMessage)
class Function2DFast(object):
def __init__(self, xValue, yValue, data):
# xValue = wave amplitudes
# yValue = mean salinity
# data = senescence and growth rates
if ( len(yValue) != numpy.size(data, 0) ):
msg = 'Function2DFast: Error: number of elements in yValue must match number of rows in data'
msg += ' len(yValue) = ' + str(len(yValue)) + ' data.shape = ' + str(data.shape)
raise exceptions.RuntimeError(msg)
if ( len(xValue) != numpy.size(data, 1) ):
msg = 'Function2DFast: Error: number of elements in xValue must match number of columns in data'
msg += ' len(xValue) = ' + str(len(Value)) + ' size(data) = ' + str(data.shape)
raise exceptions.RuntimeError(msg)
self.xValue = xValue
self.yValue = yValue
self.data = data
def toIndex(self, x, vec):
if ( x < vec[0] or vec[-1] < x ):
msg = 'Function2DFast: Error: x out of range\n'
msg += 'x = ' + str(x) + '\n'
msg += 'vec[0] = ' + str(vec[0]) + '\n'
msg += 'vec[-1] = ' + str(vec[-1]) + '\n'
raise exceptions.RuntimeError(msg)
b = 0 # b = the "bottom" index
t = len(vec)-1 # t = the "top" index
m = int(scipy.ceil((b+t)/2.0)) # m = the middle index
if ( x == vec[t] ):
b = t-1
scale = 1.0
return b,scale
while ( vec[b+1] <= x ):
if ( vec[b] <= x and x < vec[m] ):
t = m
else:
b = m
m = int(scipy.ceil((b+t)/2.0))
scale = (x - vec[b])/(vec[b+1] - vec[b])
return b,scale
def __getitem__(self, item):
i, i_scale = self.toIndex(item[0], self.xValue)
j, j_scale = self.toIndex(item[1], self.yValue)
x0 = self.data[j ,i] * (1.0 - i_scale) + self.data[j ,i+1]*i_scale
x1 = self.data[j+1,i] * (1.0 - i_scale) + self.data[j+1,i+1]*i_scale
return x0*(1.0 - j_scale) + x1*j_scale
class Function2D(object):
def __init__(self, xValue, yValue, data = 0):
# xValue = wave amplitudes
# yValue = mean salinity
# data = senescence and growth rates
if len(yValue) != numpy.size(data, 0):
msg = 'Function2D: Error: number of elements in yValue must match number of rows in data'
msg += ' len(yValue) = ' + str(len(yValue)) + ' data.shape = ' + str(data.shape)
raise exceptions.RuntimeError(msg)
if len(xValue) != numpy.size(data, 1):
msg = 'Function2D: Error: number of elements in xValue must match number of columns in data'
msg += ' len(xValue) = ' + str(len(Value)) + ' size(data) = ' + str(data.shape)
raise exceptions.RuntimeError(msg)
self.point = numpy.array( [ [x,y] for y in yValue for x in xValue ] )
self.value = numpy.array( [elt for row in data for elt in row] )
self.minX = min( xValue )
self.maxX = max( xValue )
self.minY = min( yValue )
self.maxY = max( yValue )
def __getitem__(self, item):
if ( item[0] < self.minX or self.maxX < item[0] ):
raise exceptions.RuntimeError('Function2D: Error: x coordinate out of range. ' + str(item[0]) + ' not in ' + '[ ' + str(self.minX) + ', ' + str(self.maxX) + ' ]' )
if ( item[1] < self.minY or self.maxY < item[1] ):
raise exceptions.RuntimeError('Function2D: Error: y coordinate out of range. ' + str(item[1]) + ' not in ' + '[ ' + str(self.minY) + ', ' + str(self.maxY) + ' ]' )
return interp.griddata(self.point, self.value, ([item[0]],[item[1]] ), method='linear')[0]
class ReadVegTable2D(object):
def __init__(self):
pass
def read(self, filename, species):
try:
data = pandas.read_excel(filename, species, index_col=None, parse_cols=range(1,23), skiprows=1)
waValue = data.columns.values.tolist()[1:len(data.columns)]
spcode = data.columns.values.tolist()[0]
salValue = data[spcode].tolist()
rate = numpy.asarray(data)[:,1:22]
return {'spcode':spcode, 'waValue':waValue, 'salValue':salValue, 'rate':rate }
except exceptions.IOError as error:
errorMessage = 'ReadVegTable2D: Error: Could not open file for reading : ' + filename + '\n'
errorMessage += 'ReadVegTable2D: Error: Addition error info : ' + str(error) + '\n'
raise exceptions.RuntimeError(errorMessage)
except xlrd.biffh.XLRDError as error:
errorMessage = 'ReadVegTable2D: Error: Could not find sheet named ' + species + ' in file : ' + filename + '\n'
errorMessage += 'ReadVegTable2D: Error: Addition error info : ' + str(error) + '\n'
raise exceptions.RuntimeError(errorMessage)

File diff suppressed because it is too large Load Diff

86
LAVegMOD_DM/landscape.py Normal file
View File

@ -0,0 +1,86 @@
#!/usr/bin/env python
# STD Python modules
# import exceptions
# import StringIO
import copy
import exceptions
import numpy
import re
# Third party modules
import pandas
# Model modules
import event
__author__ = 'sdukesy'
class Landscape(object):
def __init__(self):
self.data = None
self.columns = None
def copy(self, obj):
self.data = copy.deepcopy(obj.data)
def read_from_stream(self, stream, numLocs=None):
if self.data is None or stream.tell() == 0:
self.data = pandas.read_csv(stream, nrows=numLocs)
self.columns = copy.copy(self.data.columns)
else:
self.data = pandas.read_csv(stream, header=0, names=self.data.columns, nrows=numLocs)
try:
self.data.set_index('CellID', inplace=True)
except exceptions.ValueError:
errMsg = 'Landscape: Error: ValueError exception raised while reading from stream.\n'
errMsg += 'Landscape: Error: I think this means that CellID is not defined in the file\n'
errMsg += 'Landscape: Error: being read. Check on that and try again.\n'
errMsg += 'Landscape: Error: Note that spaces matter, which is kind of annoying, but there it is.'
raise exceptions.RuntimeError(errMsg)
#if not('CELLID' in self.data.columns):
# msg = 'Landscape: Error: Could not find index column \"CELLID\" in input data.\n'
# msg += 'Landscape: Error: This is needed to make things work. Fix it and come back later.\n'
# raise exceptions.RuntimeError(msg)
def iterlocs(self):
return self.data.iterrows()
def write_to_stream(self, stream, header=True, time=None):
self.data.to_csv(stream, index=False, header=header)
def __getitem__(self, cellID):
return self.data.loc[int(cellID)]
def __str__(self):
return 'Landscape.__str__() not implemented'
class WriteLandscape(event.Event):
def __init__(self, time=(0,0), name='WriteLandscape', landscape=None, stream = None, header=True):
event.Event.__init__(self, time, name)
self.landscape = landscape
self.stream = stream
self.header = header
def write(self, stream, landscape, header=True, time=None):
landscape.write_to_stream(stream, header, time)
def act(self):
print( self.name)
self.write(self.stream, self.landscape, self.header, self.time.time)
class ReadLandscape(event.Event):
def __init__(self, time=(0,0), name='ReadLandscape', landscape = None, stream = None, numLocs = None):
event.Event.__init__(self, time, name)
self.landscape = landscape
self.stream = stream
self.numLocs = numLocs
def read(self, stream, landscape, numLocs = None):
landscape.read_from_stream(stream, numLocs)
def act(self):
print(self.name)
self.read(self.stream, self.landscape, self.numLocs)

154
LAVegMOD_DM/lavegmod.py Normal file
View File

@ -0,0 +1,154 @@
#!/usr/bin/env python
##\mainpage
##
##\section Introduction
## This is the code for the vegetation module for the Louisiana
## Master Plan Modeling 2017 project: LAVegMod version 3.0.
##
## This model is a direct successor to LAVegMod version 1.0 that
## was used for the Master Plan Modeling 2012.
##
##\section Doc Documentation conventions
## I have used a number of conventions while documenting the
## model.
##
##\subsection CommonClassFeatures Common Class Features
## There are a number of features that are common throughout
## this model. These features are required by the Python
## programming language. These features represent coding elements
## that are needed to make a program function correctly. However,
## the do not really contain any information about how the model
## captures the ecology of wetland plant communities. I have chosen
## to omit a detailed description of these elements. This keeps the
## documentation focused on the important parts of the model without
## getting bogged down in the peculiarities of Python or programming
## in general.
##
## The coding elements that will not receive detailed descriptions are:
## - self
## The keyword "self" occurs everywhere in python code. This variable
## name is used as on objects reference to itself. This is a common
## concept in object oriented programming, and is equivalent to the
## key work "this" used in C++.
##
## "self" is always the first argument to any class function. However,
## only rarely does self have to be explicitly passed as an argument to
## a member function.
##
## - "__init__"(self)
## This is the name of a class constructor. Evey Python class has
## __init__(self) defined, whether you define it explicitly or not.
## I always define __init__(self) explicitly. The job of the constructor
## is to bring an object instantiated from a class up to a defined, initial
## state as soon as it is created.
##
## Sometimes you will see the constructor defined with additional arguments
## such as __init__(self, x, y, z). In these cases the constructor takes
## three arguments. That's all. Nothing more special than that.
##
##
##\subsection MemFnc Member functions
## For each member function I have documented the arguments
## that are passed to the function as well as the expected type
## , and where appropriate, the units of an argument. By "type"
## I mean the data type used to store values. Typical types
## include int, float, string, class, list, etc ... A variable
## of type "int" is an integer, that is a whole number with no
## fractional part. A "float" is a real number that may have a
## fractional part. That is, values to the right of the decimal
## place. So the number 1 is an integer, while 1.0 and 3.14159265 are
## both considered floats.
##
## Strings are used to contain words, such as "cat" or "Phragmites australis".
##
## Classes are python classes.
##
## List is used to indicate a python list.
##
## For more information about types please see the python documentation.
##
## Units describes the physical units that the values should be converted to
## before the values are passed to the function. For many variables, there is
## no sense of units. For example, a string such as "PHAU" does not have units.
## In these cases, the units are listed as "None".
##
##
##
##\section History
## Verison 1.0 of LAVegMod was originally developed using two programming
## languages. C++ was used for the core model that carried out the actual
## simulation of plant community dynamics. Around this core a set of R
## script was developed to covert input data into a file format that
## the C++ code could handle easily.
##
## As part of the MPM 2017 project, the LAVegMod was extensively modified
## and a number of features added. This formed version 2.0 of the LAVegMod
## A more complete discussion of these
## changes will be available in a report made to TWIG and CPRA.
##
## To facilitate a complete integration of the LAVegMod into an
## automated suite of models the LAVegMod has been translated into
## Python v2.8
##
##\section Authors Authors/Contributers
## __Model design__:
## - Jenneke Visser - University of Louisiana at Lafayette
## - Scott M. Duke-Sylvester - University of Louisiana at Lafayette
##
## __Python code__: Scott Duke-Sylvester - University of Louisiana at Lafayette
##
## __Model documentation__: Scott Duke-Sylvester - University of Louisiana at Lafayette
##
##\section Sponsors Sponsors
## This code is sponsored by the State of Louisiana as part of its on
## going efforts to perserve and manage Louisana's the unique coastal wetland ecosystems.
## Funding is provided by CPRA and the overall Master Plant Modeling project is managed by
## The Water Institute of the Gulf.
##
##
##\section Licence
## Copyright Scott M. Duke-Sylvester, Jenneke Visser, The University of Louisiana at Lafayette, The Water Institute of the Gulf, Louisiana Coastal Protection and Restoration Authority
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##\file
# This is the top most file in the run-time heierarchy and is the
# file that should be called from the command line to run the model.
# The command line call should look like:
# > lavegmod.py <config>
# where <config> is the name of a model configuration file.
#
#
#
# STD Python modules
import cProfile
import sys
# model modules
import config
import model
##\brief Program entry point
##\details This is the first function that is called when you
# run lavegmod.py
def main(argv):
configDict = config.Config()
configDict.config(argv)
mod = model.Model()
return mod.run()
#cProfile.run('main()', filename='cProfile_output.txt')
main(sys.argv)

View File

@ -0,0 +1,30 @@
RunType = Run // Default
// RunType = ConfigOnly
// RunType = ConfigAndReport
// RunType = Test
// RunType = ReadConfigOnly
// Verbose = TRUE
StartYear = 2010
EndYear = 2011
InitialConditionFile = ./initial_veg/MB_B272ft_v7b_veg.csv
EstFilename = LaVegMod2_Establishment_Tables_v14.xlsx
MortFilename = LaVegMod2_Mortality_Tables_v14.xlsx
HydrologyFile = ./hyd_input/LaVeg_input_TO27_combined_for_year_2010.csv
OutputFile = ./veg_output/MB_B272ft_v7b_veg.csv
OutputTemplate = ./veg_output/MB_B272ft_v7b_veg_<YEAR>.csv
Intercept = 1.83
Temp = -0.03731
Sal = -0.07766
Depth = -0.0002588
// YEAR = year
// CELLID = CellID
// SAL = mean(sal_year)
// WAVEAMP = std(dep_year)
// SUMMERWD = mean(dep_summer)
// SUMMERSAL = mean(sal_summer)
// SUMMERTEMP= mean(temp_summer)

1435
LAVegMOD_DM/model.py Normal file

File diff suppressed because it is too large Load Diff

8
Mendeley/.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

7
Mendeley/.idea/misc.xml Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 2.7 (Mendeley)" project-jdk-type="Python SDK" />
</project>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Mendeley.iml" filepath="$PROJECT_DIR$/.idea/Mendeley.iml" />
</modules>
</component>
</project>

8
NTC_DFM/.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 3.8 (D3DFM)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

4
NTC_DFM/.idea/misc.xml Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8 (D3DFM)" project-jdk-type="Python SDK" />
</project>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/NTC_DFM.iml" filepath="$PROJECT_DIR$/.idea/NTC_DFM.iml" />
</modules>
</component>
</project>

453
NTC_DFM/NTC_DFM.ipynb Normal file

File diff suppressed because one or more lines are too long

16
NTC_DFM/main.py Normal file
View File

@ -0,0 +1,16 @@
# This is a sample Python script.
# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
def print_hi(name):
# Use a breakpoint in the code line below to debug your script.
print(f'Hi, {name}') # Press Ctrl+F8 to toggle the breakpoint.
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
print_hi('PyCharm')
# See PyCharm help at https://www.jetbrains.com/help/pycharm/

8
SaintJohn/.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="PyDocumentationSettings">
<option name="renderExternalDocumentation" value="true" />
</component>
</module>

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

7
SaintJohn/.idea/misc.xml Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8 (SaintJohn)" project-jdk-type="Python SDK" />
</project>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/SaintJohn.iml" filepath="$PROJECT_DIR$/.idea/SaintJohn.iml" />
</modules>
</component>
</project>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PySciProjectComponent">
<option name="PY_SCI_VIEW" value="true" />
<option name="PY_SCI_VIEW_SUGGESTED" value="true" />
</component>
</project>

99
SaintJohn/Halifax.py Normal file
View File

@ -0,0 +1,99 @@
### Halifax Wind Speed Processing Code
# Alexander Rey, June 30, 2020
import pandas as pd
import datetime
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import scipy as sc
import statsmodels.api as sm
# %% Import Wind Speed CSV
# halifax_in = pd.read_csv("C:/Users/arey/files/Projects/St_John/2200233.csv",
# index_col='DATE', parse_dates=True, low_memory=False)
halifax_in = pd.read_csv("C:/Users/arey/files/Projects/St_John/2200284.csv",
index_col='DATE', parse_dates=True, low_memory=False)
halifax_in_split = halifax_in["WND"].str.split(",", n=5, expand=True)
halifax_in.drop(columns=["WND"], inplace=True)
halifax_in["WND0"] = halifax_in_split[0]
halifax_in["WND1"] = halifax_in_split[1]
halifax_in["WND2"] = halifax_in_split[2]
halifax_in["WND3"] = halifax_in_split[3]
halifax_in["WND4"] = halifax_in_split[4]
halifax_offshore = halifax_in[['WND0', 'WND3']].loc[halifax_in['STATION'] == 99539099999]
halifax_offshore['WND0'] = pd.to_numeric(halifax_offshore['WND0'])
halifax_offshore['WND3'] = pd.to_numeric(halifax_offshore['WND3'])
halifax_offshore = halifax_offshore[halifax_offshore.WND3 != 9999]
halifax_offshore = halifax_offshore[halifax_offshore.WND0 != 999]
halifax_offshore = halifax_offshore.reindex(pd.date_range(start='2002-01-01',
end='2008-12-31',
freq='1h'))
halifax_offshore['WND0'] = halifax_offshore['WND0'].interpolate(method='nearest',limit_area='inside',limit=24)
halifax_offshore['WND3'] = halifax_offshore['WND3'].interpolate(method='linear',limit_area='inside',limit=24)
# halifax_offshore = halifax_offshore.loc['2004-08-31':'2018-11-29']
halifax_jetty = halifax_in[['WND0', 'WND3']].loc[halifax_in['STATION'] == 71601599999] # 1601599999
halifax_jetty['WND0'] = pd.to_numeric(halifax_jetty['WND0'])
halifax_jetty['WND3'] = pd.to_numeric(halifax_jetty['WND3'])
halifax_jetty = halifax_jetty[halifax_jetty.WND3 != 9999]
halifax_jetty = halifax_jetty[halifax_jetty.WND0 != 999]
# halifax_mcnabs = halifax_mcnabs.loc['2004-08-31':'2018-11-29']
halifax_jetty = halifax_jetty.reindex(pd.date_range(start='2002-01-01',
end='2008-12-31',
freq='1h'))
halifax_jetty['WND0'] = halifax_jetty['WND0'].interpolate(method='nearest',limit_area='inside',limit=24)
halifax_jetty['WND3'] = halifax_jetty['WND3'].interpolate(method='linear',limit_area='inside',limit=24)
#% Ignore Missing in Either
offshore_null = halifax_offshore.WND0.isnull()
jetty_null = halifax_jetty.WND0.isnull()
halifax_jetty = halifax_jetty[(offshore_null==False) & (jetty_null==False)]
halifax_offshore = halifax_offshore[(offshore_null==False) & (jetty_null==False)]
# %% Make QQ plot
plt.figure()
# sm.qqplot_2samples(halifax_jetty['WND3'].loc[halifax_offshore['WND0'].isin([110, 170])]/10,
# halifax_offshore['WND3'].loc[halifax_offshore['WND0'].isin([110, 170])]/10,
# line='r',ylabel='McNabs Island Quantiles',xlabel='Offshore Quantiles')
sm.qqplot_2samples(halifax_jetty['WND3'].loc[halifax_offshore['WND0'].isin([110, 170])]/10,
halifax_offshore['WND3'].loc[halifax_offshore['WND0'].isin([110, 170])]/10,
line='r',ylabel='Shearwater Jetty Quantiles',xlabel='Offshore Quantiles')
# sm.qqplot_2samples(halifax_jetty['WND3'], halifax_offshore['WND3'], line='r', ylabel='Jetty Quantiles',xlabel='Offshore Quantiles')
plt.title('Halifax Wind (Shearwater Jetty) from 110-170 deg 2002-2008')
# plt.title('Halifax Wind (McNabs Island) from 110-170 deg 2002-2008')
plt.plot([0, 20], [0, 20], 'k-')
# plt.xlabel('Offshore Wind Speed (m/s)')
# plt.ylabel('Potash Terminal Wind Speed (m/s)')
# plt.title('St John Wind Speed Comparision July 2016-June 2020')
# plt.title('St John Wind Speed Comparision July 2016-June 2020, 90-180 deg')
# plt.xlim(0, 25)
# plt.ylim(0, 25)
# cmap = plt.get_cmap('hsv')
# norm = plt.Normalize(0, 360)
# color = cmap(norm(200.))
#
# cbar = plt.colorbar()
# cbar.ax.get_yaxis().labelpad = 15
# cbar.ax.set_ylabel('Offshore Wind Direction', rotation=270)
plt.savefig('Halifax_Jetty_110_170.png')
# plt.savefig('St_John_all.png')
plt.show()

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

BIN
SaintJohn/St_John_all.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 158 KiB

131
SaintJohn/stJohn.py Normal file
View File

@ -0,0 +1,131 @@
### St John Wind Speed Processing Code
# Alexander Rey, June 30, 2020
from erddapy import ERDDAP
import pandas as pd
import datetime
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import scipy as sc
import statsmodels.api as sm
# Import Offshore Buoy Data
e = ERDDAP(
server='https://www.smartatlantic.ca/erddap',
protocol='tabledap',
response='csv',
)
# Setup download for the buoy
e.dataset_id = 'SMA_saint_john'
e.constraints = {
'time>=': '2016-07-10T00:00:00Z',
'time<=': '2020-06-01T00:00:00Z',
}
e.variables = [
'time',
'wind_spd_avg',
'wind_dir_avg',
]
buoydat = e.to_pandas(
index_col='time (UTC)',
parse_dates=True,
).dropna()
# Setup download for the warf
e.dataset_id = 'SMA_saint_john_wharf'
e.constraints = {
'time>=': '2016-07-10T00:00:00Z',
'time<=': '2020-06-01T00:00:00Z',
}
e.variables = [
'time',
'wind_spd_avg',
'wind_dir_avg',
]
warfdat = e.to_pandas(
index_col='time (UTC)',
parse_dates=True,
).dropna()
# Setup download for the cruise terminal
e.dataset_id = 'SMA_saint_john_cruise_terminal'
e.constraints = {
'time>=': '2016-12-23T00:00:00Z',
'time<=': '2020-06-01T00:00:00Z',
}
e.variables = [
'time',
'wind_spd_avg',
'wind_dir_avg',
]
cruisedat = e.to_pandas(
index_col='time (UTC)',
parse_dates=True,
).dropna()
### Clean and process data
t_index = pd.date_range(start='2016-07-10T00:00:00Z', end='2020-06-01T00:00:00Z', freq='30Min')
# Set to 30 minute time series
buoy_resample = buoydat.resample('30Min').mean().reindex(t_index)
buoy_resample['wind_spd_avg (m s-1)'] = buoy_resample['wind_spd_avg (m s-1)'].interpolate('linear')
buoy_resample['wind_dir_avg (degree)'] = buoy_resample['wind_dir_avg (degree)'].interpolate('nearest')
warf_resample = warfdat.resample('30Min').mean().reindex(t_index)
warf_resample['wind_spd_avg (m s-1)'] = warf_resample['wind_spd_avg (m s-1)'].interpolate('linear')
warf_resample['wind_dir_avg (degree)'] = warf_resample['wind_dir_avg (degree)'].interpolate('nearest')
cruise_resample = cruisedat.resample('30Min').mean().reindex(t_index)
cruise_resample['wind_spd_avg (m s-1)'] = cruise_resample['wind_spd_avg (m s-1)'].interpolate('linear')
cruise_resample['wind_dir_avg (degree)'] = cruise_resample['wind_dir_avg (degree)'].interpolate('nearest')
# %% Make QQ plot
plt.figure()
# plt.scatter(buoy_resample['wind_spd_avg (m s-1)'], warf_resample['wind_spd_avg (m s-1)'],
# 1,buoy_resample['wind_dir_avg (degree)'],marker='.')
# sm.qqplot_2samples(warf_resample['wind_spd_avg (m s-1)'].loc[buoy_resample['wind_dir_avg (degree)'].isin([150, 220])],
# buoy_resample['wind_spd_avg (m s-1)'].loc[buoy_resample['wind_dir_avg (degree)'].isin([150, 220])],
# line='r',ylabel='Potash Terminal Quantiles',xlabel='Offshore Quantiles')
# plt.title('St John Wind (Potash Terminal) from 160-220 deg July 2016-June 2020')
sm.qqplot_2samples(cruise_resample['wind_spd_avg (m s-1)'].loc[buoy_resample['wind_dir_avg (degree)'].isin([160, 220])],
buoy_resample['wind_spd_avg (m s-1)'].loc[buoy_resample['wind_dir_avg (degree)'].isin([160, 220])],
line='r', ylabel='Cruise Terminal Quantiles', xlabel='Offshore Quantiles')
plt.title('St John Wind (Cruise Terminal) from 160-220 deg Dec 2016-June 2020')
# plt.scatter(buoy_resample['wind_spd_avg (m s-1)'].loc[buoy_resample['wind_dir_avg (degree)'].isin([90, 180])],
# warf_resample['wind_spd_avg (m s-1)'].loc[buoy_resample['wind_dir_avg (degree)'].isin([90, 180])],
# 10, marker='.')
plt.plot([0, 20], [0, 20], 'k-')
# plt.xlabel('Offshore Wind Speed (m/s)')
# plt.ylabel('Potash Terminal Wind Speed (m/s)')
# plt.title('St John Wind Speed Comparision July 2016-June 2020')
# plt.title('St John Wind Speed Comparision July 2016-June 2020, 90-180 deg')
plt.xlim(0, 20)
plt.ylim(0, 20)
# cmap = plt.get_cmap('hsv')
# norm = plt.Normalize(0, 360)
# color = cmap(norm(200.))
#
# cbar = plt.colorbar()
# cbar.ax.get_yaxis().labelpad = 15
# cbar.ax.set_ylabel('Offshore Wind Direction', rotation=270)
plt.savefig('St_John_Cruise_160_220.png')
# plt.savefig('St_John_all.png')
plt.show()