How to Open a NetCDF File and Map the Data in R

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everybody and welcome to another video in my last video I showed you how to download climate model data from the same apply project and I mentioned I was in the show how to visualize it and I haven't done that yet so we're gonna do that today so I'm using R and I'm gonna assume that you were already able to download the data and you have it saved somewhere the Met cdf thing is so here i'm going to show you how to open on that cdf file get the data out of it and plot it in a map so you can actually see the temperature projections from the climate models so here we go i'm going to start from a new screen and art and i'm gonna assume you know the basics so we're gonna go ahead and set directory just coffee so my data is saved here here you can see all the data then i've downloaded in the past these are all climate model data and today let's work with our CP 4.5 data so here we go and inside of that you can see that i've downloaded data from all these different models so access kenya sam jaya says IPS cell these are all the data that i've downloaded before so we're just gonna work from one of these then working from an old code that I wrote it's here in the left this app is called sublime it's really good to write coding and this is largely based on the work by Professor Bart line from the University of Oregon I'll link this page at the in comments below in the description box below it's back here first thing I want to do is you're gonna need all these libraries most of these are for plotting later on the only one you need to actually open the netcdf data is this one and CDF for library if you have that you'll be able to just open the data open the less you have data and all that so the first thing we're gonna do is open it and let's work with so in here you're gonna put in the file name of your netcdf file and if you're in the right directory where you save this file that's all you need to do is put in a quotation marks the name of that file of that neccessity I filed a downloaded so now you how to open and you need to get the variables on it right so first let's get the longitude variable and this function is common for all these extractions is NC variable get so you're getting a variable out of your net to your file and here you put and let's see in which is where you open your data and then you're extracting the longitude right and if you want to know what variables you have as an option go to your print and see pin right so this is all the information from that nescient file and here shows that you have all these variables right longitude latitude time and maximum air temperature because that's the data that I downloaded right so you already got watched it out if you want to see so the dimensions of their launch to variable is 192 and that's gonna vary by model so for access one dashed 1-0 this is that lunch two dimensions and then of course you need to get the latitude do the same thing except here we put in a lot and then you get the dimensions of latitude so access 1-0 as 192 longitude point points 145 latitude points the next way you need is a array of temperatures so you're going to get the data and see and for this case it's called Tazz max because that's the data that I downloaded you can also download mean temperature and minimum temperature there's other variables you can download and I showed that in my previous video so once you have that really that's all you need but I'll show you one more I'll post this code on lines you can see it but another useful thing is to learn how to get the attributes of the variable so let's say you want to know what unit the temperature is in to do and see at for attributes you're getting the attribute then you here you put task max and units so what this means is so previously to get the variable you put n c VAR get to get the actually beauties do n c @ get and this is the name of your file the variable and actually you don't wanna get you can see the unit so temperature saved in kelvin to just to show you that you can do this you can change the temporary into celsius by subtracting tuna 73 point 15 and let's see what the dimensions of the array is so the mitches is 192 145 1 1 4 0 so how it works is your temperature your temperature is saved in a three-dimensional why if you just think about it that way it's not really like that but imagine here you have latitude longitude and temperature goes out of the screen right so you have this box then each slice is at each time point so you have 144 time points and the time unit is in days after the first unit you get the first day so you can also get the units for the time again and see actually get and see it variables time units there you go day since that yeah and I downloaded monthly data so we're gonna have one slice per month for 95 years and that's all the data you need you have to watch to latitude and your temperature array so now you're done you can close it and we can start mapping and an easy way to map is you need to get a slice right you can and you can plot three dimensions but show you how to plot it in two dimensions so we can see it in the map so we get a slice of your array all longitudes all latitudes and the first time so I'm just going to be January right and then you do this is how the page that I showed does it it's an easy way to do it there you go you already have a map you can visualize your kness ETF data in kind of tell this is South America shalyah Africa this is a temperature it was kind of hard to see so I wrote this code here when I was in grad school and I'll share that in the description box below and really when you get this or in the description box all you need to do is copy this like I'm doing right now paste it right here so what we did was define a function called met map CDF temp and then that's the function what it does is fix or shift the longitude so that it's in a more conventional mapping way I guess with America in the middle kind of and then it kind of changes the temperatures and as legend so it's easier to tell o and country boundaries because right now can't really see you where everything is so that's what this function does and all you need to do is the function name right here and then it requires these variables as input the thing where you have those lat 1 and has instead name I gave it before but in our case is 10 slice and there you go we have mapped it these are maximum air temperature January 2001 not really a projection I guess because it's in the past but you can get a temperature slice of any time point right just get the array all on Institute's all latitudes and to do a little rock chat game we can see that January is winter and Northern Hemisphere and summer in the southern hemisphere so it makes sense but it's warmer South America Africa Australia right but today we'll check our work let's get it from June so it should be warmer in the northern hemisphere right so we'll do the same thing map it and there we go we have warmer the northern hemisphere a little bit colder and South America so there in Africa Australia so there you go this is pretty high-level I'm assuming you know how to work in art if you have any questions or you want me to dig deeper into any of these functions or I wrote this function or how to get more information out of here and let's see gif files I just post it in the comments below and I'll sorry about that to my phone and I'll make them letter under the video to answer those questions I hope this is helpful let me know what else you need and I'll work on making a video holiday
Info
Channel: EmpowerDat
Views: 21,509
Rating: 4.9530792 out of 5
Keywords: climate change, NetCDF, data
Id: roMf6xzB9NI
Channel Id: undefined
Length: 12min 0sec (720 seconds)
Published: Tue Apr 17 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.