{"id":3281,"date":"2023-05-19T02:27:06","date_gmt":"2023-05-19T02:27:06","guid":{"rendered":"http:\/\/ridweb.jamstec.go.jp\/RID\/?page_id=3281"},"modified":"2025-07-15T01:11:39","modified_gmt":"2025-07-15T01:11:39","slug":"download-script","status":"publish","type":"page","link":"http:\/\/ridweb.jamstec.go.jp\/RID\/download-script\/","title":{"rendered":"Download script"},"content":{"rendered":"\n<p>Updates:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>2025\/07\/12 A new feature has been added to automatically retry downloads if the server connection is interrupted<\/li>\n\n\n\n<li>2025\/07\/03 The previous script no longer functions correctly with recent wget releases. This updated version now reliably checks for newer files on the server before downloading, ensuring your local copies stay up to date<\/li>\n<\/ul>\n\n\n\n<p>The following is a Python script that downloads netCDF files provided by the reanalysis intercomparison dataset. It is left to the user to modify the script to download the desired data files.<\/p>\n\n\n\n<p>Requirements: Python 3, wget<\/p>\n\n\n\n<p>Those who wish to use the OPeNDAP functionalities can modify this script to suit their needs.<\/p>\n\n\n\n<p><strong>Usage<\/strong>: Save the following lines of code into a file, such as RIDscript.py, and then execute it in a terminal with Python using the command &#8220;python RIDscript.py&#8221;.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n# User input===========================================================================\ndestination = &quot;myRID&quot;  # Destination folder on user&#039;s computers\n\n# Selection of data holdings\n# It is a example, not an exhaustive list\ncomponents = &#x5B;&quot;zonal&quot;, &quot;single-level&quot;]\ntemporal_resolutions = &#x5B;&quot;monthly&quot;]\nsubcomponents = &#x5B;&quot;core&quot;]\nreanalyses = &#x5B;&quot;ERA5&quot;, &quot;JRA-55&quot;]\n\ncheck_for_updated_files = False\n# If True, the script verifies if there is a newer version of files available on server\n# If False, existing files are skipped (much faster)\n\n# End of user input====================================================================\n\n# Importing necessary modules\nimport os\nimport urllib.request\nfrom xml.dom import minidom\nimport time\n\nsource = &quot;https:\/\/www.jamstec.go.jp\/RID\/thredds\/catalog\/testAll\/&quot;\n\nif os.path.isdir(destination) == False:\n    print(&quot;Destination directory does not exist, creating&quot;)\n    os.makedirs(destination)\n\nif os.name == &quot;nt&quot;:\n    windows = True\nelse:\n    windows = False\n\nfor component in components:\n    for temporal_resolution in temporal_resolutions:\n        for subcomponent in subcomponents:\n            for reanalysis in reanalyses:\n\n                src = (\n                    source\n                    + component\n                    + &quot;\/common-grid\/&quot;\n                    + temporal_resolution\n                    + &quot;\/&quot;\n                    + subcomponent\n                    + &quot;\/&quot;\n                    + reanalysis\n                    + &quot;\/&quot;\n                )\n                print(src)\n\n                response = urllib.request.urlopen(src)\n                if response.getcode() == 200:\n                    print(&quot;Received response from server&quot;)\n                    dom = minidom.parse(response)\n\n                    files = dom.getElementsByTagName(&quot;dataset&quot;)\n\n                    for filenb, file in enumerate(files):\n                        filename = file.attributes&#x5B;&quot;name&quot;].value\n\n                        if &quot;.nc&quot; in filename:\n                            urlPath = file.attributes&#x5B;&quot;urlPath&quot;].value\n                            downloadpath = (\n                                &quot;https:\/\/www.jamstec.go.jp\/RID\/thredds\/fileServer\/&quot;\n                                + urlPath\n                            )\n                            opendappath = (\n                                &quot;https:\/\/www.jamstec.go.jp\/RID\/thredds\/dodsC\/&quot; + urlPath\n                            )\n                            print(&quot;Download URL:&quot;, downloadpath)\n                            print(&quot;OpenDap path&quot;, opendappath)\n\n                            # Download\n                            file_input = downloadpath\n                            file_output = (\n                                destination + &quot;\/&quot; + &quot;\/&quot;.join(file_input.split(&quot;\/&quot;)&#x5B;7::])\n                            )\n\n                            if os.path.isfile(file_output) and (\n                                check_for_updated_files == False\n                            ):\n                                print(&quot;File present on computer, skipping&quot;)\n                            else:\n                                time.sleep(2)\n\n                                wget_command = (\n                                    &quot;wget --tries=20 --no-if-modified-since --timeout=30 -x --cut-dirs=4 -nH -N &quot;\n                                    + file_input\n                                )\n                                if windows == False:\n                                    wget_code = (\n                                        &quot;cd &quot; + destination + &quot;; &quot; + wget_command\n                                    )\n                                else:\n                                    wget_code = (\n                                        &quot;cd &quot; + destination + &quot; &amp;&amp; &quot; + wget_command\n                                    )\n\n                                print(wget_code)\n\n                                success = False\n                                tries = 1\n                                maxtries = 100\n                                while success == False:\n                                    try:\n                                        os.system(wget_code)\n                                        success = True\n                                    except:\n                                        wait = 10 * tries\n                                        print(\n                                            &quot;Could not connect to server after&quot;,\n                                            tries,\n                                            &quot;tries. Waiting for&quot;,\n                                            wait,\n                                            &quot;seconds until next attempt.&quot;,\n                                        )\n                                        time.sleep(wait)\n                                        tries += 1\n\n                                    if tries &gt; maxtries:\n                                        break\n\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>Updates: The following is a Python script that downloads netCDF files provided by the reanalysis intercomparison dataset. It is left to the user to modify the script to download the desired data files. Requirements: Python 3, wget Those who wish to use the OPeNDAP functionalities can modify this script to suit their needs. Usage: Save &hellip; <a href=\"http:\/\/ridweb.jamstec.go.jp\/RID\/download-script\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Download script&#8221;<\/span><\/a><\/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-3281","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>Download script - 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\/download-script\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Download script - RID - Reanalysis Intercomparison Dataset\" \/>\n<meta property=\"og:description\" content=\"Updates: The following is a Python script that downloads netCDF files provided by the reanalysis intercomparison dataset. It is left to the user to modify the script to download the desired data files. Requirements: Python 3, wget Those who wish to use the OPeNDAP functionalities can modify this script to suit their needs. Usage: Save &hellip; Continue reading &quot;Download script&quot;\" \/>\n<meta property=\"og:url\" content=\"http:\/\/ridweb.jamstec.go.jp\/RID\/download-script\/\" \/>\n<meta property=\"og:site_name\" content=\"RID - Reanalysis Intercomparison Dataset\" \/>\n<meta property=\"article:modified_time\" content=\"2025-07-15T01:11:39+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\/download-script\/\",\"url\":\"http:\/\/ridweb.jamstec.go.jp\/RID\/download-script\/\",\"name\":\"Download script - RID - Reanalysis Intercomparison Dataset\",\"isPartOf\":{\"@id\":\"http:\/\/ridweb.jamstec.go.jp\/RID\/#website\"},\"datePublished\":\"2023-05-19T02:27:06+00:00\",\"dateModified\":\"2025-07-15T01:11:39+00:00\",\"breadcrumb\":{\"@id\":\"http:\/\/ridweb.jamstec.go.jp\/RID\/download-script\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/ridweb.jamstec.go.jp\/RID\/download-script\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/ridweb.jamstec.go.jp\/RID\/download-script\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/ridweb.jamstec.go.jp\/RID\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Download script\"}]},{\"@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":"Download script - 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\/download-script\/","og_locale":"en_US","og_type":"article","og_title":"Download script - RID - Reanalysis Intercomparison Dataset","og_description":"Updates: The following is a Python script that downloads netCDF files provided by the reanalysis intercomparison dataset. It is left to the user to modify the script to download the desired data files. Requirements: Python 3, wget Those who wish to use the OPeNDAP functionalities can modify this script to suit their needs. Usage: Save &hellip; Continue reading \"Download script\"","og_url":"http:\/\/ridweb.jamstec.go.jp\/RID\/download-script\/","og_site_name":"RID - Reanalysis Intercomparison Dataset","article_modified_time":"2025-07-15T01:11:39+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\/download-script\/","url":"http:\/\/ridweb.jamstec.go.jp\/RID\/download-script\/","name":"Download script - RID - Reanalysis Intercomparison Dataset","isPartOf":{"@id":"http:\/\/ridweb.jamstec.go.jp\/RID\/#website"},"datePublished":"2023-05-19T02:27:06+00:00","dateModified":"2025-07-15T01:11:39+00:00","breadcrumb":{"@id":"http:\/\/ridweb.jamstec.go.jp\/RID\/download-script\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/ridweb.jamstec.go.jp\/RID\/download-script\/"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/ridweb.jamstec.go.jp\/RID\/download-script\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/ridweb.jamstec.go.jp\/RID\/"},{"@type":"ListItem","position":2,"name":"Download script"}]},{"@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\/3281","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=3281"}],"version-history":[{"count":25,"href":"http:\/\/ridweb.jamstec.go.jp\/RID\/wp-json\/wp\/v2\/pages\/3281\/revisions"}],"predecessor-version":[{"id":87191,"href":"http:\/\/ridweb.jamstec.go.jp\/RID\/wp-json\/wp\/v2\/pages\/3281\/revisions\/87191"}],"wp:attachment":[{"href":"http:\/\/ridweb.jamstec.go.jp\/RID\/wp-json\/wp\/v2\/media?parent=3281"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}