|
116 | 116 | }, |
117 | 117 | "outputs": [], |
118 | 118 | "source": [ |
| 119 | + "is_log = True # Or False, depending on the mode\n", |
| 120 | + "EPSILON = 0.001\n", |
| 121 | + "\n", |
119 | 122 | "try:\n", |
| 123 | + " # Select the colormap\n", |
| 124 | + " cmap_instance = plt.get_cmap(\"viridis\")\n", |
| 125 | + "\n", |
| 126 | + " # Process data range based on log/linear scaling you selected from dashboard\n", |
| 127 | + " # If is_log is True, we will use logarithmic scaling; otherwise, we will use linear scaling\n", |
120 | 128 | " \n", |
121 | | - " # Choose a colormap for visualizing the data\n", |
122 | | - " # The colormap 'inferno' is used here, which is a perceptually uniform colormap\n", |
123 | | - " cmap_instance = plt.get_cmap(\"inferno\")\n", |
124 | | - " \n", |
125 | | - " # Extract the latitude and longitude boundaries from the metadata\n", |
126 | | - " lat_min = metadata[0][0] # Minimum latitude\n", |
127 | | - " lat_max = metadata[0][1] # Maximum latitude\n", |
128 | | - " lon_min = metadata[1][0] # Minimum longitude\n", |
129 | | - " lon_max = metadata[1][1] # Maximum longitude\n", |
| 129 | + " if not is_log:\n", |
| 130 | + " vmin = np.min(actual_data)\n", |
| 131 | + " vmax = np.max(actual_data)\n", |
| 132 | + " norm = None # Use default linear normalization\n", |
| 133 | + " else:\n", |
| 134 | + " # Ensure data is positive for log scaling\n", |
| 135 | + " actual_data = np.clip(actual_data, EPSILON, None)\n", |
| 136 | + " vmin = np.min(actual_data)\n", |
| 137 | + " vmax = np.max(actual_data)\n", |
| 138 | + " from matplotlib.colors import LogNorm\n", |
| 139 | + " norm = LogNorm(vmin=vmin, vmax=vmax)\n", |
130 | 140 | "\n", |
131 | | - " # Plot the figure with a default range\n", |
132 | | - " # The default range is determined by the full range of the colormap without considering the data limits\n", |
| 141 | + " # Extract bounds from metadata\n", |
| 142 | + " lat_min, lat_max = metadata[0]\n", |
| 143 | + " lon_min, lon_max = metadata[1]\n", |
| 144 | + "\n", |
| 145 | + " # Plotting\n", |
133 | 146 | " fig, axs = plt.subplots(1, 1, figsize=(10, 8))\n", |
134 | 147 | " axs.set_xlim(lat_min, lat_max)\n", |
135 | 148 | " axs.set_ylim(lon_min, lon_max)\n", |
136 | 149 | " axs.set_title(\"Selected Subregion Of Interest (Default Range)\")\n", |
137 | 150 | " axs.set_xlabel(\"Longitude (Degrees)\")\n", |
138 | 151 | " axs.set_ylabel(\"Latitude (Degrees)\")\n", |
139 | | - " \n", |
140 | | - " # Use imshow with a default color range (use the default colormap range)\n", |
| 152 | + "\n", |
| 153 | + " # Apply norm to imshow\n", |
141 | 154 | " data_fig = axs.imshow(\n", |
142 | 155 | " actual_data,\n", |
143 | 156 | " cmap=cmap_instance,\n", |
144 | 157 | " origin=\"lower\",\n", |
145 | 158 | " extent=(lat_min, lat_max, lon_min, lon_max),\n", |
| 159 | + " norm=norm\n", |
146 | 160 | " )\n", |
147 | | - " \n", |
148 | | - " # Add a colorbar to the plot\n", |
| 161 | + "\n", |
| 162 | + " # Add colorbar\n", |
149 | 163 | " cbar = fig.colorbar(\n", |
150 | 164 | " data_fig,\n", |
151 | 165 | " ax=axs,\n", |
152 | 166 | " fraction=0.046 * actual_data.shape[0] / actual_data.shape[1],\n", |
153 | 167 | " pad=0.04,\n", |
154 | 168 | " )\n", |
155 | | - " \n", |
156 | | - " print(\"You have successfully plotted your data with the default range.\")\n", |
157 | | - " \n", |
158 | | - " # Display the plot\n", |
| 169 | + " cbar.set_label('Value')\n", |
| 170 | + "\n", |
| 171 | + " print(\"You have successfully plotted your data with the selected color scale.\")\n", |
159 | 172 | " plt.show()\n", |
160 | 173 | "\n", |
161 | 174 | "except Exception as e:\n", |
162 | | - " # Handle any errors that occur during data loading or processing\n", |
163 | 175 | " print(f\"Error: Failed to load or process data from '{data_file}'. {str(e)}\")\n" |
164 | 176 | ] |
165 | 177 | }, |
|
184 | 196 | "metadata": {}, |
185 | 197 | "outputs": [], |
186 | 198 | "source": [ |
| 199 | + "is_log = True # Or False, depending on the mode\n", |
| 200 | + "EPSILON = 0.001\n", |
187 | 201 | "\n", |
188 | 202 | "try:\n", |
| 203 | + " # Select the colormap\n", |
| 204 | + " cmap_instance = plt.get_cmap(\"viridis\")\n", |
| 205 | + "\n", |
| 206 | + " # Process data range based on log/linear scaling you selected from dashboard\n", |
| 207 | + " # If is_log is True, we will use logarithmic scaling; otherwise, we will use linear scaling\n", |
189 | 208 | " \n", |
190 | | - " # Choose a colormap for visualizing the data\n", |
191 | | - " # The colormap 'inferno' is used here, which is a perceptually uniform colormap\n", |
192 | | - " cmap_instance = plt.get_cmap(\"inferno\")\n", |
193 | | - " \n", |
194 | | - " # Extract the latitude and longitude boundaries from the metadata\n", |
195 | | - " lat_min = metadata[0][0] # Minimum latitude\n", |
196 | | - " lat_max = metadata[0][1] # Maximum latitude\n", |
197 | | - " lon_min = metadata[1][0] # Minimum longitude\n", |
198 | | - " lon_max = metadata[1][1] # Maximum longitude\n", |
| 209 | + " if not is_log:\n", |
| 210 | + " vmin = np.min(actual_data)\n", |
| 211 | + " vmax = np.max(actual_data)\n", |
| 212 | + " norm = None # Use default linear normalization\n", |
| 213 | + " else:\n", |
| 214 | + " # Ensure data is positive for log scaling\n", |
| 215 | + " actual_data = np.clip(actual_data, EPSILON, None)\n", |
| 216 | + " vmin = np.min(actual_data)\n", |
| 217 | + " vmax = np.max(actual_data)\n", |
| 218 | + " from matplotlib.colors import LogNorm\n", |
| 219 | + " norm = LogNorm(vmin=vmin, vmax=vmax)\n", |
199 | 220 | "\n", |
200 | | - " print(\"You have successfully plotted your data with the default range.\")\n", |
| 221 | + " # Extract bounds from metadata\n", |
| 222 | + " lat_min, lat_max = metadata[0]\n", |
| 223 | + " lon_min, lon_max = metadata[1]\n", |
201 | 224 | "\n", |
202 | | - " # Replot the figure with the actual min and max range\n", |
203 | | - " # Calculate the min and max values from the data\n", |
204 | | - " vmin = actual_data.min()\n", |
205 | | - " vmax = actual_data.max()\n", |
206 | | - " \n", |
| 225 | + " # Plotting\n", |
207 | 226 | " fig, axs = plt.subplots(1, 1, figsize=(10, 8))\n", |
208 | 227 | " axs.set_xlim(lat_min, lat_max)\n", |
209 | 228 | " axs.set_ylim(lon_min, lon_max)\n", |
210 | | - " axs.set_title(\"Selected Subregion Of Interest (Min-Max Range)\")\n", |
| 229 | + " axs.set_title(\"Selected Subregion Of Interest (Default Range)\")\n", |
211 | 230 | " axs.set_xlabel(\"Longitude (Degrees)\")\n", |
212 | 231 | " axs.set_ylabel(\"Latitude (Degrees)\")\n", |
213 | | - " \n", |
214 | | - " # Use imshow with the calculated min and max range\n", |
| 232 | + "\n", |
| 233 | + " # Apply norm to imshow\n", |
215 | 234 | " data_fig = axs.imshow(\n", |
216 | 235 | " actual_data,\n", |
217 | 236 | " cmap=cmap_instance,\n", |
218 | | - " vmin=vmin,\n", |
219 | | - " vmax=vmax,\n", |
220 | 237 | " origin=\"lower\",\n", |
221 | 238 | " extent=(lat_min, lat_max, lon_min, lon_max),\n", |
| 239 | + " norm=norm\n", |
222 | 240 | " )\n", |
223 | 241 | "\n", |
224 | | - " # Add a colorbar with the min-max range\n", |
| 242 | + " # Add colorbar\n", |
225 | 243 | " cbar = fig.colorbar(\n", |
226 | 244 | " data_fig,\n", |
227 | 245 | " ax=axs,\n", |
228 | 246 | " fraction=0.046 * actual_data.shape[0] / actual_data.shape[1],\n", |
229 | 247 | " pad=0.04,\n", |
230 | 248 | " )\n", |
231 | | - " \n", |
232 | | - " # Set the ticks for the colorbar\n", |
233 | | - " cbar_ticks = np.linspace(vmin, vmax, 8)\n", |
234 | | - " cbar.set_ticks(cbar_ticks)\n", |
235 | | - " \n", |
| 249 | + " cbar.set_label('Value')\n", |
236 | 250 | " print(\"You have successfully replotted your data with the min-max range.\")\n", |
237 | 251 | " \n", |
238 | 252 | " # Calculate statistical values for the data\n", |
|
250 | 264 | " # Display the plot with min-max range\n", |
251 | 265 | " plt.show()\n", |
252 | 266 | "\n", |
| 267 | + " print(\"You have successfully plotted your data with the selected color scale.\")\n", |
| 268 | + " plt.show()\n", |
| 269 | + "\n", |
253 | 270 | "except Exception as e:\n", |
254 | | - " # Handle any errors that occur during data loading or processing\n", |
255 | | - " print(f\"Error: Failed to load or process data from '{data_file}'. {str(e)}\")\n" |
| 271 | + " print(f\"Error: Failed to load or process data from '{data_file}'. {str(e)}\")\n", |
| 272 | + "\n" |
256 | 273 | ] |
257 | 274 | }, |
258 | 275 | { |
|
276 | 293 | "metadata": {}, |
277 | 294 | "outputs": [], |
278 | 295 | "source": [ |
279 | | - "is_log = True # Or False, depending on the mode\n", |
280 | | - "EPSILON = 0.001\n", |
281 | | - "\n", |
282 | 296 | "try:\n", |
283 | | - " # Select the colormap\n", |
284 | | - " cmap_instance = plt.get_cmap(\"viridis\")\n", |
285 | | - "\n", |
286 | | - " # Process data range based on log/linear scaling you selected from dashboard\n", |
287 | | - " # If is_log is True, we will use logarithmic scaling; otherwise, we will use linear scaling\n", |
288 | 297 | " \n", |
289 | | - " if not is_log:\n", |
290 | | - " vmin = np.min(actual_data)\n", |
291 | | - " vmax = np.max(actual_data)\n", |
292 | | - " norm = None # Use default linear normalization\n", |
293 | | - " else:\n", |
294 | | - " # Ensure data is positive for log scaling\n", |
295 | | - " actual_data = np.clip(actual_data, EPSILON, None)\n", |
296 | | - " vmin = np.min(actual_data)\n", |
297 | | - " vmax = np.max(actual_data)\n", |
298 | | - " from matplotlib.colors import LogNorm\n", |
299 | | - " norm = LogNorm(vmin=vmin, vmax=vmax)\n", |
| 298 | + " # Choose a colormap for visualizing the data\n", |
| 299 | + " # The colormap 'inferno' is used here, which is a perceptually uniform colormap\n", |
| 300 | + " cmap_instance = plt.get_cmap(\"inferno\")\n", |
| 301 | + " \n", |
| 302 | + " # Extract the latitude and longitude boundaries from the metadata\n", |
| 303 | + " lat_min = metadata[0][0] # Minimum latitude\n", |
| 304 | + " lat_max = metadata[0][1] # Maximum latitude\n", |
| 305 | + " lon_min = metadata[1][0] # Minimum longitude\n", |
| 306 | + " lon_max = metadata[1][1] # Maximum longitude\n", |
300 | 307 | "\n", |
301 | | - " # Extract bounds from metadata\n", |
302 | | - " lat_min, lat_max = metadata[0]\n", |
303 | | - " lon_min, lon_max = metadata[1]\n", |
304 | 308 | "\n", |
305 | | - " # Plotting\n", |
| 309 | + " # Replot the figure with a fixed range from 0 to 3000\n", |
| 310 | + " # This range is arbitrary and meant to highlight different data ranges\n", |
| 311 | + " fixed_vmin = 0\n", |
| 312 | + " fixed_vmax = 600\n", |
| 313 | + " \n", |
306 | 314 | " fig, axs = plt.subplots(1, 1, figsize=(10, 8))\n", |
307 | 315 | " axs.set_xlim(lat_min, lat_max)\n", |
308 | 316 | " axs.set_ylim(lon_min, lon_max)\n", |
309 | | - " axs.set_title(\"Selected Subregion Of Interest (Default Range)\")\n", |
| 317 | + " axs.set_title(\"Selected Subregion Of Interest (Range 0 to 3000)\")\n", |
310 | 318 | " axs.set_xlabel(\"Longitude (Degrees)\")\n", |
311 | 319 | " axs.set_ylabel(\"Latitude (Degrees)\")\n", |
312 | | - "\n", |
313 | | - " # Apply norm to imshow\n", |
| 320 | + " \n", |
| 321 | + " # Use imshow with the fixed range from 0 to 3000\n", |
314 | 322 | " data_fig = axs.imshow(\n", |
315 | 323 | " actual_data,\n", |
316 | 324 | " cmap=cmap_instance,\n", |
| 325 | + " vmin=fixed_vmin,\n", |
| 326 | + " vmax=fixed_vmax,\n", |
317 | 327 | " origin=\"lower\",\n", |
318 | 328 | " extent=(lat_min, lat_max, lon_min, lon_max),\n", |
319 | | - " norm=norm\n", |
320 | 329 | " )\n", |
321 | 330 | "\n", |
322 | | - " # Add colorbar\n", |
| 331 | + " # Add a colorbar with the fixed range\n", |
323 | 332 | " cbar = fig.colorbar(\n", |
324 | 333 | " data_fig,\n", |
325 | 334 | " ax=axs,\n", |
326 | 335 | " fraction=0.046 * actual_data.shape[0] / actual_data.shape[1],\n", |
327 | 336 | " pad=0.04,\n", |
328 | 337 | " )\n", |
329 | | - " cbar.set_label('Value')\n", |
| 338 | + " \n", |
| 339 | + " # Set the ticks for the colorbar\n", |
| 340 | + " cbar_ticks = np.linspace(fixed_vmin, fixed_vmax, 8)\n", |
| 341 | + " cbar.set_ticks(cbar_ticks)\n", |
| 342 | + " \n", |
| 343 | + " print(\"You have successfully replotted your data with the range 0 to 3000.\")\n", |
| 344 | + " \n", |
| 345 | + " # Calculate statistical values for the data\n", |
| 346 | + " max_slope = vmax # Maximum value in the data\n", |
| 347 | + " min_slope = vmin # Minimum value in the data\n", |
| 348 | + " avg_slope = actual_data.mean() # Average value of the data\n", |
| 349 | + " std_slope = actual_data.std() # Standard deviation of the data\n", |
| 350 | + " \n", |
| 351 | + " # Print the calculated statistical values\n", |
| 352 | + " print(f\"Maximum slope value: {max_slope}\")\n", |
| 353 | + " print(f\"Minimum slope value: {min_slope}\")\n", |
| 354 | + " print(f\"Average slope value: {avg_slope}\")\n", |
| 355 | + " print(f\"Standard deviation of slope values: {std_slope}\")\n", |
330 | 356 | "\n", |
331 | | - " print(\"You have successfully plotted your data with the selected color scale.\")\n", |
| 357 | + " # Display the plot with the fixed range\n", |
332 | 358 | " plt.show()\n", |
333 | 359 | "\n", |
334 | 360 | "except Exception as e:\n", |
335 | | - " print(f\"Error: Failed to load or process data from '{data_file}'. {str(e)}\")\n" |
| 361 | + " # Handle any errors that occur during data loading or processing\n", |
| 362 | + " print(f\"Error: Failed to load or process data from '{data_file}'. {str(e)}\")" |
336 | 363 | ] |
337 | 364 | } |
338 | 365 | ], |
339 | 366 | "metadata": { |
340 | 367 | "kernelspec": { |
341 | | - "display_name": "Python 3 (ipykernel)", |
| 368 | + "display_name": "nasa", |
342 | 369 | "language": "python", |
343 | 370 | "name": "python3" |
344 | 371 | }, |
|
352 | 379 | "name": "python", |
353 | 380 | "nbconvert_exporter": "python", |
354 | 381 | "pygments_lexer": "ipython3", |
355 | | - "version": "3.11.5" |
| 382 | + "version": "3.11.11" |
356 | 383 | } |
357 | 384 | }, |
358 | 385 | "nbformat": 4, |
|
0 commit comments