import xarray as xr
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
from salishsea_tools import timeseries_tools
coordinates = xr.open_dataset('/home/vdo/MEOPAR/NEMO-forcing/grid/coordinates_seagrid_SalishSea201702.nc',decode_times=False)
bathy = xr.open_dataset('/home/vdo/MEOPAR/NEMO-forcing/grid/bathymetry_201702.nc')
coordinates
<xarray.Dataset> Dimensions: (time: 1, x: 398, y: 898) Coordinates: * time (time) float32 9.96921e+36 Dimensions without coordinates: x, y Data variables: nav_lon (y, x) float32 -123.429 -123.424 -123.419 -123.413 -123.408 ... nav_lat (y, x) float32 46.8597 46.8615 46.8634 46.8653 46.8672 46.8691 ... glamt (time, y, x) float64 -123.4 -123.4 -123.4 -123.4 -123.4 -123.4 ... glamu (time, y, x) float64 -123.4 -123.4 -123.4 -123.4 -123.4 -123.4 ... glamv (time, y, x) float64 -123.4 -123.4 -123.4 -123.4 -123.4 -123.4 ... glamf (time, y, x) float64 -123.4 -123.4 -123.4 -123.4 -123.4 -123.4 ... gphit (time, y, x) float64 46.86 46.86 46.86 46.87 46.87 46.87 46.87 ... gphiu (time, y, x) float64 46.86 46.86 46.86 46.87 46.87 46.87 46.87 ... gphiv (time, y, x) float64 46.86 46.86 46.87 46.87 46.87 46.87 46.87 ... gphif (time, y, x) float64 46.86 46.86 46.87 46.87 46.87 46.87 46.87 ... e1t (time, y, x) float64 454.9 454.9 454.9 454.8 454.8 454.8 454.8 ... e1u (time, y, x) float64 454.9 454.9 454.8 454.8 454.8 454.8 454.8 ... e1v (time, y, x) float64 454.7 454.7 454.7 454.7 454.7 454.7 454.7 ... e1f (time, y, x) float64 454.7 454.7 454.7 454.7 454.7 454.7 454.7 ... e2t (time, y, x) float64 407.2 419.5 428.0 434.3 439.1 443.1 446.4 ... e2u (time, y, x) float64 413.4 423.7 431.1 436.7 441.1 444.8 447.8 ... e2v (time, y, x) float64 396.9 415.5 426.2 433.3 438.6 442.7 446.2 ... e2f (time, y, x) float64 406.2 420.9 429.8 436.0 440.7 444.5 447.6 ... Attributes: history: [2017-02-14] Compressed Fraser river region
bathy.Bathymetry.plot()
<matplotlib.collections.QuadMesh at 0x7f5cbb678dd8>
strat = xr.open_dataset('/home/vdo/MEOPAR/NEMO-forcing/initial_strat/TSforDeepenByGridThicknessDec.nc')
strat
<xarray.Dataset> Dimensions: (deptht: 40, time_counter: 1, x: 398, y: 898) Coordinates: nav_lat (y, x) float32 46.8597 46.8615 46.8634 46.8653 46.8672 ... nav_lon (y, x) float32 -123.429 -123.424 -123.419 -123.413 ... * deptht (deptht) float32 0.5 1.5 2.50001 3.50003 4.50007 5.50015 ... * time_counter (time_counter) float32 9.96921e+36 Dimensions without coordinates: x, y Data variables: vosaline (time_counter, deptht, y, x) float32 0.0 0.0 0.0 0.0 0.0 ... votemper (time_counter, deptht, y, x) float32 0.0 0.0 0.0 0.0 0.0 ... Attributes: Conventions: CF-1.6 title: Salinity Temperature Initial Conditions based on Dec 2002 r... institution: Dept of Earth, Ocean & Atmospheric Sciences, University of ... source: https://bitbucket.org/salishsea/tools/src/tip/Find TS for n... references: REQUIRED comment: Salinity and Temperature conditions from Dec 2002 file for ... history: [2016-02-01 Deepened]
chopped_bathy = bathy.where(bathy.y > 335, drop = True)
chopped_bathy.Bathymetry.plot()
<matplotlib.collections.QuadMesh at 0x7f5cbb3e23c8>
bathy2 = chopped_bathy.where(chopped_bathy.x > 115,drop = True)
bathy2.Bathymetry.plot()
<matplotlib.collections.QuadMesh at 0x7f5cbb293518>
coords1 = coordinates.where(coordinates.y > 335, drop = True)
coords2 = coords1.where(coords1.x > 115, drop = True)
coords2
<xarray.Dataset> Dimensions: (time: 1, x: 282, y: 562) Coordinates: * time (time) float32 9.96921e+36 Dimensions without coordinates: x, y Data variables: nav_lon (y, x) float32 -123.914 -123.909 -123.904 -123.899 -123.894 ... nav_lat (y, x) float32 48.4059 48.4078 48.4098 48.4117 48.4137 48.4156 ... glamt (time, y, x) float64 -123.9 -123.9 -123.9 -123.9 -123.9 -123.9 ... glamu (time, y, x) float64 -123.9 -123.9 -123.9 -123.9 -123.9 -123.9 ... glamv (time, y, x) float64 -123.9 -123.9 -123.9 -123.9 -123.9 -123.9 ... glamf (time, y, x) float64 -123.9 -123.9 -123.9 -123.9 -123.9 -123.9 ... gphit (time, y, x) float64 48.41 48.41 48.41 48.41 48.41 48.42 48.42 ... gphiu (time, y, x) float64 48.41 48.41 48.41 48.41 48.41 48.42 48.42 ... gphiv (time, y, x) float64 48.41 48.41 48.41 48.41 48.42 48.42 48.42 ... gphif (time, y, x) float64 48.41 48.41 48.41 48.41 48.42 48.42 48.42 ... e1t (time, y, x) float64 439.5 439.5 439.5 439.5 439.5 439.4 439.4 ... e1u (time, y, x) float64 439.5 439.5 439.5 439.5 439.5 439.4 439.4 ... e1v (time, y, x) float64 439.5 439.5 439.5 439.5 439.4 439.4 439.4 ... e1f (time, y, x) float64 439.5 439.5 439.5 439.5 439.4 439.4 439.4 ... e2t (time, y, x) float64 504.7 504.6 504.6 504.6 504.6 504.6 504.5 ... e2u (time, y, x) float64 504.6 504.6 504.6 504.6 504.6 504.5 504.5 ... e2v (time, y, x) float64 504.7 504.6 504.6 504.6 504.6 504.6 504.5 ... e2f (time, y, x) float64 504.6 504.6 504.6 504.6 504.6 504.5 504.5 ... Attributes: history: [2017-02-14] Compressed Fraser river region
bathy2.to_netcdf('/data/vdo/MEOPAR/SalishSeaLake/revised_bathymetry_201702.nc')
syncing
coords2.to_netcdf('/data/vdo/MEOPAR/SalishSeaLake/revised_coordinates_seagrid_SalishSea201702.nc',engine='scipy')
syncing
new_bathy
new_coords = xr.open_dataset('/home/vdo/MEOPAR/NEMO-forcing/grid/revised_coordinates_seagrid_SalishSea201702.nc',decode_times=False)
new_coords
<xarray.Dataset> Dimensions: (time: 1, x: 282, y: 562) Coordinates: * time (time) float32 9.96921e+36 Dimensions without coordinates: x, y Data variables: nav_lon (y, x) float32 -123.914 -123.909 -123.904 -123.899 -123.894 ... nav_lat (y, x) float32 48.4059 48.4078 48.4098 48.4117 48.4137 48.4156 ... glamt (time, y, x) float64 -123.9 -123.9 -123.9 -123.9 -123.9 -123.9 ... glamu (time, y, x) float64 -123.9 -123.9 -123.9 -123.9 -123.9 -123.9 ... glamv (time, y, x) float64 -123.9 -123.9 -123.9 -123.9 -123.9 -123.9 ... glamf (time, y, x) float64 -123.9 -123.9 -123.9 -123.9 -123.9 -123.9 ... gphit (time, y, x) float64 48.41 48.41 48.41 48.41 48.41 48.42 48.42 ... gphiu (time, y, x) float64 48.41 48.41 48.41 48.41 48.41 48.42 48.42 ... gphiv (time, y, x) float64 48.41 48.41 48.41 48.41 48.42 48.42 48.42 ... gphif (time, y, x) float64 48.41 48.41 48.41 48.41 48.42 48.42 48.42 ... e1t (time, y, x) float64 439.5 439.5 439.5 439.5 439.5 439.4 439.4 ... e1u (time, y, x) float64 439.5 439.5 439.5 439.5 439.5 439.4 439.4 ... e1v (time, y, x) float64 439.5 439.5 439.5 439.5 439.4 439.4 439.4 ... e1f (time, y, x) float64 439.5 439.5 439.5 439.5 439.4 439.4 439.4 ... e2t (time, y, x) float64 504.7 504.6 504.6 504.6 504.6 504.6 504.5 ... e2u (time, y, x) float64 504.6 504.6 504.6 504.6 504.6 504.5 504.5 ... e2v (time, y, x) float64 504.7 504.6 504.6 504.6 504.6 504.6 504.5 ... e2f (time, y, x) float64 504.6 504.6 504.6 504.6 504.6 504.5 504.5 ... Attributes: history: [2017-02-14] Compressed Fraser river region
timerange1 = ['2017-01-01','2017-02-01']
Jan_time_series = timeseries_tools.make_filename_list(timerange1,'T',model = 'nowcast-green',resolution='d')
Jan_data = xr.open_mfdataset(Jan_time_series)
Jan_data
<xarray.Dataset> Dimensions: (axis_nbounds: 2, deptht: 40, nvertex: 4, time_counter: 31, x: 398, y: 898) Coordinates: nav_lat (y, x) float32 46.8597 46.8615 46.8634 46.8653 ... nav_lon (y, x) float32 -123.429 -123.424 -123.419 -123.413 ... * deptht (deptht) float32 0.5 1.5 2.50001 3.50003 4.50007 ... time_centered (time_counter) datetime64[ns] 2017-01-01T12:00:00 ... * time_counter (time_counter) datetime64[ns] 2017-01-01T12:00:00 ... Dimensions without coordinates: axis_nbounds, nvertex, x, y Data variables: bounds_lon (time_counter, y, x, nvertex) float32 -123.429 ... bounds_lat (time_counter, y, x, nvertex) float32 46.8597 ... area (time_counter, y, x) float32 180762.0 189238.0 ... deptht_bounds (time_counter, deptht, axis_nbounds) float32 0.0 ... sossheig (time_counter, y, x) float64 0.0 0.0 0.0 0.0 0.0 ... time_centered_bounds (time_counter, axis_nbounds) float64 3.692e+09 ... time_counter_bounds (time_counter, axis_nbounds) float64 3.692e+09 ... votemper (time_counter, deptht, y, x) float64 0.0 0.0 0.0 ... vosaline (time_counter, deptht, y, x) float64 0.0 0.0 0.0 ... buoy_n2 (time_counter, deptht, y, x) float64 0.0 0.0 0.0 ... mixed_depth (time_counter, y, x) float64 0.0 0.0 0.0 0.0 0.0 ... Attributes: name: SalishSea_1d_20170101_20170101 description: ocean T grid variables title: ocean T grid variables Conventions: CF-1.5 production: An IPSL model timeStamp: 2017-Jan-02 00:31:31 PST
averaged_Jan_data = Jan_data.mean(dim='time_counter')
averaged_Jan_data
<xarray.Dataset> Dimensions: (axis_nbounds: 2, deptht: 40, nvertex: 4, x: 398, y: 898) Coordinates: nav_lat (y, x) float32 46.8597 46.8615 46.8634 46.8653 ... nav_lon (y, x) float32 -123.429 -123.424 -123.419 -123.413 ... * deptht (deptht) float32 0.5 1.5 2.50001 3.50003 4.50007 ... Dimensions without coordinates: axis_nbounds, nvertex, x, y Data variables: bounds_lon (y, x, nvertex) float32 -123.429 -123.429 -123.429 ... bounds_lat (y, x, nvertex) float32 46.8597 46.8597 46.8597 ... area (y, x) float32 180762.0 189238.0 194104.0 197344.0 ... deptht_bounds (deptht, axis_nbounds) float32 0.0 1.0 1.0 2.00001 ... sossheig (y, x) float64 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... time_centered_bounds (axis_nbounds) float64 3.694e+09 3.694e+09 time_counter_bounds (axis_nbounds) float64 3.694e+09 3.694e+09 votemper (deptht, y, x) float64 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... vosaline (deptht, y, x) float64 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... buoy_n2 (deptht, y, x) float64 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... mixed_depth (y, x) float64 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
timerange2 = ['2016-06-01','2016-07-01']
Jun_time_series = timeseries_tools.make_filename_list(timerange2,'T',model='nowcast-green',resolution='d')
Jun_data = xr.open_mfdataset(Jun_time_series)
averaged_Jun_data = Jun_data.mean(dim='time_counter',keep_attrs=True)
averaged_Jun_data
<xarray.Dataset> Dimensions: (axis_nbounds: 2, deptht: 40, nvertex: 4, x: 398, y: 898) Coordinates: * deptht (deptht) float32 0.5 1.5 2.50001 3.50003 4.50007 ... nav_lat (y, x) float32 46.8597 46.8615 46.8634 46.8653 ... nav_lon (y, x) float32 -123.429 -123.424 -123.419 -123.413 ... Dimensions without coordinates: axis_nbounds, nvertex, x, y Data variables: area (y, x) float32 180762.0 189238.0 194104.0 197344.0 ... bounds_lat (y, x, nvertex) float32 46.8597 46.8597 46.8597 ... bounds_lon (y, x, nvertex) float32 -123.429 -123.429 -123.429 ... buoy_n2 (deptht, y, x) float64 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... deptht_bounds (deptht, axis_nbounds) float32 0.0 1.0 1.0 2.00001 ... mixed_depth (y, x) float64 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... sossheig (y, x) float64 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... time_centered_bounds (axis_nbounds) float64 3.675e+09 3.675e+09 time_counter_bounds (axis_nbounds) float64 3.675e+09 3.675e+09 vosaline (deptht, y, x) float64 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... votemper (deptht, y, x) float64 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... Attributes: name: SalishSea_1d_20160601_20160601 description: ocean T grid variables title: ocean T grid variables Conventions: CF-1.5 production: An IPSL model timeStamp: 2016-Jul-12 02:02:05 PDT history: Tue Jul 12 02:19:15 2016: ncks -4 -L4 -O SalishSea_1d_20160... NCO: "4.5.2"
example_strat = xr.open_dataset('/home/vdo/MEOPAR/NEMO-forcing/initial_strat/TSforDeepenByGridThickness.nc',decode_times=False)
example2 = xr.open_dataset('/home/vdo/MEOPAR/NEMO-forcing/initial_strat/TSforDeepenByGridThicknessDec.nc')
dropped_variables = ['area','bounds_lon','bounds_lat','deptht_bounds','sossheig',
'time_centered_bounds','time_counter_bounds','buoy_n2','mixed_depth']
new1 = averaged_Jan_data.drop(dropped_variables) #.shift(1)
new3
<xarray.Dataset> Dimensions: (deptht: 40, time_counter: 1, x: 398, y: 898) Coordinates: nav_lat (y, x) float32 46.8597 46.8615 46.8634 46.8653 46.8672 ... nav_lon (y, x) float32 -123.429 -123.424 -123.419 -123.413 ... * deptht (deptht) float32 0.5 1.5 2.50001 3.50003 4.50007 5.50015 ... * time_counter (time_counter) int64 3 Dimensions without coordinates: x, y Data variables: votemper (deptht, time_counter, y, x) float64 0.0 0.0 0.0 0.0 0.0 ... vosaline (deptht, time_counter, y, x) float64 0.0 0.0 0.0 0.0 0.0 ...
insert_number_here = 3
new3 = new1.assign_coords(time_counter = insert_number_here).expand_dims('time_counter',1)
USE_THIS_ONE_Jan = new3.squeeze('time_counter')
USE_THIS_ONE_Jan
<xarray.Dataset> Dimensions: (deptht: 40, x: 398, y: 898) Coordinates: nav_lat (y, x) float32 46.8597 46.8615 46.8634 46.8653 46.8672 ... nav_lon (y, x) float32 -123.429 -123.424 -123.419 -123.413 ... * deptht (deptht) float32 0.5 1.5 2.50001 3.50003 4.50007 5.50015 ... time_counter int64 3 Dimensions without coordinates: x, y Data variables: votemper (deptht, y, x) float64 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... vosaline (deptht, y, x) float64 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
USE_THIS_ONE_Jan.to_netcdf('/home/vdo/MEOPAR/NEMO-forcing/initial_strat/winter_Jan2017.nc')
syncing
USE_THIS_ONE_Jun = averaged_Jun_data.drop(dropped_variables).assign_coords(time_counter = insert_number_here).expand_dims('time_counter',1).squeeze('time_counter')
USE_THIS_ONE_Jun
<xarray.Dataset> Dimensions: (deptht: 40, x: 398, y: 898) Coordinates: * deptht (deptht) float32 0.5 1.5 2.50001 3.50003 4.50007 5.50015 ... nav_lat (y, x) float32 46.8597 46.8615 46.8634 46.8653 46.8672 ... nav_lon (y, x) float32 -123.429 -123.424 -123.419 -123.413 ... time_counter int64 3 Dimensions without coordinates: x, y Data variables: vosaline (deptht, y, x) float64 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... votemper (deptht, y, x) float64 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... Attributes: name: SalishSea_1d_20160601_20160601 description: ocean T grid variables title: ocean T grid variables Conventions: CF-1.5 production: An IPSL model timeStamp: 2016-Jul-12 02:02:05 PDT history: Tue Jul 12 02:19:15 2016: ncks -4 -L4 -O SalishSea_1d_20160... NCO: "4.5.2"
USE_THIS_ONE_Jun.to_netcdf('/home/vdo/MEOPAR/NEMO-forcing/initial_strat/summer_Jun2016.nc')
syncing
test = xr.open_dataset('/home/vdo/MEOPAR/NEMO-forcing/initial_strat/summer_Jun2016.nc')
test
<xarray.Dataset> Dimensions: (deptht: 40, x: 398, y: 898) Coordinates: * deptht (deptht) float32 0.5 1.5 2.50001 3.50003 4.50007 5.50015 ... nav_lat (y, x) float32 46.8597 46.8615 46.8634 46.8653 46.8672 ... nav_lon (y, x) float32 -123.429 -123.424 -123.419 -123.413 ... time_counter int64 3 Dimensions without coordinates: x, y Data variables: vosaline (deptht, y, x) float64 5.041 5.041 5.041 5.041 5.041 5.041 ... votemper (deptht, y, x) float64 3.092 3.092 3.092 3.092 3.092 3.092 ...
test2 = xr.open_dataset('/home/vdo/MEOPAR/NEMO-forcing/initial_strat/winter_Jan2017.nc')
test2
<xarray.Dataset> Dimensions: (deptht: 40, x: 398, y: 898) Coordinates: * deptht (deptht) float32 0.5 1.5 2.50001 3.50003 4.50007 5.50015 ... nav_lat (y, x) float32 46.8597 46.8615 46.8634 46.8653 46.8672 ... nav_lon (y, x) float32 -123.429 -123.424 -123.419 -123.413 ... time_counter int64 3 Dimensions without coordinates: x, y Data variables: vosaline (deptht, y, x) float64 5.824 5.824 5.824 5.824 5.824 5.824 ... votemper (deptht, y, x) float64 1.308 1.308 1.308 1.308 1.308 1.308 ...
new_test = test.mean(dim = ('x','y'))
saline = new_test.vosaline
temp = new_test.votemper
empty_of_variables = test.drop(['vosaline','votemper'])
#new_summer = xr.merge([empty_of_variables,saline,temp])
#new_summer.to_netcdf('/home/vdo/MEOPAR/NEMO-forcing/initial_strat/summer_Jun2016.nc')
new_test2 = test2.mean(dim=('x','y'))
empty2 = test2.drop(['vosaline','votemper'])
saline2 = new_test2.vosaline
temp2 = new_test2.votemper
#new_winter = xr.merge([empty2,saline2,temp2])
#new_winter.to_netcdf('/home/vdo/MEOPAR/NEMO-forcing/initial_strat/winter_Jan2017.nc')
new_summer
--------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-6-0e320d3f94eb> in <module>() ----> 1 new_summer NameError: name 'new_summer' is not defined
array = new_test.vosaline.values
array = np.expand_dims(array,axis=1)
array = np.expand_dims(array,axis=2)
array.shape
(40, 1, 1)
ones = np.ones((40,898,398))
ones.shape
(40, 898, 398)
new_array = array*ones
new_array.shape
(40, 898, 398)
array2 = new_test.votemper.values
array2 = np.expand_dims(array2,axis=1)
array2 = np.expand_dims(array2,axis=2)
array2 = array2*ones
array2.shape
(40, 898, 398)
new_summer = xr.Dataset({'vosaline':(['deptht','y','x'], new_array),
'votemper':(['deptht','y','x'],array2)},
coords={'deptht':(['deptht'], deptht),
'nav_lat':(['y','x'], nav_lat),
'nav_lon':(['y','x'], nav_lon),
'time_counter': 3})
#new_summer.to_netcdf('/home/vdo/MEOPAR/NEMO-forcing/initial_strat/summer_Jun2016.nc')
nav_lon = test.nav_lon.values
nav_lat = test.nav_lat.values
deptht = test.deptht.values
saline = new_test2.vosaline.values
saline = np.expand_dims(saline,axis=1)
saline = np.expand_dims(saline,axis=2)
saline = saline*ones
temp = new_test2.votemper.values
temp= np.expand_dims(temp,axis=1)
temp = np.expand_dims(temp,axis=2)
temp = temp*ones
nav_lon2 = test2.nav_lon.values
nav_lat2 = test2.nav_lat.values
deptht2 = test2.deptht.values
new_winter = xr.Dataset({'vosaline':(['deptht','y','x'], saline),
'votemper':(['deptht','y','x'],temp)},
coords={'deptht':(['deptht'], deptht2),
'nav_lat':(['y','x'], nav_lat2),
'nav_lon':(['y','x'], nav_lon2),
'time_counter': 3})
#new_winter.to_netcdf('/home/vdo/MEOPAR/NEMO-forcing/initial_strat/winter_Jan2017.nc')
new_winter
<xarray.Dataset> Dimensions: (deptht: 40, x: 398, y: 898) Coordinates: * deptht (deptht) float32 0.5 1.5 2.50001 3.50003 4.50007 5.50015 ... nav_lat (y, x) float32 46.8597 46.8615 46.8634 46.8653 46.8672 ... nav_lon (y, x) float32 -123.429 -123.424 -123.419 -123.413 ... time_counter int64 3 Dimensions without coordinates: x, y Data variables: vosaline (deptht, y, x) float64 5.824 5.824 5.824 5.824 5.824 5.824 ... votemper (deptht, y, x) float64 1.308 1.308 1.308 1.308 1.308 1.308 ...
new_summer
<xarray.Dataset> Dimensions: (deptht: 40, x: 398, y: 898) Coordinates: * deptht (deptht) float32 0.5 1.5 2.50001 3.50003 4.50007 5.50015 ... nav_lat (y, x) float32 46.8597 46.8615 46.8634 46.8653 46.8672 ... nav_lon (y, x) float32 -123.429 -123.424 -123.419 -123.413 ... time_counter int64 3 Dimensions without coordinates: x, y Data variables: vosaline (deptht, y, x) float64 5.041 5.041 5.041 5.041 5.041 5.041 ... votemper (deptht, y, x) float64 3.092 3.092 3.092 3.092 3.092 3.092 ...
new_summer.vosaline.isel(y=600).plot()
<matplotlib.collections.QuadMesh at 0x7f9e55f362e8>
mesh_mask = xr.open_dataset('/home/vdo/MEOPAR/NEMO-forcing/grid/mesh_mask201702.nc')
t_mask = mesh_mask.tmask.squeeze('t')
t_mask
<xarray.DataArray 'tmask' (z: 40, y: 898, x: 398)> [14296160 values with dtype=int8] Dimensions without coordinates: z, y, x
with_mask = xr.merge([new_summer,t_mask])
with_mask
<xarray.Dataset> Dimensions: (deptht: 40, x: 398, y: 898, z: 40) Coordinates: * deptht (deptht) float32 0.5 1.5 2.50001 3.50003 4.50007 5.50015 ... nav_lat (y, x) float32 46.8597 46.8615 46.8634 46.8653 46.8672 ... nav_lon (y, x) float32 -123.429 -123.424 -123.419 -123.413 ... time_counter int64 3 Dimensions without coordinates: x, y, z Data variables: vosaline (deptht, y, x) float64 5.041 5.041 5.041 5.041 5.041 5.041 ... votemper (deptht, y, x) float64 3.092 3.092 3.092 3.092 3.092 3.092 ... tmask (z, y, x) int8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
final_summer = with_mask.where(with_mask.tmask == 1).drop('tmask')
#final_summer.to_netcdf('/home/vdo/MEOPAR/NEMO-forcing/initial_strat/summer_Jun2016.nc')
winter_with_mask = xr.merge([new_winter,t_mask])
final_winter = winter_with_mask.where(winter_with_mask.tmask == 1).drop('tmask')
final_winter.to_netcdf('/home/vdo/MEOPAR/NEMO-forcing/initial_strat/winter_Jan2017.nc')
syncing
test = xr.open_dataset('/home/vdo/MEOPAR/NEMO-forcing/initial_strat/summer_Jun2016.nc')
test
<xarray.Dataset> Dimensions: (deptht: 40, x: 398, y: 898) Coordinates: * deptht (deptht) float32 0.5 1.5 2.50001 3.50003 4.50007 5.50015 ... nav_lat (y, x) float32 46.8597 46.8615 46.8634 46.8653 46.8672 ... nav_lon (y, x) float32 -123.429 -123.424 -123.419 -123.413 ... time_counter int64 3 Dimensions without coordinates: x, y Data variables: vosaline (deptht, y, x) float64 nan nan nan nan nan nan nan nan nan ... votemper (deptht, y, x) float64 nan nan nan nan nan nan nan nan nan ...
test.vosaline.isel(y=500).plot()
<matplotlib.collections.QuadMesh at 0x7f9e5579ca90>
test.votemper.isel(deptht=0).plot()
<matplotlib.collections.QuadMesh at 0x7f9e55683860>
test2 = xr.open_dataset('/home/vdo/MEOPAR/NEMO-forcing/initial_strat/TS20mar2016DeepSmooth.nc',decode_times=False)
test2
<xarray.Dataset> Dimensions: (deptht: 40, time_counter: 1, x: 398, y: 898) Coordinates: nav_lat (y, x) float32 46.8597 46.8615 46.8634 46.8653 46.8672 ... nav_lon (y, x) float32 -123.429 -123.424 -123.419 -123.413 ... * deptht (deptht) float32 0.5 1.5 2.50001 3.50003 4.50007 5.50015 ... * time_counter (time_counter) float32 9.96921e+36 Dimensions without coordinates: x, y Data variables: vosaline (time_counter, deptht, y, x) float32 0.0 0.0 0.0 0.0 0.0 ... votemper (time_counter, deptht, y, x) float32 0.0 0.0 0.0 0.0 0.0 ... Attributes: Conventions: CF-1.6 title: Salinity Temperature Initial Conditions based on Mar 20, 20... institution: Dept of Earth, Ocean & Atmospheric Sciences, University of ... source: https://bitbucket.org/salishsea/tools/src/tip/FindTSforSmoo... references: REQUIRED comment: Salinity and Temperature conditions from Mar 20, 2016 23:0... history: [2016-07-06 Created]
fig,ax = plt.subplots(1,1)
test2.vosaline.isel(y=500,time_counter=0).plot(ax=ax)
#ax.set_ylim((0,50))
<matplotlib.collections.QuadMesh at 0x7f9e54cf4438>
test
<xarray.Dataset> Dimensions: (deptht: 40, x: 398, y: 898) Coordinates: * deptht (deptht) float32 0.5 1.5 2.50001 3.50003 4.50007 5.50015 ... nav_lat (y, x) float32 46.8597 46.8615 46.8634 46.8653 46.8672 ... nav_lon (y, x) float32 -123.429 -123.424 -123.419 -123.413 ... time_counter int64 3 Dimensions without coordinates: x, y Data variables: vosaline (deptht, y, x) float64 nan nan nan nan nan nan nan nan nan ... votemper (deptht, y, x) float64 nan nan nan nan nan nan nan nan nan ...