Example #1
0
 def make_Cohort_BoxWhisker(self,
                            Data_dir,
                            data_files,
                            Var,
                            Log=False,
                            datatype=None,
                            max=0.,
                            Fishtype='Longfin Smelt'):
     '''
     UNDER CONSTRUCTION DO NOT USE
     
     Creates boxwhisker plots for properly set up data. Instead of coming from trawl observed data,
     data is post processed into csv files containing the q5, q25, q50, q75, and q95 (q meaning quantile)
     statistics. These values are used for creating boxwhisker plots.
     q5 = 5% quantile, bottom whisker
     q25 = 25% quantile, bottom of the box
     q50 = 50% quantile, middle of the box
     q75 = 75% quantile, top of the box
     q95 = 95% quantile, top whisker
     
     The Data acts as a direct comparison of Observed data from collected surveys to computed values.
     
     
     variable controls including chronological and Log scaling. If Chronological, user must include a pairing trawl csv file that contains
     dates for each survey and region.
     
     Inputs:
     Data_Dir: path to directory where data exists.
     data_files: list of data file names. Include full name.
                     example: ['test1.csv', 'test2.csv']
     Var: plot type variable. Abundance or Density
     Chronological: Boolean to turn on Chronological plotting.
                    If True, bars are ordered by the survey date, not the load order
     Chronological_data: list set of data to correspond with the trawl data. Only needed if Chronological is passed in as True
     Log: Plots data with a log scale instead of a true scale. Can make data with a large variation easier to view. 
     Cohorts: number of cohorts to use. Maybe use list of data sources?
     Max: set a max value used for plotting. Otherwise use the highest q50 value.
     '''
     #         cohorts = self.Surveys
     for i, cohort_file in enumerate(data_files):
         cohort = i + 1
         print 'Creating Plot for Cohort {0}...'.format(cohort)
         self.Groups = range(cohort, self.Groups[-1] + 1)
         bw_data = DataManager(self.Map_Utils.poly_names, self.Year,
                               self.Sizes, 'Boxwhisker', '', self.Groups,
                               self.Group_Type)
         Trawl_Data = os.path.join(Data_dir, cohort_file)
         bw_data.InitializeData(Trawl_Data)
         data = bw_data.get_DataFrame()
         self.Map_Utils.plot_boxwhisker(data,
                                        Var,
                                        '',
                                        Log,
                                        Fishtype,
                                        datatype=datatype,
                                        cohortNum=cohort,
                                        max=max)
         self.Map_Utils.savePlot(Var, self.output_directory)
Example #2
0
 def make_BoxWhisker(self,
                     Trawl_Data,
                     Var,
                     Chronological=False,
                     Log=False,
                     datatype=None,
                     max=0.,
                     Fishtype='Longfin Smelt'):
     '''
     Creates boxwhisker plots for properly set up data. Instead of coming from trawl observed data,
     data is post processed into csv files containing the q5, q25, q50, q75, and q95 (q meaning quantile)
     statistics. These values are used for creating boxwhisker plots.
     q5 = 5% quantile, bottom whisker
     q25 = 25% quantile, bottom of the box
     q50 = 50% quantile, middle of the box
     q75 = 75% quantile, top of the box
     q95 = 95% quantile, top whisker
     
     variable controls including chronological and Log scaling. If Chronological, user must include a pairing trawl csv file that contains
     dates for each survey and region.
     
     Inputs:
     Trawl_Data: pre processed csv file full path containing data.
     Var: plot type variable. Abundance or Density
     Chronological: Boolean to turn on Chronological plotting.
                    If True, bars are ordered by the survey date, not the load order
     Chronological_data: list set of data to correspond with the trawl data. Only needed if Chronological is passed in as True
     Log: Plots data with a log scale instead of a true scale. Can make data with a large variation easier to view. 
     Max: set a max value used for plotting. Otherwise use the highest q50 value.
     '''
     if self.Map_Utils.title_str == '':
         if datatype == 'entrainment':
             inputs = self.get_inputs('ENT')
             self.Map_Utils.title_str = inputs['ENT_Title']
         elif datatype == 'hatch':
             inputs = self.get_inputs('HATCH')
             self.Map_Utils.title_str = inputs['HATCH_Title']
     bw_data = DataManager(self.Map_Utils.poly_names, self.Year, self.Sizes,
                           'Boxwhisker', '', self.Cohorts, self.Surveys)
     bw_data.InitializeData(Trawl_Data, datatype=datatype, Label='Computed')
     #         if self.Groups != None:
     #             bw_data.apply_Chronological(Chronological, Chronological_data=Chronological_data)
     dataframe = bw_data.get_DataFrame()
     dataframe = bw_data.Organize_Data(dataframe, datatype)
     self.Map_Utils.plot_boxwhisker(dataframe,
                                    Var,
                                    Chronological,
                                    Log,
                                    Fishtype,
                                    datatype=datatype,
                                    max=max)
     self.Map_Utils.savePlot(Var, self.output_directory)
Example #3
0
    def make_Bars(self,
                  Trawl_Data,
                  static_volumes,
                  Var,
                  Chronological=False,
                  GrowthRate=0.0,
                  startDate=dt.datetime(1900, 1, 1),
                  Log=False,
                  max=0.,
                  Fishtype='Longfin Smelt'):
        '''
        Makes Bar Plots and organizes data for plotting. Allows for variable commands to customize plots.
        
        Inputs:
        Trawl_Data: csv file full pathe mm/dd/YYYY HH:MM formatted date of the sample. Hour and minute data
                    is typically 00:00 and does not matter.
                    Fields also required:h containing data. Trawl files must contain a 'SampleDate'
                    field containing t lfs_region, Survey, Year
                    failure to contain these regions will result in a script crash.
        static_volumes: File containing volume of water used for abundance calculations.
                        Must have an entry for each region.
        Var: plot type variable. Abundance or Density
        Chronological: Boolean to turn on Chronological plotting.
                       If True, bars are ordered by the survey date, not the load order
        GrowthRate: Decimal number value for growth in mm / day. If set to a non zero value, the script will calculate
                     new abundances and densities based the new surveys calculated by the growth rate. Changes survey numbers
                     per region based on how many days from hatch and growth rate.
        startDate: Excludes values that were surveyed before the specified date
        Log: Plots data with a log scale instead of a true scale. Can make data with a large variation easier to view. 
        '''

        bar_data = DataManager(self.Map_Utils.poly_names,
                               self.Year,
                               self.Sizes,
                               'Bar',
                               static_volumes,
                               self.Groups,
                               self.Group_Type,
                               startDate=startDate)
        bar_data.InitializeData(Trawl_Data)
        bar_data.apply_Growth(GrowthRate)
        bar_data.apply_Chronological(Chronological)
        data = bar_data.get_DataFrame()
        self.Map_Utils.plot_bars(data,
                                 Var,
                                 GrowthRate,
                                 Chronological,
                                 Log,
                                 Fishtype,
                                 startDate,
                                 max=max)
        self.Map_Utils.savePlot(Var, self.output_directory)
 def make_BoxWhisker(self, 
                     Trawl_Data,
                     Var,
                     Chronological=False,
                     Chronological_data=[],
                     Log=False):
     '''
     Creates boxwhisker plots for properly set up data. Instead of coming from trawl observed data,
     data is post processed into csv files containing the q5, q25, q50, q75, and q95 (q meaning quantile)
     statistics. These values are used for creating boxwhisker plots.
     q5 = 5% quantile, bottom whisker
     q25 = 25% quantile, bottom of the box
     q50 = 50% quantile, middle of the box
     q75 = 75% quantile, top of the box
     q95 = 95% quantile, top whisker
     
     variable controls including chronological and Log scaling. If Chronological, user must include a pairing trawl csv file that contains
     dates for each survey and region.
     
     Inputs:
     Trawl_Data: pre processed csv file full path containing data.
     Var: plot type variable. Abundance or Density
     Chronological: Boolean to turn on Chronological plotting.
                    If True, bars are ordered by the survey date, not the load order
     Chronological_data: list set of data to correspond with the trawl data. Only needed if Chronological is passed in as True
     Log: Plots data with a log scale instead of a true scale. Can make data with a large variation easier to view. 
     '''
     
     bw_data = DataManager(self.Map_Utils.poly_names, self.Year, self.Sizes, self.Surveys, 'Boxwhisker', '')
     bw_data.InitializeData(Trawl_Data)
     bw_data.apply_Chronological(Chronological, Chronological_data=Chronological_data)
     data = bw_data.get_DataFrame()
     self.Map_Utils.plot_boxwhisker(data, Var, Chronological, Log)
     self.Map_Utils.savePlot(Var)
Example #5
0
 def make_TimeSeries_Plots(self,
                           Datafile,
                           Var,
                           Log=False,
                           datatype='fractional_entrainment',
                           max=0.,
                           Fishtype='Longfin Smelt'):
     '''
     Creates a timeseries plot for properly set up data. At each location, cohort data is displayed over time. 
     Each cohort is represented as a line of varying color. The x axis represents time, while the y axis
     represents the variable. Areas with no data are not given a plot.
     
     datafile is traditionally set up with columns being 'REGION_COHORT', and days since hatching.
     
     Inputs:
     Datafile: full path to file containing data for the time series
     Var: plot type variable. Abundance or Density
     Log: when passed in true, use a log scale to plot. False by default. 
     datatype: used to specify different type of data. set to 'fractional_entrainment' by default.
               fractional_entrainment is used if the data values are percents (i.e. 0-1)
               more datatypes available at a later date.
     Max: set a max value used for plotting. Otherwise use the highest value.
     '''
     data = DataManager(self.Map_Utils.poly_names, self.Year, self.Sizes,
                        'timeseries', '', self.Cohorts, self.Surveys)
     data.InitializeData(Datafile,
                         datatype='entrainment',
                         Label='Fractional Entrainment')
     tsdata = data.get_DataFrame()
     date_data = data._get_Timeseries_Dates()
     self.Map_Utils.plot_timeseries(tsdata,
                                    Var,
                                    date_data,
                                    Log,
                                    Fishtype,
                                    datatype=datatype,
                                    max=max)
     self.Map_Utils.savePlot(Var, self.output_directory)
    def make_PredvsObs_BoxWhisker(self,
                                  Observed_Data_Dir,
                                  Predicted_Data_Dir,
                                  Obs_data_list,
                                  Pred_data_list,
                                  Chronological_data,
                                  Var,
                                  Chronological=False,
                                  Log=False):
        '''
        Creates boxwhisker plots for properly set up data. Instead of coming from trawl observed data,
        data is post processed into csv files containing the q5, q25, q50, q75, and q95 (q meaning quantile)
        statistics. These values are used for creating boxwhisker plots.
        q5 = 5% quantile, bottom whisker
        q25 = 25% quantile, bottom of the box
        q50 = 50% quantile, middle of the box
        q75 = 75% quantile, top of the box
        q95 = 95% quantile, top whisker
        
        The Data acts as a direct comparison of Observed data from collected surveys to computed values.
        
        
        variable controls including chronological and Log scaling. If Chronological, user must include a pairing trawl csv file that contains
        dates for each survey and region.
        
        Inputs:
        Trawl_Data: pre processed csv file full path containing data.
        Var: plot type variable. Abundance or Density
        Chronological: Boolean to turn on Chronological plotting.
                       If True, bars are ordered by the survey date, not the load order
        Chronological_data: list set of data to correspond with the trawl data. Only needed if Chronological is passed in as True
        Log: Plots data with a log scale instead of a true scale. Can make data with a large variation easier to view. 
        '''

        for i, Pred_data in enumerate(Pred_data_list):
            Cohort_num = int(os.path.basename(Pred_data).split('_')[1].split('.')[0])
            Pred_data_file = os.path.join(Predicted_Data_Dir, Pred_data)
            Obs_data_file = os.path.join(Observed_Data_Dir, Obs_data_list[i])
            print 'Creating Plot for Cohort {0}...'.format(Cohort_num)
            self.Surveys = range(Cohort_num, self.Surveys[-1]+1)
            Obs_data_Manager = DataManager(self.Map_Utils.poly_names, self.Year, self.Sizes, self.Surveys, 'Boxwhisker', '')
            Obs_data_Manager.InitializeData(Obs_data_file)
            Obs_data_Manager.get_Dates(Chronological_data)
            Pred_data_Manager = DataManager(self.Map_Utils.poly_names, self.Year, self.Sizes, self.Surveys, 'Boxwhisker', '')
            Pred_data_Manager.InitializeData(Pred_data_file, predicted=True)
            Obs_data = Obs_data_Manager.get_DataFrame()
            Avg_Pred_Data = Pred_data_Manager.get_Predicted_Timed_Data(Obs_data)
            dataframe = Pred_data_Manager.merge_Dataframes(Avg_Pred_Data, Obs_data)
            self.Map_Utils.plot_ObsVsPred_Boxwhisker(dataframe, Var, Chronological, Cohort_num, Log)
            self.Map_Utils.savePlot(Var)
Example #7
0
    def make_TotalPredvsObs_BoxWhisker(self,
                                       Obs_data_file,
                                       Pred_data_file,
                                       Var,
                                       Chronological=False,
                                       Log=False,
                                       max=0.,
                                       Fishtype='Longfin Smelt',
                                       cohort_data=True,
                                       Obs_Label=None,
                                       Pred_Label=None):
        '''
        Creates boxwhisker plots for properly set up data. Instead of coming from trawl observed data,
        data is post processed into csv files containing the q5, q25, q50, q75, and q95 (q meaning quantile)
        statistics. These values are used for creating boxwhisker plots.
        q5 = 5% quantile, bottom whisker
        q25 = 25% quantile, bottom of the box
        q50 = 50% quantile, middle of the box
        q75 = 75% quantile, top of the box
        q95 = 95% quantile, top whisker
        
        The Data acts as a direct comparison of Observed data from collected surveys to computed values.
        
        
        variable controls including chronological and Log scaling. If Chronological, user must include a pairing trawl csv file that contains
        dates for each survey and region.
        
        Inputs:
        Observed_Data_Dir: path to directory where observed data exists.
        Predicted_Data_Dir: path to directory where predicted data exists.
        Obs_data_list: list of observed data file names. Include full name.
                        example: ['test1.csv', 'test2.csv']
        Pred_data_list: list of Predicted data file names. Include full name.
                        example: ['test1.csv', 'test2.csv']
        Var: plot type variable. Abundance or Density
        Chronological: Boolean to turn on Chronological plotting.
                       If True, bars are ordered by the survey date, not the load order
        Chronological_data: list set of data to correspond with the trawl data. Only needed if Chronological is passed in as True
        Log: Plots data with a log scale instead of a true scale. Can make data with a large variation easier to view. 
        Max: set a max value used for plotting. Otherwise use the highest q50 value.        
        '''

        if Obs_Label == None and Pred_Label == None:
            inputs = self.get_inputs('TPVTO')
            Obs_Label = inputs['TPVTO_Obs_Label']
            Pred_Label = inputs['TPVTO_Pred_Label']
            self.Map_Utils.title_str = inputs['TPVTO_Title']

        print 'Reading in Observed File...'

        Obs_data_Manager = DataManager(self.Map_Utils.poly_names, self.Year,
                                       self.Sizes, 'Boxwhisker', '',
                                       self.Cohorts, self.Surveys)
        Obs_data_Manager.InitializeData(Obs_data_file,
                                        datatype='total_observed',
                                        Label=Obs_Label)
        print 'Reading in Predicted Data'
        Pred_data_Manager = DataManager(self.Map_Utils.poly_names, self.Year,
                                        self.Sizes, 'Boxwhisker', '',
                                        self.Cohorts, self.Surveys)
        Pred_data_Manager.InitializeData(Pred_data_file,
                                         datatype='total_predicted',
                                         Label=Pred_Label)

        print self.Surveys
        Obs_data = Obs_data_Manager.get_DataFrame()
        Pred_data = Pred_data_Manager.get_DataFrame()
        dataframe = Pred_data_Manager.Coordinate_Data(Pred_data, Obs_data)
        if cohort_data:
            dataframe = Pred_data_Manager.Filter_by_HatchDate(dataframe)
        self.Map_Utils.plot_ObsVsPred_Boxwhisker(dataframe,
                                                 Var,
                                                 Chronological,
                                                 'Total',
                                                 Log,
                                                 Fishtype,
                                                 max=max)
        self.Map_Utils.savePlot(Var, self.output_directory)