Exemplo n.º 1
0
def run_fire_blight_plots (stn,end_date_dt,firstblossom,orchard_history,output):
	try:
		smry_dict = {}
		smry_dict['biofix_name'] = 'First blossom open'
		daily_data = None
		hourly_data = None
		if not end_date_dt: end_date_dt = DateTime.now()
		start_date_dt = DateTime.DateTime(end_date_dt.year,4,1,0)	
		
		end_date_dt = min(end_date_dt, DateTime.DateTime(end_date_dt.year,6,15,23))

		# firstblossom can either be passed into this program, read from a file, or estimated from degree day accumulation
		if not firstblossom:
			firstblossom = newaModel.Models().get_biofix(stn,'as',end_date_dt.year)					#from file
			if not firstblossom:
				jan1_dt = DateTime.DateTime(end_date_dt.year,1,1)						
				hourly_data, daily_data, download_time, station_name = newaCommon.Base().get_hddata (stn, jan1_dt, end_date_dt)
				biofix_dd = phen_events_dict['macph_firstblossom_43']['dd'][2]					#by degree day accumulation
				ret_bf_date, ddaccum, ddmiss = newaModel.Models().accum_degday(daily_data, jan1_dt, end_date_dt, 'dd43be', biofix_dd, stn, station_name)
				if ret_bf_date: firstblossom = ret_bf_date + DateTime.RelativeDate(hour=23)
					
		smry_dict['biofix'] = "%s-%s-%s" % (firstblossom.year,firstblossom.month,firstblossom.day)
		if firstblossom < start_date_dt: start_date_dt = firstblossom
		if not orchard_history: orchard_history = 2
		smry_dict['orchard_history'] = orchard_history

		# obtain daily data
		if not daily_data:
			hourly_data, daily_data, download_time, station_name = newaCommon.Base().get_hddata (stn, start_date_dt, end_date_dt)
		smry_dict['station_name'] = station_name
		
		# format for plot routine
		obs_dict, smry_dict, dly_forecast_data = tp_for_grf(stn, daily_data, smry_dict, start_date_dt, end_date_dt)
			
		# add hourly forecast data
		start_fcst_dt = DateTime.DateTime(*download_time) + DateTime.RelativeDate(hours = +1)
		end_fcst_dt = end_date_dt + DateTime.RelativeDate(days = +5)
		hourly_data = newaModel.Models().add_hrly_fcst(stn,hourly_data,start_fcst_dt,end_fcst_dt)
		
		if firstblossom and len(hourly_data) > 0:
			# calculate degree hours using Tim Smith's table
			deghr_dict = deghr_for_grf (hourly_data,firstblossom,end_fcst_dt)
		else:
			deghr_dict = []

		# produce plot
		onLoadFunction = "produce_fireblight_graph(%s, %s, %s);" % (smry_dict, obs_dict, deghr_dict)
		return newaGraph_io.apple_disease_plot(onLoadFunction)
	except:
		print_exception()
Exemplo n.º 2
0
def run_apple_scab_plots(stn, end_date_dt, greentip, output):
    try:
        now = DateTime.now()
        smry_dict = {}
        smry_dict['biofix_name'] = 'Greentip'
        daily_data = None
        if not end_date_dt: end_date_dt = now
        start_date_dt = DateTime.DateTime(end_date_dt.year, 3, 15, 0)

        end_date_dt = min(end_date_dt,
                          DateTime.DateTime(end_date_dt.year, 6, 15, 23))

        # greentip can either be passed into this program, read from a file, or estimated from degree day accumulation
        if not greentip:
            greentip = newaModel.Models().get_biofix(
                stn, 'as', end_date_dt.year)  #from file
            if not greentip:
                jan1_dt = DateTime.DateTime(end_date_dt.year, 1, 1)
                daily_data, station_name = newaCommon.Base().get_daily(
                    stn, jan1_dt, end_date_dt)
                biofix_dd = phen_events_dict['macph_greentip_43']['dd'][
                    2]  #by degree day accumulation
                ret_bf_date, ddaccum, ddmiss = newaModel.Models().accum_degday(
                    daily_data, jan1_dt, end_date_dt, 'dd43be', biofix_dd, stn,
                    station_name)
                if ret_bf_date: greentip = ret_bf_date

        smry_dict['biofix'] = "%s-%s-%s" % (greentip.year, greentip.month,
                                            greentip.day)

        # just use observed data (no forecast) in years other than the current
        if end_date_dt.year != now.year:
            this_year = False
            end_date_dt = end_date_dt + DateTime.RelativeDate(days=+6)
        else:
            this_year = True

        # obtain hourly and daily data
        start_date_dt = DateTime.DateTime(end_date_dt.year, 3, 1,
                                          1)  #Leave this March 1
        hourly_data, daily_data, download_time, station_name, avail_vars = newaCommon.Base(
        ).get_hddata2(stn, start_date_dt, end_date_dt)
        smry_dict['station_name'] = station_name

        if this_year:
            # now add the forecast data
            start_fcst_dt = DateTime.DateTime(
                *download_time) + DateTime.RelativeDate(hours=+1)
            end_fcst_dt = end_date_dt + DateTime.RelativeDate(days=+6)
            hourly_data = newaModel.Models().add_hrly_fcst(
                stn, hourly_data, start_fcst_dt, end_fcst_dt, True)
            daily_data = newaModel.Apple().hrly_to_dly(hourly_data)
        else:
            start_fcst_dt = end_date_dt + DateTime.RelativeDate(hours=+1)
            end_fcst_dt = end_date_dt

        # format for plot routine
        if greentip:
            start_date_grf = greentip + DateTime.RelativeDate(days=-6)
        else:
            start_date_grf = start_date_dt
        obs_dict = tp_for_grf2(daily_data, start_date_grf, start_fcst_dt,
                               this_year)

        # calculate base 0C degree days for ascospore maturity
        if greentip:
            dd_data = newaCommon.Base().degday_calcs(daily_data, greentip,
                                                     end_fcst_dt, 'dd0c',
                                                     'prcp')
        else:
            dd_data = []

        if len(dd_data) > 0:
            # calculate ascospore maturity and format for plotting
            ascospore_dict = ascospore_for_grf(dd_data, daily_data)
        else:
            ascospore_dict = {}
            ascospore_dict['dates'] = []
            ascospore_dict['maturity'] = []
            ascospore_dict['error'] = []

        # produce plot
        onLoadFunction = "produce_applescab_graph(%s, %s, %s);" % (
            smry_dict, obs_dict, ascospore_dict)
        return newaGraph_io.apple_disease_plot(onLoadFunction)
    except:
        print_exception()
Exemplo n.º 3
0
def run_fire_blight_plots(stn, end_date_dt, firstblossom, orchard_history,
                          output):
    try:
        smry_dict = {}
        smry_dict['biofix_name'] = 'First blossom open'
        daily_data = None
        hourly_data = None
        if not end_date_dt: end_date_dt = DateTime.now()
        start_date_dt = DateTime.DateTime(end_date_dt.year, 4, 1, 0)

        end_date_dt = min(end_date_dt,
                          DateTime.DateTime(end_date_dt.year, 6, 15, 23))

        # firstblossom can either be passed into this program, read from a file, or estimated from degree day accumulation
        if not firstblossom:
            firstblossom = newaModel.Models().get_biofix(
                stn, 'as', end_date_dt.year)  #from file
            if not firstblossom:
                jan1_dt = DateTime.DateTime(end_date_dt.year, 1, 1)
                hourly_data, daily_data, download_time, station_name = newaCommon.Base(
                ).get_hddata(stn, jan1_dt, end_date_dt)
                biofix_dd = phen_events_dict['macph_firstblossom_43']['dd'][
                    2]  #by degree day accumulation
                ret_bf_date, ddaccum, ddmiss = newaModel.Models().accum_degday(
                    daily_data, jan1_dt, end_date_dt, 'dd43be', biofix_dd, stn,
                    station_name)
                if ret_bf_date:
                    firstblossom = ret_bf_date + DateTime.RelativeDate(hour=23)

        smry_dict['biofix'] = "%s-%s-%s" % (
            firstblossom.year, firstblossom.month, firstblossom.day)
        if firstblossom < start_date_dt: start_date_dt = firstblossom
        if not orchard_history: orchard_history = 2
        smry_dict['orchard_history'] = orchard_history

        # obtain daily data
        end_fcst_dt = end_date_dt + DateTime.RelativeDate(
            days=+6) + DateTime.RelativeDate(hour=23, minute=0, second=0)
        if not daily_data:
            hourly_data, daily_data, download_time, station_name = newaCommon.Base(
            ).get_hddata(stn, start_date_dt, end_fcst_dt)
        smry_dict['station_name'] = station_name

        # format for plot routine
        obs_dict, smry_dict, dly_forecast_data = tp_for_grf(
            stn, daily_data, smry_dict, start_date_dt, end_date_dt)

        # add hourly forecast data
        start_fcst_dt = DateTime.DateTime(
            *download_time) + DateTime.RelativeDate(hours=+1)
        if end_fcst_dt >= start_fcst_dt:
            hourly_data = newaModel.Models().add_hrly_fcst(
                stn, hourly_data, start_fcst_dt, end_fcst_dt)

        if firstblossom and len(hourly_data) > 0:
            # calculate degree hours using Tim Smith's table
            deghr_dict = deghr_for_grf(hourly_data, firstblossom, end_fcst_dt)
        else:
            deghr_dict = []

        # produce plot
        onLoadFunction = "produce_fireblight_graph(%s, %s, %s);" % (
            smry_dict, obs_dict, deghr_dict)
        return newaGraph_io.apple_disease_plot(onLoadFunction)
    except:
        print_exception()
Exemplo n.º 4
0
def run_apple_scab_plots (stn,end_date_dt,greentip,output):
	try:
		now = DateTime.now()
		smry_dict = {}
		smry_dict['biofix_name'] = 'Greentip'
		daily_data = None
		if not end_date_dt: end_date_dt = now
		start_date_dt = DateTime.DateTime(end_date_dt.year,3,15,0)	

		end_date_dt = min(end_date_dt, DateTime.DateTime(end_date_dt.year,6,15,23))

		# greentip can either be passed into this program, read from a file, or estimated from degree day accumulation
		if not greentip:
			greentip = newaModel.Models().get_biofix(stn,'as',end_date_dt.year)					#from file
			if not greentip:
				jan1_dt = DateTime.DateTime(end_date_dt.year,1,1)						
				daily_data, station_name = newaCommon.Base().get_daily (stn, jan1_dt, end_date_dt)
				biofix_dd = phen_events_dict['macph_greentip_43']['dd'][2]					#by degree day accumulation
				ret_bf_date, ddaccum, ddmiss = newaModel.Models().accum_degday(daily_data, jan1_dt, end_date_dt, 'dd43be', biofix_dd, stn, station_name)
				if ret_bf_date: greentip = ret_bf_date
					
		smry_dict['biofix'] = "%s-%s-%s" % (greentip.year,greentip.month,greentip.day)
		
		# just use observed data (no forecast) in years other than the current
		if end_date_dt.year != now.year:
			this_year = False
			end_date_dt = end_date_dt + DateTime.RelativeDate(days = +6)
		else:
			this_year = True

		# obtain hourly and daily data
		start_date_dt = DateTime.DateTime(end_date_dt.year,3,1,1)	#Leave this March 1			
		hourly_data, daily_data, download_time, station_name, avail_vars = newaCommon.Base().get_hddata2 (stn, start_date_dt, end_date_dt)
		smry_dict['station_name'] = station_name
		
		if this_year:
			# now add the forecast data
			start_fcst_dt = DateTime.DateTime(*download_time) + DateTime.RelativeDate(hours = +1)
			end_fcst_dt = end_date_dt + DateTime.RelativeDate(days = +6)
			hourly_data = newaModel.Models().add_hrly_fcst(stn,hourly_data,start_fcst_dt,end_fcst_dt,True)
			daily_data = newaModel.Apple().hrly_to_dly(hourly_data)
		else:
			start_fcst_dt = end_date_dt + DateTime.RelativeDate(hours = +1)
			end_fcst_dt = end_date_dt
		
		# format for plot routine
		if greentip:
			start_date_grf = greentip + DateTime.RelativeDate(days = -6)
		else:
			start_date_grf = start_date_dt
		obs_dict = tp_for_grf2(daily_data, start_date_grf, start_fcst_dt, this_year)
			
		# calculate base 0C degree days for ascospore maturity
		if greentip:
			dd_data = newaCommon.Base().degday_calcs(daily_data,greentip,end_fcst_dt,'dd0c','prcp')
		else:
			dd_data = []
		
		if len(dd_data) > 0:
			# calculate ascospore maturity and format for plotting
			ascospore_dict = ascospore_for_grf(dd_data,daily_data)
		else:
			ascospore_dict = {}
			ascospore_dict['dates'] = []
			ascospore_dict['maturity'] = []
			ascospore_dict['error'] = []

		# produce plot
		onLoadFunction = "produce_applescab_graph(%s, %s, %s);" % (smry_dict, obs_dict, ascospore_dict)
		return newaGraph_io.apple_disease_plot(onLoadFunction)
	except:
		print_exception()