Analysis Module: swepy.analysis¶
The Analysis class is meant to help get you up and running with quick visualization of various basic SWE metrics, like onset of complete melt by pixel.
-
class
swepy.analysis.
Analysis
(start_date, swe)¶ Bases:
object
-
count_melt_onset
()¶ Count the date that each pixel reaches zero for first time of season on a given date. Useful for comparison between years of a given region.
Helper function to manage multi-processing pool for counting melt onset date. Use __count to use a single core
Parralelize on the 2nd axis (spatially)
- Returns
df – Count of melt dates of every pixel in image
- Return type
pandas DataFrame
-
create_year_splits
()¶ Take time array from class and create an array of year split indexes
- Returns
year_splits – list of julian dates for the start of each year in time series
- Return type
list
-
display_melt_onset_change
(dict, year1, year2, interactive=False)¶ CURRENTLY ONLY WORKS IF FULL YEARS ARE SCRAPED Given a dictionary of melt onset counts by date, viz two years against eachother
- Parameters
dict (dict) – dictionary of year:list(counts by year) pairs
year1 (datetime.date) – first year to plot on bar graph
year2 (datetime.date) – second year to plot on bar graph
interactive (bool) – Unit testing parameter to help closing plots
- Returns
fig – figure for future viz if desired
- Return type
matplotlib.figure.Figure
-
display_summer_change
(interactive=False)¶ Simple built in function for displaying the generated summer change heat map
- Parameters
interactive (bool) – boolean switch for unit testing to help close plots (would like to remove)
-
make_df
(time=None, columns=['time', 'count'])¶ Given a time array, create dateframe with time and count columns
Tool for melt onset workflow
- Parameters
time (pd.series) – time series of datetime.date() objects
columns (list (Optional)) – column names to add in returned dataframe
- Returns
df – dataframe with time and count for melt onset analysis
- Return type
pd.DataFrame
-
mask_year_df
(df, year)¶ Mask single year out of pandas dataframe based on “time” column
- Parameters
df (pd.DataFrame) – dataframe containing a “time” column
year (datetime.date) – desired year to get from df
-
melt_date_year
(df)¶ Grab the counts of each year and stick them in own key of dictionary Makes for easy comparison of melt times each year.
- Parameters
df (pd.DataFrame) – dataframe with columns [“time”, “count”]
- Returns
counts_dict – dictionary with key=year : value=sum(count in year)
- Return type
dict
-
summer_diff
(summer_dict, smooth_cube=None)¶ Find the average change in summer length by pixel and overall
- Parameters
summer_dict (dict) – dictionary containing the summer lengths of each year by pixel
smooth_cube (np.array(x,x,x)) – swe cube of clean swe data, OPTIONAL
-
summer_length
(smooth_cube)¶ Function to track summer length for a pixel over each year Generates hash table of key:value = (x,y): summer length in days
- Parameters
smooth_cube (np.array) – smoothed (temporally) swe cube
- Returns
store – dict using tuple (x,y) as hash key and list of summer lengths by year as key
- Return type
dict
-