diff --git a/.gitignore b/.gitignore index 41bfb19..70aa463 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ venv - +env __pycache__ temp_files outputs -files \ No newline at end of file +files +outputs_2 +outputs_test \ No newline at end of file diff --git a/data/data/instituteLogo.jpg b/data/data/instituteLogo.jpg new file mode 100644 index 0000000..b556d76 Binary files /dev/null and b/data/data/instituteLogo.jpg differ diff --git a/data/data/ranges/HGT_ Titulo de HGT.csv b/data/data/ranges/HGT_ Titulo de HGT.csv new file mode 100644 index 0000000..586f397 --- /dev/null +++ b/data/data/ranges/HGT_ Titulo de HGT.csv @@ -0,0 +1,7 @@ +min,max,color +0,1,#FFFFFF +1,600,#0000FF +601,800,#CA976D +801,900,#FF00FF +901,1200,#EABC8E +1201,inf,#FF8000 diff --git "a/data/data/ranges/RAINNC_ Precipitaci\303\263n Acumulada en 24 horas (mm).csv" "b/data/data/ranges/RAINNC_ Precipitaci\303\263n Acumulada en 24 horas (mm).csv" new file mode 100644 index 0000000..586f397 --- /dev/null +++ "b/data/data/ranges/RAINNC_ Precipitaci\303\263n Acumulada en 24 horas (mm).csv" @@ -0,0 +1,7 @@ +min,max,color +0,1,#FFFFFF +1,600,#0000FF +601,800,#CA976D +801,900,#FF00FF +901,1200,#EABC8E +1201,inf,#FF8000 diff --git "a/data/data/ranges/T2_Temperatura \302\260C.csv" "b/data/data/ranges/T2_Temperatura \302\260C.csv" new file mode 100644 index 0000000..586f397 --- /dev/null +++ "b/data/data/ranges/T2_Temperatura \302\260C.csv" @@ -0,0 +1,7 @@ +min,max,color +0,1,#FFFFFF +1,600,#0000FF +601,800,#CA976D +801,900,#FF00FF +901,1200,#EABC8E +1201,inf,#FF8000 diff --git a/data/data/ranges/V10_Titulo V10.csv b/data/data/ranges/V10_Titulo V10.csv new file mode 100644 index 0000000..586f397 --- /dev/null +++ b/data/data/ranges/V10_Titulo V10.csv @@ -0,0 +1,7 @@ +min,max,color +0,1,#FFFFFF +1,600,#0000FF +601,800,#CA976D +801,900,#FF00FF +901,1200,#EABC8E +1201,inf,#FF8000 diff --git a/data/data/ranges/WS10m_Titulo de WS10m.csv b/data/data/ranges/WS10m_Titulo de WS10m.csv new file mode 100644 index 0000000..586f397 --- /dev/null +++ b/data/data/ranges/WS10m_Titulo de WS10m.csv @@ -0,0 +1,7 @@ +min,max,color +0,1,#FFFFFF +1,600,#0000FF +601,800,#CA976D +801,900,#FF00FF +901,1200,#EABC8E +1201,inf,#FF8000 diff --git a/data/data/ranges/ranges.csv b/data/data/ranges/ranges.csv new file mode 100644 index 0000000..586f397 --- /dev/null +++ b/data/data/ranges/ranges.csv @@ -0,0 +1,7 @@ +min,max,color +0,1,#FFFFFF +1,600,#0000FF +601,800,#CA976D +801,900,#FF00FF +901,1200,#EABC8E +1201,inf,#FF8000 diff --git a/data/shapefile/limite_nacional_2011/limite_nacional.rar b/data/shapefile/limite_nacional_2011/limite_nacional.rar new file mode 100644 index 0000000..a90c238 Binary files /dev/null and b/data/shapefile/limite_nacional_2011/limite_nacional.rar differ diff --git a/data/shapefile/limite_nacional_2011/limite_nacional_2011.dbf b/data/shapefile/limite_nacional_2011/limite_nacional_2011.dbf new file mode 100644 index 0000000..7bbeef2 Binary files /dev/null and b/data/shapefile/limite_nacional_2011/limite_nacional_2011.dbf differ diff --git a/data/shapefile/limite_nacional_2011/limite_nacional_2011.prj b/data/shapefile/limite_nacional_2011/limite_nacional_2011.prj new file mode 100644 index 0000000..c6996cc --- /dev/null +++ b/data/shapefile/limite_nacional_2011/limite_nacional_2011.prj @@ -0,0 +1 @@ +PROJCS["WGS_1984_UTM_Zone_16N",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-87.0],PARAMETER["Scale_Factor",0.9996],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0]] \ No newline at end of file diff --git a/data/shapefile/limite_nacional_2011/limite_nacional_2011.sbn b/data/shapefile/limite_nacional_2011/limite_nacional_2011.sbn new file mode 100644 index 0000000..f8933e5 Binary files /dev/null and b/data/shapefile/limite_nacional_2011/limite_nacional_2011.sbn differ diff --git a/data/shapefile/limite_nacional_2011/limite_nacional_2011.sbx b/data/shapefile/limite_nacional_2011/limite_nacional_2011.sbx new file mode 100644 index 0000000..4655fd9 Binary files /dev/null and b/data/shapefile/limite_nacional_2011/limite_nacional_2011.sbx differ diff --git a/data/shapefile/limite_nacional_2011/limite_nacional_2011.shp b/data/shapefile/limite_nacional_2011/limite_nacional_2011.shp new file mode 100644 index 0000000..5a3b8a2 Binary files /dev/null and b/data/shapefile/limite_nacional_2011/limite_nacional_2011.shp differ diff --git a/data/shapefile/limite_nacional_2011/limite_nacional_2011.shp.xml b/data/shapefile/limite_nacional_2011/limite_nacional_2011.shp.xml new file mode 100644 index 0000000..5a76610 --- /dev/null +++ b/data/shapefile/limite_nacional_2011/limite_nacional_2011.shp.xml @@ -0,0 +1,2 @@ + +2011052513205900FALSEProject "departamentos honduras (poli)" C:\SIG\@SIG_HOND\deptos_honduras_concayos.shp PROJCS['WGS_1984_UTM_Zone_16N',GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['False_Easting',500000.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',-87.0],PARAMETER['Scale_Factor',0.9996],PARAMETER['Latitude_Of_Origin',0.0],UNIT['Meter',1.0]] NAD_1927_To_WGS_1984_2 PROJCS['NAD_1927_UTM_Zone_16N',GEOGCS['GCS_North_American_1927',DATUM['D_North_American_1927',SPHEROID['Clarke_1866',6378206.4,294.9786982]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['False_Easting',500000.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',-87.0],PARAMETER['Scale_Factor',0.9996],PARAMETER['Latitude_Of_Origin',0.0],UNIT['Meter',1.0]]Erase C:\GIS_PLANOT\shapes\CB\limiteArea\deptos_honduras_concayos.shp Limite_Nacional C:\GIS_PLANOT\shapes\CB\limiteArea\CayosHN.shp #SpatialJoin C:\GIS_PLANOT\shapes\CB\limiteArea\CayosHN.shp C:\GIS_PLANOT\shapes\CB\limiteArea\deptos_honduras_concayos.shp C:\GIS_PLANOT\shapes\CB\limiteArea\CayosHN_SpatialJoin.shp JOIN_ONE_TO_ONE KEEP_ALL "NOMBRE_ NOMBRE_ true false false 50 Text 0 0 ,First,#,C:\GIS_PLANOT\shapes\CB\limiteArea\CayosHN.shp,NOMBRE_,-1,-1,C:\GIS_PLANOT\shapes\CB\limiteArea\deptos_honduras_concayos.shp,NOMBRE_,-1,-1;X_COORD X_COORD true false false 19 Double 5 18 ,First,#,C:\GIS_PLANOT\shapes\CB\limiteArea\CayosHN.shp,X_COORD,-1,-1,C:\GIS_PLANOT\shapes\CB\limiteArea\deptos_honduras_concayos.shp,X_COORD,-1,-1;Y_COORD Y_COORD true false false 19 Double 5 18 ,First,#,C:\GIS_PLANOT\shapes\CB\limiteArea\CayosHN.shp,Y_COORD,-1,-1,C:\GIS_PLANOT\shapes\CB\limiteArea\deptos_honduras_concayos.shp,Y_COORD,-1,-1" INTERSECTS "0 Unknown"Union "CayosHN_SpatialJoin #;m1101vA001970_HN #" C:\Users\nmartinez\Documents\ArcGIS\Default.gdb\CayosHN_SpatialJoin_Union ALL # GAPSm1101vA002011_HN002file://\\SEPWKSSEC050\D$\SINIT\SINIT\HOFB.mdbLocal Area Network245963.441100926399.9563001435261.4501001826447.9317001ProjectedGCS_WGS_1984WGS_1984_UTM_Zone_16N<ProjectedCoordinateSystem xsi:type='typens:ProjectedCoordinateSystem' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:typens='http://www.esri.com/schemas/ArcGIS/10.0'><WKT>PROJCS[&quot;WGS_1984_UTM_Zone_16N&quot;,GEOGCS[&quot;GCS_WGS_1984&quot;,DATUM[&quot;D_WGS_1984&quot;,SPHEROID[&quot;WGS_1984&quot;,6378137.0,298.257223563]],PRIMEM[&quot;Greenwich&quot;,0.0],UNIT[&quot;Degree&quot;,0.0174532925199433]],PROJECTION[&quot;Transverse_Mercator&quot;],PARAMETER[&quot;False_Easting&quot;,500000.0],PARAMETER[&quot;False_Northing&quot;,0.0],PARAMETER[&quot;Central_Meridian&quot;,-87.0],PARAMETER[&quot;Scale_Factor&quot;,0.9996],PARAMETER[&quot;Latitude_Of_Origin&quot;,0.0],UNIT[&quot;Meter&quot;,1.0],AUTHORITY[&quot;EPSG&quot;,32616]]</WKT><XOrigin>-5120900</XOrigin><YOrigin>-9998100</YOrigin><XYScale>10000</XYScale><ZOrigin>-100000</ZOrigin><ZScale>10000</ZScale><MOrigin>-100000</MOrigin><MScale>10000</MScale><XYTolerance>0.001</XYTolerance><ZTolerance>0.001</ZTolerance><MTolerance>0.001</MTolerance><HighPrecision>true</HighPrecision><WKID>32616</WKID></ProjectedCoordinateSystem>201105131531300020110513153130001.0North American Profile of ISO19115 2003NAPMicrosoft Windows XP Version 5.1 (Build 2600) Service Pack 2; ESRI ArcCatalog 9.2.0.1324esLímites del territorio nacional digitalizados a partir de 279 hojas cartográficas escala1:50,000 del Instituto Geográfico Nacional (IGN). La digitalización fué realizada en 1994 por el Proyecto Forestal (PROFOR) de la cooperación Alemana y contraparte de la Administración Forestal del Estado (AFE-COHDEFOR)e información de la Casilleria de HondurasMostrar los límites de la República de Honduras en mapas escala 1:50,000, con una actualizacíon de los cayos del AtlanticoREQUIRED: The name of an organization or individual that developed the data set.REQUIRED: The date when the data set is published or otherwise made available for release.m1101vA002011_HNsersCayosHN_SpatialJoinvector digital data\\PC\C$\GIS_PLANOT\shapes\CB\limiteArea\CayosHN_SpatialJoin.shpREQUIRED: The basis on which the time period of content information is determined.REQUIRED: The year (and optionally month, or month and day) for which the data set corresponds to the ground.REQUIRED: The state of the data set.REQUIRED: The frequency with which changes and additions are made to the data set after the initial data set is completed.REQUIRED: Western-most coordinate of the limit of coverage expressed in longitude.REQUIRED: Eastern-most coordinate of the limit of coverage expressed in longitude.REQUIRED: Northern-most coordinate of the limit of coverage expressed in latitude.REQUIRED: Southern-most coordinate of the limit of coverage expressed in latitude.REQUIRED: Reference to a formally registered thesaurus or a similar authoritative source of theme keywords.REQUIRED: Common-use word or phrase used to describe the subject of the data set.REQUIRED: Restrictions and legal prerequisites for accessing the data set.REQUIRED: Restrictions and legal prerequisites for using the data set after access is granted.ShapefileMicrosoft Windows Server 2008 R2 Version 6.1 (Build 7600) ; ESRI ArcGIS 10.0.0.2414m1101vA002011_HNsersUnidad de Informacion Territorial / Direccion General de Ordenamiento TerritorialSecretaria Tecnica de Planificacion y Cooperación Externa002-89.379870-83.00765816.51992512.9533861Mostrar los límites de la República de Honduras en mapas escala 1:50,000, con una actualizacíon de los cayos del Atlantico<DIV STYLE="text-align:Left;"><DIV><DIV><P STYLE="margin:0 0 0 0;"><SPAN>Límites del territorio nacional digitalizados a partir de 279 hojas cartográficas escala1:50,000 del Instituto Geográfico Nacional (IGN). La digitalización fué realizada en 1994 por el Proyecto Forestal (PROFOR) de la cooperación Alemana y contraparte de la Administración Forestal del Estado (AFE-COHDEFOR)</SPAN><SPAN>e información de la Casilleria de Honduras</SPAN></P><P><SPAN /></P></DIV></DIV></DIV>LimitesFrontera HondurasEstado de HondurasesFGDC Content Standards for Digital Geospatial MetadataFGDC-STD-001-1998local timeREQUIRED: The person responsible for the metadata information.REQUIRED: The organization responsible for the metadata information.REQUIRED: The mailing and/or physical address for the organization or individual.REQUIRED: The city of the address.REQUIRED: The state or province of the address.REQUIRED: The ZIP or other postal code of the address.REQUIRED: The telephone number by which individuals can speak to the organization or individual.20090517ISO 19115 Geographic Information - MetadataDIS_ESRI1.0datasetDownloadable Data0.0000.000002file://\\PC\C$\GIS_PLANOT\shapes\CB\limiteArea\CayosHN_SpatialJoin.shpLocal Area Network0.000ShapefilePersonal GeoDatabase Feature ClassVectorSimple4FALSE1TRUEFALSEGCS_WGS_1984WGS_1984_UTM_Zone_16Ncoordinate pairmeters0.0000000.000000D_WGS_1984WGS_19846378137.000000298.257224WGS_1984_UTM_Zone_16NEPSG7.4.110m1101vA002011_HNFeature Class1OBJECTIDOBJECTIDOID400Internal feature number.ESRISequential unique whole numbers that are automatically generated.ShapeShapeGeometry000Feature geometry.ESRICoordinates defining the features.PAISPAISString1600CODPAISCODPAISString200Shape_area_1Shape_area_1Double800Shape_LengthShape_LengthDouble800Length of feature in internal units.ESRIPositive real numbers that are automatically generated.Shape_AreaShape_AreaDouble800Area of feature in internal units squared.ESRIPositive real numbers that are automatically generated.20110513 diff --git a/data/shapefile/limite_nacional_2011/limite_nacional_2011.shx b/data/shapefile/limite_nacional_2011/limite_nacional_2011.shx new file mode 100644 index 0000000..3176e8a Binary files /dev/null and b/data/shapefile/limite_nacional_2011/limite_nacional_2011.shx differ diff --git a/data/shapefile/limites_municipales_2001/limite_municipal_2001.dbf b/data/shapefile/limites_municipales_2001/limite_municipal_2001.dbf new file mode 100644 index 0000000..e9a9f68 Binary files /dev/null and b/data/shapefile/limites_municipales_2001/limite_municipal_2001.dbf differ diff --git a/data/shapefile/limites_municipales_2001/limite_municipal_2001.prj b/data/shapefile/limites_municipales_2001/limite_municipal_2001.prj new file mode 100644 index 0000000..c6996cc --- /dev/null +++ b/data/shapefile/limites_municipales_2001/limite_municipal_2001.prj @@ -0,0 +1 @@ +PROJCS["WGS_1984_UTM_Zone_16N",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-87.0],PARAMETER["Scale_Factor",0.9996],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0]] \ No newline at end of file diff --git a/data/shapefile/limites_municipales_2001/limite_municipal_2001.sbn b/data/shapefile/limites_municipales_2001/limite_municipal_2001.sbn new file mode 100644 index 0000000..34cf216 Binary files /dev/null and b/data/shapefile/limites_municipales_2001/limite_municipal_2001.sbn differ diff --git a/data/shapefile/limites_municipales_2001/limite_municipal_2001.sbx b/data/shapefile/limites_municipales_2001/limite_municipal_2001.sbx new file mode 100644 index 0000000..bc8ebe0 Binary files /dev/null and b/data/shapefile/limites_municipales_2001/limite_municipal_2001.sbx differ diff --git a/data/shapefile/limites_municipales_2001/limite_municipal_2001.shp b/data/shapefile/limites_municipales_2001/limite_municipal_2001.shp new file mode 100644 index 0000000..c96d90c Binary files /dev/null and b/data/shapefile/limites_municipales_2001/limite_municipal_2001.shp differ diff --git a/data/shapefile/limites_municipales_2001/limite_municipal_2001.shp.AYES.14172.5572.sr.lock b/data/shapefile/limites_municipales_2001/limite_municipal_2001.shp.AYES.14172.5572.sr.lock new file mode 100644 index 0000000..e69de29 diff --git a/data/shapefile/limites_municipales_2001/limite_municipal_2001.shp.xml b/data/shapefile/limites_municipales_2001/limite_municipal_2001.shp.xml new file mode 100644 index 0000000..21a6709 --- /dev/null +++ b/data/shapefile/limites_municipales_2001/limite_municipal_2001.shp.xml @@ -0,0 +1,117 @@ + + + + + + + REQUIRED: The name of an organization or individual that developed the data set. + REQUIRED: The date when the data set is published or otherwise made available for release. + Municipios - Censo 2001 + vector digital data + \\NKMARTINEZ-PC\C$\MAPAS SEPLAN\SINIT SHAPE\m1103vA002001_HN.shp + m1103vA002001_HN + + + Límites de los 298 Municipios de la República de Honduras (año 2001) generados a partir del mapa de aldeas que fue digitalizado a partir de los mapas de los segmentos censales de 1988 de la Dirección General de Estadísticas y Censos. + +Para obtener los municipios al año del censo de población y vivienda de 2001, al mapa generado se le actualizaron los límites de nuevos municipios creados en el período de 1988 - 2001. + Mostrar los límites municipales para correlacionarlos con los datos de los censos de población y vivienda de 2001. + es + + + + REQUIRED: The year (and optionally month, or month and day) for which the data set corresponds to the ground. + + + REQUIRED: The basis on which the time period of content information is determined. + + + REQUIRED: The state of the data set. + REQUIRED: The frequency with which changes and additions are made to the data set after the initial data set is completed. + + + + -89.379870 + -83.121866 + 16.519924 + 12.955059 + + 245963.444200914181.4270001435261.4386001826447.901000 + + + REQUIRED: Reference to a formally registered thesaurus or a similar authoritative source of theme keywords. + municipios + límites municipalesmunicipalitiesmunicipal boundaries + + REQUIRED: Restrictions and legal prerequisites for accessing the data set. + REQUIRED: Restrictions and legal prerequisites for using the data set after access is granted. + Microsoft Windows Vista Version 6.1 (Build 7600) ; ESRI ArcCatalog 9.3.0.1770 + Shapefile + + Vector + + + G-polygon + 0 + + SimplePolygonFALSE0FALSEFALSE + + + + + m1103vA002001_HN + Feature Class0 + FIDFIDOID400Internal feature number.ESRISequential unique whole numbers that are automatically generated. + Shape + Feature geometry. + ESRI + + Coordinates defining the features. + + ShapeGeometry000 + + NOMBRE + NOMBREString50 + + COD_MUNI + COD_MUNIString16 + DEPDEPNumber4MUNMUNNumber4COD_MUN_COD_MUN_Number4CODPAISCODPAISString2Shape_LengShape_LengFloat1911 + Shape_Area + Area of feature in internal units squared. + ESRI + + Positive real numbers that are automatically generated. + + Shape_AreaFloat1911 + Km2Km2Float1311DensidadDensidadFloat1311 + + + Downloadable Data + 0.0000.000 + + 20100810 + + + + Abner Jimenez + REQUIRED: The organization responsible for the metadata information. + + + REQUIRED: The mailing and/or physical address for the organization or individual. + REQUIRED: The city of the address. + REQUIRED: The state or province of the address. + REQUIRED: The ZIP or other postal code of the address. + + REQUIRED: The telephone number by which individuals can speak to the organization or individual. + abnerjhn@gmail.com + + + FGDC Content Standards for Digital Geospatial Metadata + FGDC-STD-001-1998 + local time + + http://www.esri.com/metadata/esriprof80.html + ESRI Metadata Profile + + eshttp://www.esri.com/metadata/esriprof80.htmlESRI Metadata Profile + {5E699541-F233-41F3-8D9E-2028AFDF7567}2009112209122300FALSE20100810151852002010081015185200CopyFeatures C:\SINIT\SINIT\SINIT.mdb\m1103vA002001_HN "C:\MAPAS SEPLAN\SINIT SHAPE\m1103vA002001_HN.shp" # 0 0 0Metadata imported.C:\NUEVO_SINIT\metadata-aldeas.xml2009112209122300Microsoft Windows Vista Version 6.1 (Build 7600) ; ESRI ArcCatalog 9.3.0.1770m1103vA002001_HN245963.4442914181.4271826447.9011435261.43861-89.37987-83.12186616.51992412.9550591ISO 19115 Geographic Information - MetadataDIS_ESRI1.0dataset002file://\\NKMARTINEZ-PC\C$\MAPAS SEPLAN\SINIT SHAPE\m1103vA002001_HN.shpLocal Area Network0.000ShapefileGCS_WGS_1984WGS_1984_UTM_Zone_16Ncoordinate pairmeters0.0000000.000000Universal Transverse Mercator160.999600-87.0000000.000000500000.0000000.000000D_WGS_1984WGS_19846378137.000000298.257224WGS_1984_UTM_Zone_16N020100810 diff --git a/data/shapefile/limites_municipales_2001/limite_municipal_2001.shx b/data/shapefile/limites_municipales_2001/limite_municipal_2001.shx new file mode 100644 index 0000000..aea24ba Binary files /dev/null and b/data/shapefile/limites_municipales_2001/limite_municipal_2001.shx differ diff --git a/data/shapefile/limites_municipales_2001/limites_municipales_2001.rar b/data/shapefile/limites_municipales_2001/limites_municipales_2001.rar new file mode 100644 index 0000000..5c42f7c Binary files /dev/null and b/data/shapefile/limites_municipales_2001/limites_municipales_2001.rar differ diff --git a/src/postprocessing/cut_map.py b/src/postprocessing/cut_map.py index a3a8547..6ebcad6 100644 --- a/src/postprocessing/cut_map.py +++ b/src/postprocessing/cut_map.py @@ -49,3 +49,5 @@ def cut_rasters(raster_filename, shp_path): dest.write(out_image) os.remove(raster_filename) + + return raster_filename.replace(os.path.basename(raster_filename), os.path.basename(raster_filename).replace("_raster","")) diff --git a/src/postprocessing/export_average.py b/src/postprocessing/export_average.py index 1df313c..2650ce6 100644 --- a/src/postprocessing/export_average.py +++ b/src/postprocessing/export_average.py @@ -4,15 +4,18 @@ from rasterio.transform import from_origin import os from .cut_map import cut_rasters +from .generate_images import generate_image import matplotlib.pyplot as plt from datetime import datetime, timedelta -def export_raster(dataset, file_name, specific_variable, output_path, shp_path, is4Dim=False): +def export_raster(dataset, file_name, specific_variable, output_path, inputs_path, is4Dim=False): # Get the current script directory output_path_folder = os.path.join(output_path, file_name) - shp_path = os.path.join(shp_path, "limite_nacional_2011", "limite_nacional_2011.shp") + shape_path = os.path.join(inputs_path, "shapefile") + data_path = os.path.join(inputs_path, "data") + shp_path = os.path.join(shape_path, "limite_nacional_2011", "limite_nacional_2011.shp") if not os.path.exists(output_path): os.makedirs(output_path) @@ -92,10 +95,26 @@ def export_raster(dataset, file_name, specific_variable, output_path, shp_path, print(f"Raster for: {specific_variable} day: {date} created successfully") - cut_rasters(raster_filename, shp_path) + new_raster_filename = cut_rasters(raster_filename, shp_path) - print(f"Raster for: {specific_variable} day: {date} cut successfully as '{raster_filename}'") + print(f"Raster for: {specific_variable} day: {date} cut successfully as '{new_raster_filename}'") + + generate_image(new_raster_filename, search_csv(os.path.join(data_path,"ranges"), specific_variable), data_path, os.path.join(shape_path, "limites_municipales_2001", "limite_municipal_2001.shp")) return var_output + +def search_csv(ranges_path, varname): + + csvs = [os.path.join(ranges_path, file) for file in os.listdir(ranges_path)] + + def contains_keyword(file_name, keyword): + return file_name.startswith(keyword) + + filtered_files = [file for file in csvs if contains_keyword(os.path.basename(file), varname)] + + if not filtered_files: + filtered_files.append(os.path.join(ranges_path, "ranges_Default.csv")) + + return filtered_files[0] \ No newline at end of file diff --git a/src/postprocessing/extract_data.py b/src/postprocessing/extract_data.py index 95805e0..078b289 100644 --- a/src/postprocessing/extract_data.py +++ b/src/postprocessing/extract_data.py @@ -4,16 +4,17 @@ import rasterio as rio from rasterio.transform import from_origin from .export_average import export_raster +from .generate_images import generate_image import rasterio def extract_data(inputs_path, outputs_path): - shp_path = os.path.join(inputs_path, "shapefile") - inputs_path = os.path.join(inputs_path, "wrf") + + wrf_inputs_path = os.path.join(inputs_path, "wrf") # Filtrar solo los archivos - nc_files = [os.path.join(inputs_path, file) for file in os.listdir(inputs_path)] + nc_files = [os.path.join(wrf_inputs_path, file) for file in os.listdir(wrf_inputs_path)] for file in nc_files: @@ -22,29 +23,29 @@ def extract_data(inputs_path, outputs_path): dataset = nc.Dataset(file) - T2 = export_raster(dataset, file_name, "T2", outputs_path, shp_path) + T2 = export_raster(dataset, file_name, "T2", outputs_path, inputs_path) - RAINNC = export_raster(dataset, file_name, "RAINNC", outputs_path, shp_path) + RAINNC = export_raster(dataset, file_name, "RAINNC", outputs_path, inputs_path) - HGT = export_raster(dataset, file_name, "HGT", outputs_path, shp_path) + HGT = export_raster(dataset, file_name, "HGT", outputs_path, inputs_path) - SWDOWN = export_raster(dataset, file_name, "SWDOWN", outputs_path, shp_path) + SWDOWN = export_raster(dataset, file_name, "SWDOWN", outputs_path, inputs_path) - U10 = export_raster(dataset, file_name, "U10", outputs_path, shp_path) + U10 = export_raster(dataset, file_name, "U10", outputs_path, inputs_path) - V10 = export_raster(dataset, file_name, "V10", outputs_path, shp_path) + V10 = export_raster(dataset, file_name, "V10", outputs_path, inputs_path) - P = export_raster(dataset, file_name, "P", outputs_path, shp_path, True) + P = export_raster(dataset, file_name, "P", outputs_path, inputs_path, True) - PB = export_raster(dataset, file_name, "PB", outputs_path, shp_path, True) + PB = export_raster(dataset, file_name, "PB", outputs_path, inputs_path, True) - QVAPOR = export_raster(dataset, file_name, "QVAPOR", outputs_path, shp_path, True) + QVAPOR = export_raster(dataset, file_name, "QVAPOR", outputs_path, inputs_path, True) - WS10m = calcWS10m(U10, V10) + WS10m = calcWS10m(U10, V10, inputs_path) - WS2m = calcWS2m(WS10m) + WS2m = calcWS2m(WS10m, inputs_path) - RH = calcRH(T2, P, PB, QVAPOR) + RH = calcRH(T2, P, PB, QVAPOR, inputs_path) dataset.close() @@ -52,18 +53,20 @@ def extract_data(inputs_path, outputs_path): -def calcWS10m(U10, V10): +def calcWS10m(U10, V10, inputs_path): + tif_U10_files = [file for file in os.listdir(U10) if file.endswith('.tif')] + tif_V10_files = [file for file in os.listdir(V10) if file.endswith('.tif')] - for index in range(0,len(os.listdir(U10))): + for index in range(0,len(tif_U10_files)): - with rasterio.open(os.path.join(U10,os.listdir(U10)[index])) as src_u10: + with rasterio.open(os.path.join(U10,tif_U10_files[index])) as src_u10: u10 = src_u10.read(1) transform = src_u10.transform crs = src_u10.crs - with rasterio.open(os.path.join(V10,os.listdir(V10)[index])) as src_v10: + with rasterio.open(os.path.join(V10,tif_V10_files[index])) as src_v10: v10 = src_v10.read(1) print(f"Calculated WS10m") @@ -75,7 +78,7 @@ def calcWS10m(U10, V10): if not os.path.exists(os.path.join(parent_dir, 'WS10m')): os.makedirs(os.path.join(parent_dir, 'WS10m')) - file_name = os.path.join(U10,os.listdir(U10)[index]).replace("U10","WS10m") + file_name = os.path.join(U10,tif_U10_files[index]).replace("U10","WS10m") with rasterio.open( file_name, @@ -92,14 +95,17 @@ def calcWS10m(U10, V10): print(f"Raster {file_name} created successfully") + generate_image(file_name, search_csv(os.path.join(inputs_path, "data", "ranges"), "WS10m"), os.path.join(inputs_path, "data"), os.path.join(inputs_path, "shapefile", "limites_municipales_2001", "limite_municipal_2001.shp")) + return U10.replace("U10","WS10m") -def calcWS2m(WS10m): +def calcWS2m(WS10m, inputs_path): + tif_files = [file for file in os.listdir(WS10m) if file.endswith('.tif')] - for index in range(0,len(os.listdir(WS10m))): + for index in range(0,len(tif_files)): - with rasterio.open(os.path.join(WS10m,os.listdir(WS10m)[index])) as src_ws10m: + with rasterio.open(os.path.join(WS10m,tif_files[index])) as src_ws10m: ws10m = src_ws10m.read(1) transform = src_ws10m.transform @@ -116,7 +122,7 @@ def calcWS2m(WS10m): if not os.path.exists(os.path.join(parent_dir, 'WS2m')): os.makedirs(os.path.join(parent_dir, 'WS2m')) - file_name = os.path.join(WS10m,os.listdir(WS10m)[index]).replace("WS10m","WS2m") + file_name = os.path.join(WS10m,tif_files[index]).replace("WS10m","WS2m") with rasterio.open( file_name, @@ -133,27 +139,33 @@ def calcWS2m(WS10m): print(f"Raster {file_name} created successfully") + generate_image(file_name, search_csv(os.path.join(inputs_path, "data", "ranges"), "WS2m"), os.path.join(inputs_path, "data"), os.path.join(inputs_path, "shapefile", "limites_municipales_2001", "limite_municipal_2001.shp")) + return WS10m.replace("WS10m","WS2m") -def calcRH(T2, P, PB, Q): +def calcRH(T2, P, PB, Q, inputs_path): + tif_T2_files = [file for file in os.listdir(T2) if file.endswith('.tif')] + tif_P_files = [file for file in os.listdir(P) if file.endswith('.tif')] + tif_PB_files = [file for file in os.listdir(PB) if file.endswith('.tif')] + tif_Q_files = [file for file in os.listdir(Q) if file.endswith('.tif')] - for index in range(0,len(os.listdir(T2))): + for index in range(0,len(tif_T2_files)): - with rasterio.open(os.path.join(T2,os.listdir(T2)[index])) as src_t2: + with rasterio.open(os.path.join(T2,tif_T2_files[index])) as src_t2: t2 = src_t2.read(1) transform = src_t2.transform crs = src_t2.crs - with rasterio.open(os.path.join(P,os.listdir(P)[index])) as src_p: + with rasterio.open(os.path.join(P,tif_P_files[index])) as src_p: p = src_p.read(1) - with rasterio.open(os.path.join(PB,os.listdir(PB)[index])) as src_pb: + with rasterio.open(os.path.join(PB,tif_PB_files[index])) as src_pb: pb = src_pb.read(1) - with rasterio.open(os.path.join(Q,os.listdir(Q)[index])) as src_q: + with rasterio.open(os.path.join(Q,tif_Q_files[index])) as src_q: q = src_q.read(1) print(f"Calculated RH") @@ -177,7 +189,7 @@ def calcRH(T2, P, PB, Q): if not os.path.exists(os.path.join(parent_dir, 'RH')): os.makedirs(os.path.join(parent_dir, 'RH')) - file_name = os.path.join(T2,os.listdir(T2)[index]).replace("T2","RH") + file_name = os.path.join(T2,tif_T2_files[index]).replace("T2","RH") with rasterio.open( file_name, @@ -194,4 +206,21 @@ def calcRH(T2, P, PB, Q): print(f"Raster {file_name} created successfully") + generate_image(file_name, search_csv(os.path.join(inputs_path, "data", "ranges"), "RH"), os.path.join(inputs_path, "data"), os.path.join(inputs_path, "shapefile", "limites_municipales_2001", "limite_municipal_2001.shp")) + return T2.replace("T2","RH") + + +def search_csv(ranges_path, varname): + + csvs = [os.path.join(ranges_path, file) for file in os.listdir(ranges_path)] + + def contains_keyword(file_name, keyword): + return file_name.startswith(keyword) + + filtered_files = [file for file in csvs if contains_keyword(os.path.basename(file), varname)] + + if not filtered_files: + filtered_files.append(os.path.join(ranges_path, "ranges_Default.csv")) + + return filtered_files[0] \ No newline at end of file diff --git a/src/postprocessing/generate_images.py b/src/postprocessing/generate_images.py new file mode 100644 index 0000000..9590bc3 --- /dev/null +++ b/src/postprocessing/generate_images.py @@ -0,0 +1,85 @@ +import rasterio +import matplotlib.pyplot as plt +import pandas as pd +from matplotlib.colors import LinearSegmentedColormap +from matplotlib.offsetbox import OffsetImage, AnnotationBbox +import os +import geopandas as gpd +from datetime import datetime, timedelta +import numpy as np + + +def generate_image(raster_path, csv_path, data_path, shapefile_path=None): + # Definir la ruta del logo y la ruta de guardado del PNG + logo_path = os.path.join(data_path, "instituteLogo.jpg") + png_file = os.path.join(os.path.dirname(raster_path), os.path.basename(raster_path).replace(".tif", "_image.png")) + + date = os.path.basename(raster_path).split("_")[1].split(".")[0] + date_obj = datetime.strptime(date, "%Y-%m-%d") + # Sumar un día + new_date_obj = date_obj + timedelta(days=1) + + # Convertir el objeto datetime de nuevo a string + new_date_str = new_date_obj.strftime("%Y-%m-%d") + + csv_title = os.path.basename(csv_path).split("_")[1].replace(".csv", "") + + # Leer los rangos de colores desde el CSV + color_ranges = pd.read_csv(csv_path) + + with rasterio.open(raster_path) as src: + # Leer la primera banda como un arreglo numpy + band = src.read(1) + raster_bounds = src.bounds + raster_crs = src.crs + # + + # Obtener los valores mínimo y máximo del raster + raster_min = np.nanmin(band) + raster_max = np.nanmax(band) + + + # Filtrar el DataFrame de color para incluir solo los rangos dentro del rango del raster + filtered_color_ranges = color_ranges[(color_ranges['min'] <= raster_max) & (color_ranges['max'] >= raster_min)] + min_vals = filtered_color_ranges['min'].astype(float).tolist() + max_vals = filtered_color_ranges['max'].astype(float).tolist() + cmap_colors = filtered_color_ranges['color'].tolist() + + # Crear los límites y colores para el mapa de colores + boundaries = min_vals + [max_vals[-1]] # El valor máximo final para cerrar el último rango + cmap = LinearSegmentedColormap.from_list('custom_cmap', cmap_colors) + + title = f"CENAOS/WRF {csv_title} desde {date} hasta {new_date_str}" # Título que deseas agregar + + # Configurar la figura de Matplotlib con tamaño personalizado + fig, ax = plt.subplots(figsize=(12, 8)) + + # Mostrar el mapa de colores + im = ax.imshow(band, cmap=cmap, extent=[raster_bounds.left, raster_bounds.right, raster_bounds.bottom, raster_bounds.top]) + + # Añadir el shapefile si se proporciona + if shapefile_path and os.path.exists(shapefile_path): + gdf = gpd.read_file(shapefile_path) + gdf = gdf.to_crs(raster_crs) # Reproyectar al CRS del raster + gdf.plot(ax=ax, facecolor='none', edgecolor='black') + + # Añadir título + ax.set_title(title, fontsize=20) + + # Añadir logo en posición absoluta + if os.path.exists(logo_path): + logo = plt.imread(logo_path) + imagebox = OffsetImage(logo, zoom=0.2) + ab = AnnotationBbox(imagebox, (0.87, 0.11), frameon=False, xycoords='axes fraction') # Coordenadas fraccionarias del eje (0.87, 0.11) + ax.add_artist(ab) + + # Añadir barra de colores (colorbar) abajo a la izquierda + cbar = fig.colorbar(im, ax=ax, orientation='horizontal', pad=0.1, aspect=30, fraction=0.02) + cbar.set_label(csv_title, fontsize=12) + cbar.ax.tick_params(labelsize=10) + + # Guardar la visualización como un archivo PNG + plt.savefig(png_file, bbox_inches='tight') + plt.close() # Cerrar la figura para liberar recursos de memoria + + print(f'Imagen procesada guardada en: {png_file}') \ No newline at end of file diff --git a/src/postprocessing/main.py b/src/postprocessing/main.py index e4cd09d..1aa4626 100644 --- a/src/postprocessing/main.py +++ b/src/postprocessing/main.py @@ -21,6 +21,4 @@ def main(): postp = extract_data(input_path, output_path) if __name__ == "__main__": - main() - -#python resampling.py "ETHIOPIA" "D:\\CIAT\\Code\\USAID\\aclimate_resampling\\data\\" "-1" 2 2023 \ No newline at end of file + main() \ No newline at end of file