|
6 | 6 | "id": "c91b40e6",
|
7 | 7 | "metadata": {},
|
8 | 8 | "source": [
|
9 |
| - "# bodemdalingvoorspellingskaarten\n", |
10 |
| - "Convert tiff files into cloud optimised geotiff\n", |
| 9 | + "# Sea Level Rise AR6\n", |
11 | 10 | "Notebook environment to migrate netcdf files to CF compliant zarr & CoG. \n",
|
12 | 11 | "Note, this is still quite a mess, TODO: clean up.."
|
13 | 12 | ]
|
14 | 13 | },
|
15 | 14 | {
|
16 | 15 | "cell_type": "code",
|
17 |
| - "execution_count": 1, |
| 16 | + "execution_count": null, |
18 | 17 | "id": "f1aef40e",
|
19 | 18 | "metadata": {},
|
20 |
| - "outputs": [ |
21 |
| - { |
22 |
| - "data": { |
23 |
| - "application/javascript": "\n setTimeout(function() {\n var nbb_cell_id = 1;\n var nbb_unformatted_code = \"# Optional; code formatter, installed as jupyter lab extension\\n#%load_ext lab_black\\n# Optional; code formatter, installed as jupyter notebook extension\\n%load_ext nb_black\";\n var nbb_formatted_code = \"# Optional; code formatter, installed as jupyter lab extension\\n# %load_ext lab_black\\n# Optional; code formatter, installed as jupyter notebook extension\\n%load_ext nb_black\";\n var nbb_cells = Jupyter.notebook.get_cells();\n for (var i = 0; i < nbb_cells.length; ++i) {\n if (nbb_cells[i].input_prompt_number == nbb_cell_id) {\n if (nbb_cells[i].get_text() == nbb_unformatted_code) {\n nbb_cells[i].set_text(nbb_formatted_code);\n }\n break;\n }\n }\n }, 500);\n ", |
24 |
| - "text/plain": [ |
25 |
| - "<IPython.core.display.Javascript object>" |
26 |
| - ] |
27 |
| - }, |
28 |
| - "metadata": {}, |
29 |
| - "output_type": "display_data" |
30 |
| - } |
31 |
| - ], |
| 19 | + "outputs": [], |
32 | 20 | "source": [
|
33 | 21 | "# Optional; code formatter, installed as jupyter lab extension\n",
|
34 | 22 | "#%load_ext lab_black\n",
|
|
47 | 35 | },
|
48 | 36 | {
|
49 | 37 | "cell_type": "code",
|
50 |
| - "execution_count": 4, |
| 38 | + "execution_count": null, |
51 | 39 | "id": "77b089ea",
|
52 | 40 | "metadata": {},
|
53 |
| - "outputs": [ |
54 |
| - { |
55 |
| - "data": { |
56 |
| - "application/javascript": "\n setTimeout(function() {\n var nbb_cell_id = 4;\n var nbb_unformatted_code = \"# Import standard packages\\nimport os\\nimport pathlib\\nimport sys\\nimport numpy as np\\nimport geopandas as gpd\\nimport pandas as pd\\nimport matplotlib.pyplot as plt\\nimport xarray as xr\\nimport netCDF4 as nc\\nimport numpy.ma as ma\\nimport rasterio\\nimport rioxarray as rio\\nfrom datacube.utils.cog import write_cog\\n\\n# Import custom functionality\\nfrom coclicodata.drive_config import p_drive\\nfrom coclicodata.etl.cf_compliancy_checker import check_compliancy, save_compliancy\\n\\n# Define (local and) remote drives\\ngca_data_dir = p_drive.joinpath(\\\"11208003-latedeo2022\\\",\\\"020_InternationalDeltaPortfolio\\\",\\\"datasets\\\")\\n\\n# Workaround to the Windows OS (10) udunits error after installation of cfchecker: https://github.com/SciTools/iris/issues/404\\nos.environ[\\\"UDUNITS2_XML_PATH\\\"] = str(\\n home.joinpath( # change to the udunits2.xml file dir in your Python installation\\n r\\\"Anaconda3\\\\pkgs\\\\udunits2-2.2.28-h892ecd3_0\\\\Library\\\\share\\\\udunits\\\\udunits2.xml\\\"\\n )\\n)\";\n var nbb_formatted_code = \"# Import standard packages\\nimport os\\nimport pathlib\\nimport sys\\nimport numpy as np\\nimport geopandas as gpd\\nimport pandas as pd\\nimport matplotlib.pyplot as plt\\nimport xarray as xr\\nimport netCDF4 as nc\\nimport numpy.ma as ma\\nimport rasterio\\nimport rioxarray as rio\\nfrom datacube.utils.cog import write_cog\\n\\n# Import custom functionality\\nfrom coclicodata.drive_config import p_drive\\nfrom coclicodata.etl.cf_compliancy_checker import check_compliancy, save_compliancy\\n\\n# Define (local and) remote drives\\ngca_data_dir = p_drive.joinpath(\\n \\\"11208003-latedeo2022\\\", \\\"020_InternationalDeltaPortfolio\\\", \\\"datasets\\\"\\n)\\n\\n# Workaround to the Windows OS (10) udunits error after installation of cfchecker: https://github.com/SciTools/iris/issues/404\\nos.environ[\\\"UDUNITS2_XML_PATH\\\"] = str(\\n home.joinpath( # change to the udunits2.xml file dir in your Python installation\\n r\\\"Anaconda3\\\\pkgs\\\\udunits2-2.2.28-h892ecd3_0\\\\Library\\\\share\\\\udunits\\\\udunits2.xml\\\"\\n )\\n)\";\n var nbb_cells = Jupyter.notebook.get_cells();\n for (var i = 0; i < nbb_cells.length; ++i) {\n if (nbb_cells[i].input_prompt_number == nbb_cell_id) {\n if (nbb_cells[i].get_text() == nbb_unformatted_code) {\n nbb_cells[i].set_text(nbb_formatted_code);\n }\n break;\n }\n }\n }, 500);\n ", |
57 |
| - "text/plain": [ |
58 |
| - "<IPython.core.display.Javascript object>" |
59 |
| - ] |
60 |
| - }, |
61 |
| - "metadata": {}, |
62 |
| - "output_type": "display_data" |
63 |
| - } |
64 |
| - ], |
| 41 | + "outputs": [], |
65 | 42 | "source": [
|
66 | 43 | "# Import standard packages\n",
|
67 | 44 | "import os\n",
|
|
78 | 55 | "import rioxarray as rio\n",
|
79 | 56 | "from datacube.utils.cog import write_cog\n",
|
80 | 57 | "\n",
|
| 58 | + "# Make root directories importable by appending root to path\n", |
| 59 | + "cwd = pathlib.Path().resolve()\n", |
| 60 | + "sys.path.append(os.path.dirname(cwd))\n", |
| 61 | + "\n", |
| 62 | + "# Get root paths\n", |
| 63 | + "home = pathlib.Path().home()\n", |
| 64 | + "root = home.root\n", |
| 65 | + "tmp_dir = home.joinpath(\"data\", \"tmp\")\n", |
| 66 | + "\n", |
81 | 67 | "# Import custom functionality\n",
|
82 |
| - "from coclicodata.drive_config import p_drive\n", |
83 |
| - "from coclicodata.etl.cf_compliancy_checker import check_compliancy, save_compliancy\n", |
| 68 | + "from etl import p_drive\n", |
| 69 | + "from etl.CF_compliancy_checker import check_compliancy, save_compliancy\n", |
84 | 70 | "\n",
|
85 | 71 | "# Define (local and) remote drives\n",
|
86 |
| - "gca_data_dir = p_drive.joinpath(\"11208003-latedeo2022\",\"020_InternationalDeltaPortfolio\",\"datasets\")\n", |
| 72 | + "coclico_data_dir = p_drive.joinpath(\"11205479-coclico\", \"FASTTRACK_DATA\")\n", |
87 | 73 | "\n",
|
88 | 74 | "# Workaround to the Windows OS (10) udunits error after installation of cfchecker: https://github.com/SciTools/iris/issues/404\n",
|
89 | 75 | "os.environ[\"UDUNITS2_XML_PATH\"] = str(\n",
|
90 | 76 | " home.joinpath( # change to the udunits2.xml file dir in your Python installation\n",
|
91 | 77 | " r\"Anaconda3\\pkgs\\udunits2-2.2.28-h892ecd3_0\\Library\\share\\udunits\\udunits2.xml\"\n",
|
92 | 78 | " )\n",
|
93 |
| - ")\n" |
94 |
| - ] |
95 |
| - }, |
96 |
| - { |
97 |
| - "cell_type": "code", |
98 |
| - "execution_count": null, |
99 |
| - "id": "f0d2c960", |
100 |
| - "metadata": {}, |
101 |
| - "outputs": [], |
102 |
| - "source": [ |
103 |
| - "# use local or remote data dir\n", |
104 |
| - "# Make root directories importable by appending root to path\n", |
105 |
| - "#took out of the original code!\n", |
106 |
| - "cwd = pathlib.Path().resolve()\n", |
107 |
| - "sys.path.append(os.path.dirname(cwd))\n", |
108 |
| - "\n", |
109 |
| - "# Get root paths\n", |
110 |
| - "home = pathlib.Path().home()\n", |
111 |
| - "root = home.root\n", |
112 |
| - "tmp_dir = home.joinpath(\"data\", \"tmp\")\n", |
| 79 | + ")\n", |
113 | 80 | "\n",
|
| 81 | + "# use local or remote data dir\n", |
114 | 82 | "use_local_data = False\n",
|
115 | 83 | "ds_dirname = \"17_AR6_SLP_IPCC\"\n",
|
116 | 84 | "\n",
|
|
693 | 661 | "save_compliancy(cap, testfile=cog_dir.joinpath(fname.replace(\".GeoTiff\", \".nc\")), working_dir=CF_dir)"
|
694 | 662 | ]
|
695 | 663 | },
|
| 664 | + { |
| 665 | + "cell_type": "markdown", |
| 666 | + "id": "1c580844", |
| 667 | + "metadata": {}, |
| 668 | + "source": [ |
| 669 | + "##### Note, TIFFs are way less flexible in variables and therefore no CF compliancy check is needed. Data will always be an array with band, y, x as dimensions and band, y, x, spatial_ref as coordinates" |
| 670 | + ] |
| 671 | + }, |
696 | 672 | {
|
697 | 673 | "cell_type": "code",
|
698 | 674 | "execution_count": null,
|
|
701 | 677 | "outputs": [],
|
702 | 678 | "source": [
|
703 | 679 | "data = rio.open_rasterio(outpath, masked=True)\n",
|
704 |
| - "#data.plot()\n", |
705 |
| - "rds.plot()" |
| 680 | + "data.plot()\n", |
| 681 | + "#rds.plot()" |
| 682 | + ] |
| 683 | + }, |
| 684 | + { |
| 685 | + "cell_type": "code", |
| 686 | + "execution_count": null, |
| 687 | + "id": "f7c29375", |
| 688 | + "metadata": {}, |
| 689 | + "outputs": [], |
| 690 | + "source": [ |
| 691 | + "data" |
706 | 692 | ]
|
707 | 693 | },
|
708 | 694 | {
|
|
0 commit comments