def plot_map_pred_fish(self, model, year, rtime, fitdir, movdir, gname, figname): fig, ax = self.draw_water_and_polys() survey_dates = self.get_survey_dates(year) nsurveys = len(survey_dates) self.set_fate_to_number(movdir, gname, rtime) # fairly hardwired method pred_data = self.get_pred_fish(fitdir, gname, rtime, survey_dates) barxy = self.findSiteLoc(self.fates) barboxsize = [10000., 10000.] leg_args = { 'ylabel': 'Abundance', 'bars': ['January', 'February', 'March'], 'max': max_ab } map_w_bars.plot_bars(ax, fig, pred_data, barxy, barboxsize, self.xylims, leg_args, frac=False) plt.savefig(figname, dpi=900, facecolor='white', bbox_inches='tight') plt.close() plt.clf() return
def plot_map_pred(self, model, year, gname, figname): fig, ax = self.draw_water_and_polys() survey_dates = self.get_survey_dates(year) nsurveys = len(survey_dates) pred_data, count_polys = self.get_pred(gname, model, survey_dates) barxy = self.findSiteLoc(count_polys) barboxsize = [10000., 10000.] leg_args = { 'ylabel': 'Fraction', 'bars': ['January', 'February', 'March'], 'max': max_ab } map_w_bars.plot_bars(ax, fig, pred_data, barxy, barboxsize, self.xylims, leg_args, frac=True) plt.savefig(figname, dpi=900, facecolor='white', bbox_inches='tight') plt.close() plt.clf() return
def plot_map_obs_pred(self, year, month, scenarios, labels, figname): fig, ax = self.draw_water_and_polys() ngroups = len(labels) # get bardata (fraction in each region) for survey periods survey_dates = self.get_survey_dates(year) pred_data = {} for label in labels: scenario = scenarios[label] # read predicted counts gname = scenario['group_name'] rdir = scenario['run_dir'] model = scenario['model'] pred_data[label], count_polys = self.get_pred(gname, model, survey_dates, rdir=rdir) barxy = self.findSiteLoc(count_polys) obs_data, obs_polys = self.get_obs_data(year) # reorder obs_data to match order of count_polys obs_data_frac = np.zeros_like(pred_data[labels[0]]) obs_total = np.sum(obs_data, axis=0) for npol, poly in enumerate(obs_polys): n = count_polys.index(poly) obs_data_frac[n, :] = np.divide(obs_data[npol, :], obs_total) survey = month_to_survey[month] bardata = np.zeros((len(count_polys), ngroups + 1), np.float64) # first bar is observed counts bardata[:, 0] = obs_data_frac[:, survey] for nl, label in enumerate(labels): bardata[:, nl + 1] = pred_data[label][:, survey] barboxsize = [10000., 10000.] leg_args = { 'ylabel': 'Fraction', 'bars': ['Observed'] + labels, 'max': max_ab } map_w_bars.plot_bars(ax, fig, bardata, barxy, barboxsize, self.xylims, leg_args, frac=True) plt.savefig(figname, dpi=900, facecolor='white', bbox_inches='tight') plt.close() plt.clf() return
def plot_map_obs(self, longfile_path, figname, size_range, Surveys, normalize=False): ''' Creates a bar plot of the Abundance for a particular year. many surveys is untested and may look really ugly. Consider keeping 9 surveys max. ''' self.obs_df = pd.read_csv(longfile_path, parse_dates=True) fig, ax = self.draw_water_and_polys() bars = [] for num in Surveys: bars.append('Survey {0}'.format(num)) barboxsize = [10000., 10000.] #determines size of plots. Don't touch. leg_args = {'ylabel': 'Density', 'bars': bars, 'max': ''} if leg_args['ylabel'] == 'Density': leg_args['max'] = self.max_den[self.year] elif leg_args['ylabel'] == 'Abundance': leg_args['max'] = self.max_ab[self.year] plt.title('Observed {0} {1}'.format(leg_args['ylabel'], self.year)) # read observed counts obs_data = self.get_obs_data(self.year, Surveys, size_range) if leg_args['ylabel'] == 'Density': obs_data = self.Abun_to_Density_Bar( obs_data) #convert abundance data to density barxy = self.findSiteLoc(self.poly_names) #get xy for each site labels = self.findNoBarData( Surveys, self.year) #find correct labels for surveys with no data map_w_bars.plot_bars(ax, fig, obs_data, barxy, barboxsize, self.xylims, leg_args, frac=False, labels=labels) figname = '_'.join([ figname, str(self.year), '{0}mm-{1}mm.png'.format(size_range[0], size_range[1]) ]) plt.savefig(figname, dpi=900, facecolor='white', bbox_inches='tight') plt.close() plt.clf() return
def plot_map_obs_pred_fish(self, obs_file, model, year, rtime, fitdir, movdir, gname, figname): reg_ab = fit_results.load_obs_regional_abundance(obs_file) fig, ax = self.draw_water_and_polys() survey_dates = self.get_survey_dates(year) nsurveys = len(survey_dates) self.set_fate_to_number(movdir, gname, rtime) # fairly hardwired method pred_data = self.get_pred_fish(fitdir, gname, rtime, survey_dates) bardata = np.zeros((len(pred_data), nsurveys * 2), np.float64) #bardata = np.ones((len(pred_data),nsurveys*2),np.float64)*np.nan for nsur in range(nsurveys): bardata[:, nsur * 2 + 1] = pred_data[:, nsur] for nreg, pred in enumerate(pred_data): if nreg < len(reg_ab): # can't set obs seaward loss or entrain bardata[nreg, nsur * 2] = reg_ab[nreg, nsur] # for nreg, pred in enumerate(pred_data): # bardata[nreg*2,:] = pred_data[nreg,:] # if nreg < len(reg_ab): # can't set observed seaward loss or entrain # bardata[nreg*2+1,:] = reg_ab[nreg,:] barxy = self.findSiteLoc(self.fates) barboxsize = [10000., 10000.] barboxsize = [10000., 8000.] leg_args = { 'ylabel': 'Abundance', 'bars': ['January', 'February', 'March'], 'max': max_ab } map_w_bars.plot_bars(ax, fig, bardata, barxy, barboxsize, self.xylims, leg_args, frac=False, alt_hatch=True) # x out losses and entrain for obs (15 and 16)? plt.savefig(figname, dpi=900, facecolor='white', bbox_inches='tight') plt.close() plt.clf() return
def plot_map_obs_fish(self, obs_file, year, movdir, gname, rtime, figname): reg_ab = fit_results.load_obs_regional_abundance(obs_file) nreg = len(reg_ab) fig, ax = self.draw_water_and_polys() survey_dates = self.get_survey_dates(year) nsurveys = len(survey_dates) self.set_fate_to_number(movdir, gname, rtime) # fairly hardwired method barxy = self.findSiteLoc(self.fates[:nreg]) barboxsize = [10000., 10000.] barboxsize = [10000., 8000.] leg_args = { 'ylabel': 'Abundance', 'bars': ['January', 'February', 'March'], 'max': max_ab } map_w_bars.plot_bars(ax, fig, reg_ab, barxy, barboxsize, self.xylims, leg_args, frac=False, alt_hatch=False) # x out losses and entrain for obs (15 and 16)? plt.savefig(figname, dpi=900, facecolor='white', bbox_inches='tight') plt.close() plt.clf() return