oscarperpinan / solar

Solar Radiation and Photovoltaic Systems with R
http://oscarperpinan.github.io/solar/
GNU General Public License v3.0
35 stars 11 forks source link

solaR sometimes gives NaNs for Pdc and NREL input data #6

Closed abeylinNEG closed 8 years ago

abeylinNEG commented 8 years ago

NREL data from http://rredc.nrel.gov/solar/old_data/nsrdb/1991-2010/ provides for global radiation G0 zero values for night hours. From the other hand the expression fd <- D0/G0 is used in the fCompI() function. This in some cases finally produces NaN in output results for some (not all) hours where G0=0.

Problem disappears if to add to G0 very small constant

oscarperpinan commented 8 years ago

Next line in fCompI sets all variables to zero for night periods. This should remove the NaN values for night hours. However, it is still possible to have G0 = 0 during the day. Is this the problem you have found? If so, could you please provide a reproducible example (code + data)?

abeylinNEG commented 8 years ago

Oscar,

Thank you for quick response. Please see the attached file with radiance data. I am using only columns P(16), R(18) and T(20). File doesn't include temperature. You can add any meaningful value.

My last command is:

output<-fProd(gef0, module, generator, inverter, effSys)

All data but radiance is default After

< output$Pdc[1:105,]

I see three NaNs (see attached NaN.txt file. All of them appear at 7:00 AM (last 0 before nonzero values)

Regards,

Alex

On Mon, Jan 25, 2016 at 1:13 PM, Oscar Perpiñán Lamigueiro < notifications@github.com> wrote:

Next line in fCompI https://github.com/oscarperpinan/solar/blob/master/R/fCompI.R#L107 sets all variables to zero for night periods. This should remove the NaN values for night hours. However, it is still possible to have G0 = 0 during the day. Is this the problem you have found? If so, could you please provide a reproducible example (code + data)?

— Reply to this email directly or view it on GitHub https://github.com/oscarperpinan/solar/issues/6#issuecomment-174664860.

output$Pdc[1:105,] 1991-01-01 01:00:00 1991-01-01 02:00:00 1991-01-01 03:00:00 1991-01-01 04:00:00 0.0000 0.0000 0.0000 0.0000 1991-01-01 05:00:00 1991-01-01 06:00:00 1991-01-01 07:00:00 1991-01-01 08:00:00 0.0000 0.0000 0.0000 1938.2429 1991-01-01 09:00:00 1991-01-01 10:00:00 1991-01-01 11:00:00 1991-01-01 12:00:00 6289.5784 9941.8023 12324.7257 13395.1012 1991-01-01 13:00:00 1991-01-01 14:00:00 1991-01-01 15:00:00 1991-01-01 16:00:00 12874.9620 11535.6404 8585.9355 4528.6982 1991-01-01 17:00:00 1991-01-01 18:00:00 1991-01-01 19:00:00 1991-01-01 20:00:00 714.2535 0.0000 0.0000 0.0000 1991-01-01 21:00:00 1991-01-01 22:00:00 1991-01-01 23:00:00 1991-01-02 00:00:00 0.0000 0.0000 0.0000 0.0000 1991-01-02 01:00:00 1991-01-02 02:00:00 1991-01-02 03:00:00 1991-01-02 04:00:00 0.0000 0.0000 0.0000 0.0000 1991-01-02 05:00:00 1991-01-02 06:00:00 1991-01-02 07:00:00 1991-01-02 08:00:00 0.0000 0.0000 0.0000 1394.1153 1991-01-02 09:00:00 1991-01-02 10:00:00 1991-01-02 11:00:00 1991-01-02 12:00:00 4337.1744 4929.8853 8227.9739 8194.6408 1991-01-02 13:00:00 1991-01-02 14:00:00 1991-01-02 15:00:00 1991-01-02 16:00:00 8844.6304 7888.6165 5311.9963 1888.0762 1991-01-02 17:00:00 1991-01-02 18:00:00 1991-01-02 19:00:00 1991-01-02 20:00:00 496.0761 0.0000 0.0000 0.0000 1991-01-02 21:00:00 1991-01-02 22:00:00 1991-01-02 23:00:00 1991-01-03 00:00:00 0.0000 0.0000 0.0000 0.0000 1991-01-03 01:00:00 1991-01-03 02:00:00 1991-01-03 03:00:00 1991-01-03 04:00:00 0.0000 0.0000 0.0000 0.0000 1991-01-03 05:00:00 1991-01-03 06:00:00 1991-01-03 07:00:00 1991-01-03 08:00:00 0.0000 0.0000 NaN 517.5613 See NaN 1991-01-03 09:00:00 1991-01-03 10:00:00 1991-01-03 11:00:00 1991-01-03 12:00:00 1582.9710 2547.8441 3210.4251 3518.5740 1991-01-03 13:00:00 1991-01-03 14:00:00 1991-01-03 15:00:00 1991-01-03 16:00:00 3457.0685 3004.1289 2234.8213 1201.4213 1991-01-03 17:00:00 1991-01-03 18:00:00 1991-01-03 19:00:00 1991-01-03 20:00:00 0.0000 0.0000 0.0000 0.0000 1991-01-03 21:00:00 1991-01-03 22:00:00 1991-01-03 23:00:00 1991-01-04 00:00:00 0.0000 0.0000 0.0000 0.0000 1991-01-04 01:00:00 1991-01-04 02:00:00 1991-01-04 03:00:00 1991-01-04 04:00:00 0.0000 0.0000 0.0000 0.0000 1991-01-04 05:00:00 1991-01-04 06:00:00 1991-01-04 07:00:00 1991-01-04 08:00:00 0.0000 0.0000 NaN 1393.3539 See NaN 1991-01-04 09:00:00 1991-01-04 10:00:00 1991-01-04 11:00:00 1991-01-04 12:00:00 1382.3607 4530.0601 4486.2555 11143.8837 1991-01-04 13:00:00 1991-01-04 14:00:00 1991-01-04 15:00:00 1991-01-04 16:00:00 10409.8647 5242.6654 3395.4459 2662.0251 1991-01-04 17:00:00 1991-01-04 18:00:00 1991-01-04 19:00:00 1991-01-04 20:00:00 0.0000 0.0000 0.0000 0.0000 1991-01-04 21:00:00 1991-01-04 22:00:00 1991-01-04 23:00:00 1991-01-05 00:00:00 0.0000 0.0000 0.0000 0.0000 1991-01-05 01:00:00 1991-01-05 02:00:00 1991-01-05 03:00:00 1991-01-05 04:00:00 0.0000 0.0000 0.0000 0.0000 1991-01-05 05:00:00 1991-01-05 06:00:00 1991-01-05 07:00:00 1991-01-05 08:00:00 0.0000 0.0000 NaN 768.9900 See NaN 1991-01-05 09:00:00 3917.7387

abeylinNEG commented 8 years ago

Oscar,

The attached file has codes that reproduce the problem.

Alex

On Mon, Jan 25, 2016 at 2:34 PM, Alex Beylin abeylin@negll.com wrote:

Oscar,

Thank you for quick response. Please see the attached file with radiance data. I am using only columns P(16), R(18) and T(20). File doesn't include temperature. You can add any meaningful value.

My last command is:

output<-fProd(gef0, module, generator, inverter, effSys)

All data but radiance is default After

< output$Pdc[1:105,]

I see three NaNs (see attached NaN.txt file. All of them appear at 7:00 AM (last 0 before nonzero values)

Regards,

Alex

On Mon, Jan 25, 2016 at 1:13 PM, Oscar Perpiñán Lamigueiro < notifications@github.com> wrote:

Next line in fCompI https://github.com/oscarperpinan/solar/blob/master/R/fCompI.R#L107 sets all variables to zero for night periods. This should remove the NaN values for night hours. However, it is still possible to have G0 = 0 during the day. Is this the problem you have found? If so, could you please provide a reproducible example (code + data)?

— Reply to this email directly or view it on GitHub https://github.com/oscarperpinan/solar/issues/6#issuecomment-174664860.

oscarperpinan commented 8 years ago

I cannot find the data you are referring to. You can attach files using the GitHub interface (I am not sure if they work when replying by email), or use a gist to paste it.

abeylinNEG commented 8 years ago

Oscar, it takes a little time to understand how gist works. So, this time I am sending attachment again and in addition put codes to the email text

NaN_Test.R

#

Calculating solar plans productivity by using the "solaR" package

#

# require(solaR)

usStationPath<-"I:/alex-PC/_GLORA/WEATHER/Databases/US-stations.csv"

usStationFrame<-as.data.frame(read.csv(usStationPath, row.names = NULL))

solarDir<-'I:/SOLAR_DB/noaa_1991-2010_csv/'

sourceFile<-'690150_1991_solar.csv'

solarPath <- paste0(solarDir,sourceFile) solarDat<-read.csv(solarPath,head=FALSE,sep=',',stringsAsFactors=FALSE) solarDat<- solarDat[-1,]

G0<-as.numeric(solarDat$V16) B<-as.numeric(solarDat$V18) D0<-as.numeric(solarDat$V20) Ta<-rep(30,length(G0)) B0<-G0-D0 solarDataF<-data.frame(solarDat$V1, solarDat$V2, G0,B,D0,Ta,B0)

idxLocal <- with(solarDataF, as.POSIXct(paste(solarDat$V1,solarDat$V2), format='%m/%d/%Y %H:%M')) # "GMT" is "UTC" idx<-idxLocal # temporarily lat=20.77

NRELMeteo <- zoo(solarDataF[,c('G0', 'B0', 'D0', 'Ta')], idx)

Modules related data

Vocn<-57.6 # Default open-circuit voltage of the module at Standard Test Conditions (volts) Iscn<-4.7 # Default short circuit current of the module at Standard Test Conditions (amperes) Vmn<-46.08 # Default maximum power point voltage of the module at Standard Test Conditions (amperes) Imn<-4.35 # Default Maximum power current of the module at Standard Test Conditions (amperes) Ncs<-96 # Default number of cells in series inside the module Ncp<-1 # Default number of cells in parallel inside the module CoefVT<-0.0023 # Default coefficient of decrement of voltage of each cell with the temperature

volts per celsius degree

TONC<-47 # Default nominal operational cell temperature, celsius degree

Generator related data

Nms<-12 # Default number of modules in series Nmp<-11 # Default number of modules in parallel

Inverter related data

Ki<-c(0.01, 0.025, 0.05) # Default: vector of three values, coefficients of the efficiency curve of the inverter

or a matrix of nine values (3x3) if there is dependence with the

voltage (see references). Pinv<-25000 # Default nominal inverter power (watts)

Vmin<-420 # minimum voltages of the MPP range of the inverter Vmax<-750 # maximum voltages of the MPP range of the inverter Gumb<-20 # minimum irradiance for the inverter to start (W/m?)

effSys - information about the system losses

ModQual<-3 # Default average tolerance of the set of modules (%) ModDisp<-2 # Default module parameter disperssion losses (%) OhmDC<-1.5 # Default Joule losses due to the DC wiring (%) OhmAC<-1.5 # Default Joule losses due to the AC wiring (%) MPP<-1 # Default average error of the MPP algorithm of the inverter (%), TrafoMT<-1 # Default losses due to the MT transformer (%) Disp<-0.5 # Default losses due to stops of the system (%)

sType<-"fixed" # Type of module. Options: 'fixed', 'two' or 'horiz'

NRELMeteo<-NRELMeteo[-8760,]

See examples for calcGef

gef0<-calcGef(lat, modeTrk=sType, modeRad='bdI', dataRad=NRELMeteo, # Main data input sample='hour', keep.night=TRUE, sunGeometry='michalsky', corr='none', f, betaLim=90, beta=abs(lat)-10, # numeric, inclination angle of the surface (degrees).

It is only needed when modeTrk='fixed'.

            alfa=0,             # Default numeric, azimuth angle of the

surface (degrees).

It is positive to the West. It is only needed when

modeTrk='fixed'.

            iS=2,
            alb=0.2,
            horizBright=TRUE,
            HCPV=FALSE,
            modeShd='' #,
            #   struct=list(),
            #    #   distances=data.frame()

) gef0@GefI$Gef[1:103,] # highlihts problem? # module=list(Vocn,Iscn,Vmn,Imn,Ncs,Ncp,CoefVT,TONC) # generator<-list(Nms,Nmp) inverter=list(Ki,Pinv,Vmin, Vmax,Gumb) effSys=list(ModQual,ModDisp,OhmDC,OhmAC,MPP,TrafoMT,Disp)

!!!

output<-fProd(gef0, module, generator, inverter, effSys)

output<-fProd(gef0)

!!!

NRELMeteo[1:105,] output$Pdc[1:105,] is.numeric(output$Pdc[1,1])

On Thu, Jan 28, 2016 at 3:40 PM, Oscar Perpiñán Lamigueiro < notifications@github.com> wrote:

I cannot find the data you are referring to. You can attach files using the GitHub interface (I am not sure if they work when replying by email), or use a gist https://gist.github.com/ to paste it.

— Reply to this email directly or view it on GitHub https://github.com/oscarperpinan/solar/issues/6#issuecomment-176482999.

oscarperpinan commented 8 years ago

I have tried to reproduce your results but I don't get the NaN problem. Here is my code:

library(solaR)

## https://people.csail.mit.edu/jaffer/SimRoof/TMY3_Stations                                        
latitude <- 34.300
longitude <- -116.167

## Data use local sidereal time, so no time zone correction is needed.                              
z <-
read.zoo('http://rredc.nrel.gov/solar/old_data/nsrdb/1991-2010/data/hourly/690150/690150_1991_solar\
.csv',
              header = TRUE,
              sep = ',', dec = '.',
              index = c(1, 2), tz = 'UTC',
              FUN = paste, FUN2 = as.POSIXct)

NRELMeteo <- z[, c("METSTAT.Glo..Wh.m.2.",
           "METSTAT.Dir..Wh.m.2.",
           "METSTAT.Dif..Wh.m.2.")]
names(NRELMeteo) <- c('G0', 'B', 'D0')
NRELMeteo$B0 <- with(NRELMeteo, G0-D0)

gef0 <- calcGef(lat = latitude, dataRad = NRELMeteo,
                modeRad = 'bdI', corr = 'none')
as.zooI(gef0)

prod <- prodGCPV(lat = latitude, dataRad = NRELMeteo,
                 modeRad = 'bdI', corr = 'none')
as.zooI(prod)
any(is.nan(as.zooI(prod)$Pac))