I need to plot together the salinity in background and ocean coordinates as a polygon (identifying the basin). Find a manner the .nc recognize my .txt, and separete only the basin identificate.
For example, I have salinity (.nc) all the oceans and the coordinates of Indian Ocean (.txt). So, I need identify only the coordinates the Indian Ocean at the .nc and separate this basin/data to my future analysis I have two files:
salinity.nc (georeferenced salinity data in Latxlon)
#salinity (.nc)
salinity = xr.open_dataset('...salinity.nc')
salinity
salinity.coords['lon'] = ((salinity.coords['lon'] + 180) % 360) - 180
salinity = salinity.sortby(salinity.lon)
lon = salinity['lon']
lat = salinity['lat']
fig=plt.figure(figsize=(10,8))
#plot
ax = fig.add_subplot(111, projection=crs.PlateCarree())
im = ax.contourf(lon, lat, salinity, cmap="Spectral_r", extend="both")
ocean.txt (a list with 666 rows x 2 columns, in each row a latxlon point)
#indianocean (.txt)
indian = pd.read_csv('.....indianocean.txt', sep=';')
indian
#plot
fig = plt.figure(figsize = (12,12))
m = Basemap()
m.plot(indian.lon, indian.lat, marker=None,color='blue')
Updating...
I'm using a shapefile to test, could plot the shape in a map, but I need to extract the salinity data only from my shapefile coordinates.
salinity = xr.open_dataset('...salinity.nc')
indshp = gpd.read_file('....indcoord.shp')
#plot
fig=plt.figure(figsize=(10,8))
ax = fig.add_subplot(111, projection=ccrs.PlateCarree())
ax.add_geometries(indshp.geometry, crs=ccrs.PlateCarree(), facecolor='none', edgecolor='red', lw =2)
im = ax.contourf(lon, lat, salinity, cmap="Spectral_r", extend="both")
Now, how I could use the salinity data only of the shapefile?
Thanks so much!


