def descarga(): api = landsatxplore.api.API("*****@*****.**", "Pokemon22300") # Request scenes = api.search(dataset='LANDSAT_8_C1', latitude=-38.680782, longitude=-71.2800889, start_date='2019-01-24', end_date='2019-02-01', max_cloud_cover=1) #print('{} scenes found.'.format(len(scenes))) #print(scenes) for scene in scenes: #print(scene['displayId']) url = 'https://earthexplorer.usgs.gov/browse/full/landsat_8/' + scene[ 'displayId'] url_ir = 'https://earthexplorer.usgs.gov/browse/full/landsat_8/' + scene[ 'displayId'] + '_TIR' #print(url) urllib.request.urlretrieve( url, '/Users/franciscolagos/PycharmProjects/untitled/satelital_img/satelital_org_img.jpg' ) urllib.request.urlretrieve( url_ir, '/Users/franciscolagos/PycharmProjects/untitled/satelital_img/satelital_org_ir_img.jpg' ) api.logout() return True
def getEarthExplorerData(): data = json.loads(request.data) lat = float(data['lat']) lon = float(data['lon']) startDate = data['startDate'] endDate = data['endDate'] # today = date.today() # yearAgo = today + relativedelta(years = -1) # today = today.strftime('%Y-%m-%d') # yearAgo = yearAgo.strftime('%Y-%m-%d') password = getUSGSPassword() api = landsatxplore.api.API('sukhvir', password) scenes = api.search(dataset='LANDSAT_ETM_C1', latitude=lat, longitude=lon, start_date=startDate, end_date=endDate, max_cloud_cover=10) api.logout() result = { 'scenes': scenes[0:10], 'totalDataLength': len(scenes), # 'startDate': yearAgo, # 'endDate': today, } return result
def DownloadingLandsat(self): ''' # Initialize a new API instance and get an access key api = landsatxplore.api.API('Boutaina', 'boutaina123456789') type_image=self.dlg.combo_sat.currentText() stratDate=self.dlg.dateEditStart.date().toString('yyyy-MM-dd') endDate=self.dlg.dateEditEnd.date().toString('yyyy-MM-dd') cloudpoucentage=self.dlg.cloudslider.value() varLat=36.04305 varLong=-5.08955 # Request scenes = api.search( dataset=type_image, latitude=varLat, longitude=-varLong, start_date=stratDate, end_date=endDate, max_cloud_cover=cloudpoucentage) ''' # Initialize a new API instance and get an access key api = landsatxplore.api.API('Boutaina', 'boutaina123456789') # Request var_latitude = 36.04941 var_longitude = -5.18683 var_datedebut = self.dlg.dateEditStart.date().toString('yyyy-MM-dd') var_datefin = self.dlg.dateEditEnd.date().toString('yyyy-MM-dd') var_cloud = self.dlg.cloudslider.value() var_typeSat = self.dlg.combo_sat.currentText() print(var_cloud) scenes = api.search(dataset=var_typeSat, latitude=var_latitude, longitude=var_longitude, start_date=var_datedebut, end_date=var_datefin, max_cloud_cover=int(var_cloud)) print('{} Results found/النتائج المتوفرة:'.format(len(scenes))) self.dlg.lbl_number_found.setText( '{} Results found/النتائج المتوفرة:'.format(len(scenes))) for scene in scenes: print(scene['acquisitionDate']) print('&&&&&&&' + str(scene['cloudCover']) + '&&&&&&&&&') i = 0 self.dlg.tableResult.clear() for scene in scenes: item = QtWidgets.QTableWidgetItem(scene['acquisitionDate']) self.dlg.tableResult.setItem(i, 1, item) item1 = QtWidgets.QTableWidgetItem(scene['displayId']) self.dlg.tableResult.setItem(i, 0, item1) item2 = QtWidgets.QTableWidgetItem(scene['browseUrl']) self.dlg.tableResult.setItem(i, 2, item2) item3 = QtWidgets.QTableWidgetItem(str(scene['cloudCover'])) self.dlg.tableResult.setItem(i, 3, item3) i = i + 1 api.logout()
def query_images(x_list, y_list, start_date, stop_date, only_sentinel=False): bbox_poly = Polygon([[min(x_list), min(y_list)], [max(x_list), min(y_list)], [max(x_list), max(y_list)], [min(x_list), max(y_list)], [min(x_list), min(y_list)]]) api = SentinelAPI(sentineluser, sentinelpwd, 'https://scihub.copernicus.eu/dhus') print(bbox_poly) print(start_date.strftime("%Y%m%d")) print(stop_date.strftime("%Y%m%d")) print(max_cloud) products = api.query(bbox_poly, date=(start_date.strftime("%Y%m%d"), stop_date.strftime("%Y%m%d")), platformname='Sentinel-2', processinglevel='Level-2A', cloudcoverpercentage=(0, max_cloud)) products_df = api.to_dataframe(products) numero_products = products_df.shape if numero_products[0] > 0: products_df = products_df.sort_values(by='beginposition') num_record_s2, campi = products_df.shape first_available_s2_imm = products_df['beginposition'][0] if (only_sentinel): return products_df, 0 api = landsatxplore.api.API(landsatuser, landsatpwd) scenes = api.search(dataset='LANDSAT_8_C1', start_date=start_date.isoformat(), end_date=first_available_s2_imm.isoformat(), bbox=(min(y_list), min(x_list), max(y_list), max(x_list)), max_results=1000, max_cloud_cover=max_cloud) scenes_df = pd.DataFrame(scenes) numero_scene = scenes_df.shape if numero_scene[0] > 0: scenes_df = scenes_df.sort_values(by='acquisitionDate') num_record_landsat, campi = scenes_df.shape return products_df, scenes_df
def landsat8_search(dataset='LANDSAT_8_C1', bbox=(), start_date='', end_date='', max_cloud_cover=20): # Initialize a new API instance and get an access key username = '******' password = '******' api = landsatxplore.api.API(username, password) # Request # scences is a list, each item in this list is dict scenes = api.search( dataset= dataset, # [LANDSAT_TM_C1|LANDSAT_ETM_C1|LANDSAT_8_C1] TM: Landsat4 5 ETM: Landsat7 bbox=bbox, # (xmin, ymin, xmax, ymax) format start_date=start_date, # YYYY-MM-DD end_date=end_date, # YYYY-MM-DD, must have this max_cloud_cover= max_cloud_cover, # int Max. cloud cover in percent (1-100). max_results=40000) # can not exceed 50000 api.logout() return scenes
# enter user information username = "" password = "" dataset = 'LANDSAT_ETM_C1' outputFolder = './data' # enter location information latitude = 0 longitutde = 0 start_date = 'yyyy-mm-dd' end_date = 'yyyy-mm-dd' max_cloud_cover = 0 api = landsatxplore.api.API(username, password) #Scene Requests scenes = api.search(data, latitude, longitude, start_date, end_date, max_cloud_cover) for scene in scenes: ee.download(scene['entityID'], output_dir = outputFolder) ee.logout() api.logout()
from datetime import date, datetime import tarfile import traceback import landsatxplore.api from landsatxplore.earthexplorer import EarthExplorer from tqdm import tqdm # Initialize a new API instance and get an access key api = landsatxplore.api.API("remoteSensingErsl", "ErslRemoteSensing00") print("Searching for scenes") # Request # Images before 1984 scenes_early = api.search(dataset='LANDSAT_MSS_C1', bbox=(51.1931, 11.2830, 53.5990, 14.8865), start_date='1981-01-01', end_date='1983-12-31', max_cloud_cover=15, max_results=1000) # Images after 1984 scenes = api.search(dataset='LANDSAT_TM_C1', bbox=(51.1931, 11.2830, 53.5990, 14.8865), start_date='1984-01-01', end_date='1995-12-31', max_cloud_cover=15, max_results=1000) today = date.today() datemin = datetime.strptime("05-01", "%m-%d").date().replace(year=today.year) datemax = datetime.strptime("08-31", "%m-%d").date().replace(year=today.year) selected_scenes = []
try: api = landsatxplore.api.API(usr, psw) print(' -> api:', api) except: print(' -> login failed', sys.exc_info()[0]) boolErr = True errCount = errCount + 1 break # ------------------------------------------------------------------------------------------------------- print('Search: ',time.strftime("%d.%m.%Y %H:%M:%S"), ' StationId:', row['AirQualityStation'], ' lat:', row['Latitude'], ' lon:', row['Longitude'], ' DataMin:', row['DataMin'], ' DataMax:', row['DataMax']) aa = row['DataMin'].strftime("%Y-%m-%d") try: scenes = api.search( dataset='LANDSAT_8_C1', latitude= float(row['Latitude']), longitude= float(row['Longitude']), start_date = row['DataMin'].strftime("%Y-%m-%d"), end_date = row['DataMax'].strftime("%Y-%m-%d"), max_cloud_cover=100, max_results=1000) except: print("Unexpected error:", sys.exc_info()[0]) boolErr = True break print('End search: ', time.strftime("%d.%m.%Y %H:%M:%S"), ' ===> {} scenes found.'.format(len(scenes))) # ------------------------------------------------------------------------------------------------------- try: api.logout() except: print("Unexpected error:", sys.exc_info()[0]) print('Logged api out: ', time.strftime("%d.%m.%Y %H:%M:%S")) # -------------------------------------------------------------------------------------------------------
s3 = boto3.client('s3') s3_resource = boto3.resource('s3') data = pd.read_csv("all_regions_data.csv") data = data[["place", "lat", "lon"]] data = data.drop_duplicates() ################################################################## for _, row in data.iterrows(): api = landsatxplore.api.API(username, password) scenes = api.search(dataset='LANDSAT_8_C1', latitude=row['lat'], longitude=row['lon'], start_date='2016-01-01', end_date='2019-11-01', max_cloud_cover=10) print('{} scenes found.'.format(len(scenes))) length = len(scenes) place = row['place'] place_dir = os.path.join("landsat", f'{place}') path = os.path.join(f'{os.getcwd()}', f'{place_dir}') print(path) if not os.path.exists(path): os.makedirs(path)
import landsatxplore.api # Initialize a new API instance and get an access key api = landsatxplore.api.API('student_boku', 'boku_vfegis_2019') # Request scenes = api.search(dataset='ASTER_L1T', latitude=46.982292, longitude=-101.53849, start_date='2010-01-01', end_date='2019-01-01', max_cloud_cover=10) print('{} scenes found.'.format(len(scenes))) for scene in scenes: print(scene['acquisitionDate']) api.logout()
#api = landsatxplore.api.API(username, password) # ## Perform a request. Results are returned in a dictionnary #response = api.request('<request_code>', parameter1=value1, parameter2=value2) # ## Log out #api.logout() #import landsatxplore.api # Initialize a new API instance and get an access key api = landsatxplore.api.API('username', 'password') # Request scenes = api.search(dataset='LANDSAT_ETM_C1', latitude=19.53, longitude=-1.53, start_date='1995-01-01', end_date='1997-01-01', max_cloud_cover=10) print('{} scenes found.'.format(len(scenes))) for scene in scenes: print(scene['acquisitionDate']) api.logout() ee = EarthExplorer('username', 'password') ee.download(scene_id='LT51960471995178MPS00', output_dir='./data') ee.logout()
import landsatxplore.api from landsatxplore.earthexplorer import EarthExplorer api = landsatxplore.api.API('******', '*******') ee = EarthExplorer('******', '******') # Request scenes = api.search(dataset='LANDSAT_8_C1', latitude=37.01, longitude=-5.93, start_date=m, end_date=t, max_cloud_cover=100) print('{} scenes found.'.format(len(scenes))) for scene in scenes: sc = scene['displayId'] if scene['displayId'].split('_')[2] == '202034': print('downloading:', sc) ee.download(scene_id=sc, output_dir='/home/last/Descargas') ee.logout() api.logout()
import landsatxplore.api # Initialize a new API instance and get an access key api = landsatxplore.api.API('maria_sum123', 'EARTHmaria123') # Request scenes = api.search(dataset='LANDSAT_8', latitude=19.53, longitude=-1.53, start_date='2015-01-01', end_date='2016-01-01', max_cloud_cover=10) print('{} scenes found.'.format(len(scenes))) for scene in scenes: print(scene['acquisitionDate']) api.logout()
import os import arrow import landsatxplore.api from landsatxplore.earthexplorer import EarthExplorer api = landsatxplore.api.API(os.environ.get('usgs_user'), os.environ.get('usgs_password')) ee = EarthExplorer(os.environ.get('usgs_user'), os.environ.get('usgs_password')) today = arrow.now().format('YYYY-MM-DD') month = arrow.now().shift(days=-45).format('YYYY-MM-DD') scenes_oli = api.search( dataset='LANDSAT_8_C1', latitude=37.47944444, longitude=-6.25861111, start_date=month, end_date=today, max_cloud_cover=100, max_results=1000) scenes_etm = api.search( dataset='LANDSAT_ETM_C1', latitude=37.47944444, longitude=-6.25861111, start_date=month, end_date=today, max_cloud_cover=100, max_results=1000) scenes_tm = api.search( dataset='LANDSAT_TM_C1',