0

I am trying to plot wind speed in v direction and wind speed in u direction on the oceans. The code below shows what i've done so far.

Is it possible to do the following?

  • overlay wind speed u and wind speed v so that we can see the sum of both wind directions at once? I tried wind_img_u+wind_img_v, but it doesn't work.
  • how can I show the wind speeds only on the oceans (so that I can still see the map of the lands).
  • make the layer/tile translucent. I tried setting the tile opacity=0.3, but it doesn't seem to work.

Thank you!

# -*- coding: utf-8 -*-
"""
Created on Fri Jul  1 10:04:39 2022

@author: xxx
"""

import ee

# Trigger the authentication flow.
ee.Authenticate()

# Initialize the library.
ee.Initialize()


wind = ee.ImageCollection('NOAA/GFS0P25')
i_date = '2022-06-30'
f_date = '2022-07-01'
# wind= ee.ImageCollection('ECMWF/ERA5/DAILY')

import folium


def add_ee_layer(self, ee_image_object, vis_params, name):
    """Adds a method for displaying Earth Engine image tiles to folium map."""
    map_id_dict = ee.Image(ee_image_object).getMapId(vis_params)
    folium.raster_layers.TileLayer(
        tiles=map_id_dict['tile_fetcher'].url_format,
        attr='Map Data &copy; <a href="https://earthengine.google.com/">Google Earth Engine</a>',
        name=name,
        overlay=True,
        control=True,
        opacity=0.3 ####THIS DOESN'T WORK
    ).add_to(self)

# Add Earth Engine drawing method to folium.
folium.Map.add_ee_layer = add_ee_layer

wind_img_u=wind.select('u_component_of_wind_10m_above_ground').filterDate(i_date,f_date).first()
wind_img_v=wind.select('v_component_of_wind_10m_above_ground').filterDate(i_date,f_date).first()
wind_img_u=wind_img_u+wind_img_v ####THIS DOESN'T WORK

# Set visualization parameters for land surface temperature.
wind_vis_params = {
    'min': -14, 'max': 14,
    'palette': ['orange', 'yellow', 'green', 'yellow', 'orange']}

ee_tiles_names = ['Wind Speed']

# Create a new map.
lat, lon = 45.77, 4.855
my_map = folium.Map(location=[lat, lon], zoom_start=5)

# Add layers to the map using a loop.
my_map.add_ee_layer(wind_img_u, wind_vis_params, 'Wind Speed U')
my_map.add_ee_layer(wind_img_v, wind_vis_params, 'Wind Speed V')

my_map.add_child(folium.LayerControl())
folium.LayerControl(collapsed = False).add_to(my_map)

my_map.save("c:/data/weather.html")
import webbrowser
webbrowser.open("c:/data/weather.html")
bitterjam
  • 117
  • 11

1 Answers1

3

Different topics, here:

  • 1. Mathematical operations on a ee.Image

There are different options to apply mathematical operations on images. In your case, you can just replace your sum by:

wind_img_uv=wind_img_u.add(wind_img_v)

by the way, you may find here an earth engine community tutorial involving many techniques to apply mathematical operations on images.

  • 2. Applying a mask over a region

Masking around oceans can be tricky because many land cover datasets are masked in the middle of oceans or sea so the technique I propose is mayby not optimal but works. It consits in importing a dataset focusing on ocean/surface water properties and masking around it. See below:

# Import a dataset focusing on oceans/surface water properties.
# Surface water temperature for exampel:
sst = ee.ImageCollection('NASA/OCEANDATA/MODIS-Aqua/L3SMI')\
    .select(['sst']).filterDate('2017-01-01', '2018-01-01')

# Define the mask
mask = sst.mean().gte(-10)

#Apply the mask
wind_img_uv = wind_img_uv.updateMask(mask)

Then, don't forget to add the layer to your folium map with:

# Add the updated layer.
my_map.add_ee_layer(wind_img_uv, wind_vis_params, 'Wind Speed U+V')
  • 3. Modifying tiles opacity on a folium map

For me passing the opacity in the add_ee_layer works well. So please check your install.

  • Thank you Guillaume! For wind speed, i've also googled that that the right operation for calculating wind speed is (u^2+v^2)^0.5. Thanks to your advice, I've calculated the windspeed as such: ``` wind_img_u=wind.select('u_component_of_wind_10m_above_ground').filterDate(i_date,f_date).first() wind_img_v=wind.select('v_component_of_wind_10m_above_ground').filterDate(i_date,f_date).first() wind_img_u=wind_img_u.pow(2) wind_img_v=wind_img_v.pow(2) wind_img=wind_img_u.add(wind_img_v) wind_img=wind_img.pow(0.5) – bitterjam Jul 04 '22 at 10:24
  • Regarding the masking, it totally works :) Regarding the opacity, you are right, there was something wrong with my folium/Spyder IDE. I restarted and it is now fine. Guillaume, once again, thank you very much for your guidance! – bitterjam Jul 04 '22 at 11:18
  • 1
    I confirm that if you want the norm of the vector and not the sum of x and y components, it is of course not (u + v) that you should compute but the euclidian norm. In your case given by (u^2+v^2)^0.5 – Guillaume Attard Jul 04 '22 at 11:31
  • Yes indeed, Pythagoras theorem, thanks! – bitterjam Jul 05 '22 at 12:47
  • Dear Guillaume, good afternoon from here. I have been stuck with a memory limit issue with EE. In case you know how to overcome this issue, please kindly show us the way, thank you! https://stackoverflow.com/questions/73009673/earth-engine-python-eeexception-user-memory-limit-exceeded – bitterjam Jul 17 '22 at 06:35