Exemplo n.º 1
0
def combine_rs_snotel_annually(input_dir,
                               season,
                               pickles,
                               agg_step=12,
                               resolution=500,
                               huc_level='8',
                               col_of_interest='NDSI_Snow_Cover',
                               elev_stat='elev_mean',
                               sp=False,
                               total=False,
                               **kwargs):
    """Get RS data for snow drought time steps and return those data split by region."""

    combined = []
    optical_files = sorted(glob.glob(input_dir + '*.csv'))

    for file in optical_files:
        year = re.findall(
            '(\d{4})',
            os.path.split(file)[1]
        )[1]  #gets a list with the start and end of the water year, take the second one. expects files to be formatted a specific way from GEE
        #decide which season length to use depending on the RS aggregation type (SP or SCA)
        if 'SP' in file:
            snotel_data = pickles + f'short_term_snow_drought_{year}_water_year_{season}_{agg_step}_day_time_step_w_all_dates_first_day_start'
        elif 'SCA' in file:
            snotel_data = pickles + f'short_term_snow_drought_{year}_water_year_{season}_{agg_step}_day_time_step_w_all_dates'
        else:
            print('Your file contains neither sp nor SCA, try again')

        input_data = obtain_data.AcquireData(None, file, snotel_data, None,
                                             huc_level, resolution)

        short_term_snow_drought = input_data.get_snotel_data()
        optical_data = input_data.get_optical_data('NDSI_Snow_Cover')
        optical_data[f'huc{huc_level}'] = pd.to_numeric(
            optical_data['huc' + huc_level])
        optical_data['date'] = convert_date(optical_data, 'date')
        optical_data = get_df_chunk(optical_data, year)
        # if 'sar_data' in kwargs:
        # 	sar_data = input_data.get_sentinel_data('filter')

        #convert pixel counts to area
        if not sp:
            optical_data = rs_funcs.convert_pixel_count_sq_km(
                optical_data, col_of_interest, resolution)
            #optical_data['area'] = optical_data[f'huc{huc_level}'].map(kwargs.get('hucs_data'))
            #normalize snow covered area by basin area
            #optical_data[col_of_interest] = optical_data[col_of_interest]/optical_data['area'] #changed 4/9/2021 to update the NDSI_Snow_Cover col in place
        #optical_data['year'] = optical_data['date'].dt.year

        if not total:
            #combine the remote sensing and snotel data using the snotel dates of snow droughts to extract rs data
            merged = merge_dfs(
                short_term_snow_drought, optical_data,
                kwargs.get('drought_type'))  #snotel_data,rs_data,drought_type
            combined.append(merged)

        else:
            combined.append(optical_data)
    return pd.concat(combined, axis=0)
Exemplo n.º 2
0
def main(year_of_interest, season, pickles, agg_step=12, huc_level='8'):

    snotel_data = pickles + f'short_term_snow_drought_{year_of_interest}_water_year_{season}_{agg_step}_day_time_step_w_all_dates'

    if season == 'extended_winter':
        date_range = list(
            pd.date_range(start=f"{int(year_of_interest)-1}-11-01",
                          end=f"{year_of_interest}-04-30"))
        num_periods = len(date_range) / int(agg_step)

    input_data = obtain_data.AcquireData(None, None, snotel_data, None,
                                         huc_level, None)
    short_term_snow_drought = input_data.get_snotel_data()

    df = short_term_snow_drought.groupby(['station_id', 'huc_id']).agg({
        'dry':
        'count',
        'warm':
        'count',
        'warm_dry':
        'count'
    }).reset_index()

    df = df.groupby('huc_id').agg({
        'dry': 'median',
        'warm': 'median',
        'warm_dry': 'median'
    }).reset_index()
    #df1 = short_term_snow_drought.groupby(['station_id']).agg({'dry': 'count','warm':'count','warm_dry':'count'}).reset_index()

    #print(df1)
    for column in ['dry', 'warm', 'warm_dry']:
        df[f'{column}_ratio'] = df[column] / num_periods
    df.rename(columns={'station_id': 'site_num'}, inplace=True)

    #plot_snow_drought_ratios(df,stations_no_hucs,pnw_shapefile,us_boundary,year_of_interest)
    return df
Exemplo n.º 3
0
def combine_rs_snotel_annually(input_dir,season,pickles,agg_step=12,resolution=500,huc_level='8',col_of_interest='NDSI_Snow_Cover',elev_stat='elev_mean',sp=False,total=False,split=True,**kwargs): 
	"""Get RS data for snow drought time steps and return those data split by region."""
	
	west_dfs_list = []
	east_dfs_list = []
	years = []
	optical_files = sorted(glob.glob(input_dir+'*.csv'))

	for file in optical_files: 
		year = re.findall('(\d{4})', os.path.split(file)[1])[1] #gets a list with the start and end of the water year, take the second one. expects files to be formatted a specific way from GEE 
		#print(year)
		#decide which season length to use depending on the RS aggregation type (SP or SCA)
		if 'SP' in file: 
			snotel_data = pickles+f'short_term_snow_drought_{year}_water_year_{season}_{agg_step}_day_time_step_w_all_dates_first_day_start'
		elif 'SCA' in file:
			snotel_data = pickles+f'short_term_snow_drought_{year}_water_year_{season}_{agg_step}_day_time_step_w_all_dates'
		else: 
			print('Your file contains neither sp nor SCA, try again')

		input_data = obtain_data.AcquireData(None,file,snotel_data,None,huc_level,resolution)
		
		short_term_snow_drought = input_data.get_snotel_data()
		optical_data = input_data.get_optical_data('NDSI_Snow_Cover')
		optical_data[f'huc{huc_level}'] = pd.to_numeric(optical_data['huc'+huc_level]) 
		optical_data['date'] = convert_date(optical_data,'date')
			
		# if 'sar_data' in kwargs: 
		# 	sar_data = input_data.get_sentinel_data('filter')


		#convert pixel counts to area
		if not sp: 
			optical_data=rs_funcs.convert_pixel_count_sq_km(optical_data,col_of_interest,resolution)
			optical_data['area'] = optical_data[f'huc{huc_level}'].map(kwargs.get('hucs_data'))
			#normalize snow covered area by basin area
			optical_data[col_of_interest] = optical_data[col_of_interest]/optical_data['area'] #changed 4/9/2021 to update the NDSI_Snow_Cover col in place 
		#optical_data['year'] = optical_data['date'].dt.year

		if not total: 
			#combine the remote sensing and snotel data using the snotel dates of snow droughts to extract rs data 
			merged=merge_dfs(short_term_snow_drought,optical_data,kwargs.get('drought_type')) #snotel_data,rs_data,drought_type
			# print('merged')
			# print(merged)
			# try: 
			# 	print(merged[['NDSI_Snow_Cover','area']])
			# except Exception as e: 
			# 	pass
		else: 
			pass
			#print('Calculating total with no snow droughts')
		#output = split_dfs_within_winter_season
		try: 
			split_dfs=split_basins(merged,f'huc{huc_level}',year=year) #returns the merged df split into two dfs, west (0) and east (1)
		
		except UnboundLocalError as e: 
			print('stopped here')
			split_dfs=split_basins(optical_data,f'huc{huc_level}',year=year) #returns the merged df split into two dfs, west (0) and east (1)
			print(split_dfs)
		
		west_dfs_list.append(split_dfs[0])
		east_dfs_list.append(split_dfs[1])
		
	print('list',west_dfs_list)
	output_west_df = pd.concat(west_dfs_list,ignore_index=True)
	output_east_df = pd.concat(east_dfs_list,ignore_index=True)
	try: 
		if split: 
			return output_west_df,output_east_df #returns two dfs, one for each region for all the years for one drought type 
		else: 
			return merged 
	except UnboundLocalError as e: 
		return optical_data
Exemplo n.º 4
0
def main():
    """
	Plot the long term snow drought types and trends. 
	"""

    params = sys.argv[1]
    with open(str(params)) as f:
        variables = json.load(f)

        #construct variables from param file
        sp_data = variables['sp_data']
        csv_dir = variables['csv_dir']
        resolution = variables['resolution']
        huc_level = variables['huc_level']
        resolution = variables['resolution']
        pickles = variables['pickles']
        year_of_interest = variables['year_of_interest']
        season = variables['season']
        agg_step = variables['agg_step']
        optical_csv_dir = variables['optical_csv_dir']
        palette = variables['palette']
        modis_dir = variables['modis_dir']
        viirs_dir = variables['viirs_dir']
        testing = variables['testing']

        #set a few script specific user params
        plot_type = 'long_term'  #one of drought_type,long-term or something else
        plotting_param = 'SCA'
        #plot_func = 'quartile'
        elev_stat = 'elev_mean'

        #dfs = read_in_and_reformat_data(csv_dir,'huc8','NDSI_Snow_Cover',['.geo','system:index','elev_min','elev_max'],resolution,plotting_param,plot_type)
        #dfs = read_in_and_reformat_data(csv_dir,'huc8','NDSI_Snow_Cover',['.geo','system:index'],resolution,plotting_param,plot_type)

        #print('sp_data')
        #print(dfs)
        if not (plot_type == 'long_term') | (plot_type == 'drought_type'):
            fig, (ax, ax1) = plt.subplots(2)
            sns.lineplot(dfs[0]['year'], dfs[0]['NDSI_Snow_Cover'], ax=ax)
            sns.lineplot(dfs[1]['year'], dfs[1]['NDSI_Snow_Cover'], ax=ax1)

            plt.show()
            plt.close()

        elif plot_type == 'drought_type':
            west_dfs_list = []
            east_dfs_list = []
            years = []
            optical_files = sorted(glob.glob(csv_dir + '*.csv'))
            for file in optical_files:
                print(file)
                year = int(
                    re.findall('(\d{4})-\d{2}-\d{2}',
                               os.path.split(file)[1])[1]
                )  #gets a list with the start and end of the water year, take the second one
                print(year)

                if 'SP' in file:
                    print('SP')
                    snotel_data = pickles + f'short_term_snow_drought_{year}_water_year_{season}_{agg_step}_day_time_step_w_all_dates_first_day_start'
                elif 'SCA' in file:
                    print('SCA')
                    snotel_data = pickles + f'short_term_snow_drought_{year_of_interest}_water_year_{season}_{agg_step}_day_time_step_w_all_dates'
                else:
                    print('Your file contains neither sp nor SCA, try again')

                input_data = obtain_data.AcquireData(None, file, snotel_data,
                                                     None, huc_level,
                                                     resolution)

                short_term_snow_drought = input_data.get_snotel_data()
                print(short_term_snow_drought)
                optical_data = input_data.get_optical_data('NDSI_Snow_Cover')
                #optical_data = dfs[1]
                optical_data[f'huc{huc_level}'] = pd.to_numeric(
                    optical_data['huc' + huc_level])
                optical_data['date'] = _4a_rs.convert_date(
                    optical_data, 'date')

                #combine the remote sensing and snotel data using the snotel dates of snow droughts to extract rs data
                merged = merge_dfs(short_term_snow_drought, optical_data,
                                   huc_level, 'NDSI_Snow_Cover', elev_stat,
                                   plotting_param)
                split_dfs = split_basins(
                    merged, f'huc{huc_level}'
                )  #returns the merged df split into two dfs, west (0) and east (1)

                west_dfs_list.append(split_dfs[0].to_frame().T)
                east_dfs_list.append(split_dfs[1].to_frame().T)
                years.append(year)  #save these for labeling

            output_west_df = pd.concat(west_dfs_list, ignore_index=True)
            output_east_df = pd.concat(east_dfs_list, ignore_index=True)

            output_west_df['year'] = years
            output_east_df['year'] = years

            output_west_df = output_west_df.set_index('year')
            output_east_df = output_east_df.set_index('year')
            #print(output_west_df)
            #plot it
            font = {'family': 'normal', 'weight': 'normal', 'size': 18}

            plt.rc('font', **font)
            fig, (ax, ax1) = plt.subplots(2,
                                          1,
                                          sharex=True,
                                          sharey=True,
                                          figsize=(12, 8))

            font = {
                'family': 'Times New Roman',
                'weight': 'normal',
                'size': 18
            }

            plt.rc('font', **font)

            #pal=['#a6cee3','#1f78b4','#b2df8a','#33a02c']
            labels = ['Dry', 'Warm', 'Warm/dry', 'No drought']
            palette = list(palette.values())
            output_west_df.plot(
                ax=ax,
                color=palette,
                linewidth=3.5,
            )
            ax.set_xticks(years)
            ax.set_title('Western Basins SP by drought type')
            ax.set_xlabel(' ')
            ax.set_ylabel('SP')
            ax.grid()
            ax.legend(labels=labels)
            ax.tick_params(axis='x', labelsize=15)

            output_east_df.plot(ax=ax1,
                                color=palette,
                                linewidth=3.5,
                                legend=False)
            ax1.set_xticks(years)
            ax1.set_title('Eastern Basins SP by drought type')
            ax1.set_xlabel(' ')
            ax1.set_ylabel('SP')
            ax1.grid()

            plt.tight_layout()
            plt.show()
            plt.close('all')

        elif plot_type.lower(
        ) == 'long_term':  #use to make plots of the long term trends in optical data
            font = {'family': 'normal', 'weight': 'normal', 'size': 16}

            plt.rc('font', **font)
            fig, (ax, ax1) = plt.subplots(2, 1, sharex=True)

            #decide if we're plotting SP or SCA

            if plotting_param.upper() == 'SP':
                print('plotting SP')
                linewidth = 2.5
                west_yrs = dfs[0]
                east_yrs = dfs[1]

            elif plotting_param.upper() == 'SCA':
                print('plotting SCA')
                drought_types = [
                    'dry', 'warm', 'warm_dry', 'no_drought', 'original'
                ]
                count = 1  #this is used to index the output of merge_dfs function above
                drought_dict = {}
                for i in drought_types:
                    drought_dfs = combine_rs_snotel_annually(
                        csv_dir, season, elev_stat, plotting_param, count,
                        pickles, agg_step)
                    count += 1
                    drought_dict.update(
                        {i: drought_dfs}
                    )  #make a dict that is of the type {'dry':(west_df,east_df)}
                #print(drought_dict)

                linewidth = 3.5
                #print(dfs[0])
                # west_yrs_basins = dfs[0].groupby(['huc8','year'])['NDSI_Snow_Cover'].max().to_frame().reset_index()
                # #print(west_yrs_basins)
                # west_yrs = west_yrs_basins.groupby('year')['NDSI_Snow_Cover'].sum().to_frame().reset_index()
                # #print(west_yrs)

                # east_yrs_basins = dfs[1].groupby(['huc8','year'])['NDSI_Snow_Cover'].max().to_frame().reset_index()
                # east_yrs = east_yrs_basins.groupby('year')['NDSI_Snow_Cover'].sum().to_frame().reset_index()

            else:
                print(
                    'Your plotting param seems incorrect, double check and try again.'
                )
            #linreg_df_west = dfs[0].groupby('year')['NDSI_Snow_Cover'].sum().to_frame().reset_index()

            #get coeffs of linear fit
            #slope, intercept, r_value, p_value, std_err = stats.linregress(west_yrs['year'],west_yrs['NDSI_Snow_Cover'])
            #print(west_yrs['NDSI_Snow_Cover'].mean())

            #make combined dfs

            plot_west = pd.concat(
                (drought_dict['original'][0], drought_dict['dry'][0],
                 drought_dict['warm'][0], drought_dict['warm_dry'][0]),
                axis=1)  #,drought_dict['no_drought'][0]),axis=1)
            plot_east = pd.concat(
                (drought_dict['original'][1], drought_dict['dry'][1],
                 drought_dict['warm'][1], drought_dict['warm_dry'][1]),
                axis=1)  #,drought_dict['no_drought'][1]),axis=1)
            plot_west = plot_west.sort_index(
                axis=1
            ).iloc[:, :
                   5]  #this is hardcoded and assumes that 'year' which is the duplicate will come at the end. Note that it must be changed if including no drought

            plot_east = plot_east.sort_index(axis=1).iloc[:, :5]
            #plot_west['mean'] = plot_west['NDSI_Snow_Cover']
            #plot_east['mean'] = plot_east['NDSI_Snow_Cover']
            # print('original')
            # print(plot_west)
            # print(plot_east)
            plot_west_anom = (get_anom_col(plot_west,
                                           'original_NDSI_Snow_Cover', 'year'))
            plot_east_anom = (get_anom_col(plot_east,
                                           'original_NDSI_Snow_Cover', 'year'))

            plot_west_anom = plot_west_anom.drop(['original_NDSI_Snow_Cover'],
                                                 axis=1)
            plot_east_anom = plot_east_anom.drop(['original_NDSI_Snow_Cover'],
                                                 axis=1)
            plot_west_anom.rename(columns={
                'dry_NDSI_Snow_Cover': 'Dry',
                'warm_NDSI_Snow_Cover': 'Warm',
                'warm_dry_NDSI_Snow_Cover': 'Warm dry'
            },
                                  inplace=True)
            plot_east_anom.rename(columns={
                'dry_NDSI_Snow_Cover': 'Dry',
                'warm_NDSI_Snow_Cover': 'Warm',
                'warm_dry_NDSI_Snow_Cover': 'Warm dry'
            },
                                  inplace=True)
            # print('anomoly')
            # print(plot_west_anom)
            # print(plot_east_anom)
            #print(plot_west)
            #print(plot_east.groupby('year').first())
            #print(plot_east.columns)
            #print(east_yrs['NDSI_Snow_Cover'].mean())
            ax.grid()

            # Put data in long format in a dataframe.
            # df = pd.DataFrame({
            #     'country': countries2012 + countries2013,
            #     'year': ['2012'] * len(countries2012) + ['2013'] * len(countries2013),
            #     'percentage': percentage2012 + percentage2013
            # })

            # One liner to create a stacked bar chart.
            #plot_west.plot.bar(stacked=False, x='year',ax=ax)

            # ax = sns.histplot(df, x='year', hue='country', weights='percentage',
            #              multiple='stack', palette='tab20c', shrink=0.8)
            #ax.set_ylabel('percentage')
            # Fix the legend so it's not on top of the bars.
            #legend = ax.get_legend()
            #legend.set_bbox_to_anchor((1, 1))
            #sns.lineplot(data=plot_west_anom,ax=ax,linewidth=linewidth)
            plot_west_anom.plot.bar(x='year', ax=ax)  #,color=palette.values())
            # sns.lineplot(x='year',y='NDSI_Snow_Cover',data=west_yrs,ax=ax,color='#565656',linewidth=linewidth)
            # count = 0
            # for k,v in drought_dict.items():
            # 	plotting_col = [i for i in v[0].columns if 'NDSI_Snow_Cover' in i][0]
            # 	print(plotting_col)
            # 	sns.lineplot(x='year',y=plotting_col,data=v[0],ax=ax,color=palette[drought_types[count]],linewidth=linewidth)
            # 	count += 1

            ax.set_title(f'Western river basins MODVII {plotting_param}')
            #ax.set_xticks(dfs[0]['year'].unique())
            ax.set_xlabel(' ')

            ax1.grid()
            #linreg_df_east = dfs[1].groupby('year')['NDSI_Snow_Cover'].sum().to_frame().reset_index()
            plot_east_anom.plot.bar(x='year', ax=ax1,
                                    legend=False)  #,color=palette.values())

            #plot_east.plot.bar(stacked=False, x='year',ax=ax1,legend=False)
            # east_yrs['mean'] = east_yrs['NDSI_Snow_Cover'].mean()
            # sns.lineplot(x='year',y='NDSI_Snow_Cover',data=east_yrs,ax=ax1,color='#565656',linewidth=linewidth)
            # sns.lineplot(x='year',y='mean',data=east_yrs,ax=ax1,color='#000000',linewidth=linewidth)

            # count = 0
            # for k,v in drought_dict.items():
            # 	plotting_col = [i for i in v[0].columns if 'NDSI_Snow_Cover' in i][0]
            # 	sns.lineplot(x='year',y=plotting_col,data=v[1],ax=ax1,color=palette[drought_types[count]],linewidth=linewidth)
            # 	count +=1
            ax1.set_title(f'Eastern river basins MODVII {plotting_param}')
            #ax1.set_xticks(dfs[1]['year'].unique())

            ax1.set_xlabel(' ')

            #add ylabels
            if plotting_param.upper() == 'SP':
                ax.set_ylabel('DJF snow persistence')
                ax1.set_ylabel('DJF snow persistence')
            elif plotting_param.upper() == 'SCA':
                ax.set_ylabel(f'{plotting_param} total (sq km)')
                ax1.set_ylabel(f'{plotting_param} total (sq km)')
            plt.xticks(rotation=45)
            plt.show()
            plt.close('all')
        else:
            pass
Exemplo n.º 5
0
def combine_rs_snotel_annually(input_dir,
                               season,
                               elev_stat,
                               plotting_param,
                               drought_type,
                               pickles,
                               agg_step,
                               resolution=500,
                               huc_level='8',
                               col_of_interest='NDSI_Snow_Cover'):
    """Get rs data for the dates of different snow drought types from the SNOTEL record."""
    west_dfs_list = []
    east_dfs_list = []
    years = []
    optical_files = sorted(glob.glob(input_dir + '*.csv'))

    for file in optical_files:
        #print(file)
        year = int(
            re.findall('(\d{4})-\d{2}-\d{2}',
                       os.path.split(file)[1])[1]
        )  #gets a list with the start and end of the water year, take the second one

        print(year)

        if 'SP' in file:
            print('SP')
            snotel_data = pickles + f'short_term_snow_drought_{year}_water_year_{season}_{agg_step}_day_time_step_w_all_dates_first_day_start'
        elif 'SCA' in file:
            print('SCA')
            #decide which season length to use depending on the RS aggregation type (SP or SCA)
            snotel_data = pickles + f'short_term_snow_drought_{year}_water_year_{season}_{agg_step}_day_time_step_w_all_dates'
        else:
            print('Your file contains neither sp nor SCA, try again')

        input_data = obtain_data.AcquireData(None, file, snotel_data, None,
                                             huc_level, resolution)

        short_term_snow_drought = input_data.get_snotel_data()
        optical_data = input_data.get_optical_data('NDSI_Snow_Cover')
        optical_data[f'huc{huc_level}'] = pd.to_numeric(
            optical_data['huc' + huc_level])
        optical_data['date'] = _4a_rs.convert_date(optical_data, 'date')

        #convert pixel counts to area
        optical_data = rs_funcs.convert_pixel_count_sq_km(
            optical_data, col_of_interest, resolution)

        #combine the remote sensing and snotel data using the snotel dates of snow droughts to extract rs data
        #split the dfs by time period in the winter

        early_df = optical_data.loc[(
            optical_data['date'] >= f'{year-1}-11-01'
        ) & (
            optical_data['date'] < f'{year-1}-12-31'
        )]  #optical_data[optical_data["date"].isin(pd.date_range(start_date, end_date))]
        mid_df = optical_data.loc[(optical_data['date'] >= f'{year}-01-01')
                                  & (optical_data['date'] < f'{year}-03-01')]
        late_df = optical_data.loc[(optical_data['date'] >= f'{year}-03-02')
                                   & (optical_data['date'] < f'{year}-05-01')]

        merged = merge_dfs(
            short_term_snow_drought, early_df, huc_level, 'NDSI_Snow_Cover',
            elev_stat, plotting_param
        )[drought_type]  #drought type is passed as an integer starting at one

        split_dfs = split_basins(
            merged, f'huc{huc_level}', year=year
        )  #returns the merged df split into two dfs, west (0) and east (1)

        west_dfs_list.append(split_dfs[0])  #.T)#.to_frame().T)
        east_dfs_list.append(split_dfs[1])  #.T)#.to_frame().T)

    output_west_df = pd.concat(west_dfs_list, ignore_index=True)
    output_east_df = pd.concat(east_dfs_list, ignore_index=True)

    grouping_col = [
        i for i in output_west_df.columns if 'NDSI_Snow_Cover' in i
    ][0]

    output_west_df = output_west_df.groupby(
        'year')[grouping_col].sum().reset_index()  #.to_frame().reset_index()
    output_east_df = output_east_df.groupby(
        'year')[grouping_col].sum().reset_index()  #.to_frame().reset_index()

    # output_west_df['year']=years
    # output_east_df['year']=years

    # output_west_df = output_west_df.set_index('year')
    # output_east_df = output_east_df.set_index('year')

    return output_west_df, output_east_df
def main():
    """
	Plot the long term snow drought types and trends. 
	"""

    params = sys.argv[1]
    with open(str(params)) as f:
        variables = json.load(f)

        #construct variables from param file
        season = variables["season"]
        pnw_shapefile = variables["pnw_shapefile"]
        huc_shapefile = variables['huc_shapefile']
        us_boundary = variables['us_boundary']
        stations = variables["stations"]
        pickles = variables["pickles"]
        agg_step = variables["agg_step"]
        year_of_interest = int(variables["year_of_interest"])
        hucs_data = variables["hucs_data"]
        sentinel_csv_dir = variables["sentinel_csv_dir"]
        optical_csv_dir = variables["optical_csv_dir"]
        huc_level = variables["huc_level"]
        resolution = variables["resolution"]
        palette = variables["palette"]

        #user defined functions
        plot_func = 'quartile'
        elev_stat = 'elev_mean'
        #self,sentinel_data,optical_data,snotel_data,hucs_data,huc_level,resolution):
        #get all the data
        snotel_data = pickles + f'short_term_snow_drought_{year_of_interest}_water_year_{season}_{agg_step}_day_time_step_w_all_dates'

        #instantiate the acquireData class and read in snotel, sentinel and modis/viirs data
        input_data = obtain_data.AcquireData(sentinel_csv_dir, optical_csv_dir,
                                             snotel_data, hucs_data, huc_level,
                                             resolution)
        short_term_snow_drought = input_data.get_snotel_data()
        sentinel_data = input_data.get_sentinel_data('filter')
        optical_data = input_data.get_optical_data('NDSI_Snow_Cover')

        # pd.set_option("display.max_rows", None, "display.max_columns", None) #change to print an entire df
        # #combine the sentinel and optical data

        #drop redundant columns
        sentinel_data.drop(columns=['elev_min', 'elev_mean', 'elev_max'],
                           inplace=True)
        rs_df = rs_funcs.merge_remote_sensing_data(optical_data, sentinel_data)
        #remove snow persistence values lower than 20% as per (Saavedra et al)
        if 'SP' in optical_csv_dir:
            rs_df = rs_df.loc[rs_df['NDSI_Snow_Cover'] >= 0.2]
        else:
            pass

        rs_df['wet_snow_by_area'] = rs_df['filter'] / rs_df[
            'NDSI_Snow_Cover']  #calculate wet snow as fraction of snow covered area

        #make sure that the cols used for merging are homogeneous in type
        rs_df['huc8'] = pd.to_numeric(rs_df['huc' + huc_level])
        rs_df['date'] = convert_date(rs_df, 'date')

        #create the different snow drought type dfs

        #do dry first
        dry_combined = create_snow_drought_subset(short_term_snow_drought,
                                                  'dry', huc_level)
        #merge em
        dry_combined = dry_combined.merge(
            rs_df, on=['date', 'huc' + huc_level], how='inner'
        )  #changed rs_df to sentinel data 2/1/2021 to accommodate missing modis data temporarily
        #get the rs data for the time periods of interest for a snow drought type
        #dry_optical=dry_combined.groupby('huc'+huc_level)['ndsi_pct_change'].mean()
        dry_combined.rename(columns={'wet_snow_by_area': 'dry_WSCA'},
                            inplace=True)
        dry_combined = dry_combined.sort_values('dry_WSCA').drop_duplicates(
            subset=[f'huc{huc_level}', 'date'], keep='first')

        #dry_sar = dry_combined.groupby('huc'+huc_level)['dry_WSCA',elev_stat].median() #changed col from pct change to filter 2/1/2021
        #then do warm
        warm_combined = create_snow_drought_subset(short_term_snow_drought,
                                                   'warm', huc_level)
        #merge em
        warm_combined = warm_combined.merge(rs_df,
                                            on=['date', 'huc' + huc_level],
                                            how='inner')
        #get the rs data for the time periods of interest for a snow drought type
        #warm_optical=warm_combined.groupby('huc'+huc_level)['ndsi_pct_change'].min()
        warm_combined.rename(columns={'wet_snow_by_area': 'warm_WSCA'},
                             inplace=True)
        warm_combined = warm_combined.sort_values('warm_WSCA').drop_duplicates(
            subset=[f'huc{huc_level}', 'date'], keep='first')

        #warm_sar = warm_combined.groupby('huc'+huc_level)['warm_WSCA',elev_stat].median()

        #then do warm/dry
        warm_dry_combined = create_snow_drought_subset(short_term_snow_drought,
                                                       'warm_dry', huc_level)
        #merge em
        warm_dry_combined = warm_dry_combined.merge(
            rs_df, on=['date', 'huc' + huc_level], how='inner')
        #get the rs data for the time periods of interest for a snow drought type
        #warm_dry_optical=warm_dry_combined.groupby('huc'+huc_level)['ndsi_pct_change'].sum()
        warm_dry_combined.rename(columns={'wet_snow_by_area': 'warm_dry_WSCA'},
                                 inplace=True)
        warm_dry_combined = warm_dry_combined.sort_values(
            'warm_dry_WSCA').drop_duplicates(
                subset=[f'huc{huc_level}', 'date'], keep='first')

        print(warm_dry_combined)
        #warm_dry_sar = warm_dry_combined.groupby('huc'+huc_level)['warm_dry_WSCA',elev_stat].median()

        #try making a df of time steps that DO NOT have snow droughts for comparing
        no_snow_drought = create_snow_drought_subset(short_term_snow_drought,
                                                     'date', huc_level)
        no_drought_combined = no_snow_drought.merge(
            rs_df, on=['date', 'huc' + huc_level], how='inner')

        no_drought_combined.rename(
            columns={'wet_snow_by_area': 'no_drought_WSCA'}, inplace=True)
        no_drought_combined = warm_dry_combined.sort_values(
            'warm_dry_WSCA').drop_duplicates(
                subset=[f'huc{huc_level}', 'date'], keep='first')