{"action":"created","comment":{"url":"https://api.github.com/repos/PecanProject/pecan/pulls/comments/60837733","id":60837733,"diff_hunk":"@@ -0,0 +1,237 @@\n+#-------------------------------------------------------------------------------\n+# Copyright (c) 2012 University of Illinois, NCSA.\n+# All rights reserved. This program and the accompanying materials\n+# are made available under the terms of the \n+# University of Illinois/NCSA Open Source License\n+# which accompanies this distribution, and is available at\n+# http://opensource.ncsa.illinois.edu/license.html\n+#-------------------------------------------------------------------------------\n+#\n+## R Code to convert NetCDF CF met files into MAESPA met files\n+\n+##If files already exist in \"Outfolder\", the default function is NOT to overwrite them and \n+##only gives user the notice that file already exists. If user wants to overwrite the existing files, just change \n+##overwrite statement below to TRUE.\n+\n+##' met2model wrapper for MAESPA\n+##'\n+##' @title met2model.MAESPA\n+##' @export\n+##' @param in.path location on disk where inputs are stored\n+##' @param in.prefix prefix of input and output files\n+##' @param outfolder location on disk where outputs will be stored\n+##' @param start_date the start date of the data to be downloaded (will only use the year part of the date)\n+##' @param end_date the end date of the data to be downloaded (will only use the year part of the date)\n+##' @param overwrite should existing files be overwritten\n+##' @param verbose should the function be very verbose\n+##' \n+##' @author Tony Gardella\n+\n+met2model.MAESPA <- function(in.path, in.prefix, outfolder, start_date, end_date, ..., overwrite=FALSE,verbose=FALSE){\n+  \n+  \n+  library(PEcAn.utils)\n+  print(\"START met2model.MAESPA\")\n+  start.date <- as.POSIXlt(start_date, tz = \"GMT\")\n+  end.date<- as.POSIXlt(end_date, tz = \"GMT\")\n+  out.file <- paste(in.prefix, strptime(start.date, \"%Y-%m-%d\"),strptime(end.date, \"%Y-%m-%d\"),\"dat\", sep=\".\")\n+  out.file.full <- file.path(outfolder, out.file)\n+  \n+  results <- data.frame(file = out.file.full,\n+                        host = fqdn(),\n+                        mimetype ='text/plain',\n+                        formatname = 'maespa.met' ,\n+                        startdate = start_date ,\n+                        enddate = end_date,\n+                        dbfile.name = out.file,\n+                        stringsAsFactors = FALSE)\n+  print(\"internal results\")\n+  print(results)\n+  \n+  if (file.exists(out.file.full) && !overwrite) {\n+    logger.debug(\"File '\", out.file.full, \"' already exists, skipping to next file.\")\n+    return(invisible(results))\n+  }\n+  \n+  \n+  require(ncdf4)\n+  require(lubridate)\n+  require(PEcAn.data.atmosphere)\n+  \n+  ## check to see if the outfolder is defined, if not create directory for output\n+  if(!file.exists(outfolder)){\n+    dir.create(outfolder)\n+  }\n+  \n+  out <- NULL\n+  \n+  # get start/end year since inputs are specified on year basis\n+  start_year <- year(start.date)\n+  end_year <- year(end.date)\n+  \n+  ## loop over files\n+  for(year in start_year:end_year){\n+    print(year)\n+    \n+    old.file <- file.path(in.path, paste(in.prefix, year, \"nc\", sep=\".\"))\n+    \n+    if(file.exists(old.file)){\n+      ## open netcdf\n+      nc <- nc_open(old.file)\n+      ## convert time to seconds\n+      sec   <- nc$dim$time$vals  \n+      sec = udunits2::ud.convert(sec,unlist(strsplit(nc$dim$time$units,\" \"))[1],\"seconds\")\n+      \n+      ifelse(leap_year(year),\n+             dt <- (366*24*60*60)/length(sec), #leap year\n+             dt <- (365*24*60*60)/length(sec)) #non-leap year\n+      tstep = round(86400/dt)\n+      dt = 86400/tstep\n+      \n+      #Check wich variabales are available and which are not\n+      \n+      ## extract variables\n+      lat  <- ncvar_get(nc,\"latitude\")\n+      lon  <- ncvar_get(nc,\"longitude\")       \n+      RAD <-  ncvar_get(nc,\"surface_downwelling_shortwave_flux_in_air\") #W m-2\n+      PAR <-   try(ncvar_get(nc,\"surface_downwelling_photosynthetic_photon_flux_in_air\")) #mol m-2 s-1\n+      TAIR <-  ncvar_get(nc,\"air_temperature\") #K\n+      `RH%` <- try(ncvar_get(nc,\"relative_humidity\")) #percentage\n+      PPT <-  ncvar_get(nc,\"precipitation_flux\") #kg m-2 s-1\n+      CA <- try(ncvar_get(nc,\"mole_fraction_of_carbon_dioxide_in_air\")) #mol/mol\n+      PRESS <-  ncvar_get(nc,\"air_pressure\")# Pa\n+      \n+      # TSOIL <-  try(ncvar_get(nc,\"soil_temperature\")) #K\n+      # VMFD <-  try(ncvar_get(nc,\"vapour_pressure_mole_fraction_deficit\")) \n+      # WIND <- try(ncvar_get(nc,\"wind_speed\")) #m/s   \n+      # SW <-  try(ncvar_get(nc,\"soil_moisture\"))# kg m-2\n+      # SWP <- ncvar_get(nc,\"soil_water_potential)# MPa\n+      # TDEW <- try(ncvar_get(nc, \"dew_point_temperature\")) #Celsius\n+      # FBEAM <- ncvar_get try((nc,\"fraction_of_surface_downwelling_photosynthetic_photon_flux_in_air\") #frction of direct beam\n+      # RH <- try(ncvar_get(nc,\"relative_humidity\"))# fraction\n+      \n+          if(!is.numeric(PAR)){\n+            print(\"Photosynthetically Active Radiation(PAR)Calculated from RAD.If RAD absent, calculated from TAIR (DELTAT needed).\")}else{\n+              #4.6= unit conversion of W/m2 to mmol/m2/s\n+              #0.4805 = based on the approximation that PAR is 0.45-0.50 of the total radiation\n+              PAR <- PAR*4.6*0.4805##Convert W/m2 to mmol/m2/s \n+            }\n+          # ºC   air temperature. If nonexistant. Error.\n+          TAIR <- udunits2::ud.convert(TAIR,\"kelvin\",\"celsius\") \n+          \n+          ####ppm. atmospheric CO2 concentration. Constant from Enviiron namelist used instead\n+          if(!is.numeric(CA)){print(\"Atmospheric CO2 concentration will be set to constant value set in ENVIRON namelist \")\n+                              rm(CA)\n+                              defaultCO2= 400 #400 is estimation of atmospheric CO2 in ppm)\n+          }else{defaultCO2= 400} #400 is estimation of atmospheric CO2 in ppm))\n+          \n+          nc_close(nc)\n+        } else {\n+          print(\"Skipping to next year\")\n+          next\n+        }\n+        \n+        ##build time variables (year, month, day of year)\n+        skip = FALSE\n+        nyr <- floor(length(sec)/86400/365*dt)\n+        yr <- NULL\n+        doy <- NULL\n+        hr <- NULL\n+        asec <- sec\n+        for(y in year+1:nyr-1){","path":"models/maespa/R/met2model.MAESPA.R","position":141,"original_position":141,"commit_id":"6152d2494eb26fc780bc1167283fc4f67e3863d3","original_commit_id":"6152d2494eb26fc780bc1167283fc4f67e3863d3","user":{"login":"istfer","id":13728388,"avatar_url":"https://avatars.githubusercontent.com/u/13728388?v=3","gravatar_id":"","url":"https://api.github.com/users/istfer","html_url":"https://github.com/istfer","followers_url":"https://api.github.com/users/istfer/followers","following_url":"https://api.github.com/users/istfer/following{/other_user}","gists_url":"https://api.github.com/users/istfer/gists{/gist_id}","starred_url":"https://api.github.com/users/istfer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/istfer/subscriptions","organizations_url":"https://api.github.com/users/istfer/orgs","repos_url":"https://api.github.com/users/istfer/repos","events_url":"https://api.github.com/users/istfer/events{/privacy}","received_events_url":"https://api.github.com/users/istfer/received_events","type":"User","site_admin":false},"body":"@tonygardella could you comment your code in this section here a little","created_at":"2016-04-24T01:59:39Z","updated_at":"2016-04-24T01:59:39Z","html_url":"https://github.com/PecanProject/pecan/pull/784#discussion_r60837733","pull_request_url":"https://api.github.com/repos/PecanProject/pecan/pulls/784","_links":{"self":{"href":"https://api.github.com/repos/PecanProject/pecan/pulls/comments/60837733"},"html":{"href":"https://github.com/PecanProject/pecan/pull/784#discussion_r60837733"},"pull_request":{"href":"https://api.github.com/repos/PecanProject/pecan/pulls/784"}}},"pull_request":{"url":"https://api.github.com/repos/PecanProject/pecan/pulls/784","id":65817755,"html_url":"https://github.com/PecanProject/pecan/pull/784","diff_url":"https://github.com/PecanProject/pecan/pull/784.diff","patch_url":"https://github.com/PecanProject/pecan/pull/784.patch","issue_url":"https://api.github.com/repos/PecanProject/pecan/issues/784","number":784,"state":"open","locked":false,"title":"MAESPA: changes to get model2netcdf running","user":{"login":"tonygardella","id":8570691,"avatar_url":"https://avatars.githubusercontent.com/u/8570691?v=3","gravatar_id":"","url":"https://api.github.com/users/tonygardella","html_url":"https://github.com/tonygardella","followers_url":"https://api.github.com/users/tonygardella/followers","following_url":"https://api.github.com/users/tonygardella/following{/other_user}","gists_url":"https://api.github.com/users/tonygardella/gists{/gist_id}","starred_url":"https://api.github.com/users/tonygardella/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tonygardella/subscriptions","organizations_url":"https://api.github.com/users/tonygardella/orgs","repos_url":"https://api.github.com/users/tonygardella/repos","events_url":"https://api.github.com/users/tonygardella/events{/privacy}","received_events_url":"https://api.github.com/users/tonygardella/received_events","type":"User","site_admin":false},"body":"These changes will let MAESPA run the reference run and convert it's output to PEcAn standard netcdf files.\r\n\r\nNext up on my code review is: @colinaverill","created_at":"2016-04-08T17:10:55Z","updated_at":"2016-04-24T01:59:40Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5c75fdf8ad002307deb0a0a3d007347c2efffaf6","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/PecanProject/pecan/pulls/784/commits","review_comments_url":"https://api.github.com/repos/PecanProject/pecan/pulls/784/comments","review_comment_url":"https://api.github.com/repos/PecanProject/pecan/pulls/comments{/number}","comments_url":"https://api.github.com/repos/PecanProject/pecan/issues/784/comments","statuses_url":"https://api.github.com/repos/PecanProject/pecan/statuses/6152d2494eb26fc780bc1167283fc4f67e3863d3","head":{"label":"tonygardella:master","ref":"master","sha":"6152d2494eb26fc780bc1167283fc4f67e3863d3","user":{"login":"tonygardella","id":8570691,"avatar_url":"https://avatars.githubusercontent.com/u/8570691?v=3","gravatar_id":"","url":"https://api.github.com/users/tonygardella","html_url":"https://github.com/tonygardella","followers_url":"https://api.github.com/users/tonygardella/followers","following_url":"https://api.github.com/users/tonygardella/following{/other_user}","gists_url":"https://api.github.com/users/tonygardella/gists{/gist_id}","starred_url":"https://api.github.com/users/tonygardella/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tonygardella/subscriptions","organizations_url":"https://api.github.com/users/tonygardella/orgs","repos_url":"https://api.github.com/users/tonygardella/repos","events_url":"https://api.github.com/users/tonygardella/events{/privacy}","received_events_url":"https://api.github.com/users/tonygardella/received_events","type":"User","site_admin":false},"repo":{"id":40121211,"name":"pecan","full_name":"tonygardella/pecan","owner":{"login":"tonygardella","id":8570691,"avatar_url":"https://avatars.githubusercontent.com/u/8570691?v=3","gravatar_id":"","url":"https://api.github.com/users/tonygardella","html_url":"https://github.com/tonygardella","followers_url":"https://api.github.com/users/tonygardella/followers","following_url":"https://api.github.com/users/tonygardella/following{/other_user}","gists_url":"https://api.github.com/users/tonygardella/gists{/gist_id}","starred_url":"https://api.github.com/users/tonygardella/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tonygardella/subscriptions","organizations_url":"https://api.github.com/users/tonygardella/orgs","repos_url":"https://api.github.com/users/tonygardella/repos","events_url":"https://api.github.com/users/tonygardella/events{/privacy}","received_events_url":"https://api.github.com/users/tonygardella/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tonygardella/pecan","description":"The Predictive Ecosystem Analyzer (PEcAn) is an integrated ecological bioinformatics toolbox.","fork":true,"url":"https://api.github.com/repos/tonygardella/pecan","forks_url":"https://api.github.com/repos/tonygardella/pecan/forks","keys_url":"https://api.github.com/repos/tonygardella/pecan/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tonygardella/pecan/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tonygardella/pecan/teams","hooks_url":"https://api.github.com/repos/tonygardella/pecan/hooks","issue_events_url":"https://api.github.com/repos/tonygardella/pecan/issues/events{/number}","events_url":"https://api.github.com/repos/tonygardella/pecan/events","assignees_url":"https://api.github.com/repos/tonygardella/pecan/assignees{/user}","branches_url":"https://api.github.com/repos/tonygardella/pecan/branches{/branch}","tags_url":"https://api.github.com/repos/tonygardella/pecan/tags","blobs_url":"https://api.github.com/repos/tonygardella/pecan/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tonygardella/pecan/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tonygardella/pecan/git/refs{/sha}","trees_url":"https://api.github.com/repos/tonygardella/pecan/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tonygardella/pecan/statuses/{sha}","languages_url":"https://api.github.com/repos/tonygardella/pecan/languages","stargazers_url":"https://api.github.com/repos/tonygardella/pecan/stargazers","contributors_url":"https://api.github.com/repos/tonygardella/pecan/contributors","subscribers_url":"https://api.github.com/repos/tonygardella/pecan/subscribers","subscription_url":"https://api.github.com/repos/tonygardella/pecan/subscription","commits_url":"https://api.github.com/repos/tonygardella/pecan/commits{/sha}","git_commits_url":"https://api.github.com/repos/tonygardella/pecan/git/commits{/sha}","comments_url":"https://api.github.com/repos/tonygardella/pecan/comments{/number}","issue_comment_url":"https://api.github.com/repos/tonygardella/pecan/issues/comments{/number}","contents_url":"https://api.github.com/repos/tonygardella/pecan/contents/{+path}","compare_url":"https://api.github.com/repos/tonygardella/pecan/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tonygardella/pecan/merges","archive_url":"https://api.github.com/repos/tonygardella/pecan/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tonygardella/pecan/downloads","issues_url":"https://api.github.com/repos/tonygardella/pecan/issues{/number}","pulls_url":"https://api.github.com/repos/tonygardella/pecan/pulls{/number}","milestones_url":"https://api.github.com/repos/tonygardella/pecan/milestones{/number}","notifications_url":"https://api.github.com/repos/tonygardella/pecan/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tonygardella/pecan/labels{/name}","releases_url":"https://api.github.com/repos/tonygardella/pecan/releases{/id}","deployments_url":"https://api.github.com/repos/tonygardella/pecan/deployments","created_at":"2015-08-03T11:29:42Z","updated_at":"2016-01-14T14:56:32Z","pushed_at":"2016-04-23T22:15:04Z","git_url":"git://github.com/tonygardella/pecan.git","ssh_url":"git@github.com:tonygardella/pecan.git","clone_url":"https://github.com/tonygardella/pecan.git","svn_url":"https://github.com/tonygardella/pecan","homepage":"www.pecanproject.org","size":119668,"stargazers_count":0,"watchers_count":0,"language":"R","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"PecanProject:master","ref":"master","sha":"8f59098f66be5baa12f1ef159eb83591d4bba891","user":{"login":"PecanProject","id":2879854,"avatar_url":"https://avatars.githubusercontent.com/u/2879854?v=3","gravatar_id":"","url":"https://api.github.com/users/PecanProject","html_url":"https://github.com/PecanProject","followers_url":"https://api.github.com/users/PecanProject/followers","following_url":"https://api.github.com/users/PecanProject/following{/other_user}","gists_url":"https://api.github.com/users/PecanProject/gists{/gist_id}","starred_url":"https://api.github.com/users/PecanProject/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PecanProject/subscriptions","organizations_url":"https://api.github.com/users/PecanProject/orgs","repos_url":"https://api.github.com/users/PecanProject/repos","events_url":"https://api.github.com/users/PecanProject/events{/privacy}","received_events_url":"https://api.github.com/users/PecanProject/received_events","type":"Organization","site_admin":false},"repo":{"id":6857384,"name":"pecan","full_name":"PecanProject/pecan","owner":{"login":"PecanProject","id":2879854,"avatar_url":"https://avatars.githubusercontent.com/u/2879854?v=3","gravatar_id":"","url":"https://api.github.com/users/PecanProject","html_url":"https://github.com/PecanProject","followers_url":"https://api.github.com/users/PecanProject/followers","following_url":"https://api.github.com/users/PecanProject/following{/other_user}","gists_url":"https://api.github.com/users/PecanProject/gists{/gist_id}","starred_url":"https://api.github.com/users/PecanProject/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PecanProject/subscriptions","organizations_url":"https://api.github.com/users/PecanProject/orgs","repos_url":"https://api.github.com/users/PecanProject/repos","events_url":"https://api.github.com/users/PecanProject/events{/privacy}","received_events_url":"https://api.github.com/users/PecanProject/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/PecanProject/pecan","description":"The Predictive Ecosystem Analyzer (PEcAn) is an integrated ecological bioinformatics toolbox.","fork":false,"url":"https://api.github.com/repos/PecanProject/pecan","forks_url":"https://api.github.com/repos/PecanProject/pecan/forks","keys_url":"https://api.github.com/repos/PecanProject/pecan/keys{/key_id}","collaborators_url":"https://api.github.com/repos/PecanProject/pecan/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/PecanProject/pecan/teams","hooks_url":"https://api.github.com/repos/PecanProject/pecan/hooks","issue_events_url":"https://api.github.com/repos/PecanProject/pecan/issues/events{/number}","events_url":"https://api.github.com/repos/PecanProject/pecan/events","assignees_url":"https://api.github.com/repos/PecanProject/pecan/assignees{/user}","branches_url":"https://api.github.com/repos/PecanProject/pecan/branches{/branch}","tags_url":"https://api.github.com/repos/PecanProject/pecan/tags","blobs_url":"https://api.github.com/repos/PecanProject/pecan/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/PecanProject/pecan/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/PecanProject/pecan/git/refs{/sha}","trees_url":"https://api.github.com/repos/PecanProject/pecan/git/trees{/sha}","statuses_url":"https://api.github.com/repos/PecanProject/pecan/statuses/{sha}","languages_url":"https://api.github.com/repos/PecanProject/pecan/languages","stargazers_url":"https://api.github.com/repos/PecanProject/pecan/stargazers","contributors_url":"https://api.github.com/repos/PecanProject/pecan/contributors","subscribers_url":"https://api.github.com/repos/PecanProject/pecan/subscribers","subscription_url":"https://api.github.com/repos/PecanProject/pecan/subscription","commits_url":"https://api.github.com/repos/PecanProject/pecan/commits{/sha}","git_commits_url":"https://api.github.com/repos/PecanProject/pecan/git/commits{/sha}","comments_url":"https://api.github.com/repos/PecanProject/pecan/comments{/number}","issue_comment_url":"https://api.github.com/repos/PecanProject/pecan/issues/comments{/number}","contents_url":"https://api.github.com/repos/PecanProject/pecan/contents/{+path}","compare_url":"https://api.github.com/repos/PecanProject/pecan/compare/{base}...{head}","merges_url":"https://api.github.com/repos/PecanProject/pecan/merges","archive_url":"https://api.github.com/repos/PecanProject/pecan/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/PecanProject/pecan/downloads","issues_url":"https://api.github.com/repos/PecanProject/pecan/issues{/number}","pulls_url":"https://api.github.com/repos/PecanProject/pecan/pulls{/number}","milestones_url":"https://api.github.com/repos/PecanProject/pecan/milestones{/number}","notifications_url":"https://api.github.com/repos/PecanProject/pecan/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/PecanProject/pecan/labels{/name}","releases_url":"https://api.github.com/repos/PecanProject/pecan/releases{/id}","deployments_url":"https://api.github.com/repos/PecanProject/pecan/deployments","created_at":"2012-11-25T23:48:26Z","updated_at":"2016-03-14T13:18:42Z","pushed_at":"2016-04-23T22:15:05Z","git_url":"git://github.com/PecanProject/pecan.git","ssh_url":"git@github.com:PecanProject/pecan.git","clone_url":"https://github.com/PecanProject/pecan.git","svn_url":"https://github.com/PecanProject/pecan","homepage":"www.pecanproject.org","size":338893,"stargazers_count":41,"watchers_count":41,"language":"R","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":75,"mirror_url":null,"open_issues_count":174,"forks":75,"open_issues":174,"watchers":41,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/PecanProject/pecan/pulls/784"},"html":{"href":"https://github.com/PecanProject/pecan/pull/784"},"issue":{"href":"https://api.github.com/repos/PecanProject/pecan/issues/784"},"comments":{"href":"https://api.github.com/repos/PecanProject/pecan/issues/784/comments"},"review_comments":{"href":"https://api.github.com/repos/PecanProject/pecan/pulls/784/comments"},"review_comment":{"href":"https://api.github.com/repos/PecanProject/pecan/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/PecanProject/pecan/pulls/784/commits"},"statuses":{"href":"https://api.github.com/repos/PecanProject/pecan/statuses/6152d2494eb26fc780bc1167283fc4f67e3863d3"}}}}