DOI: 10.5061/dryad.3j9kd51zq
title: Code from: Climate, ecological dynamics, and the seasonal distribution of birds in mountains

description: Biodiversity is unevenly distributed along elevational gradients. The
 predominant hypothesis is that macroevolutionary dynamics and climatic
 niche conservatism explain today’s elevational patterns of biodiversity,
 but the alternative energy efficiency hypothesis emphasizes modern
 ecological interactions related to energy budgets. We test these competing
 hypotheses by examining seasonal elevational ranges for 10,998 bird
 populations in 34 mountain regions. Multiple lines of evidence support the
 energy efficiency hypothesis, including that many mountain birds do not
 seasonally track their thermal niche with high fidelity, while simulation
 models based on optimal energy balancing under current environmental
 conditions yield predictions that tightly match empirical data. Our
 results reveal that altitudinal migration, which is widespread yet
 considerably understudied, is a behavioural mechanism fulfilling the same
 ecological function as long-distance latitudinal migration. Overall, this
 work provides a better understanding and predictive capacity for mountain
 birds under global change.
description: # Code from: Climate, ecological dynamics, and the seasonal distribution
 of birds in mountains Dataset DOI:
 [10.5061/dryad.3j9kd51zq](https://doi.org/10.5061/dryad.3j9kd51zq) ##
 Description of the data and file structure This repository contains the
 scripts needed to run the analyses presented in Somveille M, Freeman BG,
 La Sorte FA & Tuanmu M. Mountains as ecological arenas: how climate
 and competition shape the seasonal distribution of birds along elevational
 gradients. Science Advances Large datasets (ebird data, climate data) must
 be downloaded using the links provided in the manuscript. The code files
 are numbered and ordered as follows: * 01_mountain_ranges.R contains the
 code for initial processing of the mountain range data. This script uses
 the file mountain-key.csv, which contains the name and ID of all mountain
 ranges as well as the files in ne_10m_geography_regions_polys.zip which
 contains the mountain range polygons. It outputs a shapefile containing
 the mountain range polygons after initial processing (i.e.,
 mountain_ranges.dbf, mountain_ranges.shp, mountain_ranges.prj, mountain_ranges.shx).  * 02_mountain_ranges_ebird.R contains the code for processing eBird data within each mountain range and filtering out mountain ranges with insufficient ebird data. It outputs a shapefile containing the mountain range polygons after this second filtering step (i.e, mountain_ranges_2.dbf, mountain_ranges_2.shp, mountain_ranges_2.prj, mountain_ranges_2.shx).  * 03_mountain_slopes_delineation.R contains the code for delineating mountain slopes * 04_sample_completeness.R contains the code for filtering mountain ranges based on sampling completeness. This code outputs an RData file (mnt_slopes_data_new.RData) containing the final set of mountain slopes and the eBird data in each of the slopes used in the rest of the analysis. This RData file contains 4 objects: * ebrd2_slopes: a data frame with all eBird observations across all mountain slopes included in the analysis, with each row corresponding to an observation and columns indicating the species name (scientificname), latitude, longitude, checklist ID (sampling_event_identifier), year, day, mountain range ID (mnt_ID), season, mountain slope name (slope) and elevation (in meters above sea level) * mountain_ranges: a SpatVector object containing the polygons of the mountain ranges * mountain_slope_polys: an sf object containing the polygons of the mountain slopes * slopes_mountain_name: a vector indicating which mountain range each slope belongs to * 05_environmental_data.R contains the code for extracting and processing environmental data * 06_empirical_patterns.R contains the code for computing and plotting the empirical patterns * 07_thermal_tracking.R contains the code for quantifying empirical seasonal thermal tracking * 08_simulated_patterns_and_analysis.R contains the code for simulating and analysing the patterns based on energy efficiency. This file contains the code to calibrate the model, which uses empirical data on the global latitudinal patterns of bird migration (stored in PresAbs_global.zip) * 09_future_predictions.R contains the code for predicting future patterns under climate warming * 10_eastern_himalayas.R contains the code for predicting the Eastern Himalayas ## Code/software RStudio (Software capable of running R) is used for statistical analysis and data visualization.