Skip to content

Instantly share code, notes, and snippets.

@mdsumner
Created September 6, 2022 11:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdsumner/6575e4f68a7974dc0aeeee096f3a63af to your computer and use it in GitHub Desktop.
Save mdsumner/6575e4f68a7974dc0aeeee096f3a63af to your computer and use it in GitHub Desktop.

https://twitter.com/TheRealJimShady/status/1567088699027890176?s=20&t=-GBIRyz6D0-bq1MGkM_WUQ

f <- "jimshady/returnPeriodShift_HELIX_dis_rcp85_r1_statistics.nc"
ncdf4::nc_open(f)

# File jimshady/returnPeriodShift_HELIX_dis_rcp85_r1_statistics.nc (NC_FORMAT_NETCDF4):
# 
#      2 variables (excluding dimension variables):
#         int baseline_year[]   (Contiguous storage)  
#             description: baseline year
#         float baseline_rp_shift[lat,lon,baseline_rp,warming_lev]   (Contiguous storage)  
#             description: shifted return periods of the baseline return values (years)
#             coordinates: lon lat
# 
#      4 dimensions:
#         lat  Size:360 
#             description: latitude
#             long_name: latitude
#             standard_name: latitude
#             units: degrees_north
#         lon  Size:720 
#             description: longitude
#             long_name: longitude
#             standard_name: longitude
#             units: degrees_east
#         warming_lev  Size:3 
#             description: warming level
#         baseline_rp  Size:6 
#             description: return period at the baseline (years)
#             
library(terra)
r <- rast("jimshady/returnPeriodShift_HELIX_dis_rcp85_r1_statistics.nc")
## set the wonky y-up extent first (else the downstream interpretation gets extra wonk)
ext(r) <- c(-90, 90, -180, 180)

## now transpose and flip in the normal way to get YX->XY  (log for contrast)
par(mfrow = c(2, 1))
plot(log(flip(trans(r[[1]]), "horizontal")))
maps::map(add = TRUE)
plot(log(flip(trans(r), "horizontal"))[[18]])
maps::map(add = TRUE)

image

## compare with not fixing
par(mfrow = c(1, 2))
plot(log(rast(f)[[1]]))
plot(log(rast(f)[[18]]))

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment