def extract_wx_data(time_obj, wx_path): """ This function was writen to reenstate wx file parsing for tha greed upon NOAA weather data format for any study area within the USA. This is THE function that should be used for reading weather data, the others will not be supported. It expects data in the format as retrieved from this URL: [http://gis.ncdc.noaa.gov/map/viewer/#app=cdo&cfg=cdo&theme=hourly&layers=1&node=gi] Please see the readme for more detailed instructions on data download. Inputs: time_obj A datetime object representing the image data aquisition datetime wx_path filepath to the weather data. (hourly data) Returns: an array with specific ordering of climate variables. """ # format weather (daily and hourly) as a time series object wx = time_series.time_series("wx_data") tdo = textio.read_DS3505(wx_path, has_headers = True) wx.from_tdo(tdo) time_lable = "YR--MODAHRMN" time_format = "%Y%m%d%H%M" start_time = "200001010000" wx.define_time(time_lable, time_format, start_time) # bin the data into days pull out the one we want. wx.make_subsets("%j", cust_center_time = time_obj) day_name = time_obj.strftime("%Y-%m-%d") wx.interrogate() # if it cant find a subset in wx with the input dates name, wx data is for wrong time. try: wx_day = wx[day_name] except: raise Exception("wx data has no entries for date of landsat acquisition ({0})".format(time_obj)) # get min/max temperatures and convert to Celcius (statistical operations clean up NoData) print("Centered statistics around {0}".format(wx_day.center_time)) Tstats = wx_day.column_stats("TEMP") temp_C_min = (Tstats["TEMP_min_v"] - 32) * (5.0/9) # F --> C temp_C_max = (Tstats["TEMP_max_v"] - 32) * (5.0/9) # F --> C # get instantaneous variables at input @param time_obj by interpolating between nearest values temp_C_mid = (wx_day.interp_col(time_obj, "TEMP") - 32) * (5.0/9) # F --> C P_air = wx_day.interp_col(time_obj, "STP" ) # in millibars wind_speed = wx_day.interp_col(time_obj, "SPD" ) * 0.51444 # knots --> meters / second dewp_C = (wx_day.interp_col(time_obj, "DEWP") - 32) * (5.0/9) # F --> C # this format is for legacy support, just an array of values, not a dict. print("Temperature is {0}C".format(temp_C_mid)) return [temp_C_min, temp_C_max, temp_C_mid, P_air, wind_speed, dewp_C]
def get_orm_data_for_report(query_set, time_field, series_range, aggregation = None, func = None, annotate_field = None): """ Function to get data for reports, using django orm for the queries. This function will receive the queryset, the name of the time field to be passed to the time series function, the series range, the aggregation and the function to be passed for aggregation in the time series. """ return time_series.time_series(query_set, time_field, series_range, func, aggregation, annotate_field)
# . estimate optimal parameters: validation phase # - SSE tool # . do forecasting: validation phase ####################################################################################### ####################################################################################### # master parameters for the whole program # fname = './data/AAPL_2015_2016_2017.csv' price = 'adj_close' # do forecasting on the adjusted close price confd = {'1sigma':0.6827, '2sigma':0.9545,'3sigma':0.9973} # confidence intervals CI = '3sigma' # forecast with 3-sigma confidence # Load the whole time series ts = time_series(fname) ####################################################################################### # master parameters for the local modeling framework #day_len = 504 # first 2 years #day_len = 252 # first one year #day_len = 191 # first nine months #day_len = 122 # first six months #day_len = 61 # first three months #day_len = 40 # first two months #day_len = 20 # first month # 5 datasets to estimate the suitable window size in the training-testing phase #day_start = [0,63,126,189,252] day_start = [0,63] day_len = 63