├── .gitignore ├── .pre-commit-config.yaml ├── CITATION.cff ├── LICENSE ├── QRcode.png ├── README.md ├── img ├── objstore_rm1.png ├── objstore_rm2.png ├── objstore_rm3.png ├── objstore_rm4.png ├── xarray_zarr_output1.png └── zarr_output2.png ├── notebooks ├── access-analyse_temperature.ipynb ├── catalogue_temperature.yaml └── pangeo-forge_testing.ipynb └── scripts ├── convert_G2G_beam.py └── convert_G2G_beam.sbatch /.gitignore: -------------------------------------------------------------------------------- 1 | *.out 2 | *.err 3 | .ipynb_checkpoints/ 4 | data/ 5 | *~ 6 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | # See https://pre-commit.com for more information 2 | # See https://pre-commit.com/hooks.html for more hooks 3 | repos: 4 | - repo: https://github.com/pre-commit/pre-commit-hooks 5 | rev: v3.2.0 6 | hooks: 7 | - id: trailing-whitespace 8 | - id: end-of-file-fixer 9 | - id: check-yaml 10 | - id: check-added-large-files 11 | - id: check-ast 12 | - id: check-case-conflict 13 | - id: check-json 14 | - id: check-merge-conflict 15 | - id: mixed-line-ending 16 | - id: requirements-txt-fixer 17 | - id: trailing-whitespace 18 | - repo: https://github.com/psf/black 19 | rev: 23.7.0 20 | hooks: 21 | - id: black 22 | - id: black-jupyter 23 | 24 | default_language_version: 25 | python: python3.9 26 | -------------------------------------------------------------------------------- /CITATION.cff: -------------------------------------------------------------------------------- 1 | # This CITATION.cff file was generated with cffinit. 2 | # Visit https://bit.ly/cffinit to generate yours today! 3 | 4 | cff-version: 1.2.0 5 | title: object_store_tutorial 6 | message: >- 7 | If you use this software, please cite it using the 8 | metadata from this file. 9 | type: software 10 | authors: 11 | - given-names: Matt James 12 | family-names: Brown 13 | email: matbro@ceh.ac.uk 14 | affiliation: UKCEH 15 | orcid: 'https://orcid.org/0000-0003-1127-0279' 16 | - given-names: Amulya 17 | family-names: Chevuturi 18 | email: amuche@ceh.ac.uk 19 | affiliation: UKCEH 20 | orcid: 'https://orcid.org/0000-0003-2815-7221' 21 | identifiers: 22 | - type: doi 23 | value: 10.5281/zenodo.10625691 24 | description: Latest version 25 | repository-code: 'https://github.com/NERC-CEH/object_store_tutorial' 26 | abstract: >- 27 | This GitHub repository offers sample notebooks and guides 28 | for utilizing Object Storage. The README introduces Object 29 | Storage and provides instructions for using the resources 30 | within this respository which will help you to access 31 | Object Storage, upload data to it, and use that data from 32 | external platforms. 33 | keywords: 34 | - object storage 35 | - JASMIN 36 | - beam 37 | - pangeo 38 | - pangeo-forge 39 | - pange-forge-recipes 40 | - apache beam 41 | - cloud compute 42 | - cloud 43 | - tutorial 44 | - chunks 45 | - chunking 46 | - netcdf 47 | - zarr 48 | - arco 49 | - big data 50 | - gridded 51 | - gridded data 52 | license: GPL-3.0 53 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /QRcode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NERC-CEH/object_store_tutorial/cdeb4480dcefca17374154ea7c539d1213626e2b/QRcode.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # README for the GitHub repository 2 | This GitHub repository offers sample notebooks and guides for utilizing Object Storage. This README introduces Object Storage and provides instructions for using the resources within this respository for accessing Object Storage, uploading data to it, and using that data from external platforms. 3 | 4 | **Authors:** *Matt Brown* and *Amulya Chevuturi*, UK Centre for Ecology & Hydrology, Wallingford, UK (matbro@ceh.ac.uk; amuche@ceh.ac.uk) 5 | 6 | **Contact:** For more information please contact Matt Fry (mfry@ceh.ac.uk) 7 | 8 | **Acknowledgements**: This work was undertaken at UK Centre for Ecology & Hydrology (UKCEH) and supported by Natural Environment Research Council's Hydro-JULES research programme (HJ; NE/S017380/1), UK Status, Change and Projections of the Environment programme (UK-SCAPE; NE/R016429/1) and Piloting an Information Management Framework for Environmental Digital Twins (PIMFe; NE/X016765/1). 9 | 10 | # Head in the Clouds - Object Store: Cloud Storage 11 | ## What is Object Storage? 12 | Object storage is a cloud-native technology specifically designed for efficiently managing large unstructured datasets. While object store offers significant cost-effectiveness compared to disk storage, it requires data to be appropriately adapted to fully realise its benefits. Data retrieval from object store is over HTTP in complete "objects", which are either entire files or file chunks. This is different to the traditional file storage: 13 | ![comparison of disk and object storage](img/objstore_rm1.png) 14 | 15 | As this is relatively new technology, there is a clear lack of established tools and best-practice for converting file types for optimal use with object storage, particularly for large gridded and N-dimensional datasets used in environmental and climate sciences. The performance and speed of object storage are contingent upon the data's structure, chunking, and the specific analysis requirements of the user. Consequently, a better understanding of these interactions is essential before widespread adoption. 16 | 17 | ## An Introduction to Object Storage 18 | In this tutorial we are using object storage provided by [JASMIN](https://www.ceda.ac.uk/services/jasmin/) in the UK. You do not need access to JASMIN or a JASMIN account to follow the tutorials, except for the stage of uploading the data, but the recipes provided in this repository can be modified to allow upload to any other Object Store. Furthermore, if your main objective is to learn how to access data from the JASMIN Object Store, the provided notebooks are accessible without requiring a JASMIN login. They are intentionally designed to be platform-agnostic and operate independently of JASMIN firewalls, making them compatible with widely used platforms such as Google Colab, among others. 19 | For those wishing to gain upload/admin access to [JASMIN Object Storage](https://help.jasmin.ac.uk/article/4847-using-the-jasmin-object-store) a JASMIN account is needed, as access is restricted by access keys and secret tokens. JASMIN is available to anyone working on a [NERC](https://www.ukri.org/councils/nerc/)-funded project or institution. Follow the steps provided in the webpage above to set up your own JASMIN Object Store access if you wish, once you have an account. You can then contact the JASMIN team to set up a tenancy for you. 20 | 21 | # Thinking Chunky Thoughts - Data Chunking Strategies 22 | ## What is chunking and why is it important? 23 | Object store allows for the storage of files of datasets as objects, that can be of any size. To enhance accessibility and network efficiency, these objects are intelligently smaller and manageable "chunks" of the dataset when being stored in the object store. Users can access a part or a full object by accessing different chunks over a network, optimizing data storage and retrieval in distributed environments. The type of chunking strategy applied is cruicial for optimizing performance, scalability, and cost-efficiency while ensuring data integrity and security. The most optimal chunking strategy may depend on user requirements and the capabilities of the object store and network being used. Following are a list of reasons to chunk objects correctly when being stored in an object store: 24 | - *Scalability*: It is easier to store, retrieve, and analyse large datasets when they are divided into manageable chunks. This allows for better distribution and parallel processing, making it easier to scale your storage solution as your data grows. Appropriately sized chunks, you can improve the performance of data operations like reading, writing, and updating. Very small chunks may result in increased metadata overhead and reduced efficiency, while overly large chunks are difficult to transfer over the internet and can hinder efficient resource allocation. Appropriatly chunked dataset can be processed in parallel and transfered easily over the network, which can significantly speed up data analysis and access. 25 | - *Cost Efficiency*: Storing large, unoptimized data objects can lead to unnecessary storage costs. Breaking data into smaller chunks allows for efficient resource allocation thus reducing costs. Chunking aids data redundancy and recovery mechanismsm as chunked data is often replicated across multiple storage devices and thus builds resilence in the system, which makes it more reliable. 26 | - *Data Versioning, Incremental Updates and Access Control*: Chunking allows for updating/replacing a small portion of a large dataset, instead of rewriting the entire dataset. This also simplifies versioning and tracking changes over time. Some object stores offer access control at the chunk level, allowing for fine-grained access permissions and security policies for individual chunks. This enhances data security and isolation. 27 | 28 | ## Dataset chunking 29 | To demonstrate an efficient data chunking strategy for an illustrative climate dataset, we have converted the dataset into six distinct chunk types and assessed their performance on the JASMIN Object Store. The climate dataset used in our study is the [CHESS-SCAPE: Future projections of meteorological variables at 1 km resolution for the United Kingdom 1980-2080 derived from UK Climate Projections 2018](https://catalogue.ceda.ac.uk/uuid/8194b416cbee482b89e0dfbe17c5786c) This dataset contains daily values of various variables, including mean, maximum, minimum, and daily range of air temperature (K), specific humidity (kg kg-1), relative humidity (%), wind speed (m s-1), downward longwave radiation (W m-2), downward shortwave radiation (W m-2), precipitation (kg m-2 s-2), surface air pressure (Pa) available for four ensemble members (ENS-01, ENS-04, ENS-06, ENS-15). CHESS-SCAPE has 100 years of daily data for a 360-day calendar (i.e., time axis has 36000 steps), with a horizonatl resolution of 1km over UK at the Ordnance Survey / British National Grid projection (i.e., x-axis or longitude has 656 steps and y-axis or latitude has 1057 steps). 30 | 31 | For evaluating the optimal chunking strategy, we have focused on chunking the daily maximum air temperature data for ENS-01, that amounts to a total of 93GB. The original dataset is stored in the NetCDF format, organized into monthly files, resulting in 79MB chunks. The NetCDF dataset is stored as "continous", which means no additional chunks other than individual files are considered as chunks. To facilitate our analysis, we converted the data to ZARR files, for six different chunk types. Additionally, we have retained the original NetCDF files for reference. 32 | 33 | | **File Type** | **Storage Type** | **Chunk Types** | **Chunk Size** | **Number of Chunks** | **X $\times$ Y $\times$ T $\times$ Bytes** | **Abbreviated Name** 34 | | -------------------- | -------------------- | -------------------- | -------------------- | -------------------- | -------------------- | -------------------- | 35 | | Zarr | Object store | 10km full time | 14MB | 6996 |10 $\times$ 10 $\times$ 36000 $\times$ 4 | 10km 36 | | Zarr | Object store | 100km 10 yearly | 144MB | 770 | 100 $\times$ 100 $\times$ 3600 $\times$ 4 | 100km-10yr 37 | | Zarr | Object store | 100km yearly | 14MB | 7700 | 100 $\times$ 100 $\times$ 360 $\times$ 4 | 100km-Yr 38 | | Zarr | Object store | Full region yearly | 998MB | 100 | 656 $\times$ 1057 $\times$ 360 $\times$ 4 | Yearly 39 | | Zarr | Object store | Full region seasonal | 238MB | 400 | 656 $\times$ 1057 $\times$ 90 $\times$ 4 | Seasonal 40 | | Zarr | Object store | Full region monthly | 83MB | 1200 | 656 $\times$ 1057 $\times$ 30 $\times$ 4 | Monthly 41 | | NetCDF | Disk | Full region monthly | 83MB | 1200 | 656 $\times$ 1057 $\times$ 30 $\times$ 4 | NetCDF-Monthly 42 | 43 | We use the zarr file format as it is better optimised for object storage as instead of storing a dataset across multiple NetCDF files. In this format, we store the entire dataset in explicit chunks within a single .zarr file (a bit like a .zip or .tar archive file). Data on object storage is accessed by downloading 'objects' which correspond to files or chunks of files. NetCDF files can be chunked too, but accessing zarr data on the object store is more efficient than equivalent NetCDF data because: (i) the metadata is stored in one place instead of in every individual file, (ii) the chunking has to be specified explcitly when creating zarr data but not with NetCDF, leading to suboptimal chunk (object) sizes if the data is even chunked at all, and (iii) data duplication from file overheads is reduced as there is only one zarr 'file' instead of many NetCDF files. This is why conversion to zarr is good idea when putting data on object storage. 44 | ![chunking strategies](img/objstore_rm2.png) 45 | 46 | ## Best chunk size 47 | In environmental and climate sciences, three primary use cases exist for the analysis of 3-D gridded data. The following figure illustrates examples of these three use cases, each represented by distinctive colored symbols: (i) extracting time series data for a single grid point; (ii) retrieving variables across the entire spatial grid; (iii) obtaining area-averaged time series data for a specific region within the whole domain. 48 | ![experiments](img/objstore_rm3.png) 49 | 50 | We evaluate the six differently chunked zarr files, along with original NetCDF files across the three use cases. We showcase the wall time required with each chunk type to complete calculations for the three use cases through a spiderweb plot shown below, using the colored symbols corresponding three use cases from the figure above. 51 | ![results](img/objstore_rm4.png) 52 | 53 | The choice of the most effective chunk size depends on your specific object store architechture, use case applications, and available network capacity. In our study, we found that the best-performing chunk size is the yearly chunk with a horizontal domain of 100km $\times$ 100km (100km-yr; 14MB). In our study we found that chunks larger than 100MB do not offer optimal performance conditions. However, in a [different experiment](https://github.com/cedadev/cmip6-object-store) chunk sizes around 250MB (100MB to 1GB) have found to have optimal performance for JASMIN object storage. For each of our use cases, the NetCDF format consistently exhibits inferior performance compared to its zarr counterpart. This conclusion is also valid when considering the use of [kerchunk](https://fsspec.github.io/kerchunk/) to optimise chunking of NetCDF files (not shown). The use case experiments for different chunks provide similar conclusions when conducted from the JASMIN or DataLabs platforms (not shown). Overall performance times are generally lower in JASMIN than in DataLabs, and the largest chunked files (Yearly; 998MB) sometimes fail to load in DataLabs but always load in JASMIN, most likely due to differences in network connections. 54 | 55 | A chunk of identical size (10km; 14MB) matching our best-performing chunk type (100km-yr; 14MB) demonstrates improved performance exclusively when extracting time series for a single grid point. In the other two cases, it doesn't yield the same advantage, as the 10km chunk type is better suited for that specific use case of extracting single grid time series. For the use case of extracting a single grid time series for 10km chunks, only one chunk is extracted over the network for analysis, making the whole process much faster. In [another experiment](https://github.com/dte-ce/dte_zarr_gen/), it was found that chunking mostly by time and not by space heavily penalises those wishing to do long time-series analyses, but that the penalty in the inverse case (users wishing to do large spatial analyses with data chunked mostly by space and not by time) is not as large. This is because space is at minimum 2-D, whereas time is only ever 1-D, and the timescale of analyses is generally never 104 days and spatial scales never 106 km. To optimize performance for different use cases and because object storage is relatively cheaper than other storage options, the same dataset is stored in two or three copies with different chunk types. 56 | 57 | From the discussion above it is clear that data managers need to have a clear discussion of chunking strategies for a particular dataset based on use cases and network requirements for the said dataset before uploading the data. However, we can provide a few general conclusions that can implemented as good practice guide for datasets on object stores: (i) zarr format provides more optimized performance than NetCDF; (ii) medium-sized chunks perform the best, especially for users with limited network bandwidth; (iii) chunking data over all dimensions (spatially and temporally) is generally the best way to improving overall performance. 58 | 59 | # Heavy Lifting - Converting and Uploading Data to Object Storage 60 | 61 | The example laid out here is also available in this repo as a [jupyter notebook](notebooks/pangeo-forge_testing.\timipynb) and a [script](scripts/convert_G2G_beam.py), as well as an example [job submission script](scripts/convert_G2G_beam.sbatch) for running on a HPC that uses SLURM. These files are intended to serve as examples for adapation to your own datasets. 62 | 63 | Unfortunately converting data for object storage is not a simple process, even once you've decided on a suitable chunk size. The data has to be converted to the 'zarr' file format, chunked as desired and uploaded to the object store. Fortunately, tools are in development that make this process a lot more straightforward, and handle a lot of the complexity automatically. One such tool is [Pangeo Forge](https://pangeo-forge.readthedocs.io/en/latest/index.html). The [Pangeo Forge website](https://pangeo-forge.readthedocs.io/en/latest/index.html) is the place to go for the full documentation, installation guide, tutorials and a user guide but in this section I will run through an example demonstrating the most likely scenario for users wishing to get their data on to the object store: where there is some data stored on disk that needs to be concatenated over one dimension, rechunked and output as a zarr file on disk ready for upload to object storage. 64 | 65 | ## Installation 66 | Pangeo forge has several python packages, the key one being pangeo-forge-recipes. The recommended installation method is to install it into a separate environment with Anaconda. The [Anaconda documentation](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html) has instructions on how to do this. Pangeo-forge has many dependencies which anaconda will attempt to resolve and install automatically, however at time of writing I found some conflicts still existed with Anaconda's handling of the dependencies, so it is better to manually install the following packages and versions when creating the anaconda environment: 67 | - pangeo-forge-recipes 68 | - python < 3.10 69 | - pandas < 2.0 70 | - aiobotocore >= 2.5.4 71 | - s3fs >= 2023.9.2 72 | For example: 73 | ``` 74 | conda create --name object_storage -c conda-forge pangeo-forge-recipes python\<3.10 pandas\<2.0 aiobotocore\>\=2.5.4 s3fs \>\=2023.9.2 75 | ``` 76 | The aiobotocore and s3fs packages are only used when reading/writing directly from/to object storage - not in the following example. 77 | 78 | ## The Data 79 | In this example we will be using simulated daily-mean river flow data, output from the [G2G hydrological model](https://doi.org/10.1016/j.jhydrol.2009.08.031) in netcdf format. The data itself is not important, we are more interested here in the structure and format of the data. To get a feel for this, here is the output of the ncdump -h command on one of the data files, which I have highlighted to show the key bits of information: 80 |

 81 | 
 82 | netcdf G2G_DailyRiverFlow_NATURAL_RCM01_19801201_20801130 {
 83 | dimensions:
 84 |         Time = UNLIMITED ; // (36000 currently) --------> The 36000 and the dates in the filename tell us this is 100 years of daily data.
 85 |         RCM = 1 ; --------> This file only contains one 'RCM' (which stands for 'regional climate model')
 86 |         Northing = 1000 ;
 87 |         Easting = 700 ;  ---------> Northing and Easting suggest it is gridded data
 88 | variables:
 89 |         string RCM(RCM) ;
 90 |         float Northing(Northing) ;
 91 |                 Northing:_FillValue = NaNf ;
 92 |                 Northing:standard_name = "Northing" ;
 93 |                 Northing:axis = "Y" ;
 94 |                 Northing:units = "GB National Grid" ;
 95 |         float Easting(Easting) ;
 96 |                 Easting:_FillValue = NaNf ;
 97 |                 Easting:standard_name = "Easting" ;
 98 |                 Easting:axis = "X" ;
 99 |                 Easting:units = "GB National Grid" ;
100 |         float Time(Time) ;
101 |                 Time:_FillValue = NaNf ;
102 |                 Time:standard_name = "Time" ;
103 |                 Time:axis = "T" ;
104 |                 Time:units = "days since 1961-01-01" ;
105 |                 Time:calendar = "360_day" ;
106 |         float dmflow(RCM, Time, Northing, Easting) ;  ------> The main data variable. It is 3 dimensional (the RCM is only a singleton dimension)
107 |                 dmflow:_FillValue = -999.f ;
108 |                 dmflow:units = "m3 s-1" ;
109 |                 dmflow:standard_name = "dmflow" ;
110 |                 dmflow:long_name = "Daily mean river flow" ;
111 |                 dmflow:missing_value = -999.f ;
112 | 
113 | // global attributes:
114 |                 :_NCProperties = "version=2,netcdf=4.8.1,hdf5=1.12.2" ;
115 | 
116 | 117 | This information tells us we have 100 years of daily, gridded data for a single RCM in this file. From the other filenames: 118 |

119 | G2G_DailyRiverFlow_NATURAL_RCM01_19801201_20801130.nc
120 | G2G_DailyRiverFlow_NATURAL_RCM04_19801201_20801130.nc
121 | G2G_DailyRiverFlow_NATURAL_RCM05_19801201_20801130.nc
122 | G2G_DailyRiverFlow_NATURAL_RCM06_19801201_20801130.nc
123 | G2G_DailyRiverFlow_NATURAL_RCM07_19801201_20801130.nc
124 | G2G_DailyRiverFlow_NATURAL_RCM08_19801201_20801130.nc
125 | G2G_DailyRiverFlow_NATURAL_RCM09_19801201_20801130.nc
126 | G2G_DailyRiverFlow_NATURAL_RCM10_19801201_20801130.nc
127 | G2G_DailyRiverFlow_NATURAL_RCM11_19801201_20801130.nc
128 | G2G_DailyRiverFlow_NATURAL_RCM12_19801201_20801130.nc
129 | G2G_DailyRiverFlow_NATURAL_RCM13_19801201_20801130.nc
130 | G2G_DailyRiverFlow_NATURAL_RCM15_19801201_20801130.nc
131 | 
132 | 133 | we can deduce that each file contains a single RCM, but is otherwise identical. 134 | Therefore, to combine these files into a single, zarr dataset we need to concatenate over the RCM dimension. 135 | 136 | Now that we know these key pieces of information, the next step is to create a workflow or 'recipe' that does this. 137 | 138 | ## The Workflow 139 | 140 | The first step is to define a 'ConcatDim' object/variable which contains the name of the dimension along which we want to concatenate the files, the values of the dimensions in the files (in the order that we'd like them contacatenated) and, optionally, the number of dimension elements within each file, if it is constant (e.g. for monthly files on a 360 calendar this would be 30). 141 | 142 | ``` 143 | from pangeo_forge_recipes.patterns import ConcatDim 144 | RCMs = ['01', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '15'] 145 | RCM_concat_dim = ConcatDim("RCM", RCMs, nitems_per_file=1) 146 | ``` 147 | 148 | Next, we define the function that translates a given RCM (e.g. '04') into a file path. The function must have the same number of arguments as the number of Combine Dimensions and the name of the argument must match the name of the the Combine Dimension. 149 | 150 | ``` 151 | indir = '/users/sgsys/matbro/object_storage/object_storage/data/preproc' 152 | pre = 'G2G_DailyRiverFlow_NATURAL_RCM' 153 | suf = '_19801201_20801130.nc' 154 | def make_path(RCM): 155 | return(os.path.join(indir, pre + RCM + suf)) 156 | ``` 157 | 158 | Then this function and the ConcatDim object are put into a FilePattern object: 159 | 160 | ``` 161 | from pangeo_forge_recipes.patterns import FilePattern 162 | pattern = FilePattern(make_path, RCM_concat_dim) 163 | ``` 164 | 165 | Before running the full workflow it is a good idea to test it out on a subset of the files. pangeo-forge-recipes has a built in function for this: 166 | 167 | ``` 168 | pattern_pruned = pattern.prune() 169 | ``` 170 | 171 | Next, we need to specify where we want the converted data to be output and what chunks we want to convert the data to. Note that here we are choosing to chunk the data yearly and by 100km, as that is the optimum chunk size when both temporal-heavy and spatial-heavy analyses are likely to be carried out on the data (see ['Thinking Chunky Thoughts'](#thinking-chunky-thoughts---data-chunking-strategies)). 172 | 173 | ``` 174 | target_root = '/users/sgsys/matbro/object_storage/object_storage/data/output' ## output folder 175 | tn = 'test.zarr' ## output filename 176 | 177 | target_chunks = {'RCM': 1, 'Time': 360, 178 | 'Northing': 100, 179 | 'Easting': 100} ## length of each dimension of the desired chunks 180 | ``` 181 | 182 | The next step is to create the workflow/recipe we would like to run. Pangeo-forge-recipes uses apache beam as the backend, and requires the workflow to be specified using apache-beam syntax, which is a little unusual compared to most other python code, but simple enough to understand. Each step in the workflow is separated by a '|'. Pangeo-forge-recipes has workflow functions which are wrappers around more fiddly apache-beam code, simplifying the workflow massively. We use beam's 'Create' function to initialise the workflow and create the apache-beam workflow object containing our data, then pass this to the pangeo-forge-recipe workflow function 'OpenWithXarray' (which as you might expect uses the xarray module to open our netcdf files), then pass this to 'StoreToZarr' (which also does what you would expect). At each workflow step we pass the various options we've decided upon. Whilst that was a lot of detail, the workflow we have created essentially just does the following: Find the NetCDF files and their metadata --> open them with xarray --> convert/rechunk and write to disk as a zarr file. 183 | 184 | ``` 185 | transforms = ( 186 | beam.Create(pattern_pruned.items()) 187 | | OpenWithXarray(file_type=pattern_pruned.file_type) 188 | | StoreToZarr( 189 | target_root=target_root, 190 | store_name=tn, 191 | combine_dims=pattern.combine_dim_keys, 192 | target_chunks=target_chunks 193 | ) 194 | ) 195 | ``` 196 | 197 | We haven't actually run the workflow yet, just set it up ready to be run. To run it: 198 | 199 | ``` 200 | with beam.Pipeline() as p: 201 | p | transforms 202 | ``` 203 | 204 | If you have access to multiple cores or a cluster/HPC it is easy to run the pipeline in parallel and likely dramatically speed up the process. To do this, use: 205 | 206 | ``` 207 | from apache_beam.options.pipeline_options import PipelineOptions 208 | 209 | beam_options = PipelineOptions(direct_num_workers=8, direct_running_mode="multi_processing") 210 | with beam.Pipeline(options=beam_options) as p: 211 | p | transforms 212 | ``` 213 | to run the pipeline, changing 'direct_num_workers' to the number of workers (the number of cores) you wish to use. 214 | You can run the pipeline on a SLURM cluster in this way, see [scripts/convert_G2G_beam.sbatch](scripts/convert_G2G_beam.sbatch) 215 | 216 | The resulting dataset is formatted as a zarr datastore in the chunks we specified earlier: 217 | ``` 218 | import xarray as xr 219 | xr.open_dataset('/work/scratch-pw2/mattjbr/testoutput.zarr') 220 | ``` 221 | ![notebook output 1](img/xarray_zarr_output1.png) 222 | 223 | ``` 224 | import zarr 225 | tzar = zarr.open('/work/scratch-pw2/mattjbr/testoutput.zarr/dmflow') 226 | tzar.info 227 | ``` 228 | ![notebook output 2](img/zarr_output2.png) 229 | 230 | Pangeo forge has greater capabilities than what we have shown here: it can read/write directly to/from object storage, concatenate over multiple dimensions and be customized to perform any pre- or post-processing tasks. More information and examples is available on the [pangeo-forge website](https://pangeo-forge.readthedocs.io/en/latest/index.html). 231 | 232 | Some further notes on [Apache Beam](https://beam.apache.org/). It is a backend that is designed to run large and complex data workflows in parallel. To achieve the best performance it has several 'runners' that translate the beam workflows into workflows specific to the compute architecture that the workflow is running on. By default beam uses a generic runner that can run on any architecture (the 'Direct Runner'), and that is what is used in the example here. The generic nature of the Direct Runner means that it does not have optimal performance. Furthermore, it is geared more towards testing than actually running full workloads, and so raises more errors than the other runners. This becomes a particular problem when writing files directly to object storage, as this is done over http which can often timeout or dropout, stalling the workflow. The main other runners developed at time of writing are for Google Cloud Dataflow, Apache Flink, and Apache Spark compute architecture. Fortunately manually uploading data from disk to object storage outside of the pangeo-forge recipe is not too complicated. 233 | 234 | ## The upload 235 | 236 | To upload data we use the [s4cmd](https://github.com/bloomreach/s4cmd) command line tool. This can be safely installed in the same conda environment as pangeo-forge-recipes using pip: 237 | ``` 238 | pip install s4cmd 239 | ``` 240 | 241 | Create a '.s3cfg' file in the home directory of whichever linux/compute system you are on containing your s3 access key/token and secret key (essentially a username and password respectively) like so: 242 | ``` 243 | [default] 244 | access_key = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 245 | secret_key = yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy 246 | ``` 247 | 248 | List the buckets in your object store with 249 | ``` 250 | s4cmd ls --endpoint endpoint_url 251 | ``` 252 | where endpoint_url is the web address/'endpoint' of your object storage. 253 | 254 | Make a new bucket in your object store with 255 | ``` 256 | s4cmd mb s3:// --endpoint endpoint_url 257 | ``` 258 | 259 | Upload data to this bucket with 260 | ``` 261 | s4cmd sync -c 15 path/to/folder/for/upload s3:// -t 5 --endpoint endpoint_url 262 | ``` 263 | - This command will upload everything WITHIN path/to/folder/for/upload into s3:// 264 | - The same applies with path/to/folder/for/upload/ <----- Note the trailing slash 265 | - The '-c' option parallelises the upload (here over 15 threads) 266 | - The '-t' option is the timeout in seconds - how long a request will wait for a response before being retried. 267 | 268 | Further work will look at deploying apache beam on one of the support compute architectures using pangeo-forge-runner to allow for seamless read/write from/to object storage, and skip this pesky data upload step. 269 | 270 | # Attractor Beam - Accessing data from Object Store from any platform 271 | ## Accessing Object Store 272 | As mentioned before, the object store data's access can be controlled by the owners. To change access controls for JASMIN object storage, use the caringo portal from CEDA JASMIN webpage. More details about the caringo portal is provided [here](https://help.jasmin.ac.uk/article/4847-using-the-jasmin-object-store). If the bucket is not public, you would need the access credentials (key and secret), which is specific for each individual and should not be shared. If the bucket is public, anyone with the endpoint_url and url_path can access the data from any platform, even beyond the JASMIN firewalls. 273 | 274 | There are different python packages that can access Object Store data; [boto3](https://pypi.org/project/boto3/), [s3fs](https://pypi.org/project/s3fs/) and [intake](https://github.com/intake/intake). In this section, we will show examples of accessing Object Store data using intake and s3fs. Although, s3fs can be used to read the dataset itself, it is also good in exploring the Object Store tenancy (based on the user access), and that is the example we provide. We read the data through intake package, however, when we read data through this package we have to know the data path and names exactly to access the files. With the intake package, we need a catalogue.yaml file, which has the catalogue of data we are attempting to read. This catalogue file would need all the information of the dataset: endpoint_url, url_path, bucket name etc. More details are provided in the sub-section below. 275 | 276 | ## Example notebooks 277 | In this repository, we have examples of two datasets uploaded to JASMIN Object Store: 278 | - CHESS-SCAPE data: The variable we are extracting from this dataset is the daily maximum air temperature. We create an example [notebook access-analyse_temperature.ipynb](https://github.com/NERC-CEH/object_store_tutorial/blob/main/notebooks/access-analyse_temperature.ipynb), in which we extract the model daily maximum air temperature and compare it against COSMOS site observations. There is also a corresponding [catalogue_temperature.yaml file](https://github.com/NERC-CEH/object_store_tutorial/blob/main/notebooks/catalogue_temperature.yaml) which contains the data catalogue (paths, names etc.) 279 | - G2G data: The variable we are extracting from this dataset is daily streamflow. This dataset is not yet public, thus, we have not made the example notebooks available yet. Please watch this space for future updates on this. 280 | 281 | ## Running on different platforms 282 | The example notebooks have been tested in and will work on three different platforms: [DataLabs](https://datalab.datalabs.ceh.ac.uk/projects), [JASMIN Notebook Service](https://help.jasmin.ac.uk/article/4851-jasmin-notebook-service) and [Google Colab](https://colab.research.google.com/). For DataLabs and JASMIN Notebook Service, the whole GitHub repository can be cloned and run directly on these platforms. For running the notebooks on Google Colab, please remember to create a copy of the notebook before running it. Then the associated catalogue yaml file should be uploaded to the file system, otherwise the notebook will fail. The notebook itself has more detailed information about running the notebooks on any platform. 283 | 284 | ## Using the DASK Cluster 285 | The process of reading and analysing data from Object Store can be sped up by using parallel computing power provided by a DASK Cluster. Please note that all platform may not provide this service and our notebok examples do work without initialising a DASK Client. However, to those who are interested in using DASK, please find more details in the links provided below: 286 | - [DataLabs](https://datalab-docs.datalabs.ceh.ac.uk/tutorials/datalabs-dask-cluster/index.html) 287 | - [JASMIN Notebook Service](https://github.com/cedadev/jasmin-daskgateway) 288 | - [Google Colab](https://saturncloud.io/docs/using-saturn-cloud/external-connect/colab_external_connect/) 289 | 290 | # Citation 291 | If you use this tutorial in your work, or it helped you, please cite this repository by using the 'Cite this repository' button on the [main repository page](https://github.com/NERC-CEH/object_store_tutorial/), to the right of the files, or the CITATION.cff file in the root of the repository. 292 | 293 | # Disclaimer 294 | 295 | THIS REPOSITORY IS PROVIDED THE AUTHORS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS REPOSITORY, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 296 | -------------------------------------------------------------------------------- /img/objstore_rm1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NERC-CEH/object_store_tutorial/cdeb4480dcefca17374154ea7c539d1213626e2b/img/objstore_rm1.png -------------------------------------------------------------------------------- /img/objstore_rm2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NERC-CEH/object_store_tutorial/cdeb4480dcefca17374154ea7c539d1213626e2b/img/objstore_rm2.png -------------------------------------------------------------------------------- /img/objstore_rm3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NERC-CEH/object_store_tutorial/cdeb4480dcefca17374154ea7c539d1213626e2b/img/objstore_rm3.png -------------------------------------------------------------------------------- /img/objstore_rm4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NERC-CEH/object_store_tutorial/cdeb4480dcefca17374154ea7c539d1213626e2b/img/objstore_rm4.png -------------------------------------------------------------------------------- /img/xarray_zarr_output1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NERC-CEH/object_store_tutorial/cdeb4480dcefca17374154ea7c539d1213626e2b/img/xarray_zarr_output1.png -------------------------------------------------------------------------------- /img/zarr_output2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NERC-CEH/object_store_tutorial/cdeb4480dcefca17374154ea7c539d1213626e2b/img/zarr_output2.png -------------------------------------------------------------------------------- /notebooks/catalogue_temperature.yaml: -------------------------------------------------------------------------------- 1 | sources: 2 | e01_tmax_year100km: 3 | description: Maximum Temperature for ens-01 in yearly 100km chunks 4 | driver: zarr 5 | args: 6 | urlpath: 's3://ens01-year100kmchunk/tmax_01_year100km.zarr' 7 | consolidated: False 8 | storage_options: 9 | anon: True 10 | use_ssl: True 11 | client_kwargs: 12 | endpoint_url: 'https://chess-scape-o.s3-ext.jc.rl.ac.uk' 13 | e04_tmax_year100km: 14 | description: Maximum Temperature for ens-04 in yearly 100km chunks 15 | driver: zarr 16 | args: 17 | urlpath: 's3://ens04-year100kmchunk/tmax_04_year100km.zarr' 18 | consolidated: False 19 | storage_options: 20 | anon: True 21 | use_ssl: True 22 | client_kwargs: 23 | endpoint_url: 'https://chess-scape-o.s3-ext.jc.rl.ac.uk' 24 | e06_tmax_year100km: 25 | description: Maximum Temperature for ens-06 in yearly 100km chunks 26 | driver: zarr 27 | args: 28 | urlpath: 's3://ens06-year100kmchunk/tmax_06_year100km.zarr' 29 | consolidated: False 30 | storage_options: 31 | anon: True 32 | use_ssl: True 33 | client_kwargs: 34 | endpoint_url: 'https://chess-scape-o.s3-ext.jc.rl.ac.uk' 35 | e15_tmax_year100km: 36 | description: Maximum Temperature for ens-15 in yearly 100km chunks 37 | driver: zarr 38 | args: 39 | urlpath: 's3://ens15-year100kmchunk/tmax_15_year100km.zarr' 40 | consolidated: False 41 | storage_options: 42 | anon: True 43 | use_ssl: True 44 | client_kwargs: 45 | endpoint_url: 'https://chess-scape-o.s3-ext.jc.rl.ac.uk' 46 | -------------------------------------------------------------------------------- /notebooks/pangeo-forge_testing.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "id": "a46a32ac-ba6f-4e52-ad08-a8d3a67a24ad", 7 | "metadata": {}, 8 | "outputs": [], 9 | "source": [ 10 | "import os\n", 11 | "import s3fs\n", 12 | "import xarray as xr\n", 13 | "import apache_beam as beam\n", 14 | "from pangeo_forge_recipes.storage import FSSpecTarget\n", 15 | "from pangeo_forge_recipes.patterns import ConcatDim, FilePattern\n", 16 | "from pangeo_forge_recipes.transforms import OpenWithXarray, StoreToZarr" 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "id": "8ce7e6df-b098-42dc-8684-d8f195116f49", 22 | "metadata": {}, 23 | "source": [ 24 | "Example notebook for converting and rechunking gridded netcdf data ready for object storage, using pangeo-forge-recipes. Please note that his notebook is intended to serve as an example only, and be adapted for your own datasets." 25 | ] 26 | }, 27 | { 28 | "cell_type": "markdown", 29 | "id": "76190116-7090-4590-9204-dbb0a4c756bc", 30 | "metadata": {}, 31 | "source": [ 32 | "The files are organised as one file per RCM/ensemble member (12 in total)." 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": 2, 38 | "id": "c31a048f-9a69-41bb-a817-8bfc4fe63349", 39 | "metadata": {}, 40 | "outputs": [ 41 | { 42 | "name": "stdout", 43 | "output_type": "stream", 44 | "text": [ 45 | "G2G_DailyRiverFlow_NATURAL_RCM01_19801201_20801130.nc\n", 46 | "G2G_DailyRiverFlow_NATURAL_RCM04_19801201_20801130.nc\n", 47 | "G2G_DailyRiverFlow_NATURAL_RCM05_19801201_20801130.nc\n", 48 | "G2G_DailyRiverFlow_NATURAL_RCM06_19801201_20801130.nc\n", 49 | "G2G_DailyRiverFlow_NATURAL_RCM07_19801201_20801130.nc\n", 50 | "G2G_DailyRiverFlow_NATURAL_RCM08_19801201_20801130.nc\n", 51 | "G2G_DailyRiverFlow_NATURAL_RCM09_19801201_20801130.nc\n", 52 | "G2G_DailyRiverFlow_NATURAL_RCM10_19801201_20801130.nc\n", 53 | "G2G_DailyRiverFlow_NATURAL_RCM11_19801201_20801130.nc\n", 54 | "G2G_DailyRiverFlow_NATURAL_RCM12_19801201_20801130.nc\n", 55 | "G2G_DailyRiverFlow_NATURAL_RCM13_19801201_20801130.nc\n", 56 | "G2G_DailyRiverFlow_NATURAL_RCM15_19801201_20801130.nc\n" 57 | ] 58 | } 59 | ], 60 | "source": [ 61 | "!ls ../data/G2G/preproc" 62 | ] 63 | }, 64 | { 65 | "cell_type": "markdown", 66 | "id": "f57856bb-aa4b-4542-ab07-9d1388138ffe", 67 | "metadata": {}, 68 | "source": [ 69 | "One of the files looks like:" 70 | ] 71 | }, 72 | { 73 | "cell_type": "code", 74 | "execution_count": 3, 75 | "id": "568dff82-3780-4f4b-9073-1efb56a5d098", 76 | "metadata": {}, 77 | "outputs": [ 78 | { 79 | "name": "stdout", 80 | "output_type": "stream", 81 | "text": [ 82 | "netcdf G2G_DailyRiverFlow_NATURAL_RCM01_19801201_20801130 {\n", 83 | "dimensions:\n", 84 | "\tTime = UNLIMITED ; // (36000 currently)\n", 85 | "\tRCM = 1 ;\n", 86 | "\tNorthing = 1000 ;\n", 87 | "\tEasting = 700 ;\n", 88 | "variables:\n", 89 | "\tstring RCM(RCM) ;\n", 90 | "\tfloat Northing(Northing) ;\n", 91 | "\t\tNorthing:_FillValue = NaNf ;\n", 92 | "\t\tNorthing:standard_name = \"Northing\" ;\n", 93 | "\t\tNorthing:axis = \"Y\" ;\n", 94 | "\t\tNorthing:units = \"GB National Grid\" ;\n", 95 | "\tfloat Easting(Easting) ;\n", 96 | "\t\tEasting:_FillValue = NaNf ;\n", 97 | "\t\tEasting:standard_name = \"Easting\" ;\n", 98 | "\t\tEasting:axis = \"X\" ;\n", 99 | "\t\tEasting:units = \"GB National Grid\" ;\n", 100 | "\tfloat Time(Time) ;\n", 101 | "\t\tTime:_FillValue = NaNf ;\n", 102 | "\t\tTime:standard_name = \"Time\" ;\n", 103 | "\t\tTime:axis = \"T\" ;\n", 104 | "\t\tTime:units = \"days since 1961-01-01\" ;\n", 105 | "\t\tTime:calendar = \"360_day\" ;\n", 106 | "\tfloat dmflow(RCM, Time, Northing, Easting) ;\n", 107 | "\t\tdmflow:_FillValue = -999.f ;\n", 108 | "\t\tdmflow:units = \"m3 s-1\" ;\n", 109 | "\t\tdmflow:standard_name = \"dmflow\" ;\n", 110 | "\t\tdmflow:long_name = \"Daily mean river flow\" ;\n", 111 | "\t\tdmflow:missing_value = -999.f ;\n", 112 | "}\n" 113 | ] 114 | } 115 | ], 116 | "source": [ 117 | "!ncdump -h ../data/G2G/preproc/G2G_DailyRiverFlow_NATURAL_RCM01_19801201_20801130.nc" 118 | ] 119 | }, 120 | { 121 | "cell_type": "markdown", 122 | "id": "08611a59-ba4a-482b-bf24-c970b3b310cb", 123 | "metadata": {}, 124 | "source": [ 125 | "--- " 126 | ] 127 | }, 128 | { 129 | "cell_type": "markdown", 130 | "id": "9258e6ab-8955-4721-9d4b-50c515158dd2", 131 | "metadata": {}, 132 | "source": [ 133 | "First step is to define a 'ConcatDim' object/variable which contains the name of the dimension along which we want to concatenate the files, the values of the dimensions in the files (in the order that we'd like them contacatenate?) and the number of dimension elements within each file, if it is constant (e.g. for monthly files on a 360 calendar this would be 30). " 134 | ] 135 | }, 136 | { 137 | "cell_type": "code", 138 | "execution_count": 2, 139 | "id": "35263bd5-cdc8-4285-8b67-3d73d3ad5b10", 140 | "metadata": {}, 141 | "outputs": [], 142 | "source": [ 143 | "RCMs = [\"01\", \"04\", \"05\", \"06\", \"07\", \"08\", \"09\", \"10\", \"11\", \"12\", \"13\", \"15\"]\n", 144 | "RCM_concat_dim = ConcatDim(\"RCM\", RCMs, nitems_per_file=1)" 145 | ] 146 | }, 147 | { 148 | "cell_type": "markdown", 149 | "id": "69a0d33a-381e-42af-a3dc-0b51e3a03035", 150 | "metadata": {}, 151 | "source": [ 152 | "Next, we define the function that translates a given RCM into a file path. The function must have the same number of arguments as the number of Combine Dimensions and the name of the argument must match the name of the the Combine Dimension." 153 | ] 154 | }, 155 | { 156 | "cell_type": "code", 157 | "execution_count": 3, 158 | "id": "2947483a-ee40-4ffb-8aa5-d86b9e17dd9b", 159 | "metadata": {}, 160 | "outputs": [], 161 | "source": [ 162 | "indir = \"/home/users/mattjbr/object_storage/data/G2G/preproc\"\n", 163 | "pre = \"G2G_DailyRiverFlow_NATURAL_RCM\"\n", 164 | "suf = \"_19801201_20801130.nc\"\n", 165 | "\n", 166 | "\n", 167 | "def make_path(RCM):\n", 168 | " return os.path.join(indir, pre + RCM + suf)" 169 | ] 170 | }, 171 | { 172 | "cell_type": "markdown", 173 | "id": "ce5eabc2-9bb8-4a87-8ccb-90d82318a56e", 174 | "metadata": {}, 175 | "source": [ 176 | "Then these are put into a FilePattern object" 177 | ] 178 | }, 179 | { 180 | "cell_type": "code", 181 | "execution_count": 4, 182 | "id": "f996bf94-a0d2-4d6b-8a52-135795528084", 183 | "metadata": {}, 184 | "outputs": [], 185 | "source": [ 186 | "pattern = FilePattern(make_path, RCM_concat_dim)" 187 | ] 188 | }, 189 | { 190 | "cell_type": "markdown", 191 | "id": "0e9ed41d-f70e-4a08-aa9c-dfeb673c1369", 192 | "metadata": {}, 193 | "source": [ 194 | "Next, we prune the FilePattern for testing" 195 | ] 196 | }, 197 | { 198 | "cell_type": "code", 199 | "execution_count": 5, 200 | "id": "62469968-65c1-4839-8c78-07dcd55d3436", 201 | "metadata": {}, 202 | "outputs": [], 203 | "source": [ 204 | "pattern_pruned = pattern.prune()" 205 | ] 206 | }, 207 | { 208 | "cell_type": "markdown", 209 | "id": "abc38e31-3665-466a-a38b-cd78a901d668", 210 | "metadata": {}, 211 | "source": [ 212 | "And create the test recipe, outputting to local disk, and specifying the chunks to rechunk the dataset to" 213 | ] 214 | }, 215 | { 216 | "cell_type": "code", 217 | "execution_count": null, 218 | "id": "534fe305-f59f-4a12-9286-929b96b74578", 219 | "metadata": {}, 220 | "outputs": [], 221 | "source": [ 222 | "target_root = (\n", 223 | " \"/users/sgsys/matbro/object_storage/object_storage/data/output\" ## output folder\n", 224 | ")\n", 225 | "tn = \"test.zarr\" ## output filename\n", 226 | "\n", 227 | "target_chunks = {\n", 228 | " \"RCM\": 1,\n", 229 | " \"Time\": 360,\n", 230 | " \"Northing\": 100,\n", 231 | " \"Easting\": 100,\n", 232 | "} ## length of each dimension of the desired chunks\n", 233 | "\n", 234 | "transforms = (\n", 235 | " beam.Create(pattern_pruned.items())\n", 236 | " | OpenWithXarray(file_type=pattern_pruned.file_type)\n", 237 | " | StoreToZarr(\n", 238 | " target_root=target_root,\n", 239 | " store_name=tn,\n", 240 | " combine_dims=pattern.combine_dim_keys,\n", 241 | " target_chunks=target_chunks,\n", 242 | " )\n", 243 | ")" 244 | ] 245 | }, 246 | { 247 | "cell_type": "markdown", 248 | "id": "442dd386-fc63-418c-8bca-8e5d69eceb32", 249 | "metadata": {}, 250 | "source": [ 251 | "Run the recipe in parallel" 252 | ] 253 | }, 254 | { 255 | "cell_type": "code", 256 | "execution_count": null, 257 | "id": "f420e4cb-6750-48a6-82ce-1cae2fd5d5d8", 258 | "metadata": {}, 259 | "outputs": [], 260 | "source": [ 261 | "from apache_beam.options.pipeline_options import PipelineOptions\n", 262 | "\n", 263 | "beam_options = PipelineOptions(\n", 264 | " direct_num_workers=8, direct_running_mode=\"multi_processing\"\n", 265 | ")\n", 266 | "with beam.Pipeline(options=beam_options) as p:\n", 267 | " p | transforms" 268 | ] 269 | }, 270 | { 271 | "cell_type": "markdown", 272 | "id": "7e42995e-3219-4fe3-abc5-dd4cd577d2e1", 273 | "metadata": {}, 274 | "source": [ 275 | "Alternatively, the converted dataset can be output direct to object storage, however this is quite buggy with the beam's 'Direct' runner, and tends to stall out. Future work will look at using beam's other runners." 276 | ] 277 | }, 278 | { 279 | "cell_type": "code", 280 | "execution_count": null, 281 | "id": "593ec147-47c3-43a6-b039-cd29bb233bf6", 282 | "metadata": {}, 283 | "outputs": [], 284 | "source": [ 285 | "fs = s3fs.S3FileSystem(\n", 286 | " anon=False,\n", 287 | " key=\"xxxxxxxxxxxxxxxxxxxxxxxxxxxx\",\n", 288 | " secret=\"yyyyyyyyyyyyyyyyyyyyyyyyyyy\",\n", 289 | " client_kwargs={\"endpoint_url\": \"https://chess-scape-o.s3-ext.jc.rl.ac.uk\"},\n", 290 | ")\n", 291 | "\n", 292 | "target_root = FSSpecTarget(fs=fs, root_path=\"s3://g2g-test\")\n", 293 | "tn = \"test.zarr\"\n", 294 | "\n", 295 | "target_chunks = {\n", 296 | " \"RCM\": 1,\n", 297 | " \"Time\": 360,\n", 298 | " \"Northing\": 100,\n", 299 | " \"Easting\": 100,\n", 300 | "} ## length of each dimension of the desired chunks\n", 301 | "\n", 302 | "transforms = (\n", 303 | " beam.Create(pattern_pruned.items())\n", 304 | " | OpenWithXarray(file_type=pattern_pruned.file_type)\n", 305 | " | StoreToZarr(\n", 306 | " target_root=target_root,\n", 307 | " store_name=tn,\n", 308 | " combine_dims=pattern.combine_dim_keys,\n", 309 | " target_chunks=target_chunks,\n", 310 | " )\n", 311 | ")" 312 | ] 313 | }, 314 | { 315 | "cell_type": "markdown", 316 | "id": "dbc8638e-a6b4-43ad-88df-cf63825812d6", 317 | "metadata": {}, 318 | "source": [ 319 | "-------------" 320 | ] 321 | }, 322 | { 323 | "cell_type": "markdown", 324 | "id": "2839cf2d-bee7-4620-8354-71dccbfd4ada", 325 | "metadata": {}, 326 | "source": [ 327 | "Check the output dataset:" 328 | ] 329 | }, 330 | { 331 | "cell_type": "code", 332 | "execution_count": 11, 333 | "id": "8f4542fa-159d-4540-967a-b555aad5c473", 334 | "metadata": {}, 335 | "outputs": [ 336 | { 337 | "data": { 338 | "text/html": [ 339 | "
\n", 340 | "\n", 341 | "\n", 342 | "\n", 343 | "\n", 344 | "\n", 345 | "\n", 346 | "\n", 347 | "\n", 348 | "\n", 349 | "\n", 350 | "\n", 351 | "\n", 352 | "\n", 353 | "\n", 354 | "
<xarray.Dataset>\n",
703 |        "Dimensions:   (Easting: 700, Northing: 1000, RCM: 2, Time: 36000)\n",
704 |        "Coordinates:\n",
705 |        "  * Easting   (Easting) float32 500.0 1.5e+03 2.5e+03 ... 6.985e+05 6.995e+05\n",
706 |        "  * Northing  (Northing) float32 9.995e+05 9.985e+05 9.975e+05 ... 1.5e+03 500.0\n",
707 |        "  * RCM       (RCM) int64 1 4\n",
708 |        "  * Time      (Time) object 1980-12-01 00:00:00 ... 2080-11-30 00:00:00\n",
709 |        "Data variables:\n",
710 |        "    dmflow    (RCM, Time, Northing, Easting) float32 ...
" 738 | ], 739 | "text/plain": [ 740 | "\n", 741 | "Dimensions: (Easting: 700, Northing: 1000, RCM: 2, Time: 36000)\n", 742 | "Coordinates:\n", 743 | " * Easting (Easting) float32 500.0 1.5e+03 2.5e+03 ... 6.985e+05 6.995e+05\n", 744 | " * Northing (Northing) float32 9.995e+05 9.985e+05 9.975e+05 ... 1.5e+03 500.0\n", 745 | " * RCM (RCM) int64 1 4\n", 746 | " * Time (Time) object 1980-12-01 00:00:00 ... 2080-11-30 00:00:00\n", 747 | "Data variables:\n", 748 | " dmflow (RCM, Time, Northing, Easting) float32 ..." 749 | ] 750 | }, 751 | "execution_count": 11, 752 | "metadata": {}, 753 | "output_type": "execute_result" 754 | } 755 | ], 756 | "source": [ 757 | "xr.open_dataset(\"/work/scratch-pw2/mattjbr/testoutput.zarr\")" 758 | ] 759 | }, 760 | { 761 | "cell_type": "code", 762 | "execution_count": 15, 763 | "id": "92271486-2187-442d-804d-8f1624d454f7", 764 | "metadata": {}, 765 | "outputs": [], 766 | "source": [ 767 | "import zarr\n", 768 | "\n", 769 | "tzar = zarr.open(\"/work/scratch-pw2/mattjbr/testoutput.zarr/dmflow\")" 770 | ] 771 | }, 772 | { 773 | "cell_type": "code", 774 | "execution_count": 16, 775 | "id": "4eca21b0-26b0-4754-9d82-cb75b985d267", 776 | "metadata": {}, 777 | "outputs": [ 778 | { 779 | "data": { 780 | "text/html": [ 781 | "
Typezarr.core.Array
Data typefloat32
Shape(2, 36000, 1000, 700)
Chunk shape(1, 360, 100, 100)
OrderC
Read-onlyFalse
CompressorBlosc(cname='lz4', clevel=5, shuffle=SHUFFLE, blocksize=0)
Store typezarr.storage.DirectoryStore
No. bytes201600000000 (187.8G)
No. bytes stored31345654783 (29.2G)
Storage ratio6.4
Chunks initialized14000/14000
" 782 | ], 783 | "text/plain": [ 784 | "Type : zarr.core.Array\n", 785 | "Data type : float32\n", 786 | "Shape : (2, 36000, 1000, 700)\n", 787 | "Chunk shape : (1, 360, 100, 100)\n", 788 | "Order : C\n", 789 | "Read-only : False\n", 790 | "Compressor : Blosc(cname='lz4', clevel=5, shuffle=SHUFFLE, blocksize=0)\n", 791 | "Store type : zarr.storage.DirectoryStore\n", 792 | "No. bytes : 201600000000 (187.8G)\n", 793 | "No. bytes stored : 31345654783 (29.2G)\n", 794 | "Storage ratio : 6.4\n", 795 | "Chunks initialized : 14000/14000" 796 | ] 797 | }, 798 | "execution_count": 16, 799 | "metadata": {}, 800 | "output_type": "execute_result" 801 | } 802 | ], 803 | "source": [ 804 | "tzar.info" 805 | ] 806 | }, 807 | { 808 | "cell_type": "code", 809 | "execution_count": null, 810 | "id": "05fc5ff2-9411-4d53-962d-8c01811c2fe8", 811 | "metadata": {}, 812 | "outputs": [], 813 | "source": [] 814 | } 815 | ], 816 | "metadata": { 817 | "kernelspec": { 818 | "display_name": "Python 3 (ipykernel)", 819 | "language": "python", 820 | "name": "python3" 821 | }, 822 | "language_info": { 823 | "codemirror_mode": { 824 | "name": "ipython", 825 | "version": 3 826 | }, 827 | "file_extension": ".py", 828 | "mimetype": "text/x-python", 829 | "name": "python", 830 | "nbconvert_exporter": "python", 831 | "pygments_lexer": "ipython3", 832 | "version": "3.9.16" 833 | } 834 | }, 835 | "nbformat": 4, 836 | "nbformat_minor": 5 837 | } 838 | -------------------------------------------------------------------------------- /scripts/convert_G2G_beam.py: -------------------------------------------------------------------------------- 1 | # MJB (UKCEH) Nov-2023 2 | # Example script for a pangeo-forge-recipe to convert 3 | # gridded netcdf files to a zarr datastore ready for upload 4 | # to object storage. 5 | # See jupyter notebook for more details and explanations/comments 6 | # Please note that this notebook is intended to serve as an example only, 7 | # and be adapted for your own datasets. 8 | 9 | import os 10 | import apache_beam as beam 11 | from pangeo_forge_recipes.patterns import ConcatDim, FilePattern 12 | from apache_beam.options.pipeline_options import PipelineOptions 13 | from pangeo_forge_recipes.transforms import OpenWithXarray, StoreToZarr 14 | 15 | 16 | RCMs = ["01", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "15"] 17 | indir = "/home/users/mattjbr/object_storage/data/G2G/preproc" 18 | pre = "G2G_DailyRiverFlow_NATURAL_RCM" 19 | suf = "_19801201_20801130.nc" 20 | td = "/work/scratch-pw2/mattjbr" 21 | tn = "fulloutput_yearly_100km_chunks.zarr" 22 | target_chunks = {"RCM": 1, "Time": 360, "Northing": 100, "Easting": 100} 23 | nprocs = 64 24 | 25 | if not os.path.exists(td): 26 | os.makedirs(td) 27 | 28 | 29 | def make_path(RCM): 30 | return os.path.join(indir, pre + RCM + suf) 31 | 32 | 33 | RCM_concat_dim = ConcatDim("RCM", RCMs, nitems_per_file=1) 34 | 35 | pattern = FilePattern(make_path, RCM_concat_dim) 36 | 37 | transforms = ( 38 | beam.Create(pattern.items()) 39 | | OpenWithXarray(file_type=pattern.file_type) 40 | | StoreToZarr( 41 | target_root=td, 42 | store_name=tn, 43 | combine_dims=pattern.combine_dim_keys, 44 | target_chunks=target_chunks, 45 | ) 46 | ) 47 | 48 | beam_options = PipelineOptions( 49 | direct_num_workers=nprocs, direct_running_mode="multi_processing" 50 | ) 51 | with beam.Pipeline(options=beam_options) as p: 52 | p | transforms 53 | -------------------------------------------------------------------------------- /scripts/convert_G2G_beam.sbatch: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #SBATCH -p par-multi 3 | #SBATCH -o %J.out 4 | #SBATCH -e %J.err 5 | #SBATCH -n 64 6 | #SBATCH --time=20:00:00 7 | #SBATCH --mem=40GB 8 | 9 | # Example SLURM job script for running the convert_G2G_beam.py 10 | # script on a SLURM-controlled HPC 11 | 12 | # set up conda env 13 | export PATH=/home/users/mattjbr/miniconda3/bin:$PATH 14 | source /home/users/mattjbr/miniconda3/bin/activate apache 15 | 16 | # run script 17 | /home/users/mattjbr/miniconda3/envs/apache/bin/ipython /gws/nopw/j04/ceh_generic/matbro/object_storage/scripts/convert_G2G_beam.py 18 | --------------------------------------------------------------------------------