|
2 | 2 | "cells": [
|
3 | 3 | {
|
4 | 4 | "cell_type": "code",
|
5 |
| - "execution_count": null, |
| 5 | + "execution_count": 1, |
6 | 6 | "id": "8d311496-9c7f-4390-8f76-f6bc5a8914c7",
|
7 | 7 | "metadata": {},
|
8 |
| - "outputs": [], |
| 8 | + "outputs": [ |
| 9 | + { |
| 10 | + "name": "stdout", |
| 11 | + "output_type": "stream", |
| 12 | + "text": [ |
| 13 | + "2022-02-10 20:59:38,451 - pint.util - WARNING - Redefining 'year' (<class 'pint.definitions.UnitDefinition'>)\n", |
| 14 | + "2022-02-10 20:59:38,453 - pint.util - WARNING - Redefining 'yr' (<class 'pint.definitions.UnitDefinition'>)\n", |
| 15 | + "2022-02-10 20:59:38,454 - pint.util - WARNING - Redefining 'degree_Celsius' (<class 'pint.definitions.UnitDefinition'>)\n", |
| 16 | + "2022-02-10 20:59:38,455 - pint.util - WARNING - Redefining '°C' (<class 'pint.definitions.UnitDefinition'>)\n", |
| 17 | + "2022-02-10 20:59:38,456 - pint.util - WARNING - Redefining 'celsius' (<class 'pint.definitions.UnitDefinition'>)\n", |
| 18 | + "2022-02-10 20:59:38,457 - pint.util - WARNING - Redefining 'degC' (<class 'pint.definitions.UnitDefinition'>)\n", |
| 19 | + "2022-02-10 20:59:38,458 - pint.util - WARNING - Redefining 'degreeC' (<class 'pint.definitions.UnitDefinition'>)\n", |
| 20 | + "2022-02-10 20:59:38,458 - pint.util - WARNING - Redefining 'C' (<class 'pint.definitions.UnitDefinition'>)\n", |
| 21 | + "2022-02-10 20:59:38,459 - pint.util - WARNING - Redefining 'deg_C' (<class 'pint.definitions.UnitDefinition'>)\n", |
| 22 | + "2022-02-10 20:59:38,460 - pint.util - WARNING - Redefining 'degrees_north' (<class 'pint.definitions.UnitDefinition'>)\n", |
| 23 | + "2022-02-10 20:59:38,463 - pint.util - WARNING - Redefining 'degrees_east' (<class 'pint.definitions.UnitDefinition'>)\n", |
| 24 | + "2022-02-10 20:59:38,464 - pint.util - WARNING - Redefining '[speed]' (<class 'pint.definitions.DimensionDefinition'>)\n", |
| 25 | + "2022-02-10 20:59:43,080 - xclim - INFO - Matplotlib installed. Setting make_graph to True.\n" |
| 26 | + ] |
| 27 | + } |
| 28 | + ], |
9 | 29 | "source": [
|
10 | 30 | "import importlib as il\n",
|
11 | 31 | "il.invalidate_caches()\n",
|
|
53 | 73 | },
|
54 | 74 | {
|
55 | 75 | "cell_type": "code",
|
56 |
| - "execution_count": null, |
| 76 | + "execution_count": 3, |
57 | 77 | "id": "a5e79bb5-b724-4b15-8eb7-4b4199e26a43",
|
58 | 78 | "metadata": {},
|
59 | 79 | "outputs": [],
|
|
68 | 88 | },
|
69 | 89 | {
|
70 | 90 | "cell_type": "code",
|
71 |
| - "execution_count": null, |
72 |
| - "id": "d99e5d78-431d-4f58-9b0c-d41f02106ca4", |
| 91 | + "execution_count": 4, |
| 92 | + "id": "fdab51b5-4087-46a2-a23e-1f0d3c2442ec", |
73 | 93 | "metadata": {},
|
74 | 94 | "outputs": [],
|
75 | 95 | "source": [
|
76 | 96 | "# Load IDF data\n",
|
77 |
| - "IDF_files=glob.glob('IDF-files/IDF_v-3.20_2021_03_26_*/*.txt')\n", |
| 97 | + "input_path = \"path to input\n", |
| 98 | + "IDF_files=glob.glob('/***REMOVED******REMOVED***/IDF-files/IDF_v-3.20_2021_03_26_*/*')\n", |
78 | 99 | "tmp=ECCC_IDF_reader.read_ECCC_IDF(IDF_files[0])\n",
|
79 | 100 | "n_stations=len(IDF_files)\n",
|
80 | 101 | "station_names=[ECCC_IDF_reader.read_ECCC_IDF(f)['location']['name'] for f in IDF_files]\n",
|
|
91 | 112 | "outputs": [],
|
92 | 113 | "source": [
|
93 | 114 | "#create new, empty xarray dataset to hold all results\n",
|
| 115 | + "#change model to realization to work in xclim\n", |
94 | 116 | "IDF_da=xr.DataArray(np.empty((n_stations,n_durations,n_return_periods,n_rcps,n_models,n_time)),\n",
|
95 | 117 | " dims=[ 'station', 'duration', 'return_period', 'rcp', 'model', 'time',],\n",
|
96 | 118 | " coords=dict(station=station_ID,\n",
|
97 | 119 | " duration=tmp['IDF_rates'].index.values,\n",
|
98 | 120 | " return_period=tmp['IDF_rates'].columns.values,\n",
|
99 | 121 | " rcp=rcps,\n",
|
100 |
| - " models=temperature_data.coords['model'],\n", |
| 122 | + " model=temperature_data.coords['model'],\n", |
101 | 123 | " time=temperature_data.coords['time'],\n",
|
102 | 124 | " ))\n",
|
103 | 125 | "\n",
|
|
114 | 136 | "IDF_station_longitude_da=xr.DataArray(np.empty((n_stations)),\n",
|
115 | 137 | " dims=[ 'station'],\n",
|
116 | 138 | " coords=dict(station=station_ID,))\n",
|
| 139 | + "#add ref array for each station\n", |
| 140 | + "IDF_station_ref_da=xr.DataArray(np.empty((n_stations)),\n", |
| 141 | + " dims=[ 'station'],\n", |
| 142 | + " coords=dict(station=station_ID,))\n", |
117 | 143 | "\n",
|
118 | 144 | "for n,f in enumerate(tqdm(IDF_files)):\n",
|
119 | 145 | " IDF_dict=ECCC_IDF_reader.read_ECCC_IDF(f)\n",
|
|
124 | 150 | " #Get mid-point of IDF period of record\n",
|
125 | 151 | " base_time=int(np.mean((IDF_dict['period']['start_date'],\n",
|
126 | 152 | " IDF_dict['period']['end_date'])))\n",
|
127 |
| - " ibase_T=np.argmin(abs(mod_time_as_int-base_time-15))\n", |
| 153 | + " \n", |
| 154 | + " #Use to determine which 30y period to use - subtract 15 from base_time so that you choose a 30y period with base_time in middle (there must be a better way)\n", |
| 155 | + " ibase_T=np.argmin(abs(mod_time_as_int-(base_time-15)))\n", |
128 | 156 | " \n",
|
129 | 157 | " print(ibase_T)\n",
|
130 | 158 | " \n",
|
131 | 159 | " dT=T-T[:,:,ibase_T] #calculate dT - broadcast to all models, RCPs, times\n",
|
132 |
| - " dT.attrs['units']='delta_degreeC'\n", |
| 160 | + " dT.attrs['units']='delta_degreeC' #change units for CC equation\n", |
133 | 161 | " \n",
|
134 | 162 | " pr_baseline=xr.DataArray(IDF_dict['IDF_rates'],\n",
|
135 | 163 | " coords=dict(duration=IDF_da.coords['duration'],\n",
|
|
143 | 171 | " \n",
|
144 | 172 | " IDF_station_latitude_da.loc[IDF_dict['location']['ID']] = IDF_dict['location']['latitude']\n",
|
145 | 173 | " IDF_station_longitude_da.loc[IDF_dict['location']['ID']] = IDF_dict['location']['longitude']\n",
|
| 174 | + " IDF_station_ref_da.loc[IDF_dict['location']['ID']] =mod_time_as_int[ibase_T] #add each stations ref period for later use\n", |
146 | 175 | " #TODO: add station name variable accumulator\n",
|
147 | 176 | "\n"
|
148 | 177 | ]
|
149 | 178 | },
|
150 | 179 | {
|
151 | 180 | "cell_type": "code",
|
152 |
| - "execution_count": null, |
| 181 | + "execution_count": 69, |
153 | 182 | "id": "e7c2efdf-4537-4f0e-be38-47e31ae5916e",
|
154 | 183 | "metadata": {},
|
155 | 184 | "outputs": [],
|
156 | 185 | "source": [
|
| 186 | + "#used lat and lon to align with other ds on CD.ca\n", |
157 | 187 | "IDF_df=xr.Dataset(dict(IDF_data=IDF_da,\n",
|
158 | 188 | " IDF_confidence=IDF_confidence_da,\n",
|
159 |
| - " IDF_station_latitude=IDF_station_latitude_da,\n", |
160 |
| - " IDF_station_longitude=IDF_station_longitude_da,))" |
| 189 | + " lat=IDF_station_latitude_da,\n", |
| 190 | + " lon=IDF_station_longitude_da,\n", |
| 191 | + " ref=IDF_station_ref_da,\n", |
| 192 | + " ))" |
161 | 193 | ]
|
162 | 194 | },
|
163 | 195 | {
|
164 | 196 | "cell_type": "code",
|
165 |
| - "execution_count": null, |
| 197 | + "execution_count": 70, |
166 | 198 | "id": "026f8724-014c-454e-a3c4-f846839b2427",
|
167 | 199 | "metadata": {},
|
168 | 200 | "outputs": [],
|
169 | 201 | "source": [
|
170 |
| - "fname='national_IDF_projection_dataset.nc'" |
| 202 | + "fname='/notebook_dir/writable-workspace/IDF/national_IDF_projection_dataset.nc'" |
171 | 203 | ]
|
172 | 204 | },
|
173 | 205 | {
|
174 | 206 | "cell_type": "code",
|
175 |
| - "execution_count": null, |
| 207 | + "execution_count": 71, |
176 | 208 | "id": "101a81d2-0825-43c8-9639-d65beae7dd75",
|
177 | 209 | "metadata": {},
|
178 | 210 | "outputs": [],
|
|
247 | 279 | "metadata": {},
|
248 | 280 | "outputs": [],
|
249 | 281 | "source": []
|
250 |
| - }, |
251 |
| - { |
252 |
| - "cell_type": "code", |
253 |
| - "execution_count": null, |
254 |
| - "id": "53313f84-18ac-47c3-abfb-57b071568287", |
255 |
| - "metadata": {}, |
256 |
| - "outputs": [], |
257 |
| - "source": [] |
258 | 282 | }
|
259 | 283 | ],
|
260 | 284 | "metadata": {
|
|
273 | 297 | "name": "python",
|
274 | 298 | "nbconvert_exporter": "python",
|
275 | 299 | "pygments_lexer": "ipython3",
|
276 |
| - "version": "3.7.10" |
| 300 | + "version": "3.8.12" |
277 | 301 | }
|
278 | 302 | },
|
279 | 303 | "nbformat": 4,
|
|
0 commit comments