peterson-tim-j / AWAPer

Builds netCDF files of the Bureau of Meteorology Australian Water Availability Project daily national climate grids and extract catchment average data
18 stars 5 forks source link

Issues with solar radiation #19

Closed buzacott closed 4 years ago

buzacott commented 4 years ago

First of all nice package.

I've encountered an issue with the solar radiation netCDF file. I used makeNetCDF_file to download data from 1990 to 2018 and it seems from 2010-11-01 no rad data is saved. I looked at the downloaded grid files and they don't seem to have a problem.

Here is a plot for mean solar radiation for Australia from 1990-2018 showing when the issue occurs: MeanRadPlot

It seems that dates from 2010-11-01 have fill values.

Here is a reproducible example:

library(AWAPer)
library(lubridate)
library(ncdf4)

setwd('~/Data/AWAPer/')

# Make a new netCDF file
makeNetCDF_file(updateFrom = as.Date('2010-10-27'),
                updateTo   = as.Date('2010-11-03'),
                keepFiles  = TRUE)

# Open solar file
nc = nc_open('AWAP_solar.nc')

solar = nc$var$solarrad
varsize = solar$varsize
ndims = solar$ndims
nt = varsize[ndims]

time = ncvar_get(nc, 'time')
origin = as_date('1990-01-01')
delta = as.integer(as_date('2010-11-01') - origin)
indx = delta + 1
print(origin + time[indx])

start = c(1, 1, indx)
count = varsize
count[ndims] = 1

slice = ncvar_get(nc, varid = 'solarrad', start=start, count=count)

image(slice)

nc_close(nc)

# Look at downloaded grid file
library(raster)
R.utils::gunzip('solarrad20101101.grid.gz')
r = raster('solarrad20101101.grid')
plot(r)
# No problems

# precip/tmax etc is unaffected
nc = nc_open('AWAP.nc')

precip = nc$var$precip
varsize = precip$varsize
ndims = precip$ndims
nt = varsize[ndims]

time = ncvar_get(nc, 'time')
origin = as_date('1900-01-01')
delta = as.integer(as_date('2010-11-01') - origin)
indx = delta + 1
print(origin + time[indx])

start = c(1, 1, indx)
count = varsize
count[ndims] = 1

slice = ncvar_get(nc, varid = 'precip', start=start, count=count)

image(slice)

nc_close(nc)
buzacott commented 4 years ago

Ah, this is a lot simpler. Running catchment extraction is fine - I think it is just not setting the fill values to NA properly from 2010-11-01 for whatever reason.

peterson-tim-j commented 4 years ago

Hi Alex, Thanks the bug detection. I have just noticed that the NODATA value in the BoM solar grids change over time. I'll make a fix to the code very soon. Once done, I'll close this issue.

peterson-tim-j commented 4 years ago

Hi Alex. I just pushed a new version (0.1.42) that handles the NODATA value changing over time (in solar data and all other variables). Below is the solar radiation image plos from your example code. If you're happy with then pls close this issue.

Also, in case you'd missed it the paper for the package is at https://onlinelibrary.wiley.com/doi/abs/10.1002/hyp.13637

issue19

buzacott commented 4 years ago

Awesome, thanks.