ebook img

Introduction to Environmental Data Science PDF

403 Pages·2023·76.715 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Introduction to Environmental Data Science

Introduction to Environmental Data Science Introduction to Environmental Data Science focuses on data science methods in the R language applied to environmental research, with sections on exploratory data analysis in R including data abstraction, transformation, and visualization; spatial data analysis in vector and raster models; statistics & modelling ranging from exploratory to modelling, considering confirmatory statis- tics and extending to machine learning models; time series analysis, focusing especially on car- bon and micrometeorological flux; and communication. Introduction to Environmental Data Science. It is an ideal textbook to teach undergraduate to graduate level students in environmen- tal science, environmental studies, geography, earth science, and biology, but can also serve as a reference for environmental professionals working in consulting, NGOs, and government agen- cies at the local, state, federal, and international levels. Features • Gives thorough consideration of the needs for environmental research in both spatial and temporal domains. • Features examples of applications involving field-collected data ranging from individual ob- servations to data logging. • Includes examples also of applications involving government and NGO sources, ranging from satellite imagery to environmental data collected by regulators such as EPA. • Contains class-tested exercises in all chapters other than case studies. Solutions manual available for instructors. • All examples and exercises make use of a GitHub package for functions and especially data. Taylor & Francis Taylor & Francis Group http://taylorandfrancis.com Introduction to Environmental Data Science Jerry D. Davis Designed cover image: By Anna Studwell and Jerry D. Davis First edition published 2023 by CRC Press 6000 Broken Sound Parkway NW, Suite 300, Boca Raton, FL 33487-2742 and by CRC Press 4 Park Square, Milton Park, Abingdon, Oxon, OX14 4RN CRC Press is an imprint of Taylor & Francis Group, LLC © 2023 Jerry D. Davis Reasonable efforts have been made to publish reliable data and information, but the author and publisher cannot assume responsibility for the validity of all materials or the consequences of their use. The authors and publishers have attempted to trace the copyright holders of all material reproduced in this publication and apologize to copyright holders if permission to publish in this form has not been obtained. If any copyright material has not been acknowl- edged please write and let us know so we may rectify in any future reprint. Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced, transmitted, or utilized in any form by any electronic, mechanical, or other means, now known or hereafter invented, including pho- tocopying, microfilming, and recording, or in any information storage or retrieval system, without written permission from the publishers. For permission to photocopy or use material electronically from this work, access www.copyright.com or contact the Copyright Clearance Center, Inc. (CCC), 222 Rosewood Drive, Danvers, MA 01923, 978-750-8400. For works that are not available on CCC please contact [email protected] Trademark notice: Product or corporate names may be trademarks or registered trademarks and are used only for identification and explanation without intent to infringe. ISBN: 978-1-032-32218-6 (hbk) ISBN: 978-1-032-33034-1 (pbk) ISBN: 978-1-003-31782-1 (ebk) DOI: 10.1201/9781003317821 Typeset in LM Roman by KnowledgeWorks Global Ltd. Publisher’s note: This book has been prepared from camera-ready copy provided by the authors. “Dandelion fluff – Ephemeral stalk sheds seeds to the universe” by Anna Studwell Taylor & Francis Taylor & Francis Group http://taylorandfrancis.com Contents Author/editor biographies xiii List of Figures xv 1 Background, Goals and Data 1 1.1 Environmental Data Science . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.2 Environmental Data and Methods . . . . . . . . . . . . . . . . . . . . . . . 1 1.3 Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 1.3.1 Some definitions: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 1.4 Exploratory Data Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 1.5 Software and Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 1.5.1 Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 1.6 Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 I Exploratory Data Analysis 11 2 Introduction to R 13 2.1 Data Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 2.1.1 Scalars and assignment . . . . . . . . . . . . . . . . . . . . . . . . . 14 2.2 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 2.3 Expressions and Statements . . . . . . . . . . . . . . . . . . . . . . . . . . 17 2.4 Data Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 2.4.1 Integers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 2.5 Rectangular Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 2.6 Data Structures in R . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 2.6.1 Vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 2.6.2 Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 2.6.3 Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 2.6.4 Data frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 2.6.5 Factors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 2.7 Accessors and Subsetting . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 2.7.1 [] Subsetting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 2.7.2 [[]] The mysterious double bracket . . . . . . . . . . . . . . . . . . 41 2.7.3 $ Accessing a vector from a data frame. . . . . . . . . . . . . . . . . 42 2.8 Programming scripts in RStudio . . . . . . . . . . . . . . . . . . . . . . . . 42 2.8.1 function : creating your own . . . . . . . . . . . . . . . . . . . . . . 43 2.8.2 if : conditional operations . . . . . . . . . . . . . . . . . . . . . . . . 44 2.8.3 for loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 2.8.4 Subsetting with logic . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 2.8.5 Apply functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 2.9 RStudio projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 2.9.1 R Markdown . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 vii viii Contents 2.10 Exercises: Introduction to R . . . . . . . . . . . . . . . . . . . . . . . . . . 53 3 Data Abstraction 55 3.1 The Tidyverse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 3.2 Tibbles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 3.2.1 Building a tibble from vectors . . . . . . . . . . . . . . . . . . . . . . 57 3.2.2 tribble . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 3.2.3 read_csv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 3.3 Summarizing variable distributions . . . . . . . . . . . . . . . . . . . . . . 60 3.3.1 Stratifying variables by site using a Tukey box plot . . . . . . . . . . 62 3.4 Database operations with dplyr . . . . . . . . . . . . . . . . . . . . . . . . 63 3.4.1 Select, mutate, and the pipe . . . . . . . . . . . . . . . . . . . . . . . 63 3.4.2 filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 3.4.3 Writing a data frame to a csv . . . . . . . . . . . . . . . . . . . . . . 67 3.4.4 Summarize by group . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 3.4.5 Count . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 3.4.6 Sorting after summarizing . . . . . . . . . . . . . . . . . . . . . . . . 69 3.4.7 The dot operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 3.5 String abstraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 3.5.1 Detecting matches . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 3.5.2 Subsetting strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 3.5.3 String length . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 3.5.4 Replacing substrings with other text (“mutating” strings) . . . . . . 73 3.5.5 Concatenating and splitting . . . . . . . . . . . . . . . . . . . . . . . 74 3.6 Dates and times with lubridate . . . . . . . . . . . . . . . . . . . . . . . . 76 3.7 Calling functions explicitly with :: . . . . . . . . . . . . . . . . . . . . . . 77 3.8 Exercises: Data Abstraction . . . . . . . . . . . . . . . . . . . . . . . . . . 77 4 Visualization 79 4.1 plot in base R . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 4.2 ggplot2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 4.3 Plotting one variable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 4.3.1 Histogram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 4.3.2 Density plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 4.3.3 Boxplot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 4.4 Plotting Two Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 4.4.1 Two continuous variables . . . . . . . . . . . . . . . . . . . . . . . . 90 4.4.2 Two variables, one discrete . . . . . . . . . . . . . . . . . . . . . . . 92 4.4.3 Color systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 4.4.4 Trend line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 4.5 General Symbology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 4.5.1 Categorical symbology . . . . . . . . . . . . . . . . . . . . . . . . . . 99 4.5.2 Log scales instead of transform . . . . . . . . . . . . . . . . . . . . . 99 4.6 Graphs from Grouped Data . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 4.6.1 Faceted graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102 4.7 Titles and Subtitles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102 4.8 Pairs Plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 4.9 Exercises: Visualization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 5 Data Transformation 107 5.1 Data joins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 Contents ix 5.2 Set operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 5.3 Binding rows and columns . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 5.4 Pivoting data frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 5.4.1 pivot_longer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 5.4.2 pivot_wider . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 5.4.3 A free_y faceted graph using a pivot . . . . . . . . . . . . . . . . . . 116 5.5 Exercise: Transformation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 II Spatial 121 6 Spatial Data and Maps 123 6.1 Spatial Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 6.1.1 Simple geometry building in sf . . . . . . . . . . . . . . . . . . . . . 125 6.1.2 Building points from a data frame . . . . . . . . . . . . . . . . . . . 128 6.1.3 SpatVectors in terra . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 6.1.4 Creating features from shapefiles . . . . . . . . . . . . . . . . . . . . 133 6.2 Coordinate Referencing Systems . . . . . . . . . . . . . . . . . . . . . . . . 135 6.3 Creating sf Data from Data Frames . . . . . . . . . . . . . . . . . . . . . . 137 6.3.1 Removing geometry . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 6.4 Base R’s plot() with terra . . . . . . . . . . . . . . . . . . . . . . . . . . . 138 6.4.1 Using maptiles to create a basemap . . . . . . . . . . . . . . . . . . 139 6.5 Raster data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141 6.5.1 Building rasters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141 6.5.2 Vector to raster conversion . . . . . . . . . . . . . . . . . . . . . . . 143 6.6 ggplot2 for Maps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146 6.6.1 Rasters in ggplot2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 6.7 tmap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150 6.8 Interactive Maps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 6.8.1 Leaflet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 6.8.2 Mapview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 6.8.3 tmap (view mode) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156 6.8.4 Interactive mapping of individual penguins abstracted from a big dataset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 6.9 Exercises: Spatial Data and Maps . . . . . . . . . . . . . . . . . . . . . . . 159 6.9.1 Project preparation . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 7 Spatial Analysis 163 7.1 Data Frame Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164 7.1.1 Using grouped summaries, and filtering by a selection . . . . . . . . 165 7.2 Spatial Analysis Operations . . . . . . . . . . . . . . . . . . . . . . . . . . 168 7.2.1 Using topology to subset. . . . . . . . . . . . . . . . . . . . . . . . . 168 7.2.2 Centroid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 7.2.3 Distance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 7.2.4 Buffers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178 7.2.5 Spatial overlay: union and intersection . . . . . . . . . . . . . . . . . 179 7.2.6 Clip with st_crop . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182 7.2.7 Spatial join with st_join . . . . . . . . . . . . . . . . . . . . . . . . 183 7.2.8 Further exploration of spatial analysis . . . . . . . . . . . . . . . . . 184 7.3 Exercises: Spatial Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . 184 8 Raster Spatial Analysis 187

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.