julieshortridge / Climate-Analysis

0 stars 0 forks source link

Spatial Extents #3

Closed nalarsson closed 1 year ago

nalarsson commented 1 year ago

Shapefile with desired extent + attributes. Attributes include counties names, fips codes, etc.

States

nalarsson commented 1 year ago

CMIP NETCDF file extent with spatial reference. File is "ATL_tasmax_day_UKESM1-0-LL_historical_r1i1p1f2_gn_1950.nc." Coordinate system is "World Geodetic System 1984"

CMIPExtent_OverlayedStates

nalarsson commented 1 year ago

Creating summary tables for data. These are for the UKESM1-0-LL historical data for year 1950. There is no tasmax data for this model; let me know if you want me to make a tasmax summary for a different model/emissions scenario or if you want to download a tasmax file from this model and I can do a summary on that.

Units: Temperature is in Celsius, Precipitation is in mm/day

summary_tasmin.csv summary_pr.csv summary_pr_adjustedunits.csv

nalarsson commented 1 year ago

Edit SOMETIMES, ncvar_get() runs without the "varid=" in the command. If I run

ncvar_get(ncin,pat)

it works, but only sometimes.


Error with ncvar_get() command.

ncvar_get(ncin, varid="pr") Error in R_nc4_inq_varndims: NetCDF: Not a valid ID Error in ncvar_ndims(ncid, varid) : error returned from C call

ncin is the variable that stores the nc_open command. No issues with this command.

This was the error I tried to show on Friday, but then I ran my code again and it wasn't producing the error. I've tried running the code on a few files to see if a single file was corrupted, but that isn't the case. I've also confirmed that the "pr" variable does exist in the file I'm working with; I've run names(ncin$var) and "pr" is returned, and I have visually confirmed that data exists in this file.

This is preventing me from creating summaries of files with units we can understand, but I am able to keep working on other aspects of the NetCDF tutorial.

nalarsson commented 1 year ago

Just so you're aware, time is "days since 1850-01-01" in CMIP6. In CMIP5, it was "days since 1860-01-01". Doesn't seem like it will be an issue but I took note just in case.

Another time update: all the files appear to have 360 days in them. I check this for files in the UKESM-0-LL historical and ssp585 files. Working on more currently just to make sure this is constant across emissions scenarios and models. Skipped to the "extracting and processing" part of the tutorial. Let me know your thoughts on this time thing.

nalarsson commented 1 year ago

Issues with selecting correct cell from raster. Here's what I have checked so far. I'm stumped, let me know if you have any advice.

Checked extents of raster and county shapefile:

extent(tmin.raster) class : Extent xmin : -90 xmax : -73 ymin : 30 ymax : 43 extent(app.counties) class : Extent xmin : -90.3103 xmax : -75.24227 ymin : 32.0346 ymax : 41.97752

Confirmed accuracy in logic for selecting raster bb.lon [1] -80.41394

bb.xcoord <- max(which(lon < bb.lon.east)) bb.xcoord [1] 38 lon[bb.xcoord] [1] 279.375 lon[bb.xcoord]-360 [1] -80.625 bb.lat [1] 37.22957 bb.ycoord <- max(which(lat < bb.lat)) bb.ycoord [1] 29 lat[bb.ycoord] [1] 37.125

Lat/Lon for Montgomery County, which is highlighted in blue on the map.

Montgomery.County@bbox
min max x -80.61406 -80.17640 y 36.98157 37.36679

First photo: What I think is the more correct one. CheckSpatialExtent

Second photo: Switched lat/lon to make sure I didn't mess that up. CheckSpatialExtentError

nalarsson commented 1 year ago

Using extract() to county file now. Issue still not fixed but is no longer relevant.