|
259 | 259 | "\n", |
260 | 260 | " \"\"\"\n", |
261 | 261 | "\n", |
262 | | - " bbox = ((lon_min, lat_min), (lon_max, lat_max))\n", |
| 262 | + " if lon_min > lon_max or lat_min > lat_max:\n", |
| 263 | + " print('ERROR: The minimum longitude/latitude is larger than the maximum longitude/latitude.')\n", |
| 264 | + " raise KeyboardInterrupt()\n", |
| 265 | + " \n", |
| 266 | + " else:\n", |
| 267 | + " bbox = ((lon_min, lat_min), (lon_max, lat_max))\n", |
263 | 268 | "\n", |
264 | | - " print('SEARCH BOUNDING BOX')\n", |
265 | | - " print(f'Latitudes: from {lat_min} to {lat_max}')\n", |
266 | | - " print(f'Longitudes: from {lon_min} to {lon_max}')\n", |
| 269 | + " print('SEARCH BOUNDING BOX')\n", |
| 270 | + " print(f'Latitudes: from {lat_min} to {lat_max}')\n", |
| 271 | + " print(f'Longitudes: from {lon_min} to {lon_max}')\n", |
267 | 272 | "\n", |
268 | 273 | " return bbox" |
269 | 274 | ] |
|
832 | 837 | " print('The sum will be matched to the sensor data by nearest neighbours.')\n", |
833 | 838 | "\n", |
834 | 839 | " model_ds_time = model_ds_time.component.sum(dim = 'hybrid', skipna = False)\n", |
835 | | - " \n", |
| 840 | + " \n", |
836 | 841 | " match_df_time['step_index'] = match_df_time.apply(lambda row: nearest_neighbour(model_times, row['delta_time']), axis = 1)\n", |
837 | 842 | " match_df_time['model_time'] = match_df_time.apply(lambda row: model_ds_time.valid_time[row['step_index']].values, axis = 1)\n", |
838 | 843 | " match_df_time['model_column'] = match_df_time.apply(lambda row: model_ds_time.sel(\n", |
|
2230 | 2235 | "\n", |
2231 | 2236 | " # Reverse geocoding\n", |
2232 | 2237 | " merge_df['country'] = merge_df.apply(lambda row: geocoder.google([row['latitude'], row['longitude']], \n", |
2233 | | - " method='reverse', key = google_api_key).country_long, axis = 1)\n", |
| 2238 | + " method = 'reverse', key = google_api_key).country_long, \n", |
| 2239 | + " axis = 1)\n", |
2234 | 2240 | "\n", |
2235 | 2241 | " # Find data for the countries in search list\n", |
2236 | 2242 | " merge_df = merge_df[merge_df['country'].isin(plot_countries)]\n", |
|
2463 | 2469 | " # Drop NaN values\n", |
2464 | 2470 | " merge_df = merge_df.dropna()\n", |
2465 | 2471 | "\n", |
| 2472 | + " # Transform string to tuple (if there is only one element)\n", |
| 2473 | + " if isinstance(regions_names, str):\n", |
| 2474 | + " regions_names = tuple([regions_names])\n", |
| 2475 | + " \n", |
2466 | 2476 | " # Drop the dates that have NaN values\n", |
2467 | 2477 | " plot_dates = np.intersect1d(plot_dates, np.unique(merge_df.index.get_level_values(2)))\n", |
2468 | 2478 | "\n", |
|
2665 | 2675 | " Returns:\n", |
2666 | 2676 | " trends_table (dataframe): Trends table\n", |
2667 | 2677 | " \"\"\"\n", |
2668 | | - "\n", |
| 2678 | + " \n", |
2669 | 2679 | " if len(np.unique(merge_df.reset_index()['time'])) >= 12:\n", |
2670 | 2680 | " \n", |
2671 | 2681 | " # Sinusoidal model\n", |
2672 | 2682 | " def objective_function_sin(X, C, D, E, N):\n", |
2673 | 2683 | " return C * np.sin(D * X + E) + N\n", |
2674 | 2684 | "\n", |
| 2685 | + " # Drop NaN values\n", |
| 2686 | + " merge_df = merge_df.dropna()\n", |
| 2687 | + "\n", |
2675 | 2688 | " # Transform string to tuple (if there is only one element)\n", |
2676 | 2689 | " if isinstance(regions_names, str):\n", |
2677 | 2690 | " regions_names = tuple([regions_names])\n", |
|
2681 | 2694 | "\n", |
2682 | 2695 | " trends_table = []\n", |
2683 | 2696 | "\n", |
2684 | | - " # Drop NaN values\n", |
2685 | | - " merge_df = merge_df.dropna()\n", |
2686 | | - "\n", |
2687 | 2697 | " for region_lats, region_lons, region_name in zip(regions_lats, regions_lons, regions_names):\n", |
2688 | 2698 | "\n", |
2689 | 2699 | " summary_region = []\n", |
|
3099 | 3109 | " coords_list (list): List of search coordinates (e.g. (lat, lon, lat, lon, ...)\n", |
3100 | 3110 | " regions_names (list): Region names\n", |
3101 | 3111 | " \"\"\"\n", |
3102 | | - " \n", |
| 3112 | + "\n", |
3103 | 3113 | " if ((sensor_break_date != None and model_break_date != None and sensor_break_date != model_break_date) or\n", |
3104 | 3114 | " (sensor_break_date != None and model_break_date == None) or\n", |
3105 | 3115 | " (sensor_break_date == None and model_break_date != None)):\n", |
|
0 commit comments