arrow_back

Rent-a-VM to Process Earthquake Data

登录 加入
访问 700 多个实验和课程

Rent-a-VM to Process Earthquake Data

实验 40 分钟 universal_currency_alt 1 个积分 show_chart 入门级
info 此实验可能会提供 AI 工具来支持您学习。
访问 700 多个实验和课程

GSP008

Google Cloud self-paced labs logo

Overview

Using Google Cloud to set up a virtual machine to process earthquake data frees you from IT minutia to focus on your scientific goals. You can ingest and process data, then present the results in various formats. In this lab, you will ingest real-time earthquake data published by the United States Geological Survey (USGS) and create maps that look like the following:

World map displaying earthquake indicators

In this lab you will spin up a virtual machine, access it remotely, and then manually create a pipeline to retrieve, process and publish the data.

What you will learn

In this lab, you will learn how to do the following:

  • Create a Compute Engine instance with specific security permissions.
  • SSH into the instance.
  • Install the software package Git (for source code version control).
  • Ingest data into the Compute Engine instance.
  • Transform data on the Compute Engine instance.
  • Store the transformed data on Cloud Storage.
  • Publish Cloud Storage data to the web.

Setup

Before you click the Start Lab button

Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources are made available to you.

This hands-on lab lets you do the lab activities in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials you use to sign in and access Google Cloud for the duration of the lab.

To complete this lab, you need:

  • Access to a standard internet browser (Chrome browser recommended).
Note: Use an Incognito (recommended) or private browser window to run this lab. This prevents conflicts between your personal account and the student account, which may cause extra charges incurred to your personal account.
  • Time to complete the lab—remember, once you start, you cannot pause a lab.
Note: Use only the student account for this lab. If you use a different Google Cloud account, you may incur charges to that account.

How to start your lab and sign in to the Google Cloud console

  1. Click the Start Lab button. If you need to pay for the lab, a dialog opens for you to select your payment method. On the left is the Lab Details pane with the following:

    • The Open Google Cloud console button
    • Time remaining
    • The temporary credentials that you must use for this lab
    • Other information, if needed, to step through this lab
  2. Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).

    The lab spins up resources, and then opens another tab that shows the Sign in page.

    Tip: Arrange the tabs in separate windows, side-by-side.

    Note: If you see the Choose an account dialog, click Use Another Account.
  3. If necessary, copy the Username below and paste it into the Sign in dialog.

    {{{user_0.username | "Username"}}}

    You can also find the Username in the Lab Details pane.

  4. Click Next.

  5. Copy the Password below and paste it into the Welcome dialog.

    {{{user_0.password | "Password"}}}

    You can also find the Password in the Lab Details pane.

  6. Click Next.

    Important: You must use the credentials the lab provides you. Do not use your Google Cloud account credentials. Note: Using your own Google Cloud account for this lab may incur extra charges.
  7. Click through the subsequent pages:

    • Accept the terms and conditions.
    • Do not add recovery options or two-factor authentication (because this is a temporary account).
    • Do not sign up for free trials.

After a few moments, the Google Cloud console opens in this tab.

Note: To access Google Cloud products and services, click the Navigation menu or type the service or product name in the Search field. Navigation menu icon and Search field

Task 1. Create Compute Engine instance with the necessary API access

  1. To create a Compute Engine instance, from the Navigation menu click on Compute Engine > VM instances.

  2. Click Create Instance and wait for the "Create an instance" form to load.

  3. In the Machine configuration.

    Use default Region and Zone for creating the instance.

  4. Click OS and storage.

    Click Change and select the following values:

    • Operating System: Debian
    • Version: Debian GNU/Linux 11 (bullseye) x86/64

    Click Select.

  5. Click Security.

    • In the Access scopes section, select Allow full access to all Cloud APIs.
  6. Click Create.

You'll see a green circle with a check when the instance is created.

Click Check my progress below to verify you're on track in this lab.

Create a Compute Engine instance with the necessary API access

Task 2. SSH into the instance

You can remotely access your Compute Engine instance using Secure Shell (SSH):

  1. Click the SSH button next to your newly created VM:

The VM instance details displays.

Note: Make sure your browser is not blocking pop-ups.

SSH keys are automatically transferred; no extra software is needed to ssh directly from the browser.

  1. To find some information about the Compute Engine instance, type the following into the command-line:
cat /proc/cpuinfo

You should see a similar output:

processor : 0 vendor_id : GenuineIntel cpu family : 6 model : 63 model name : Intel(R) Xeon(R) CPU @ 2.30GHz ....

Task 3. Install software

  1. Still in the SSH window, enter the following commands:
sudo apt-get update sudo apt-get -y -qq install git sudo apt-get install python-mpltoolkits.basemap
  1. Enter Y when asked if it's acceptable to use additional disk space.
sudo apt install python3-pip -y pip install --upgrade basemap basemap-data basemap-data-hires pyproj pip install matplotlib==3.3.4 numpy==1.23.5
  1. Verify that git is now installed:
git --version

You should see a similar output:

git version 2.20.1

Click Check my progress below to verify you're on track in this lab.

Install software

Task 4. Ingest USGS data

  1. Still in the SSH window, enter the following command to download the code from GitHub:
git clone https://github.com/GoogleCloudPlatform/training-data-analyst Note: If you get a git authorization error, it is likely that the GitHub URL has a typo in it. Please copy and paste the above code.
  1. Navigate to the folder corresponding to this lab:
cd training-data-analyst/CPB100/lab2b
  1. Examine the ingest code using less:
less ingest.sh

The less command allows you to view the file (Press the spacebar to scroll down; the letter b to back up a page; the letter q to quit).

  1. Enter q to exit the editor.

The program ingest.sh downloads a dataset of earthquakes in the past 7 days from the US Geological Survey. Notice where the file is downloaded to (disk or Cloud Storage.)

  1. Enter the following command to run the ingest code:
bash ingest.sh

Click Check my progress below to verify you're on track in this lab.

Ingest USGS data

Task 5. Transform the data

You will use a Python program to transform the raw data into a map of earthquake activity:

The transformation code is explained in detail in this notebook.

Feel free to read the narrative to understand what the transformation code does. The notebook itself was written in Datalab, a Google Cloud product that you will use later in this set of labs.

  1. Still in the Compute Engine instance, enter the following command to install the necessary Python packages on the Compute Engine instance:
bash install_missing.sh
  1. Enter the following command to run the transformation code:
python3 transform.py
  1. You will notice a new image file earthquakes.png in your current directory if you enter the following command:
ls -l

Click Check my progress below to verify you're on track in this lab.

Transform the data

Task 6. Create a Cloud Storage bucket

Return to the Cloud Console for this step.

  1. From the Navigation menu select Cloud Storage:

  2. Click on + Create, then create your bucket with the following characteristics:

  • Choose a globally unique bucket name (but not a name you'd like to use for your own projects), then click Continue.
  • You can leave it as Multi-Regional, or improve speed and reduce costs by making it Regional (choose the same region as your Compute Engine instance).
  • For Choose how to control access to objects, uncheck the box for Enforce public access prevention on this bucket and select Fine-grained for Access control.
  1. Then, click Create.

Take note of your bucket name. You will insert its name whenever the instructions ask for <YOUR-BUCKET>.

Task 7. Store data

You will now learn how to store the original and transformed data in Cloud Storage.

  1. In the SSH window of the Compute Engine instance, run the following, changing <YOUR-BUCKET> to the bucket name you created earlier:
gsutil cp earthquakes.* gs://<YOUR-BUCKET>/earthquakes/

This command copies the files to your bucket in Cloud Storage.

  1. Return to the Cloud Console and on the Storage Browser page click on the Refresh button near the top of the page. Now click on the bucket name then the /earthquakes folder.

You should now see the following three files in the earthquakes folder:

  • earthquakes.csv
  • earthquakes.htm
  • earthquakes.png

Click Check my progress below to verify you're on track in this lab.

Create bucket and Store data

Task 8. Publish Cloud Storage files to web

You will now publish the files in your bucket to the web.

  1. To create a publicly accessible URL for the files, click the three dots at the end of the earthquakes.htm file and select Edit access from the dropdown menu.

  2. In the overlay that appears, click the + Add entry button.

  3. Add a permission for all users by entering in the following:

  • Select Public for the Entity.
  • Enter allUsers for the Name.
  • Select Reader for the Access.
  • Then click Save.

Edit access page

  1. Repeat the above steps for earthquakes.png.

  2. Click on the name of a file and notice the URL of the published Cloud Storage file and how it relates to your bucket name and content. It should resemble the following:

https://storage.cloud.google.com/YOUR-BUCKET-NAME/earthquakes/earthquakes.png
  1. If you click on the earthquakes.png image file and then on the public URL, a new tab will be opened with the following image loaded:

World map with earthquake indicators

  1. Go ahead and close the SSH window.

Congratulations!

You have completed this lab and learned how to spin up a compute engine instance, access it remotely, then manually create a pipeline to retrieve, process and publish the data.

Next steps / Learn more

Here are some follow-up steps:

Google Cloud training and certification

...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.

Manual Last Updated July 1, 2025

Lab Last Tested July 1, 2025

Copyright 2025 Google LLC. All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.

准备工作

  1. 实验会创建一个 Google Cloud 项目和一些资源,供您使用限定的一段时间
  2. 实验有时间限制,并且没有暂停功能。如果您中途结束实验,则必须重新开始。
  3. 在屏幕左上角,点击开始实验即可开始

使用无痕浏览模式

  1. 复制系统为实验提供的用户名密码
  2. 在无痕浏览模式下,点击打开控制台

登录控制台

  1. 使用您的实验凭证登录。使用其他凭证可能会导致错误或产生费用。
  2. 接受条款,并跳过恢复资源页面
  3. 除非您已完成此实验或想要重新开始,否则请勿点击结束实验,因为点击后系统会清除您的工作并移除该项目

此内容目前不可用

一旦可用,我们会通过电子邮件告知您

太好了!

一旦可用,我们会通过电子邮件告知您

一次一个实验

确认结束所有现有实验并开始此实验

使用无痕浏览模式运行实验

请使用无痕模式或无痕式浏览器窗口运行此实验。这可以避免您的个人账号与学生账号之间发生冲突,这种冲突可能导致您的个人账号产生额外费用。