{"id":35755,"date":"2024-08-07T07:04:14","date_gmt":"2024-08-07T07:04:14","guid":{"rendered":"http:\/\/ridweb.jamstec.go.jp\/RID\/?page_id=35755"},"modified":"2024-08-07T07:09:59","modified_gmt":"2024-08-07T07:09:59","slug":"xarray-and-opendap","status":"publish","type":"page","link":"http:\/\/ridweb.jamstec.go.jp\/RID\/xarray-and-opendap\/","title":{"rendered":"Xarray and OPeNDAP"},"content":{"rendered":"\n<p>This is a minimal example of RID usage using Xarray and OPeNDAP in Python. This script may be modified to load locally-stored NetCDF files (instead of OPeNDAP URLs). Thanks to Tobias Kerzenmacher for providing this example. <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport xarray as xr\n\n# Generate the list of URLs based on the known pattern\nbase_url = &quot;https:\/\/www.jamstec.go.jp\/RID\/thredds\/dodsC\/testAll\/zonal\/common-grid\/monthly\/tem-qg\/ERA5\/ERA5_zonal_common-grid_monthly_tem-qg_20{}-{}.nc&quot;\nyears = &#x5B;f&quot;{year:02d}&quot; for year in range(2, 13)]  # Adjust the range as needed\nmonths = &#x5B;f&quot;{month:02d}&quot; for month in range(1, 13)]\n\n# Create a list of all URLs\nurls = &#x5B;base_url.format(year, month) for year in years for month in months]\n\ndef prepro(ds):\n    ds=ds.drop_vars(&#039;days_included&#039;).drop_vars(&#039;days_averaged&#039;)\n    return ds\n\n# Open the dataset using xarray&#039;s open_mfdataset\nds = xr.open_mfdataset(urls, preprocess = prepro, combine=&#039;by_coords&#039;)&#x5B;&#x5B;&#039;wres&#039;, &#039;vres&#039;]]\n\n# Remove problematic attributes\nds_cleaned = ds.copy()\nif &#039;_NCProperties&#039; in ds_cleaned.attrs:\n    del ds_cleaned.attrs&#x5B;&#039;_NCProperties&#039;]  # Remove the _NCProperties attribute\n    \n# Save the dataset to a NetCDF file\noutput_file = &#039;jamstec_era5_vres_wres.nc&#039;\nds_cleaned.to_netcdf(output_file)\n\nprint(f&quot;Dataset saved to {output_file}&quot;)\n\nds_cleaned.wres.isel(time=1).T.plot.contourf(yscale=&#039;log&#039;, levels=11, yincrease=False, xlim=&#x5B;-45, 45], ylim=&#x5B;10000,100], vmin=-0.0001, vmax=0.0001, extend=&#039;both&#039;)\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>This is a minimal example of RID usage using Xarray and OPeNDAP in Python. This script may be modified to load locally-stored NetCDF files (instead of OPeNDAP URLs). Thanks to Tobias Kerzenmacher for providing this example.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-35755","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Xarray and OPeNDAP - RID - Reanalysis Intercomparison Dataset<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/ridweb.jamstec.go.jp\/RID\/xarray-and-opendap\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Xarray and OPeNDAP - RID - Reanalysis Intercomparison Dataset\" \/>\n<meta property=\"og:description\" content=\"This is a minimal example of RID usage using Xarray and OPeNDAP in Python. This script may be modified to load locally-stored NetCDF files (instead of OPeNDAP URLs). Thanks to Tobias Kerzenmacher for providing this example.\" \/>\n<meta property=\"og:url\" content=\"http:\/\/ridweb.jamstec.go.jp\/RID\/xarray-and-opendap\/\" \/>\n<meta property=\"og:site_name\" content=\"RID - Reanalysis Intercomparison Dataset\" \/>\n<meta property=\"article:modified_time\" content=\"2024-08-07T07:09:59+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"http:\/\/ridweb.jamstec.go.jp\/RID\/xarray-and-opendap\/\",\"url\":\"http:\/\/ridweb.jamstec.go.jp\/RID\/xarray-and-opendap\/\",\"name\":\"Xarray and OPeNDAP - RID - Reanalysis Intercomparison Dataset\",\"isPartOf\":{\"@id\":\"http:\/\/ridweb.jamstec.go.jp\/RID\/#website\"},\"datePublished\":\"2024-08-07T07:04:14+00:00\",\"dateModified\":\"2024-08-07T07:09:59+00:00\",\"breadcrumb\":{\"@id\":\"http:\/\/ridweb.jamstec.go.jp\/RID\/xarray-and-opendap\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/ridweb.jamstec.go.jp\/RID\/xarray-and-opendap\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/ridweb.jamstec.go.jp\/RID\/xarray-and-opendap\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/ridweb.jamstec.go.jp\/RID\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Xarray and OPeNDAP\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/ridweb.jamstec.go.jp\/RID\/#website\",\"url\":\"http:\/\/ridweb.jamstec.go.jp\/RID\/\",\"name\":\"RID - Reanalysis Intercomparison Dataset\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/ridweb.jamstec.go.jp\/RID\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Xarray and OPeNDAP - RID - Reanalysis Intercomparison Dataset","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/ridweb.jamstec.go.jp\/RID\/xarray-and-opendap\/","og_locale":"en_US","og_type":"article","og_title":"Xarray and OPeNDAP - RID - Reanalysis Intercomparison Dataset","og_description":"This is a minimal example of RID usage using Xarray and OPeNDAP in Python. This script may be modified to load locally-stored NetCDF files (instead of OPeNDAP URLs). Thanks to Tobias Kerzenmacher for providing this example.","og_url":"http:\/\/ridweb.jamstec.go.jp\/RID\/xarray-and-opendap\/","og_site_name":"RID - Reanalysis Intercomparison Dataset","article_modified_time":"2024-08-07T07:09:59+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"http:\/\/ridweb.jamstec.go.jp\/RID\/xarray-and-opendap\/","url":"http:\/\/ridweb.jamstec.go.jp\/RID\/xarray-and-opendap\/","name":"Xarray and OPeNDAP - RID - Reanalysis Intercomparison Dataset","isPartOf":{"@id":"http:\/\/ridweb.jamstec.go.jp\/RID\/#website"},"datePublished":"2024-08-07T07:04:14+00:00","dateModified":"2024-08-07T07:09:59+00:00","breadcrumb":{"@id":"http:\/\/ridweb.jamstec.go.jp\/RID\/xarray-and-opendap\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/ridweb.jamstec.go.jp\/RID\/xarray-and-opendap\/"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/ridweb.jamstec.go.jp\/RID\/xarray-and-opendap\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/ridweb.jamstec.go.jp\/RID\/"},{"@type":"ListItem","position":2,"name":"Xarray and OPeNDAP"}]},{"@type":"WebSite","@id":"http:\/\/ridweb.jamstec.go.jp\/RID\/#website","url":"http:\/\/ridweb.jamstec.go.jp\/RID\/","name":"RID - Reanalysis Intercomparison Dataset","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/ridweb.jamstec.go.jp\/RID\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"http:\/\/ridweb.jamstec.go.jp\/RID\/wp-json\/wp\/v2\/pages\/35755","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/ridweb.jamstec.go.jp\/RID\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/ridweb.jamstec.go.jp\/RID\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/ridweb.jamstec.go.jp\/RID\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/ridweb.jamstec.go.jp\/RID\/wp-json\/wp\/v2\/comments?post=35755"}],"version-history":[{"count":6,"href":"http:\/\/ridweb.jamstec.go.jp\/RID\/wp-json\/wp\/v2\/pages\/35755\/revisions"}],"predecessor-version":[{"id":35764,"href":"http:\/\/ridweb.jamstec.go.jp\/RID\/wp-json\/wp\/v2\/pages\/35755\/revisions\/35764"}],"wp:attachment":[{"href":"http:\/\/ridweb.jamstec.go.jp\/RID\/wp-json\/wp\/v2\/media?parent=35755"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}