# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # Plotting with cartopy
#

import numpy as np
import matplotlib.pyplot as plt
import xarray as xr
import cartopy.crs as ccrs

# # Read in data using xarray
# - Read in the Saildrone USV file either from a local disc or using OpenDAP.
# `xr.open_dataset(filename_usv).rename({'longitude':'lon','latitude':'lat'})`
#

filename_usv = './data/saildrone-gen_5-antarctica_circumnavigation_2019-sd1020-20190119T040000-20190803T043000-1440_minutes-v1.1564857794963.nc'
ds_usv = 


# * Read in satellite data.  Mask land using `.where(ds_sst.mask==1)` and plot the results

#If you are offline use the first url
#url = './data/20111101120000-CMC-L4_GHRSST-SSTfnd-CMC0.2deg-GLOB-v02.0-fv02.0.nc')
url = 'https://podaac-opendap.jpl.nasa.gov/opendap/allData/ghrsst/data/GDS2/L4/GLOB/CMC/CMC0.2deg/v2/2011/305/20111101120000-CMC-L4_GHRSST-SSTfnd-CMC0.2deg-GLOB-v02.0-fv02.0.nc'
ds_sst = 


#
# ## explore the in situ data and quickly plot using cartopy
#
# * first set up the axis with the projection you want: https://scitools.org.uk/cartopy/docs/latest/crs/projections.html
#
# * plot to that axis and tell the projection that your data is in
# * set a background image
# * draw coastlines
# * add a colorbary and label it

# +
#for polar data, plot temperature
ax = plt.axes(projection=ccrs.SouthPolarStereo())

(ds_sst.analysed_sst-273.15).plot(ax=ax, transform=ccrs.PlateCarree(),vmin=0,vmax=12)

cs1 = ax.scatter(ds_usv.lon, ds_usv.lat, transform=ccrs.PlateCarree(),s=10.0, c=ds_usv.TEMP_CTD_MEAN, edgecolor='none', cmap='jet',vmin=0,vmax=12)

ax.set_extent([-180, 180, -90, -45], crs=ccrs.PlateCarree())

ax.background_img('ne_shaded')

ax.coastlines(resolution='50m')

cax = plt.colorbar(cs1)

cax.set_label('SST (K)')
# -

# # Exercise!

# +
#now you try to plot plot salinity  ds_usv.SAL_MEAN


# -

# # Read in Baja Saildrone data
# * rename lat and lon
# `xr.open_dataset(url).rename({'longitude':'lon','latitude':'lat'})`

#read in the Baja Saildrone data
url = 'https://podaac-opendap.jpl.nasa.gov/opendap/hyrax/allData/insitu/L2/saildrone/Baja/saildrone-gen_4-baja_2018-sd1002-20180411T180000-20180611T055959-1_minutes-v1.nc'
ds_usv = 


# # Exercise! Plot the Baja data and set the extent of your figure

#for NON polar ds_usv data, use ccrs.PlateCarree()
lonmin,lonmax = ds_usv.lon.min().data-2,ds_usv.lon.max().data+2
latmin,latmax = ds_usv.lat.min().data-2,ds_usv.lat.max().data+2


# now add an extent to your figure
ax.set_xlim(lonmin,lonmax)
ax.set_ylim(latmin,latmax)


StarcoderdataJupyterScriptsDedupFiltered