eodags1.py 2.75 KB
Newer Older
Lozac'h Loic's avatar
Lozac'h Loic committed
1
2
3
4
5
6
7
8
9
'''
Created on 18 juin 2021

@author: loic
'''
import os
from eodag.utils.logging import setup_logging
from eodag.api.core import EODataAccessGateway
from frozenapp.models import TileEnvelope
Lozac'h Loic's avatar
Lozac'h Loic committed
10
11
12
13
from django.contrib.gis.db.models.functions import Transform
from eodag.utils import ProgressCallback
from contextlib import closing
from io import StringIO
Lozac'h Loic's avatar
Lozac'h Loic committed
14

Lozac'h Loic's avatar
Lozac'h Loic committed
15
16
17
18
19
# os.environ["EODAG__PEPS__AUTH__CREDENTIALS__USERNAME"] = "loic.lozach"
# os.environ["EODAG__PEPS__AUTH__CREDENTIALS__PASSWORD"] = "PMUQc22$"
# os.environ["EODAG__SCIHUB__AUTH__CREDENTIALS__USERNAME"] = "loic.lozach"
# os.environ["EODAG__SCIHUB__AUTH__CREDENTIALS__PASSWORD"] = "PMUQc22$"
CONFIG_SCIHUB_ENDPOINT="https://apihub.copernicus.eu/apihub/"
Lozac'h Loic's avatar
Lozac'h Loic committed
20
21
22
23
24
25
26
27
28

class EodagS1Downloader():
    '''
    classdocs
    '''
    
    mEODataAccessGateway = None
    user_conf_file_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),"eodag/user_conf.yml")
    locations_conf_path = None
Lozac'h Loic's avatar
Lozac'h Loic committed
29
#     providers_conf_file_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),"eodag/providers.yml")
Lozac'h Loic's avatar
Lozac'h Loic committed
30
31
32
33
34
35


    def __init__(self, mrgstile, startdate, enddate):
        '''
        Constructor
        '''
Lozac'h Loic's avatar
Lozac'h Loic committed
36
        setup_logging(verbose=3)
Lozac'h Loic's avatar
Lozac'h Loic committed
37
        
Lozac'h Loic's avatar
Lozac'h Loic committed
38
        qs_tile =  TileEnvelope.objects.annotate(wgs84=Transform('geom',4326)).filter(tile__exact=mrgstile
Lozac'h Loic's avatar
Lozac'h Loic committed
39
40
41
42
                                                  )
        if len(qs_tile) != 1 :
            print("Can't find tile "+mrgstile)
            exit()
Lozac'h Loic's avatar
Lozac'h Loic committed
43
44
45
            
#         geomwgs84 = Transform(qs_tile[0].geom, 4326)
        print(qs_tile[0].wgs84)
Lozac'h Loic's avatar
Lozac'h Loic committed
46
        
Lozac'h Loic's avatar
Lozac'h Loic committed
47
        mpolywkt= str(qs_tile[0].wgs84.ewkt).split(";")
Lozac'h Loic's avatar
Lozac'h Loic committed
48
49
50
        print(mpolywkt[1])
        
        self.mEODataAccessGateway = EODataAccessGateway(self.user_conf_file_path)
Lozac'h Loic's avatar
Lozac'h Loic committed
51
52
        print("debug")
        print(self.mEODataAccessGateway.get_preferred_provider())
Lozac'h Loic's avatar
Lozac'h Loic committed
53
54
        
        product_type = 'S1_SAR_GRD'
Lozac'h Loic's avatar
Lozac'h Loic committed
55
        sensor_mode = 'IW'
Lozac'h Loic's avatar
Lozac'h Loic committed
56
57
58
        
        products, estimated_total_nbr_of_results = self.mEODataAccessGateway.search(
                productType=product_type,
Lozac'h Loic's avatar
Lozac'h Loic committed
59
                sensoroperationalmode=sensor_mode,
Lozac'h Loic's avatar
Lozac'h Loic committed
60
61
62
63
64
65
66
67
68
                start=startdate,
                end=enddate,
                geom=mpolywkt[1]
            )
        
        print(
                f"The search has found an estimated number of {estimated_total_nbr_of_results} products matching "
                f"our criteria. It has returned the first {len(products)} ones available."
            )
Lozac'h Loic's avatar
Lozac'h Loic committed
69
70
71
72
73
74
75
        for prod in products:
            print(prod.as_dict()['properties']["identifier"])
            
        print("Starting Download...")
        with closing(StringIO()) as tqdm_out:
            with ProgressCallback(file=tqdm_out) as bar:
                self.mEODataAccessGateway.download_all(products, bar, 30, 2880, extract=False, outputs_prefix="/data/S1/download")
Lozac'h Loic's avatar
Lozac'h Loic committed
76