bczernecki / climate

The R climate package: an interface for downloading in-situ meteorological (and hydrological) dataset
https://bczernecki.github.io/climate/
Other
71 stars 19 forks source link

Error when trying to find the nearest meteorological stations in Spain #88

Closed jbaezarh closed 3 months ago

jbaezarh commented 6 months ago

When I try to get the nearest meteorological station to any point in Spain, I get the following error: nearest_stations_ogimet(country="Spain", date = Sys.Date(), add_map = TRUE, point = c(-5, 37), no_of_stations = 100)

[1] "http://ogimet.com/cgi-bin/gsynres?lang=en&state=Spain&osum=no&fmt=html&ord=REV&ano=2024&mes=02&day=20&hora=06&ndays=1&Send=send" [100%] Downloaded 31584 bytes... C:\Users\usuario\AppData\Local\Temp\RtmpuejQSX\file9c07d751ed Problems with downloading data. Run function with argument allow_failure = FALSE to see more details Warning messages: 1: In strsplit(a, "Decoded synops since") : unable to translate '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">Synop report summary by countries<meta name="r...' to a wide string 2: In strsplit(a, "Decoded synops since") : input string 1 is invalid

I hope this can be solved as soon as possible, it would help me a lot!!

aglogowski commented 6 months ago

Try without date=Sys.Date() as it works as default and maybe couse an issue? I get a requierd map and result while running nearest_stations_ogimet(country = "Spain",add_map = T,point = c(-5,37),no_of_stations = 100)

jbaezarh commented 6 months ago

Thank you very much for your quick answer. I tried as you said and I keep having the same error: nearest_stations_ogimet(country = "Spain",add_map = T,point = c(-5,37),no_of_stations = 100)

[1] "http://ogimet.com/cgi-bin/gsynres?lang=en&state=Spain&osum=no&fmt=html&ord=REV&ano=2024&mes=02&day=21&hora=06&ndays=1&Send=send" [100%] Downloaded 31675 bytes... C:\Users\usuario\AppData\Local\Temp\RtmpkrZ130\file573c11ba59f3 Problems with downloading data. Run function with argument allow_failure = FALSE to see more details Warning messages: 1: In strsplit(a, "Decoded synops since") : unable to translate '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">Synop report summary by countries<meta name="r...' to a wide string 2: In strsplit(a, "Decoded synops since") : input string 1 is invalid

Then, I tried with allow_failure = FALSE as it sais, and I get the same problem: nearest_stations_ogimet(country = "Spain",add_map = T,point = c(-5,37),no_of_stations = 100, allow_failure = FALSE)

[1] "http://ogimet.com/cgi-bin/gsynres?lang=en&state=Spain&osum=no&fmt=html&ord=REV&ano=2024&mes=02&day=21&hora=06&ndays=1&Send=send" [100%] Downloaded 31675 bytes... C:\Users\usuario\AppData\Local\Temp\RtmpkrZ130\file573c22381705 Error in [.data.frame(result, , 3:4) : undefined columns selected Además: Warning messages: 1: In strsplit(a, "Decoded synops since") : unable to translate '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">Synop report summary by countries<meta name="r...' to a wide string 2: In strsplit(a, "Decoded synops since") : input string 1 is invalid

And when I try with any other country I get the expected map and data:

nearest_stations_ogimet(country = "France",add_map = T,point = c(-5,37),no_of_stations = 100, allow_failure = FALSE)

[1] "http://ogimet.com/cgi-bin/gsynres?lang=en&state=France&osum=no&fmt=html&ord=REV&ano=2024&mes=02&day=21&hora=06&ndays=1&Send=send" [100%] Downloaded 22001 bytes... C:\Users\usuario\AppData\Local\Temp\RtmpkrZ130\file573c7e7b2a76 wmo_id station_names lon lat alt distance 123 07600 Socoa -1.683347 43.38334 21 807.0929 124 07602 Biarritz -1.533344 43.46668 75 823.2178 125 07603 Dax -1.066668 43.68335 33 870.0722 127 07610 Pau -0.400008 43.38334 188 882.7744 128 07621 Tarbes Ossun Lourdes 0.000000 43.18334 384 892.1834 126 07607 Mont-De-Marsan -0.500010 43.90002 62 924.2456 104 07503 Biscarosse -1.233338 44.41667 35 933.2903 103 07502 Cazaux -1.116669 44.53334 23 950.9059 102 07500 Cap Ferret -1.233338 44.61668 9 953.3518 130 07627 St-Girons 1.100002 43.00000 419 959.9868 129 07622 Auch 0.600012 43.68335 125 978.2833 105 07510 Bordeaux / Merignac -0.683347 44.81668 51 1001.8480 106 07524 Agen 0.583345 44.16667 62 1019.2924 131 07630 Toulouse / Blagnac 1.366674 43.61668 152 1030.2256 109 07540 Montauban 1.366674 44.01667 108 1063.0192 133 07635 Carcassonne 2.283339 43.20000 132 1073.1486 107 07530 Bergerac 0.516677 44.81668 52 1073.4253 78 07314 Chassiron -1.400008 46.03333 11 1091.0286 148 07747 Perpignan 2.866684 42.73335 44 1092.1526 149 07749 Cap Bear 3.133336 42.51668 82 1102.6420 88 07412 Cognac -0.300006 45.65001 31 1104.5115 132 07632 Albi 2.100002 43.90002 172 1110.8053 79 07316 La Rochelle Aeroport -1.183337 46.16667 23 1114.0556 143 07666 Leucate 3.050001 42.91669 42 1120.8985 108 07535 Gourdon 1.383341 44.73335 260 1125.0575 76 07300 St-Sauveur -2.316673 46.68335 32 1127.3809 91 07439 Brive-Souillac 1.483343 45.03333 295 1158.2272 77 07306 La Roche-Sur-Yon -1.366674 46.70001 91 1162.1503 80 07330 Niort -0.400008 46.30001 61 1164.0914 90 07438 Brive 1.466676 45.13334 112 1165.8150 56 07207 Le Talut -3.216671 47.28334 34 1170.9771 134 07638 Beziers-Vias 3.350007 43.31667 17 1174.7103 111 07552 Rodez 2.466676 44.40001 582 1179.4606 57 07217 St-Nazaire -2.150003 47.30001 4 1199.0492 58 07222 Nantes -1.600012 47.13334 27 1199.2161 113 07558 Millau 3.016667 44.11667 712 1202.7249 54 07203 Beg Melen -3.500010 47.65001 41 1206.6894 135 07641 Sete 3.683347 43.38334 80 1209.1635 89 07434 Limoges 1.166670 45.85002 402 1210.2200 110 07549 Aurillac 2.416675 44.88335 639 1214.3925 55 07205 Lann Bihoue -3.433342 47.75001 49 1218.8568 81 07335 Poitiers 0.300006 46.58335 129 1228.6973 53 07201 Quimper -4.150003 47.96669 89 1234.1159 136 07643 Montpellier 3.950019 43.56668 5 1245.4543 114 07560 Mont Aigoual 3.566678 44.11667 1567 1249.5453 26 07109 Lanveoc Poulmic -4.433342 48.26667 87 1265.6809 112 07554 Mende 3.450009 44.53334 932 1270.1234 60 07230 Beaucouze -0.600012 47.46668 50 1273.8706 22 07100 Ouessant-Stiff -5.050001 48.46668 64 1286.5351 27 07110 Brest -4.366674 48.45001 94 1286.6166 83 07361 Gueret St Laurent 1.950019 46.16667 365 1290.6549 23 07101 Ploudalmezeau -4.650013 48.53334 40 1294.5985 32 07130 Rennes -1.733348 48.06667 38 1294.6065 59 07228 Marce -0.316673 47.55001 53 1295.0640 24 07106 Landivisiau -4.133336 48.51668 109 1295.7863 138 07646 Nimes / Garons 4.416675 43.75001 94 1299.9158 137 07645 Nimes / Courbessac 4.400008 43.85002 60 1304.9726 25 07107 Brignogan -4.316673 48.66668 9 1311.2060 30 07120 Saint-Brieuc -2.850017 48.53334 138 1316.2944 33 07134 Laval -0.733348 48.01667 101 1325.4947 29 07118 Lannion -3.466676 48.75001 88 1329.4900 139 07647 Istres 4.916685 43.51668 25 1331.3530 62 07240 Tours 0.716681 47.43334 109 1334.7871 93 07471 Le Puy 3.750015 45.06667 832 1335.2530 28 07117 Ploumanac'H -3.466676 48.81668 55 1336.9074 82 07354 Chateauroux Deols 1.733348 46.86668 161 1340.2193 31 07125 Dinard -2.066668 48.58335 67 1340.6367 92 07460 Clermont-Ferrand 3.133336 45.78335 333 1343.0761 116 07570 Aubenas 4.366674 44.53334 281 1348.6294 141 07650 Marseille / Marignane 5.200004 43.43334 21 1353.0192 140 07648 Salon 5.100002 43.60001 60 1353.6806 115 07563 Avignon 4.900018 43.90002 38 1353.9150 61 07235 Le Mans 0.183337 47.93335 59 1357.5573 118 07579 Orange 4.850017 44.13334 60 1364.5040 119 07586 Carpentras 5.050001 44.06667 99 1378.4233 64 07247 Romorantin 1.683347 47.31667 88 1379.1562 117 07577 Montelimar 4.716681 44.56668 73 1381.7443 63 07245 Blois 1.200004 47.66668 121 1384.2456 84 07374 Vichy 3.383341 46.16667 249 1393.7168 66 07255 Bourges 2.350007 47.05000 161 1396.9505 142 07661 Cap Cepet 5.933352 43.06667 115 1402.8741 34 07139 Alencon 0.100002 48.43334 145 1404.6169 94 07475 St-Etienne Boutheon 4.283339 45.51668 404 1413.4740 67 07257 Avord 2.633346 47.05000 177 1415.9491 144 07667 Hyeres 6.133336 43.08333 4 1423.4311 35 07140 Chateaudun 1.366674 48.05000 132 1430.8356 68 07260 Nevers 3.100002 46.98335 183 1442.4032 65 07249 Orleans 1.766682 47.98335 126 1447.3894 8 07027 Caen -0.450009 49.16667 78 1457.3923 85 07379 Saint-Yan 4.000000 46.40001 243 1460.1101 145 07675 Le Luc 6.383341 43.36667 81 1463.3603 120 07588 St-Auban-Sur-Durance 5.983353 44.05000 459 1464.3130 6 07020 La Hague -1.933352 49.71668 6 1467.6693 7 07024 Cherbourg / Maupertus -1.450009 49.65001 140 1474.1177 36 07143 Chartres 1.500010 48.45001 155 1477.2209 95 07480 Lyon / Bron 4.933352 45.71668 201 1482.7460 98 07486 Grenoble / St. Geoirs 5.300006 45.35001 397 1487.6650 96 07481 Lyon / Satolas 5.066668 45.71668 250 1494.0213 10 07031 Deauville 0.166670 49.35001 146 1501.9994 86 07385 Macon 4.783349 46.28334 222 1513.1763

I guess it might be somethig of my computer, cause you could run the function. If you have any idea on how I could solve it I would really appreciate it

aglogowski commented 6 months ago

Did you try to reduce number of stations as the the error says that string is to wide. Sometimes when you change a bit coordinates the function work better. What is the output when you type sys.Date() the format supposed to be as follows: "2024-02-21"

jbaezarh commented 6 months ago

Yes, the format of sys.Date() is that one. And I also tried reducing the numer of stations and changing the coordinates, but the error keep appearing

gaferguz commented 6 months ago

I was facing the same issue, I think it might be related with some special characters appearing in one of Spanish stations, so the code breaks because strsplit() function does not work very well in such cases:

    b = strsplit(a, "Decoded synops since")

In my case, I was able to dodge that error by manually changing the function "nearest_stations_ogimet" like this:

    # b1 = lapply(b, function(x) substr(x, 1, 400)) #Esta parte se sustituye por la de abajo
    b1 = lapply(b, function(x) substr(iconv(x, from = 'UTF-8', to = 'ASCII//TRANSLIT'), 1, 400)) #Aqui esta el fallo

I hope it helps

bczernecki commented 3 months ago

Changes introduced in the upcoming package version. Thanks for the solution!