Penggunaan Google Earth Engine Python API dalam Colab Notebook (GEE-002)

Earth Engine Python API menawarkan kemampuan untuk berinteraksi langsung dengan server Earth Engine menggunakan Python. Anda dapat menggunakan modul Python yang terinstal secara lokal di perangkat Anda ataupun di dalam cloud yang dapat diakses dengan menggunakan interpreter command-line atau dengan menggunakan Jupyter.

Perbedaan antara Earth Engine dengan menggunakan API Python dan Javascript sangatlah kecil, kebanyakan hanya berkaitan dengan variaasinya dalam mendefinisikan fungsi dan variabel, kapitalisasi logical operator, dan karakter objek yang spesifik terhadap bahasa pemrogramannya.

API Earth Engine untuk Python dapat dideploy ke dalam notebook Google Colaboratory (yang interfacenya sangat mirip dengan Jupyter notebook). Colab notebook memang sebenarnya adalah Jupyter notebook yang dijalankan dalam cloud dan terintegrasi dengan Google Drive personal Anda, membuatnya mudah untuk dipersiapkan, diakses, dan dibagikan. Jika Anda merasa kurang familiar dengan Google Colab atau environment Jupyter, Anda dapat mulai mengeksplornya dengan mengunjungi Google Colab.

Gambar 1.1 — Antarmuka utama Google Colaboratory

A. Membuka Colab Notebook

Notebook dapat dibuka dari Google Drive Anda atau dari antarmuka Colaboratory. Untuk membuat notebook Colab baru, Anda dapat membuka halaman utama Colab. Dari halaman utama Google Colab, File > New > New Python 3 notebook. Jika Anda telah membuat file baru ini, Anda dapat mengaksesnya langsung dari Google Drive, double click pada file .ipynb yang telah Anda buat, atau dibuka melalui antarmuka Google Colab.

B. Mengimpor API dan Mendapatkan Credentials

Bagian ini mendemonstrasikan tentang bagaimana cara mengimpor API Earth Engine Python dan mengotentikasi aksesnya. Konten ini tersedia dalam notebook Colab.

Earth Engine API telah secara default terintegrasi dalam Google Colaboratory sehingga Anda tidak perlu melakukan instalasi layaknya pip dalam Python di perangkat Anda. Anda hanya membutuhkan proses impor dan otentikasi. Langkah-langkah ini harus dilakukan pada setiap sesi Colab atau ketika Anda memulai kernel Colab kembali atau ketika Colab VM menghendaki untuk diulang ketika Anda tidak melakukan apapun.

1) Mengimpor API

Jalankan perintah berikut untuk mengimpor API ke dalam sesi yang anda jalankan.

import ee

2) Mengotentikasi dan Menginisialisasi

Jalankan fungsi ee.Authenticate untuk mengotentikasi akses Anda ke server Earth Engine dan fungsi ee.Initialize untuk menginisialisasinya (Anda harus sudah mendaftar ke dalam Earth Engine sebelum melakukan otentikasi). Tambahkan code cell, masukkan line berikut :

# Melakukan otentikasi akun anda terhadap GEE
ee.Authenticate()

# Menginisialisasi library GEE
ee.Initialize()

Dalam langkah ini Anda akan diminta untuk memberikan akses kepada akun Earth Engine Anda.

Gambar 1.2 — Contoh perintah otentikasi

3) Tes API Anda

Tes API Anda dengan mencari ketinggian dari Gunung Merapi menggunakan data ketinggian global (SRTM 30 m). Perhatikan bahwa sebelum menggunakan API Anda harus menginisialisasinya terlebih dahulu. Jalankan script Python di bawah ini dalam cell baru.

# Print ketinggian puncak Merapidem = ee.Image('USGS/SRTMGL1_003')
xy = ee.Geometry.Point([110.4369693, -7.540696])
elev = dem.sample(xy, 30).first().get('elevation').getInfo()
print('Puncak Merapi (m):', elev, 'mdpl')

Jika Anda mendapat keluaran tinggi Puncak Merapi maka Anda berhasil menggunakan Google Colab untuk Google Earth Engine.

Gambar 1.3 — Output dari script pencarian elevasi

Updated:

This Post Has 151 Comments

  1. hello there and thank you for your information – I
    have certainly picked up something new from right here.
    I did however expertise some technical issues using this web site, since
    I experienced to reload the site many times previous to I could get it to load correctly.

    I had been wondering if your web hosting is OK? Not that I
    am complaining, but sluggish loading instances times will often affect
    your placement in google and can damage your high quality score if advertising and marketing with Adwords.
    Anyway I’m adding this RSS to my email and could look out for much more of your respective intriguing content.
    Ensure that you update this again very soon..

  2. It’s difficult to find experienced people about this subject, but you sound like you know what you’re talking about! Thanks

  3. Hi, I do think your blog may be having browser compatibility issues. Whenever I look at your web site in Safari, it looks fine however when opening in I.E., it has some overlapping issues. I simply wanted to give you a quick heads up! Besides that, excellent website!

  4. Hi, I do think this is a great site. I stumbledupon it 😉 I will return yet again since i have book-marked it. Money and freedom is the greatest way to change, may you be rich and continue to guide others.

  5. This is a very good tip especially to those new to the blogosphere. Brief but very accurate info… Thank you for sharing this one. A must read post!

  6. Oh my goodness! Incredible article dude! Many thanks, However I am having troubles with your RSS. I don’t know the reason why I cannot subscribe to it. Is there anybody else having similar RSS problems? Anybody who knows the answer can you kindly respond? Thanx!

  7. That is a good tip especially to those new to the blogosphere. Brief but very accurate info… Many thanks for sharing this one. A must read article.

  8. You have made some really good points there. I looked on the web for more info about the issue and found most people will go along with your views on this site.

  9. Howdy! I could have sworn I’ve visited your blog before but after looking at some of the articles I realized it’s new to me. Anyways, I’m definitely delighted I found it and I’ll be book-marking it and checking back often.

  10. Hello! I could have sworn I’ve been to this blog before but after going through a few of the posts I realized it’s new to me. Nonetheless, I’m definitely pleased I stumbled upon it and I’ll be bookmarking it and checking back regularly!

  11. An outstanding share! I’ve just forwarded this onto a coworker who has been conducting a little research on this. And he in fact bought me dinner due to the fact that I stumbled upon it for him… lol. So let me reword this…. Thank YOU for the meal!! But yeah, thanx for spending some time to discuss this subject here on your blog.

  12. Hi there, I think your site could be having browser compatibility issues. Whenever I take a look at your website in Safari, it looks fine but when opening in I.E., it has some overlapping issues. I merely wanted to provide you with a quick heads up! Apart from that, excellent site!

  13. I’m impressed, I must say. Seldom do I come across a blog that’s equally educative and interesting, and let me tell you, you have hit the nail on the head. The problem is something too few men and women are speaking intelligently about. Now i’m very happy I came across this in my hunt for something relating to this.

  14. Hi, There’s no doubt that your blog could be having browser compatibility problems. Whenever I take a look at your site in Safari, it looks fine but when opening in Internet Explorer, it has some overlapping issues. I simply wanted to give you a quick heads up! Besides that, great blog!

  15. An outstanding share! I have just forwarded this onto a colleague who had been doing a little research on this. And he in fact bought me dinner because I discovered it for him… lol. So let me reword this…. Thanks for the meal!! But yeah, thanx for spending the time to discuss this matter here on your internet site.

  16. Right here is the right webpage for anyone who really wants to find out about this topic. You understand a whole lot its almost hard to argue with you (not that I actually would want to…HaHa). You definitely put a new spin on a topic that has been written about for years. Excellent stuff, just excellent.

  17. After I originally left a comment I appear to have clicked the -Notify me when new comments are added- checkbox and now whenever a comment is added I get four emails with the same comment. There has to be an easy method you are able to remove me from that service? Appreciate it.

  18. Hello there! I simply wish to offer you a big thumbs up for the excellent information you’ve got here on this post. I’ll be returning to your blog for more soon.

  19. Having read this I thought it was very informative. I appreciate you taking the time and energy to put this article together. I once again find myself personally spending way too much time both reading and leaving comments. But so what, it was still worthwhile!

  20. Can I simply say what a relief to find someone that genuinely understands what they’re talking about on the internet. You actually know how to bring a problem to light and make it important. More and more people need to check this out and understand this side of the story. I can’t believe you aren’t more popular given that you certainly have the gift.

  21. Right here is the perfect web site for anyone who would like to find out about this topic. You understand a whole lot its almost hard to argue with you (not that I actually would want to…HaHa). You definitely put a new spin on a subject that’s been written about for decades. Great stuff, just great.

Leave a Reply