{
  "id": 5850,
  "title": "R NetCDF4 reading input files but always return almost duplicate data",
  "url": "/competitions/ams-2014-solar-energy-prediction-contest/discussion/5850",
  "author_name": "",
  "post_date": "2013-09-23T06:16:52.717Z",
  "votes": null,
  "comment_count": 6,
  "views": 1974,
  "content": "<p>Hi all,</p>\n<p>I'm mostly a Python user so I'm using the R to read NetCD4 for data exploration. However, I met some odd issues:</p>\n<p><strong>Despite I read from two different NC files which are clearly different files, the data returned is almost the same - except the dataset$filename attribute.</strong></p>\n<p><code>require(ncdf4)</code></p>\n<p><code>d1 &lt;- nc_open('ulwrf_tatm_latlon_subset_19940101_20071231.nc')</code></p>\n<p><code>d2 &lt;- nc_open('tmin_2m_latlon_subset_19940101_20071231.nc')</code></p>\n<p><code>v1 &lt;- ncvar_get(d1)</code></p>\n<p><code>v2 &lt;- ncvar_get(d2)</code></p>\n<p><code>cat(d1$filename) #&nbsp;ulwrf_tatm_latlon_subset_19940101_20071231.nc</code></p>\n<p><code>cat(attr(d1$var, 'name'), '\\n') #&nbsp;intTime intValidTime Upward_Long-Wave_Rad_Flux</code></p>\n<p><code></code><code>cat(sum(v1), '\\n') #&nbsp;10327017841</code></p>\n<p><code>cat(d2$filename) #&nbsp;tmin_2m_latlon_subset_19940101_20071231.nc</code></p>\n<p><code>cat(attr(d2$var, 'name'), '\\n') #&nbsp;intTime intValidTime Upward_Long-Wave_Rad_Flux</code></p>\n<p><code>cat(sum(v2), '\\n') #&nbsp;10327017841</code><code><code><br></code></code></p>\n<p>&nbsp;</p>\n<p>Now, from the above, I would expect these two return different values. However, except the filename attribute, the rest are exactly duplicated. I am a little puzzled, what did I do wrong here?</p>",
  "messages": [
    {
      "id": "31376",
      "postDate": "09/23/2013 06:16:52",
      "content": "<p>Hi all,</p>\n<p>I'm mostly a Python user so I'm using the R to read NetCD4 for data exploration. However, I met some odd issues:</p>\n<p><strong>Despite I read from two different NC files which are clearly different files, the data returned is almost the same - except the dataset$filename attribute.</strong></p>\n<p><code>require(ncdf4)</code></p>\n<p><code>d1 &lt;- nc_open('ulwrf_tatm_latlon_subset_19940101_20071231.nc')</code></p>\n<p><code>d2 &lt;- nc_open('tmin_2m_latlon_subset_19940101_20071231.nc')</code></p>\n<p><code>v1 &lt;- ncvar_get(d1)</code></p>\n<p><code>v2 &lt;- ncvar_get(d2)</code></p>\n<p><code>cat(d1$filename) #&nbsp;ulwrf_tatm_latlon_subset_19940101_20071231.nc</code></p>\n<p><code>cat(attr(d1$var, 'name'), '\\n') #&nbsp;intTime intValidTime Upward_Long-Wave_Rad_Flux</code></p>\n<p><code></code><code>cat(sum(v1), '\\n') #&nbsp;10327017841</code></p>\n<p><code>cat(d2$filename) #&nbsp;tmin_2m_latlon_subset_19940101_20071231.nc</code></p>\n<p><code>cat(attr(d2$var, 'name'), '\\n') #&nbsp;intTime intValidTime Upward_Long-Wave_Rad_Flux</code></p>\n<p><code>cat(sum(v2), '\\n') #&nbsp;10327017841</code><code><code><br></code></code></p>\n<p>&nbsp;</p>\n<p>Now, from the above, I would expect these two return different values. However, except the filename attribute, the rest are exactly duplicated. I am a little puzzled, what did I do wrong here?</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "31377",
      "postDate": "09/23/2013 06:19:16",
      "content": "<p>In case someone is suspecting the files are wrong... I've made submissions based on these files.</p>\n<p>The file sizes are as follows:</p>\n<p><span style=\"line-height: 1.4\">&quot;63,238,020 ulwrf_tatm_latlon_subset_19940101_20071231.nc&quot;</span></p>\n<p><span style=\"line-height: 1.4\">&quot;93,599,518 tmin_2m_latlon_subset_19940101_20071231.nc&quot;</span></p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "31407",
      "postDate": "09/23/2013 15:18:46",
      "content": "<p>Nevermind above. It seems I thought I have invoked nc_close (in the larger script, not this repro script) but didn't.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "31409",
      "postDate": "09/23/2013 15:48:22",
      "content": "<p>I experienced the same issues and I solved it by opening one file at a time. You have to call the function nc_close(...) before opening the next file.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "31411",
      "postDate": "09/23/2013 15:58:27",
      "content": "<p>What ' s the meaning of sum(v1) ?</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "31413",
      "postDate": "09/23/2013 16:32:20",
      "content": "<p>Thanks for response. I was just checking the values if they are equal or not. No problem... I noticed my mistake already. =]</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "31414",
      "postDate": "09/23/2013 16:32:56",
      "content": "<p>Indeed Azerty. I thought I invoked it but apparently I missed it, and missed it during debugging. Thanks for your reply.</p>",
      "rawMarkdown": "",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 31377,
      "author_name": "ericchio",
      "author_url": "",
      "post_date": "09/23/2013 06:19:16",
      "content": "<p>In case someone is suspecting the files are wrong... I've made submissions based on these files.</p>\n<p>The file sizes are as follows:</p>\n<p><span style=\"line-height: 1.4\">&quot;63,238,020 ulwrf_tatm_latlon_subset_19940101_20071231.nc&quot;</span></p>\n<p><span style=\"line-height: 1.4\">&quot;93,599,518 tmin_2m_latlon_subset_19940101_20071231.nc&quot;</span></p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 31407,
      "author_name": "ericchio",
      "author_url": "",
      "post_date": "09/23/2013 15:18:46",
      "content": "<p>Nevermind above. It seems I thought I have invoked nc_close (in the larger script, not this repro script) but didn't.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 31409,
      "author_name": "lpkronek",
      "author_url": "",
      "post_date": "09/23/2013 15:48:22",
      "content": "<p>I experienced the same issues and I solved it by opening one file at a time. You have to call the function nc_close(...) before opening the next file.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 31411,
      "author_name": "herimanitra",
      "author_url": "",
      "post_date": "09/23/2013 15:58:27",
      "content": "<p>What ' s the meaning of sum(v1) ?</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 31413,
      "author_name": "ericchio",
      "author_url": "",
      "post_date": "09/23/2013 16:32:20",
      "content": "<p>Thanks for response. I was just checking the values if they are equal or not. No problem... I noticed my mistake already. =]</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 31414,
      "author_name": "ericchio",
      "author_url": "",
      "post_date": "09/23/2013 16:32:56",
      "content": "<p>Indeed Azerty. I thought I invoked it but apparently I missed it, and missed it during debugging. Thanks for your reply.</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "31376": "",
    "31377": "",
    "31407": "",
    "31409": "",
    "31411": "",
    "31413": "",
    "31414": ""
  },
  "source": "meta"
}