Skip to content

Commit

Permalink
Fixed mapping replication factors and moved CSV write to cli.py
Browse files Browse the repository at this point in the history
  • Loading branch information
RoryPTB committed Jul 7, 2023
1 parent fce61c0 commit 10254de
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 132 deletions.
46 changes: 23 additions & 23 deletions data/example_with_bufr/station_list.csv
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
station_name,wigos_station_identifier,traditional_station_identifier,facility_type,latitude,longitude,elevation,barometer_height,territory_name,wmo_region
OCNA SUGATAG,0-20000-0-15015,15015,Land (fixed),47.77706163,23.94046026,503,0,Romania,6
BOTOSANI,0-20000-0-15020,15020,Land (fixed),47.73565324,26.64555017,161,0,Romania,6
IASI,0-20000-0-15090,15090,Land (fixed),47.16333333,27.62722222,74.29,0,Romania,6
CEAHLAU TOACA,0-20000-0-15108,15108,Land (fixed),46.97751,25.94993997,1897,0,Romania,6
CLUJ-NAPOCA,0-20000-0-15120,15120,Land (fixed),46.7777705,23.57130529,410,0,Romania,6
BACAU,0-20000-0-15150,15150,Land (fixed),46.55777778,26.89666667,174,0,Romania,6
MIERCUREA CIUC,0-20000-0-15170,15170,Land (fixed),46.37131666,25.77261668,661,0,Romania,6
ARAD,0-20000-0-15200,15200,Land (fixed),46.1335164,21.35362152,116.59,0,Romania,6
DEVA,0-20000-0-15230,15230,Land (fixed),45.86492301,22.89880624,240,0,Romania,6
SIBIU,0-20000-0-15260,15260,Land (fixed),45.79018,24.036245,450,0,Romania,6
VARFU OMU,0-20000-0-15280,15280,Land (fixed),45.4457928,25.45669098,2504,0,Romania,6
CARANSEBES,0-20000-0-15292,15292,Land (fixed),45.41667,22.22917,241,0,Romania,6
GALATI,0-20000-0-15310,15310,Land (fixed),45.47291814,28.03230106,69,0,Romania,6
TULCEA,0-20000-0-15335,15335,Land (fixed),45.19050648,28.82416076,4.36,0,Romania,6
RAMNICU VALCEA,0-20000-0-15346,15346,Land (fixed),45.08882112,24.36281391,237,0,Romania,6
BUZAU,0-20000-0-15350,15350,Land (fixed),45.13266329,26.85173192,97,0,Romania,6
SULINA,0-20000-0-15360,15360,Land (fixed),45.1623111,29.7268286,69,0,Romania,6
DROBETA-TURNU SEVERIN,0-20000-0-15410,15410,Land (fixed),44.6264587,22.62607371,77,0,Romania,6
BUCURESTI BANEASA,0-20000-0-15420,15420,Land (fixed),44.510433,26.07819041,90,0,Romania,6
CRAIOVA,0-20000-0-15450,15450,Land (fixed),44.31014043,23.86698474,192,0,Romania,6
CALARASI,0-20000-0-15460,15460,Land (fixed),44.20573853,27.33830807,18.72,0,Romania,6
ROSIORII DE VEDE,0-20000-0-15470,15470,Land (fixed),44.10721334,24.97874007,102.15,0,Romania,6
CONSTANTA,0-20000-0-15480,15480,Land (fixed),44.21381439,28.64556468,12.8,0,Romania,6
OCNA SUGATAG,0-20000-0-15015,15015,Land (fixed),47.77706163,23.94046026,503,504.43,Romania,6
BOTOSANI,0-20000-0-15020,15020,Land (fixed),47.73565324,26.64555017,161,162.2,Romania,6
IASI,0-20000-0-15090,15090,Land (fixed),47.16333333,27.62722222,74.29,75.69,Romania,6
CEAHLAU TOACA,0-20000-0-15108,15108,Land (fixed),46.97751,25.94993997,1897,1898.5,Romania,6
CLUJ-NAPOCA,0-20000-0-15120,15120,Land (fixed),46.7777705,23.57130529,410,411.5,Romania,6
BACAU,0-20000-0-15150,15150,Land (fixed),46.55777778,26.89666667,174,175.4,Romania,6
MIERCUREA CIUC,0-20000-0-15170,15170,Land (fixed),46.37131666,25.77261668,661,662.4,Romania,6
ARAD,0-20000-0-15200,15200,Land (fixed),46.1335164,21.35362152,116.59,117.6,Romania,6
DEVA,0-20000-0-15230,15230,Land (fixed),45.86492301,22.89880624,240,241.52,Romania,6
SIBIU,0-20000-0-15260,15260,Land (fixed),45.79018,24.036245,450,451.5,Romania,6
VARFU OMU,0-20000-0-15280,15280,Land (fixed),45.4457928,25.45669098,2504,2507,Romania,6
CARANSEBES,0-20000-0-15292,15292,Land (fixed),45.41667,22.22917,241,242.52,Romania,6
GALATI,0-20000-0-15310,15310,Land (fixed),45.47291814,28.03230106,69,70.4,Romania,6
TULCEA,0-20000-0-15335,15335,Land (fixed),45.19050648,28.82416076,4.36,5.6,Romania,6
RAMNICU VALCEA,0-20000-0-15346,15346,Land (fixed),45.08882112,24.36281391,237,238.3,Romania,6
BUZAU,0-20000-0-15350,15350,Land (fixed),45.13266329,26.85173192,97,98,Romania,6
SULINA,0-20000-0-15360,15360,Land (fixed),45.1623111,29.7268286,12.69,13.89,Romania,6
DROBETA-TURNU SEVERIN,0-20000-0-15410,15410,Land (fixed),44.6264587,22.62607371,77,78.2,Romania,6
BUCURESTI BANEASA,0-20000-0-15420,15420,Land (fixed),44.510433,26.07819041,90,91.2,Romania,6
CRAIOVA,0-20000-0-15450,15450,Land (fixed),44.31014043,23.86698474,192,193.4,Romania,6
CALARASI,0-20000-0-15460,15460,Land (fixed),44.20573853,27.33830807,18.72,19.92,Romania,6
ROSIORII DE VEDE,0-20000-0-15470,15470,Land (fixed),44.10721334,24.97874007,102.15,103.55,Romania,6
CONSTANTA,0-20000-0-15480,15480,Land (fixed),44.21381439,28.64556468,12.8,14,Romania,6
136 changes: 68 additions & 68 deletions data/gts_data/station_list.csv
Original file line number Diff line number Diff line change
@@ -1,69 +1,69 @@
station_name,wigos_station_identifier,traditional_station_identifier,facility_type,latitude,longitude,elevation,barometer_height,territory_name
"CABO SAN ANTONIO, PINAR DEL RIO",0-20000-0-78310,78310,Land (fixed),21.86666667,84.95,0,0,Cuba
PINAR DEL RIO,0-20000-0-78315,78315,Land (fixed),22.41666667,83.68333333,0,0,Cuba
"BAHIA HONDA, PINAR DEL RIO",0-20000-0-78318,78318,Land (fixed),22.91666667,83.16666667,0,0,Cuba
"BATABANO, LA HABANA",0-20000-0-78322,78322,Land (fixed),22.71666667,82.28333333,0,0,Cuba
"PUNTA DEL ESTE, ISLA DE LA JUVENTUD",0-20000-0-78324,78324,Land (fixed),21.55,82.53333333,0,0,Cuba
"CASA BLANCA, LA HABANA",0-20000-0-78325,78325,Land (fixed),23.16666667,82.35,0,0,Cuba
VARADERO,0-20000-0-78328,78328,Land (fixed),23.25,81.41666667,0,0,Cuba
"PLAYA GIRON, MATANZAS",0-20000-0-78333,78333,Land (fixed),22.06666667,81.03333333,0,0,Cuba
"CANTARRANA, CIENFUEGOS",0-20000-0-78344,78344,Land (fixed),21.91666667,80.16666667,0,0,Cuba
"JUCARO, CIEGO DE AVILA",0-20000-0-78345,78345,Land (fixed),21.61666667,78.85,0,0,Cuba
"CAIBARIEN, VILLA CLARA",0-20000-0-78348,78348,Land (fixed),22.51666667,79.45,0,0,Cuba
"SANCTI SPIRITUS, SANCTI SPIRITUS",0-20000-0-78349,78349,Land (fixed),21.93333333,79.45,0,0,Cuba
"SANTA CRUZ DEL SUR, CAMAGUEY",0-20000-0-78351,78351,Land (fixed),20.71666667,78,0,0,Cuba
"NUEVITAS, CAMAGUEY",0-20000-0-78353,78353,Land (fixed),21.53333333,77.25,0,0,Cuba
CAMAGUEY,0-20000-0-78355,78355,Land (fixed),21.4,77.85,0,0,Cuba
"PUERTO PADRE, LAS TUNAS",0-20000-0-78358,78358,Land (fixed),21.2,76.61666667,0,0,Cuba
"CABO CRUZ, GRANMA",0-20000-0-78360,78360,Land (fixed),19.85,77.23333333,0,0,Cuba
"CONTRAMAESTRE, SANTIAGO DE CUBA",0-20000-0-78363,78363,Land (fixed),20.28333333,76.25,0,0,Cuba
"PUNTA LUCRECIA, HOLGUIN",0-20000-0-78365,78365,Land (fixed),21.06666667,75.61666667,0,0,Cuba
"PUNTA DE MAISI, GUANTANAMO",0-20000-0-78369,78369,Land (fixed),20.25,74.15,0,0,Cuba
X,0-20000-0-78308,78308,Land (fixed),0,0,0,0,Cuba
X,0-20000-0-78309,78309,Land (fixed),0,0,0,0,Cuba
"SANTA LUCIA, PINAR DEL RIO",0-20000-0-78312,78312,Land (fixed),22.66666667,83.96666667,0,0,Cuba
"ISABEL RUBIO, PINAR DEL RIO",0-20000-0-78313,78313,Land (fixed),22.16666667,84.1,0,0,Cuba
"SAN JUAN Y MARTINEZ, PINAR DEL RIO",0-20000-0-78314,78314,Land (fixed),22.28333333,83.83333333,0,0,Cuba
"LA PALMA, PINAR DEL RIO",0-20000-0-78316,78316,Land (fixed),22.76666667,83.55,0,0,Cuba
"PASO REAL DE SAN DIEGO, PINAR DEL RIO",0-20000-0-78317,78317,Land (fixed),22.55,83.3,0,0,Cuba
"ARTEMISA, LA HABANA",0-20000-0-78319,78319,Land (fixed),22.8,82.75,0,0,Cuba
"GUIRA DE MELENA, LA HABANA",0-20000-0-78320,78320,Land (fixed),22.78333333,82.51666667,0,0,Cuba
"LA FE, ISLA DE LA JUVENTUD",0-20000-0-78321,78321,Land (fixed),21.73333333,82.76666667,0,0,Cuba
"GUINES, LA HABANA",0-20000-0-78323,78323,Land (fixed),22.85,82.03333333,0,0,Cuba
X,0-20000-0-78326,78326,Land (fixed),0,0,0,0,Cuba
"UNION DE REYES, MATANZAS",0-20000-0-78327,78327,Land (fixed),22.76666667,81.53333333,0,0,Cuba
"INDIO HATUEY, MATANZAS",0-20000-0-78329,78329,Land (fixed),22.81666667,81,0,0,Cuba
"JOVELLANOS, MATANZAS",0-20000-0-78330,78330,Land (fixed),22.78333333,81.18333333,0,0,Cuba
"JAGUEY GRANDE, MATANZAS",0-20000-0-78331,78331,Land (fixed),22.63333333,81.26666667,0,0,Cuba
"COLON, MATANZAS",0-20000-0-78332,78332,Land (fixed),22.68333333,80.93333333,0,0,Cuba
X,0-20000-0-78334,78334,Land (fixed),0,0,0,0,Cuba
"AGUADA DE PASAJEROS, CIENFUEGOS",0-20000-0-78335,78335,Land (fixed),22.38333333,80.85,0,0,Cuba
"TRINIDAD, SANCTI SPIRITUS",0-20000-0-78337,78337,Land (fixed),21.78333333,79.98333333,0,0,Cuba
"SAGUA LA GRANDE, VILLA CLARA",0-20000-0-78338,78338,Land (fixed),22.81666667,80.08333333,0,0,Cuba
"CAYO COCO, CIEGO DE AVILA",0-20000-0-78339,78339,Land (fixed),22.51666667,78.45,0,0,Cuba
"BAINOA, LA HABANA",0-20000-0-78340,78340,Land (fixed),23.03333333,81.91666667,0,0,Cuba
"EL JIBARO, SANCTI SPIRITUS",0-20000-0-78341,78341,Land (fixed),21.71666667,79.21666667,0,0,Cuba
"TOPES DE COLLANTES, SANCTI SPIRITUS",0-20000-0-78342,78342,Land (fixed),21.91666667,80.01666667,0,0,Cuba
"EL YABU, VILLA CLARA",0-20000-0-78343,78343,Land (fixed),22.43333333,79.98333333,0,0,Cuba
"VENEZUELA, CIEGO DE AVILA",0-20000-0-78346,78346,Land (fixed),21.78333333,78.78333333,0,0,Cuba
"CAMILO CIENFUEGOS, CIEGO DE AVILA",0-20000-0-78347,78347,Land (fixed),22.15,78.75,0,0,Cuba
"FLORIDA, CAMAGUEY",0-20000-0-78350,78350,Land (fixed),21.51666667,78.23333333,0,0,Cuba
"ESMERALDA, CAMAGUEY",0-20000-0-78352,78352,Land (fixed),21.85,78.11666667,0,0,Cuba
"PALO SECO, CAMAGUEY",0-20000-0-78354,78354,Land (fixed),21.13333333,77.31666667,0,0,Cuba
X,0-20000-0-78356,78356,Land (fixed),0,0,0,0,Cuba
"LAS TUNAS, LAS TUNAS",0-20000-0-78357,78357,Land (fixed),20.95,76.95,0,0,Cuba
"MANSANILLO, GRANMA",0-20000-0-78359,78359,Land (fixed),20.33333333,77.13333333,0,0,Cuba
"JUCARITO, GRANMA",0-20000-0-78361,78361,Land (fixed),20.66666667," 76.9000",0,0,Cuba
"LA JIQUIMA, HOLGUIN",0-20000-0-78362,78362,Land (fixed),20.93333333,76.53333333,0,0,Cuba
"UNIVERSIDAD, SANTIAGO DE CUBA",0-20000-0-78364,78364,Land (fixed),20.05,75.81666667,0,0,Cuba
"GRAN PIEDRA, SANTIAGO DE CUBA",0-20000-0-78366,78366,Land (fixed),20.03333333,75.63333333,0,0,Cuba
"GUANTANAMO, GUANTANAMO",0-20000-0-78368,78368,Land (fixed),20.13333333,75.23333333,0,0,Cuba
"GUARO, HOLGUIN",0-20000-0-78370,78370,Land (fixed),20.66666667,75.78333333,0,0,Cuba
"PINARES DE MAYARI, HOLGUIN",0-20000-0-78371,78371,Land (fixed),20.48333333,75.8,0,0,Cuba
X,0-20000-0-78372,78372,Land (fixed),0,0,0,0,Cuba
"SANTIAGO DE LAS VEGAS, CIUDAD HABANA",0-20000-0-78373,78373,Land (fixed),22.96666667,82.38333333,0,0,Cuba
"TAPASTE, LA HABANA",0-20000-0-78374,78374,Land (fixed),23.01666667,82.13333333,0,0,Cuba
"MELENA DEL SUR, LA HABANA",0-20000-0-78375,78375,Land (fixed),22.76666667,82.13333333,0,0,Cuba
"BAUTA, LA HABANA",0-20000-0-78376,78376,Land (fixed),22.96666667,22.96666667,0,0,Cuba
"VEGUITAS, GRANMA",0-20000-0-78377,78377,Land (fixed),20.31666667,76.88333333,0,0,Cuba
"VELASCO, HOLGUIN",0-20000-0-78378,78378,Land (fixed),21.08333333,76.3,0,0,Cuba
"CABO SAN ANTONIO, PINAR DEL RIO",0-20000-0-78310,78310,Land (fixed),21.86666667,84.95,,,Cuba
PINAR DEL RIO,0-20000-0-78315,78315,Land (fixed),22.41666667,83.68333333,,,Cuba
"BAHIA HONDA, PINAR DEL RIO",0-20000-0-78318,78318,Land (fixed),22.91666667,83.16666667,,,Cuba
"BATABANO, LA HABANA",0-20000-0-78322,78322,Land (fixed),22.71666667,82.28333333,,,Cuba
"PUNTA DEL ESTE, ISLA DE LA JUVENTUD",0-20000-0-78324,78324,Land (fixed),21.55,82.53333333,,,Cuba
"CASA BLANCA, LA HABANA",0-20000-0-78325,78325,Land (fixed),23.16666667,82.35,,,Cuba
VARADERO,0-20000-0-78328,78328,Land (fixed),23.25,81.41666667,,,Cuba
"PLAYA GIRON, MATANZAS",0-20000-0-78333,78333,Land (fixed),22.06666667,81.03333333,,,Cuba
"CANTARRANA, CIENFUEGOS",0-20000-0-78344,78344,Land (fixed),21.91666667,80.16666667,,,Cuba
"JUCARO, CIEGO DE AVILA",0-20000-0-78345,78345,Land (fixed),21.61666667,78.85,,,Cuba
"CAIBARIEN, VILLA CLARA",0-20000-0-78348,78348,Land (fixed),22.51666667,79.45,,,Cuba
"SANCTI SPIRITUS, SANCTI SPIRITUS",0-20000-0-78349,78349,Land (fixed),21.93333333,79.45,,,Cuba
"SANTA CRUZ DEL SUR, CAMAGUEY",0-20000-0-78351,78351,Land (fixed),20.71666667,78,,,Cuba
"NUEVITAS, CAMAGUEY",0-20000-0-78353,78353,Land (fixed),21.53333333,77.25,,,Cuba
CAMAGUEY,0-20000-0-78355,78355,Land (fixed),21.4,77.85,,,Cuba
"PUERTO PADRE, LAS TUNAS",0-20000-0-78358,78358,Land (fixed),21.2,76.61666667,,,Cuba
"CABO CRUZ, GRANMA",0-20000-0-78360,78360,Land (fixed),19.85,77.23333333,,,Cuba
"CONTRAMAESTRE, SANTIAGO DE CUBA",0-20000-0-78363,78363,Land (fixed),20.28333333,76.25,,,Cuba
"PUNTA LUCRECIA, HOLGUIN",0-20000-0-78365,78365,Land (fixed),21.06666667,75.61666667,,,Cuba
"PUNTA DE MAISI, GUANTANAMO",0-20000-0-78369,78369,Land (fixed),20.25,74.15,,,Cuba
X,0-20000-0-78308,78308,Land (fixed),0,0,,,Cuba
X,0-20000-0-78309,78309,Land (fixed),0,0,,,Cuba
"SANTA LUCIA, PINAR DEL RIO",0-20000-0-78312,78312,Land (fixed),22.66666667,83.96666667,,,Cuba
"ISABEL RUBIO, PINAR DEL RIO",0-20000-0-78313,78313,Land (fixed),22.16666667,84.1,,,Cuba
"SAN JUAN Y MARTINEZ, PINAR DEL RIO",0-20000-0-78314,78314,Land (fixed),22.28333333,83.83333333,,,Cuba
"LA PALMA, PINAR DEL RIO",0-20000-0-78316,78316,Land (fixed),22.76666667,83.55,,,Cuba
"PASO REAL DE SAN DIEGO, PINAR DEL RIO",0-20000-0-78317,78317,Land (fixed),22.55,83.3,,,Cuba
"ARTEMISA, LA HABANA",0-20000-0-78319,78319,Land (fixed),22.8,82.75,,,Cuba
"GUIRA DE MELENA, LA HABANA",0-20000-0-78320,78320,Land (fixed),22.78333333,82.51666667,,,Cuba
"LA FE, ISLA DE LA JUVENTUD",0-20000-0-78321,78321,Land (fixed),21.73333333,82.76666667,,,Cuba
"GUINES, LA HABANA",0-20000-0-78323,78323,Land (fixed),22.85,82.03333333,,,Cuba
X,0-20000-0-78326,78326,Land (fixed),0,0,,,Cuba
"UNION DE REYES, MATANZAS",0-20000-0-78327,78327,Land (fixed),22.76666667,81.53333333,,,Cuba
"INDIO HATUEY, MATANZAS",0-20000-0-78329,78329,Land (fixed),22.81666667,81,,,Cuba
"JOVELLANOS, MATANZAS",0-20000-0-78330,78330,Land (fixed),22.78333333,81.18333333,,,Cuba
"JAGUEY GRANDE, MATANZAS",0-20000-0-78331,78331,Land (fixed),22.63333333,81.26666667,,,Cuba
"COLON, MATANZAS",0-20000-0-78332,78332,Land (fixed),22.68333333,80.93333333,,,Cuba
X,0-20000-0-78334,78334,Land (fixed),0,0,,,Cuba
"AGUADA DE PASAJEROS, CIENFUEGOS",0-20000-0-78335,78335,Land (fixed),22.38333333,80.85,,,Cuba
"TRINIDAD, SANCTI SPIRITUS",0-20000-0-78337,78337,Land (fixed),21.78333333,79.98333333,,,Cuba
"SAGUA LA GRANDE, VILLA CLARA",0-20000-0-78338,78338,Land (fixed),22.81666667,80.08333333,,,Cuba
"CAYO COCO, CIEGO DE AVILA",0-20000-0-78339,78339,Land (fixed),22.51666667,78.45,,,Cuba
"BAINOA, LA HABANA",0-20000-0-78340,78340,Land (fixed),23.03333333,81.91666667,,,Cuba
"EL JIBARO, SANCTI SPIRITUS",0-20000-0-78341,78341,Land (fixed),21.71666667,79.21666667,,,Cuba
"TOPES DE COLLANTES, SANCTI SPIRITUS",0-20000-0-78342,78342,Land (fixed),21.91666667,80.01666667,,,Cuba
"EL YABU, VILLA CLARA",0-20000-0-78343,78343,Land (fixed),22.43333333,79.98333333,,,Cuba
"VENEZUELA, CIEGO DE AVILA",0-20000-0-78346,78346,Land (fixed),21.78333333,78.78333333,,,Cuba
"CAMILO CIENFUEGOS, CIEGO DE AVILA",0-20000-0-78347,78347,Land (fixed),22.15,78.75,,,Cuba
"FLORIDA, CAMAGUEY",0-20000-0-78350,78350,Land (fixed),21.51666667,78.23333333,,,Cuba
"ESMERALDA, CAMAGUEY",0-20000-0-78352,78352,Land (fixed),21.85,78.11666667,,,Cuba
"PALO SECO, CAMAGUEY",0-20000-0-78354,78354,Land (fixed),21.13333333,77.31666667,,,Cuba
X,0-20000-0-78356,78356,Land (fixed),0,0,,,Cuba
"LAS TUNAS, LAS TUNAS",0-20000-0-78357,78357,Land (fixed),20.95,76.95,,,Cuba
"MANSANILLO, GRANMA",0-20000-0-78359,78359,Land (fixed),20.33333333,77.13333333,,,Cuba
"JUCARITO, GRANMA",0-20000-0-78361,78361,Land (fixed),20.66666667," 76.9000",,,Cuba
"LA JIQUIMA, HOLGUIN",0-20000-0-78362,78362,Land (fixed),20.93333333,76.53333333,,,Cuba
"UNIVERSIDAD, SANTIAGO DE CUBA",0-20000-0-78364,78364,Land (fixed),20.05,75.81666667,,,Cuba
"GRAN PIEDRA, SANTIAGO DE CUBA",0-20000-0-78366,78366,Land (fixed),20.03333333,75.63333333,,,Cuba
"GUANTANAMO, GUANTANAMO",0-20000-0-78368,78368,Land (fixed),20.13333333,75.23333333,,,Cuba
"GUARO, HOLGUIN",0-20000-0-78370,78370,Land (fixed),20.66666667,75.78333333,,,Cuba
"PINARES DE MAYARI, HOLGUIN",0-20000-0-78371,78371,Land (fixed),20.48333333,75.8,,,Cuba
X,0-20000-0-78372,78372,Land (fixed),0,0,,,Cuba
"SANTIAGO DE LAS VEGAS, CIUDAD HABANA",0-20000-0-78373,78373,Land (fixed),22.96666667,82.38333333,,,Cuba
"TAPASTE, LA HABANA",0-20000-0-78374,78374,Land (fixed),23.01666667,82.13333333,,,Cuba
"MELENA DEL SUR, LA HABANA",0-20000-0-78375,78375,Land (fixed),22.76666667,82.13333333,,,Cuba
"BAUTA, LA HABANA",0-20000-0-78376,78376,Land (fixed),22.96666667,22.96666667,,,Cuba
"VEGUITAS, GRANMA",0-20000-0-78377,78377,Land (fixed),20.31666667,76.88333333,,,Cuba
"VELASCO, HOLGUIN",0-20000-0-78378,78378,Land (fixed),21.08333333,76.3,,,Cuba
43 changes: 15 additions & 28 deletions synop2bufr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,22 +144,7 @@ def parse_synop(message: str, year: int, month: int) -> dict:
else:
output['minute'] = 0

# Translate wind instrument flag from the SYNOP code to the BUFR code
if 'wind_indicator' in decoded:
try:
iw = decoded['wind_indicator']['value']
except Exception:
iw = None

# If iw = 1 or 4, the wind was obtained from an
# anemometer and thus the corresponding wind data
# should be encoded
if iw == 1 or iw == 4:
ENCODE_WIND = True
else:
ENCODE_WIND = False
else:
ENCODE_WIND = False
# ! Removed wind instrument indicator as it is not used in 307096

if 'station_id' in decoded:
try:
Expand Down Expand Up @@ -232,7 +217,7 @@ def parse_synop(message: str, year: int, month: int) -> dict:
output['cloud_cover'] = None

# Wind direction is already in degrees
if ('surface_wind' in decoded) and ENCODE_WIND:
if ('surface_wind' in decoded):
# See B/C1.10.5.3
# NOTE: Every time period in the following code shall be a negative number, # noqa
# to indicate measurements have been taken up until the present.
Expand Down Expand Up @@ -1036,7 +1021,7 @@ def rad_convert(rad, time):
# wind gust speed for region VI (groups 910fmfm and 911fxfx).
# These are given and required to be in m/s.

if ('highest_gust' in decoded) and ENCODE_WIND:
if ('highest_gust' in decoded):
try:
output['highest_gust_1'] = decoded['highest_gust']['gust_1']['speed']['value'] # noqa
except Exception:
Expand Down Expand Up @@ -1406,18 +1391,19 @@ def transform(data: str, metadata: str, year: int,
# now identifier based on WSI and observation date as identifier
isodate = message.get_datetime().strftime('%Y%m%dT%H%M%S')

# Write message to CSV file
# Write message to CSV object in memory
try:
with open(f"decoded_{isodate}.csv",
"a", newline="") as output_csv:
dict_writer = csv.DictWriter(output_csv, msg.keys())
csv_object = StringIO()
dict_writer = csv.DictWriter(csv_object, msg.keys())

# Add headers
dict_writer.writeheader()

# Check if CSV file is empty before adding headers
if os.stat(f"decoded_{isodate}.csv").st_size == 0:
dict_writer.writeheader()
# Write data to rows
dict_writer.writerow(msg)

# Write data to rows
dict_writer.writerow(msg)
# Get string from CSV object
csv_string = csv_object.getvalue()
except Exception:
LOGGER.warning(
f"Unable to write report of station {tsi} to CSV")
Expand All @@ -1442,7 +1428,8 @@ def transform(data: str, metadata: str, year: int,
message.get_element("bufrHeaderCentre"),
"data_category": message.get_element("dataCategory")
},
"result": status
"result": status,
"csv": csv_string
}

# time_ = datetime.now(timezone.utc).isoformat()
Expand Down
Loading

0 comments on commit 10254de

Please sign in to comment.