|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": null, |
| 6 | + "id": "653324a3-e972-46d1-a80e-57bcf64c8a7a", |
| 7 | + "metadata": {}, |
| 8 | + "outputs": [], |
| 9 | + "source": [ |
| 10 | + "import uxarray as ux\n", |
| 11 | + "import matplotlib.pyplot as plt\n", |
| 12 | + "import cartopy.crs as ccrs\n", |
| 13 | + "import cartopy.feature as cfeature\n", |
| 14 | + "import os\n", |
| 15 | + "import OpenVisus as ov\n", |
| 16 | + "import xarray as xr\n", |
| 17 | + "from tqdm import tqdm\n", |
| 18 | + "import time\n", |
| 19 | + "from sys import getsizeof" |
| 20 | + ] |
| 21 | + }, |
| 22 | + { |
| 23 | + "cell_type": "code", |
| 24 | + "execution_count": null, |
| 25 | + "id": "1c1b063e-b8fb-49ba-b1bb-7b0883307ed6", |
| 26 | + "metadata": {}, |
| 27 | + "outputs": [], |
| 28 | + "source": [ |
| 29 | + "# !pip install OpenVisus openvisuspy boto3 xmltodict panel bokeh\n", |
| 30 | + "# !pip install tqdm" |
| 31 | + ] |
| 32 | + }, |
| 33 | + { |
| 34 | + "cell_type": "code", |
| 35 | + "execution_count": null, |
| 36 | + "id": "41d3f40d-6771-457b-b67a-6ffae1627420", |
| 37 | + "metadata": {}, |
| 38 | + "outputs": [], |
| 39 | + "source": [ |
| 40 | + "main_dir='/glade/derecho/scratch/digital-earths-hackathon/conus404/native_grid'\n", |
| 41 | + "home_dir='/glade/u/home/dpanta'\n", |
| 42 | + "idx_dir='/glade/u/home/dpanta/idx'" |
| 43 | + ] |
| 44 | + }, |
| 45 | + { |
| 46 | + "cell_type": "code", |
| 47 | + "execution_count": null, |
| 48 | + "id": "b3b2a300-7496-4945-8932-06f8058a0b40", |
| 49 | + "metadata": {}, |
| 50 | + "outputs": [], |
| 51 | + "source": [ |
| 52 | + "st_file='/glade/derecho/scratch/digital-earths-hackathon/conus404/native_grid/2020-10_eastward_wind.nc'\n", |
| 53 | + "\n", |
| 54 | + "\n", |
| 55 | + "files=[\n", |
| 56 | + "'2020-12_eastward_wind.nc',\n", |
| 57 | + "'2020-12_northward_wind.nc',\n", |
| 58 | + "'2020-12_precipitation_flux.nc',\n", |
| 59 | + "'2020-12_specific_humidity.nc',\n", |
| 60 | + "'2020-12_surface_air_pressure.nc',\n", |
| 61 | + "'2020-12_surface_temperature.nc',\n", |
| 62 | + "'2020-12_toa_outgoing_longwave_flux.nc',\n", |
| 63 | + "'2020-12_toa_outgoing_shortwave_flux.nc',\n", |
| 64 | + "]" |
| 65 | + ] |
| 66 | + }, |
| 67 | + { |
| 68 | + "cell_type": "code", |
| 69 | + "execution_count": null, |
| 70 | + "id": "f5a5464a-4ab9-4844-a5f7-9449437e1d70", |
| 71 | + "metadata": { |
| 72 | + "scrolled": true |
| 73 | + }, |
| 74 | + "outputs": [], |
| 75 | + "source": [ |
| 76 | + "ds=xr.open_dataset(st_file)\n", |
| 77 | + "ds" |
| 78 | + ] |
| 79 | + }, |
| 80 | + { |
| 81 | + "cell_type": "code", |
| 82 | + "execution_count": null, |
| 83 | + "id": "fd8061d0-ae23-416b-b20a-e947b61e8673", |
| 84 | + "metadata": {}, |
| 85 | + "outputs": [], |
| 86 | + "source": [ |
| 87 | + "import datetime\n", |
| 88 | + "\n", |
| 89 | + "idx_filename=f\"/glade/derecho/scratch/dpanta/idx/conus404_all.idx\"\n", |
| 90 | + "fields=['eastward_wind','northward_wind','precipitation_flux','specific_humidity','surface_air_pressure','surface_temperature','toa_outgoing_longwave_flux', 'toa_outgoing_shortwave_flux']\n", |
| 91 | + "arco=\"4mb\"\n", |
| 92 | + "fld_idx=[]\n", |
| 93 | + "for fld in fields:\n", |
| 94 | + " print(f'Setting Field::: {fld}')\n", |
| 95 | + " st_file=f'/glade/derecho/scratch/digital-earths-hackathon/conus404/native_grid/2020-10_{fld}.nc'\n", |
| 96 | + "\n", |
| 97 | + " ds = xr.open_dataset(st_file, group=\"/\", mask_and_scale=False) \n", |
| 98 | + " data=ds[f\"{fld}\"][0,:,:].values\n", |
| 99 | + " if int(len(data.shape))>1:\n", |
| 100 | + " \n", |
| 101 | + " print(f\"{fld}::::{data.shape}\")\n", |
| 102 | + " try:\n", |
| 103 | + " vmin,vmax=np.min(data),np.max(data)\n", |
| 104 | + " except:\n", |
| 105 | + " vmin,vmax=0,0\n", |
| 106 | + " fld=ov.Field.fromString(f\"\"\"{fld} {str(data.dtype)} format(row_major) min({vmin}) max({vmax})\"\"\")\n", |
| 107 | + " fld_idx.append(fld)" |
| 108 | + ] |
| 109 | + }, |
| 110 | + { |
| 111 | + "cell_type": "code", |
| 112 | + "execution_count": null, |
| 113 | + "id": "e86db120-d1bb-4ad6-b987-b7db41d8bb45", |
| 114 | + "metadata": {}, |
| 115 | + "outputs": [], |
| 116 | + "source": [ |
| 117 | + "T=744\n", |
| 118 | + "W,H=data.shape\n" |
| 119 | + ] |
| 120 | + }, |
| 121 | + { |
| 122 | + "cell_type": "code", |
| 123 | + "execution_count": null, |
| 124 | + "id": "f9f092b3-d793-40c4-872b-dbef1daea331", |
| 125 | + "metadata": {}, |
| 126 | + "outputs": [], |
| 127 | + "source": [ |
| 128 | + "print('Creating IDX Metadata file now...')\n", |
| 129 | + "db=ov.CreateIdx(\n", |
| 130 | + " url=idx_filename, \n", |
| 131 | + "\tdims=[H,W], \n", |
| 132 | + "\tfields=fld_idx, \n", |
| 133 | + "\tcompression=\"raw\", \n", |
| 134 | + "\tarco=arco,\n", |
| 135 | + "\ttime=[0,T,\"time_%d/\"])\n", |
| 136 | + "print('Created...')\n", |
| 137 | + "\n", |
| 138 | + "# db=ov.LoadDataset(idx_filename)" |
| 139 | + ] |
| 140 | + }, |
| 141 | + { |
| 142 | + "cell_type": "code", |
| 143 | + "execution_count": null, |
| 144 | + "id": "89c82d00-1c6a-4271-9c67-1c4da16cc900", |
| 145 | + "metadata": {}, |
| 146 | + "outputs": [], |
| 147 | + "source": [ |
| 148 | + "print('Writing to idx...')\n", |
| 149 | + "for i in range(len(fields)):\n", |
| 150 | + " print(f'Writing field {fields[i]}...')\n", |
| 151 | + " st_file=f'/glade/derecho/scratch/digital-earths-hackathon/conus404/native_grid/2020-10_{fields[i]}.nc'\n", |
| 152 | + " ds = xr.open_dataset(st_file, group=\"/\", mask_and_scale=False) \n", |
| 153 | + " data=ds[f\"{fields[i]}\"][...].values\n", |
| 154 | + " for t in range(data.shape[0]):\n", |
| 155 | + " data_to_write=data[t,:,:]\n", |
| 156 | + " try:\n", |
| 157 | + " db.write(data_to_write,time=t,field=fields[i])\n", |
| 158 | + " except:\n", |
| 159 | + " pass\n", |
| 160 | + "print('Writing data completed...')\n", |
| 161 | + "print('Compressing data now...')\n", |
| 162 | + "db.compressDataset(['zip'])\n", |
| 163 | + "print('Data compressed!!!')" |
| 164 | + ] |
| 165 | + }, |
| 166 | + { |
| 167 | + "cell_type": "code", |
| 168 | + "execution_count": null, |
| 169 | + "id": "640d1cf3-6f2f-46a3-8630-474f7225dc3b", |
| 170 | + "metadata": {}, |
| 171 | + "outputs": [], |
| 172 | + "source": [] |
| 173 | + } |
| 174 | + ], |
| 175 | + "metadata": { |
| 176 | + "kernelspec": { |
| 177 | + "display_name": "Python 3 (ipykernel)", |
| 178 | + "language": "python", |
| 179 | + "name": "python3" |
| 180 | + }, |
| 181 | + "language_info": { |
| 182 | + "codemirror_mode": { |
| 183 | + "name": "ipython", |
| 184 | + "version": 3 |
| 185 | + }, |
| 186 | + "file_extension": ".py", |
| 187 | + "mimetype": "text/x-python", |
| 188 | + "name": "python", |
| 189 | + "nbconvert_exporter": "python", |
| 190 | + "pygments_lexer": "ipython3", |
| 191 | + "version": "3.10.13" |
| 192 | + } |
| 193 | + }, |
| 194 | + "nbformat": 4, |
| 195 | + "nbformat_minor": 5 |
| 196 | +} |
0 commit comments