how to subset 3D precipitation data based on sowing date informationDrop factor levels in a subsetted data frameHow to join (merge) data frames (inner, outer, left, right)How to convert a factor to integernumeric without loss of information?How to drop columns by name in a data frameFaster reading of time series from netCDF?How to properly plot projected gridded data in ggplot2?Subset based on range of datesExtracting data from dataframe using different dataframe without headers (R)sub seasonal temperature data extraction from gridded data using by function

I found a password with hashcat, but it doesn't work

What is the meaning of "понаехать"?

UK - Working without a contract. I resign and guy wants to sue me

Encounter design and XP thresholds

Why isn't my calculation that we should be able to see the sun well beyond the observable universe valid?

Why is it easier to balance a non-moving bike standing up than sitting down?

What does it mean to not be able to take the derivative of a function multiple times?

Why are < or > requried to use /dev/tcp

Should the party get XP for a monster they never attacked?

Why does independence imply zero correlation?

What is the origin of Scooby-Doo's name?

Android Material and appcompat Manifest merger failed in react-native or ExpoKit

Similarity score: Can Sklearn SVR predict values greater than 1 and less than 0?

Loss of power when I remove item from the outlet

Why does the Saturn V have standalone inter-stage rings?

I don't like coffee, neither beer. How to politely work my way around that in a business situation?

How can I get my left hand to sound legato when I'm leaping?

Is a single radon daughter atom in air a solid?

What can I do with a research project that is my university’s intellectual property?

Am I legally required to provide a (GPL licensed) source code even after a project is abandoned?

What is appropriate short form for "laboratoires" in French?

Understanding the reasoning of the woman who agreed with Shlomo to "cut the baby in half"

Shooting someone's past self using special relativity

Will generated tokens be progressively stronger when using Cathar's Crusade and Sorin, Grim Nemesis?



how to subset 3D precipitation data based on sowing date information


Drop factor levels in a subsetted data frameHow to join (merge) data frames (inner, outer, left, right)How to convert a factor to integernumeric without loss of information?How to drop columns by name in a data frameFaster reading of time series from netCDF?How to properly plot projected gridded data in ggplot2?Subset based on range of datesExtracting data from dataframe using different dataframe without headers (R)sub seasonal temperature data extraction from gridded data using by function






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I have a 3-dimensional array of daily precipitation data [lon, lat, 365] and a 3-dimension file of sowing date [lon, lat, 30]. One sowing for each year on a grid cell. I have a code (given below) to extract season total (sowing to harvest) precipitation on each grid cell.



BUT, now I want to extract precipitation values only from day 30-60 after sowing date on each grid cell (i.e. sowing = day 157 on x,y grid cell for Kharif season and day 305 is sowing date for rabi crop on x, y grid cell). The result would be a 3- dimensional array of 30 days after sowing date [lon, lat, 30days].
I need different windows of days after sowing i.e. day 30-60, 80-100. Sowing date could be different in each grid cell so day 30 after sowing can be different in different grid cells but the length of days (day 30- 60) should be same. any help to select specific days length within the season based on sowing (sdate) and harvest (hdate) files is highly appreciated please



I have tried "by" function to extract 30 days precipitation data within the season from an array of precipitation with 377 176 376 dimensions. for each grid cell, sowing and harvest dates are different, and i tried to extract total precipitation data for 30 days after sowing. i used SDATE [dim(sdate)= 377 176 30] file as index but having error :
[1] 1982
Error in tapply(seq_len(22L), list(sdate[year] = 305L), function (x) :
arguments must have same length
In addition: Warning message:
In sdate[year - 1]:c(326:340) :
numerical expression has 15 elements: only the first used



#precipitation aray
prec<-array(0,dim=nyear)



for (year in c(2:30)) #first year not, because growing season might have started in year 0

print(year+1980)
inputprec.file<-paste("E:/Paper_2018/Prec/","prec_",1980+year,".nc",sep="")
inputprec.file.previous<-paste("E:/Paper_2018/Prec/","prec_",1980+year-1,".nc",sep="")

nc<-nc_open(inputprec.file)
lons<-ncvar_get(nc,"longitude")
lats<-ncvar_get(nc,"latitude")
val<-ncvar_get(nc,"pr")
nc_close(nc)

x<-which(abs(lons-lon)<0.01)
y<-which(abs(lats-lat)<0.01)
#for kharif season harvest date (260) is > sowing (157)

if(hdate[year]>sdate[year])

prec[year]<-sum(val[x,y,sdate[year]:hdate[year]]) # season total
else


#for Rabi sowing start in November and harvets occurs in March-April next year
prec[year]<-sum(val[x,y,1:hdate[year]]) # code to extract winter season total precipitation from sdate: hdate spans over two years (1982-1983)
# nc<-nc_open(inputprec.file.previous)
# val<-ncvar_get(nc,"pr")
# nc_close(nc)
prec[year]<-prec[year]+sum(val[x,y,sdate[year-1]:365])












share|improve this question




























    0















    I have a 3-dimensional array of daily precipitation data [lon, lat, 365] and a 3-dimension file of sowing date [lon, lat, 30]. One sowing for each year on a grid cell. I have a code (given below) to extract season total (sowing to harvest) precipitation on each grid cell.



    BUT, now I want to extract precipitation values only from day 30-60 after sowing date on each grid cell (i.e. sowing = day 157 on x,y grid cell for Kharif season and day 305 is sowing date for rabi crop on x, y grid cell). The result would be a 3- dimensional array of 30 days after sowing date [lon, lat, 30days].
    I need different windows of days after sowing i.e. day 30-60, 80-100. Sowing date could be different in each grid cell so day 30 after sowing can be different in different grid cells but the length of days (day 30- 60) should be same. any help to select specific days length within the season based on sowing (sdate) and harvest (hdate) files is highly appreciated please



    I have tried "by" function to extract 30 days precipitation data within the season from an array of precipitation with 377 176 376 dimensions. for each grid cell, sowing and harvest dates are different, and i tried to extract total precipitation data for 30 days after sowing. i used SDATE [dim(sdate)= 377 176 30] file as index but having error :
    [1] 1982
    Error in tapply(seq_len(22L), list(sdate[year] = 305L), function (x) :
    arguments must have same length
    In addition: Warning message:
    In sdate[year - 1]:c(326:340) :
    numerical expression has 15 elements: only the first used



    #precipitation aray
    prec<-array(0,dim=nyear)



    for (year in c(2:30)) #first year not, because growing season might have started in year 0

    print(year+1980)
    inputprec.file<-paste("E:/Paper_2018/Prec/","prec_",1980+year,".nc",sep="")
    inputprec.file.previous<-paste("E:/Paper_2018/Prec/","prec_",1980+year-1,".nc",sep="")

    nc<-nc_open(inputprec.file)
    lons<-ncvar_get(nc,"longitude")
    lats<-ncvar_get(nc,"latitude")
    val<-ncvar_get(nc,"pr")
    nc_close(nc)

    x<-which(abs(lons-lon)<0.01)
    y<-which(abs(lats-lat)<0.01)
    #for kharif season harvest date (260) is > sowing (157)

    if(hdate[year]>sdate[year])

    prec[year]<-sum(val[x,y,sdate[year]:hdate[year]]) # season total
    else


    #for Rabi sowing start in November and harvets occurs in March-April next year
    prec[year]<-sum(val[x,y,1:hdate[year]]) # code to extract winter season total precipitation from sdate: hdate spans over two years (1982-1983)
    # nc<-nc_open(inputprec.file.previous)
    # val<-ncvar_get(nc,"pr")
    # nc_close(nc)
    prec[year]<-prec[year]+sum(val[x,y,sdate[year-1]:365])












    share|improve this question
























      0












      0








      0








      I have a 3-dimensional array of daily precipitation data [lon, lat, 365] and a 3-dimension file of sowing date [lon, lat, 30]. One sowing for each year on a grid cell. I have a code (given below) to extract season total (sowing to harvest) precipitation on each grid cell.



      BUT, now I want to extract precipitation values only from day 30-60 after sowing date on each grid cell (i.e. sowing = day 157 on x,y grid cell for Kharif season and day 305 is sowing date for rabi crop on x, y grid cell). The result would be a 3- dimensional array of 30 days after sowing date [lon, lat, 30days].
      I need different windows of days after sowing i.e. day 30-60, 80-100. Sowing date could be different in each grid cell so day 30 after sowing can be different in different grid cells but the length of days (day 30- 60) should be same. any help to select specific days length within the season based on sowing (sdate) and harvest (hdate) files is highly appreciated please



      I have tried "by" function to extract 30 days precipitation data within the season from an array of precipitation with 377 176 376 dimensions. for each grid cell, sowing and harvest dates are different, and i tried to extract total precipitation data for 30 days after sowing. i used SDATE [dim(sdate)= 377 176 30] file as index but having error :
      [1] 1982
      Error in tapply(seq_len(22L), list(sdate[year] = 305L), function (x) :
      arguments must have same length
      In addition: Warning message:
      In sdate[year - 1]:c(326:340) :
      numerical expression has 15 elements: only the first used



      #precipitation aray
      prec<-array(0,dim=nyear)



      for (year in c(2:30)) #first year not, because growing season might have started in year 0

      print(year+1980)
      inputprec.file<-paste("E:/Paper_2018/Prec/","prec_",1980+year,".nc",sep="")
      inputprec.file.previous<-paste("E:/Paper_2018/Prec/","prec_",1980+year-1,".nc",sep="")

      nc<-nc_open(inputprec.file)
      lons<-ncvar_get(nc,"longitude")
      lats<-ncvar_get(nc,"latitude")
      val<-ncvar_get(nc,"pr")
      nc_close(nc)

      x<-which(abs(lons-lon)<0.01)
      y<-which(abs(lats-lat)<0.01)
      #for kharif season harvest date (260) is > sowing (157)

      if(hdate[year]>sdate[year])

      prec[year]<-sum(val[x,y,sdate[year]:hdate[year]]) # season total
      else


      #for Rabi sowing start in November and harvets occurs in March-April next year
      prec[year]<-sum(val[x,y,1:hdate[year]]) # code to extract winter season total precipitation from sdate: hdate spans over two years (1982-1983)
      # nc<-nc_open(inputprec.file.previous)
      # val<-ncvar_get(nc,"pr")
      # nc_close(nc)
      prec[year]<-prec[year]+sum(val[x,y,sdate[year-1]:365])












      share|improve this question














      I have a 3-dimensional array of daily precipitation data [lon, lat, 365] and a 3-dimension file of sowing date [lon, lat, 30]. One sowing for each year on a grid cell. I have a code (given below) to extract season total (sowing to harvest) precipitation on each grid cell.



      BUT, now I want to extract precipitation values only from day 30-60 after sowing date on each grid cell (i.e. sowing = day 157 on x,y grid cell for Kharif season and day 305 is sowing date for rabi crop on x, y grid cell). The result would be a 3- dimensional array of 30 days after sowing date [lon, lat, 30days].
      I need different windows of days after sowing i.e. day 30-60, 80-100. Sowing date could be different in each grid cell so day 30 after sowing can be different in different grid cells but the length of days (day 30- 60) should be same. any help to select specific days length within the season based on sowing (sdate) and harvest (hdate) files is highly appreciated please



      I have tried "by" function to extract 30 days precipitation data within the season from an array of precipitation with 377 176 376 dimensions. for each grid cell, sowing and harvest dates are different, and i tried to extract total precipitation data for 30 days after sowing. i used SDATE [dim(sdate)= 377 176 30] file as index but having error :
      [1] 1982
      Error in tapply(seq_len(22L), list(sdate[year] = 305L), function (x) :
      arguments must have same length
      In addition: Warning message:
      In sdate[year - 1]:c(326:340) :
      numerical expression has 15 elements: only the first used



      #precipitation aray
      prec<-array(0,dim=nyear)



      for (year in c(2:30)) #first year not, because growing season might have started in year 0

      print(year+1980)
      inputprec.file<-paste("E:/Paper_2018/Prec/","prec_",1980+year,".nc",sep="")
      inputprec.file.previous<-paste("E:/Paper_2018/Prec/","prec_",1980+year-1,".nc",sep="")

      nc<-nc_open(inputprec.file)
      lons<-ncvar_get(nc,"longitude")
      lats<-ncvar_get(nc,"latitude")
      val<-ncvar_get(nc,"pr")
      nc_close(nc)

      x<-which(abs(lons-lon)<0.01)
      y<-which(abs(lats-lat)<0.01)
      #for kharif season harvest date (260) is > sowing (157)

      if(hdate[year]>sdate[year])

      prec[year]<-sum(val[x,y,sdate[year]:hdate[year]]) # season total
      else


      #for Rabi sowing start in November and harvets occurs in March-April next year
      prec[year]<-sum(val[x,y,1:hdate[year]]) # code to extract winter season total precipitation from sdate: hdate spans over two years (1982-1983)
      # nc<-nc_open(inputprec.file.previous)
      # val<-ncvar_get(nc,"pr")
      # nc_close(nc)
      prec[year]<-prec[year]+sum(val[x,y,sdate[year-1]:365])









      r multidimensional-array subset






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 25 at 7:23









      QuratQurat

      113




      113






















          0






          active

          oldest

          votes












          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55332929%2fhow-to-subset-3d-precipitation-data-based-on-sowing-date-information%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55332929%2fhow-to-subset-3d-precipitation-data-based-on-sowing-date-information%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript