Skip to content

Commit

Permalink
Merge pull request #3 from CIAT-DAPA/develop
Browse files Browse the repository at this point in the history
some changes
  • Loading branch information
santiago123x authored Sep 20, 2024
2 parents c75db64 + 4bb5445 commit c4de10d
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 53 deletions.
29 changes: 2 additions & 27 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
affine==2.4.0
asttokens==2.4.1
attrs==24.2.0
cads-api-client==1.3.2
cads-api-client==1.3.3
cdsapi==0.7.3
certifi==2024.8.30
cftime==1.6.4
Expand All @@ -10,51 +9,27 @@ click==8.1.7
click-plugins==1.1.1
cligj==0.7.2
colorama==0.4.6
comm==0.2.2
debugpy==1.8.5
decorator==5.1.1
exceptiongroup==1.2.2
executing==2.1.0
geopandas==1.0.1
gsconfig-py3==1.0.7
idna==3.10
ipykernel==6.29.5
ipython==8.27.0
jedi==0.19.1
jupyter_client==8.6.2
jupyter_core==5.7.2
matplotlib-inline==0.1.7
multiurl==0.3.1
nest-asyncio==1.6.0
netCDF4==1.7.1.post2
numpy==2.1.1
packaging==24.1
pandas==2.2.2
parso==0.8.4
platformdirs==4.3.3
prompt_toolkit==3.0.47
psutil==6.0.0
pure_eval==0.2.3
Pygments==2.18.0
pandas==2.2.3
pyogrio==0.9.0
pyparsing==3.1.4
pyproj==3.6.1
python-dateutil==2.9.0.post0
pytz==2024.2
pywin32==306
pyzmq==26.2.0
rasterio==1.3.11
requests==2.32.3
rioxarray==0.17.0
shapely==2.0.6
six==1.16.0
snuggs==1.4.7
stack-data==0.6.3
tornado==6.4.1
tqdm==4.66.5
traitlets==5.14.3
typing_extensions==4.12.2
tzdata==2024.1
urllib3==2.2.3
wcwidth==0.2.13
xarray==2024.9.0
5 changes: 3 additions & 2 deletions src/download_forecast/chirps_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@

class ChirpsData():

def __init__(self, output_path, country, start_date, end_date):
def __init__(self, output_path, country, start_date, end_date, download_data_path):

self.output_path = output_path
self.download_data_path = download_data_path
self.country = country
self.start_date = start_date
self.end_date = end_date
Expand All @@ -27,7 +28,7 @@ def __init__(self, output_path, country, start_date, end_date):
self.country_path = os.path.join(self.shapefile_path, self.country)
self.chirps_output_path = os.path.join(self.output_path,"PREC")

self.downloaded_data_path = os.path.join(self.project_root,"downloadedData")
self.downloaded_data_path = os.path.join(self.download_data_path,"downloadedData")

self.chirps_path = os.path.join(self.downloaded_data_path,"CHIRPS")

Expand Down
9 changes: 6 additions & 3 deletions src/download_forecast/era5_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import xarray as xr
import rioxarray
import cdsapi
import calendar
from zipfile import ZipFile
from datetime import datetime, timedelta
from concurrent.futures import ThreadPoolExecutor
Expand All @@ -18,9 +19,10 @@

class Era5Data():

def __init__(self, output_path, country, start_date, end_date):
def __init__(self, output_path, country, start_date, end_date, download_data_path):

self.output_path = output_path
self.download_data_path = download_data_path
self.country = country
self.start_date = start_date
self.end_date = end_date
Expand All @@ -35,7 +37,7 @@ def __init__(self, output_path, country, start_date, end_date):
self.era5_tmin_output_path = os.path.join(self.output_path,"TMIN")
self.era5_srad_output_path = os.path.join(self.output_path,"SRAD")

self.downloaded_data_path = os.path.join(self.project_root,"downloadedData")
self.downloaded_data_path = os.path.join(self.download_data_path,"downloadedData")

self.era5_path = os.path.join(self.downloaded_data_path,"ERA5")

Expand Down Expand Up @@ -122,7 +124,8 @@ def check_files_exist(self, variable, start_date, end_date, directory):

# Recorrer los meses
for month in months:
days = self.generate_days() # Array con los días '01' a '31'
_, num_days_in_month = calendar.monthrange(year, int(month))
days = [f"{day:02d}" for day in range(1, num_days_in_month + 1)] # Días en formato '01', '02', etc.

# Recorrer los días
for day in days:
Expand Down
52 changes: 31 additions & 21 deletions src/download_forecast/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,48 @@

def main():

parser = argparse.ArgumentParser(description="Download satellite data packages")
try:

parser.add_argument("-o", "--outputs", help="Outputs path", required=True)
parser.add_argument("-s", "--startDate", help="Start date to download example: 2024-07", required=True)
parser.add_argument("-e", "--endDate", help="End date to download example: 2024-09", required=True)
parser.add_argument("-c", "--country", help="Country", required=True)
parser.add_argument("-w", "--workspace", help="Geoserver workspace", required=True)
parser = argparse.ArgumentParser(description="Download satellite data packages")

parser.add_argument("-o", "--outputs", help="Outputs path", required=True)
parser.add_argument("-s", "--startDate", help="Start date to download example: 2024-07", required=True)
parser.add_argument("-e", "--endDate", help="End date to download example: 2024-09", required=True)
parser.add_argument("-c", "--country", help="Country", required=True)
parser.add_argument("-d", "--download", help="Download data path", required=True)
parser.add_argument("-w", "--workspace", help="Geoserver workspace", required=True)

args = parser.parse_args()

print("Reading inputs")
print(args)
args = parser.parse_args()

output_path = args.outputs
print("Reading inputs")
print(args)

start_date = args.startDate
output_path = args.outputs

end_date = args.endDate

country = args.country
download_path = args.download

workspace = args.workspace
start_date = args.startDate

cd = ChirpsData(output_path, country, start_date, end_date)
cd.main()
end_date = args.endDate

country = args.country

e5 = Era5Data(output_path, country, start_date, end_date)
e5.main()
workspace = args.workspace

geo = UploadGeoserver(output_path, country, start_date, end_date, workspace)
geo.main()
tools = Tools()
tools.validate_dates(start_date, end_date)

cd = ChirpsData(output_path, country, start_date, end_date, download_path)
cd.main()

e5 = Era5Data(output_path, country, start_date, end_date, download_path)
e5.main()

geo = UploadGeoserver(output_path, country, start_date, end_date, workspace)
geo.main()
except ValueError as e:
print(f"Error: {e}")

if __name__ == "__main__":
main()
12 changes: 12 additions & 0 deletions src/download_forecast/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ def has_file(self, directory):
if files: # Si hay al menos un archivo en el directorio actual
return True
return False

def validate_dates(self, start_date_str, end_date_str):

DATE_FORMAT = "%Y-%m"
# Convertir las cadenas a objetos datetime
start_date = datetime.strptime(start_date_str, DATE_FORMAT)
end_date = datetime.strptime(end_date_str, DATE_FORMAT)

# Verificar que la fecha de inicio sea menor o igual a la final
if start_date > end_date:
raise ValueError("La fecha de inicio debe ser menor o igual a la fecha final.")



class Response:
Expand Down

0 comments on commit c4de10d

Please sign in to comment.