├── .gitignore ├── DataSet From DARWIN ├── Main_MakeGridDarwin2.jl ├── MakeGridDarwin2.jl ├── README.md └── test.jl ├── Presentations └── Summary of our Conversation to date_27_1_2020.pptx ├── README.md └── cnh └── histo ├── README.md ├── fixdarwinlongitudes.py ├── makebathymasks.py ├── makechlmask.py ├── makeregmask.py ├── oc-hist-plot.py ├── oc-histo-plot.py ├── plotbathy.py ├── plotrrs.py ├── plotutils.py └── rrs-hist-plot.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | MANIFEST 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | .pytest_cache/ 49 | 50 | # Translations 51 | *.mo 52 | *.pot 53 | 54 | # Django stuff: 55 | *.log 56 | local_settings.py 57 | db.sqlite3 58 | 59 | # Flask stuff: 60 | instance/ 61 | .webassets-cache 62 | 63 | # Scrapy stuff: 64 | .scrapy 65 | 66 | # Sphinx documentation 67 | docs/_build/ 68 | 69 | # PyBuilder 70 | target/ 71 | 72 | # Jupyter Notebook 73 | .ipynb_checkpoints 74 | 75 | # pyenv 76 | .python-version 77 | 78 | # celery beat schedule file 79 | celerybeat-schedule 80 | 81 | # SageMath parsed files 82 | *.sage.py 83 | 84 | # Environments 85 | .env 86 | .venv 87 | env/ 88 | venv/ 89 | ENV/ 90 | env.bak/ 91 | venv.bak/ 92 | 93 | # Spyder project settings 94 | .spyderproject 95 | .spyproject 96 | 97 | # Rope project settings 98 | .ropeproject 99 | 100 | # mkdocs documentation 101 | /site 102 | 103 | # mypy 104 | .mypy_cache/ 105 | -------------------------------------------------------------------------------- /DataSet From DARWIN/Main_MakeGridDarwin2.jl: -------------------------------------------------------------------------------- 1 | #Main_MakeGridDarwin2.jl This script will generate the master half degree netcdf file and then will put it on the other grids using the functions 2 | #in MakeGridDarwin2.jl 3 | 4 | include("MakeGridDarwin2.jl") 5 | 6 | if ~isfile("MasterHalf.nc") 7 | MakeMasterHalf() 8 | end 9 | realnames=["Latitude","Longitude","Month","THETA", "SALT", "Chl", "Rirr412", "Rirr443", "Rirr490", "Rirr510", "Rirr555","Rirr670","MXLDEPTH","Bottom Depth", "Wind Speed", "TKE","PAR","Euphotic Depth"] 10 | for n in [.5 1 2 4] 11 | MakeDarwinGrid(n,realnames) 12 | end -------------------------------------------------------------------------------- /DataSet From DARWIN/MakeGridDarwin2.jl: -------------------------------------------------------------------------------- 1 | #This module/script is intended to mine the CBIOMES-Global Atlas for a specific set of variables which we will 2 | #regrid and put into a single NetCDF files function MakeMasterHalf() will make the master NetCDF file for the half degree grid. Function 3 | #MakeDarwinGrid(deg,names) takes the grid degrees and the variable names and generates the netCDF files for the other resolutions. 4 | Module 5 | 6 | using Plots, Distributions, NetCDF, NCDatasets, Interpolations 7 | 8 | function MakeMasterHalf() 9 | #This is the starting folder for the Climatology 10 | #name="C:\\Users\\folle\\Dropbox (MIT)\\201805-CBIOMES-climatology\\interp" 11 | name="C:\\Users\\folle\\Documents\\CBIOMES\\interp" 12 | #This is the filename for the .5 degree monthly climatology 13 | filename="HalfDegree.nc" 14 | #These are the variable names which we would like on the grid 15 | #Lat, lon, time, T, S, PAR, Wave Bands, Chl, mixed layer depth, *bottom depth*, 16 | #Wind Speed, *Ekman pumping*, *Kd*, *Euphotic Depth*, and Eddy Kinetic Energy 17 | varnamest=["THETA", "SALT", "Rirr001", "Rirr002", "Rirr003", "Rirr004", "Rirr005", 18 | "Rirr006", "Rirr007", "Rirr008", "Rirr009", "Rirr010", "Rirr011", "Rirr012", "Rirr013", "Chl", 19 | "MXLDEPTH", "EXFwspee", "GGL90TKE","PAR"] 20 | 21 | # Check if .nc file exists 22 | if isfile(filename) 23 | # Open a file as read-only 24 | ds = Dataset(filename,"r") 25 | varnames=[] 26 | println("1") 27 | println(length(varnamest)) 28 | for n in 1:length(varnamest) 29 | # check if a file has a variable with a given name 30 | if ~haskey(ds,varnamest[n]) 31 | push!(varnames,varnamest[n]) 32 | end 33 | end 34 | end 35 | if ~isfile(filename) 36 | varnames=varnamest 37 | end 38 | println(varnames) 39 | #This is the single giant array 40 | Tg=Array{Float64,4}(undef,720,360,12,length(varnames)) 41 | 42 | #This part of the code generates an array of paths to the individual files 43 | A=[] 44 | for (root, dirs, files) in walkdir(name) 45 | for file in files 46 | if occursin(r".nc$", file) 47 | append!(A,[joinpath.(root, file)]) 48 | end 49 | end 50 | end 51 | 52 | #This Part searches for the individual files for each data type and extracts the 53 | #surface layer only. If there are multiple files the code sums them! 54 | for m in 1:length(varnames) 55 | fieldsort=varnames[m] 56 | b=[] 57 | field=[] 58 | for n in 1:length(A) 59 | if occursin(fieldsort,A[n]) append!(b,n) 60 | end 61 | end 62 | B=A[b] 63 | #B=B[1:5] 64 | for n in 1:length(B) 65 | f=[first(split(basename(B[n]),"."))] 66 | println(varnames[m]) 67 | append!(field,f) 68 | end 69 | #println(field) 70 | tmp=ncread(B[1],field[1]) 71 | println(B[1]) 72 | println(field[1]) 73 | println(size(tmp)) 74 | if length(size(tmp))==4 75 | tmp=tmp[:,:,1,:] 76 | end 77 | T=tmp 78 | if length(B)>1 79 | s1, s2, s3 = size(tmp,1), size(tmp,2), size(tmp,3) 80 | T=Array{Float64,4}(undef,s1,s2,s3,length(B)) 81 | for n in 1:length(B) 82 | tmp=ncread(B[n],field[n]) 83 | println(size(tmp)) 84 | if length(size(tmp))==4 85 | T[:,:,:,n]=tmp[:,:,1,:] 86 | end 87 | if length(size(tmp))==3 88 | T[:,:,:,n]=tmp 89 | end 90 | end 91 | T=sum(T,dims=4) 92 | end 93 | T=T[:,:,:] 94 | Tg[:,:,:,m]=T 95 | nccreate(filename, fieldsort,"Lon",collect(-179.75:.5:179.75),"Lat",collect(-89.75:.5:89.75),"Month",collect(1:12)) 96 | ncwrite(T,filename, fieldsort) 97 | end 98 | 99 | #This Part of the code interpolates the Darwin remote reflectance bands to get the occi bands 100 | wv_cci=[412, 443, 490, 510, 555, 670] #cci wavebands 101 | wv_drwn3=[400,425,450,475,500,525,550,575,600,625,650,675,700];#DARWIN wavebands 102 | wbcci=Array{Float64,4}(undef,720,360,12,6) 103 | wbdrwn=Array{Float64,4}(undef,720,360,12,length(wv_drwn3)) 104 | dwnbands=["Rirr001", "Rirr002", "Rirr003", "Rirr004", "Rirr005", 105 | "Rirr006", "Rirr007", "Rirr008", "Rirr009", "Rirr010", "Rirr011", "Rirr012", "Rirr013"] 106 | #export dwnbands, wbdrwn,filename,dwnbands 107 | for n in 1:length(wbdrwn[1,1,1,:]) 108 | wbdrwn[:,:,:,n]=ncread(filename,dwnbands[n]) 109 | end 110 | #using Interpolations to interpolate bands (currently linear) 111 | for n in 1:720 112 | for m in 1:360 113 | for o in 1:12 114 | itp=LinearInterpolation(wv_drwn3,wbdrwn[n,m,o,:]) 115 | wbcci[n,m,o,:]=itp.(wv_cci) 116 | end 117 | end 118 | end 119 | #export wbcci 120 | #[412, 443, 490, 510, 555, 670] 121 | OCCIbands=["Rirr412", "Rirr443", "Rirr490", "Rirr510", "Rirr555", 122 | "Rirr670"] 123 | #export OCCIbands 124 | if ~isfile("InterpedWavebands.nc") 125 | for n in 1:6 126 | nccreate("InterpedWavebands3.nc", OCCIbands[n],"Lon",collect(-179.75:.5:179.75),"Lat",collect(-89.75:.5:89.75),"Month",collect(1:12)) 127 | ncwrite(wbcci[:,:,:,n],"InterpedWavebands3.nc", OCCIbands[n]) 128 | end 129 | end 130 | ## This part gets the bottom depth by finding the first grid cell where the Temperature field does not exist 131 | dept=ncread(name*"\\PhysicalOceanography\\THETA.0001.nc","dep"); 132 | tem=ncread(name*"\\PhysicalOceanography\\THETA.0001.nc","THETA"); 133 | depth=zeros(length(dept)+1); 134 | depth[2:end]=dept; 135 | ind=(length(depth) .- sum(isnan.(tem), dims=3)); 136 | bdepth=permutedims(depth[ind],[1, 2,4,3]); 137 | bdepth=bdepth[:,:,:]; 138 | if isfile("BottomDepth.nc") 139 | rm("BottomDepth.nc") 140 | end 141 | nccreate("BottomDepth.nc", "Bottom Depth","Lon",collect(-179.75:.5:179.75),"Lat",collect(-89.75:.5:89.75),"Month",collect(1:12)) 142 | ncwrite(bdepth,"BottomDepth.nc", "Bottom Depth") 143 | 144 | ## This part finds the 'Euphotic Depth' which we define as the location where PAR is at 1% of its original value 145 | # export bdepth 146 | bdepth=ncread("BottomDepth.nc","Bottom Depth") 147 | PAR=ncread(name*"\\IrradianceReflectance\\PAR.0001.nc","PAR"); 148 | dept=ncread(name*"\\IrradianceReflectance\\PAR.0001.nc","dep"); 149 | s1, s2, s3, s4 = size(PAR,1), size(PAR,2), size(PAR,3), size(PAR,4) 150 | PARs=PAR[:,:,1,:] 151 | Eudepth=zeros(size(bdepth)) 152 | tmp=PAR 153 | #tmp=Array{Float64,4}(undef,s1,s2,s3,s4) 154 | for n in collect(1:s3) 155 | tmp[:,:,n,:]=tmp[:,:,n,:]./PARs 156 | end 157 | # export bdepth, tmp, dept, Eudepth 158 | for n in 1:720 159 | for m in 1:360 160 | for o in 1:12 161 | #export n, m, o 162 | #The negative in the tmp variable is to make the PAR strictly increasing 163 | if ~(bdepth[n,m,o]==0) 164 | bd=bdepth[n,m,o] 165 | if minimum(tmp[n,m,dept.=0) 176 | # # println(t) 177 | # # println(size(dept.=1 257 | vartmp=ncread("MasterHalf.nc",names[n]) 258 | nccreate("DarwinGrid"*string(deg)*".nc", names[n],"Londim",collect(.5:deg:360),"Latdim",collect(-89.75:deg:89.75),"Monthdim",collect(1:12)) 259 | #println(size(vartmp[1:Int(deg/.5):end,1:Int(deg/.5):end,:])) 260 | #println(size(vartmp)) 261 | tmp=vartmp[1:Int(deg/.5):end,1:Int(deg/.5):end,:]; 262 | #println(size(tmp)) 263 | #println(n) 264 | #println(names[n]) 265 | #export n, tmp, names 266 | #println(sztmp) 267 | println(size(tmp)) 268 | ncwrite(tmp,"DarwinGrid"*string(deg)*".nc", names[n]) 269 | end 270 | if sum(k.==names[n])==0 271 | tmp=zeros(length(collect(.5:deg:360)), length(collect(-89.75:deg:89.75)),12) 272 | if names[n]=="Latitude" 273 | Lat=collect(-89.75:deg:89.75); 274 | for m in 1:length(Lat) 275 | #fill!(HalfDegree[:,n,:,1],Lat[n]) 276 | tmp2=fill(Lat[m],size(tmp[:,m,:])) 277 | tmp[:,m,:]=tmp2 278 | end 279 | nccreate("DarwinGrid"*string(deg)*".nc", names[n],"Londim",collect(.5:deg:360),"Latdim",collect(-89.75:deg:89.75),"Monthdim",collect(1:12)) 280 | ncwrite(tmp,"DarwinGrid"*string(deg)*".nc", names[n]) 281 | sztmp=size(tmp) 282 | end 283 | if names[n]=="Longitude" 284 | Lon=collect(.5:(deg/.5):360); 285 | for m in 1:length(Lon) 286 | #fill!(HalfDegree[:,n,:,1],Lat[n]) 287 | tmp2=fill(Lon[m],size(tmp[m,:,:])) 288 | tmp[m,:,:]=tmp2 289 | end 290 | nccreate("DarwinGrid"*string(deg)*".nc", names[n],"Londim",collect(.5:(deg):360),"Latdim",collect(-89.75:(deg):89.75),"Monthdim",collect(1:12)) 291 | ncwrite(tmp,"DarwinGrid"*string(deg)*".nc", names[n]) 292 | end 293 | if names[n]=="Month" 294 | Mon=collect(1:1:12); 295 | for m in 1:length(Mon) 296 | #fill!(HalfDegree[:,n,:,1],Lat[n]) 297 | tmp2=fill(Mon[m],size(tmp[:,:,m])) 298 | tmp[:,:,m]=tmp2 299 | end 300 | nccreate("DarwinGrid"*string(deg)*".nc", names[n],"Londim",collect(.5:(deg):360),"Latdim",collect(-89.75:(deg):89.75),"Monthdim",collect(1:12)) 301 | ncwrite(tmp,"DarwinGrid"*string(deg)*".nc", names[n]) 302 | end 303 | end 304 | end 305 | end 306 | 307 | #realnames=["Latitude","Longitude","Month","THETA", "SALT", "Chl", "Rirr412", "Rirr443", "Rirr490", "Rirr510", "Rirr555", 308 | #"Rirr670","MXLDEPTH","Bottom Depth", "Wind Speed", "TKE"] -------------------------------------------------------------------------------- /DataSet From DARWIN/README.md: -------------------------------------------------------------------------------- 1 | # Dataset for Provinces: CBIOMES-global 2 | 3 | **Content:** 4 | `Re-Sampled Dataset from CBIOMES-global (alpha version)` 5 | 6 | This folder contains the code to build current versions of the .5, 1, 2, and 4 degree gridded, global surface variables from the CBIOMES-global (alpha version). Each variable in the netcdf file is in a matrix A[:,:,:] where the first entry is the longitude, the second is the latitude and the third index is the month. 7 | 8 | To generate the netCDF files for the .5, 1, 2, and 4 degree grids (DARWINGrid0.5.nc, DARWINGrid1.0.nc, DARWINGrid2.0.nc, DARWINGrid4.0.nc) first modify the "name" string on line 10 of "MakeGridDarwin2.jl" to be the file system path to the CBIOMES-global atlas. Next, run "Main_MakeGridDarwin2.jl". 9 | 10 | - `CBIOMES-global (alpha version)` is a global ocean state estimate that covers the period from 1992 to 2011. It is based on Forget et al 2015 for ocean physics and on Dutkiewicz et al 2015 for marine biogeochemistry and ecosystems with 35 phytoplankton types, 16 zooplankton types, and the allometric relationships of Ward et al 2012. 11 | 12 | This folder contains code written in Julia to generate gridded data for the following variables and a code that will extract/calculate them if given the path to a folder containing the CBIOMES-global Atlas. 13 | 14 | - "Lat" (degrees) 15 | - "Lon" (degrees) 16 | - "Month" (month) 17 | - "THETA" (degrees C) 18 | - "SALT" (psu) 19 | - "Chl" (mg/l) 20 | - "Rirr412" (irradiance reflectance for waveband at wavelength) 21 | - "Rirr443" (irradiance reflectance for waveband at wavelength) 22 | - "Rirr490" (irradiance reflectance for waveband at wavelength) 23 | - "Rirr510" (irradiance reflectance for waveband at wavelength) 24 | - "Rirr555" (irradiance reflectance for waveband at wavelength) 25 | - "Rirr670" (irradiance reflectance for waveband at wavelength) 26 | - "MXLDEPTH" (depth, meters) 27 | - "Bottom Depth" (depth, meters) 28 | - "Wind Speed" (m/s) 29 | - "TKE" (m^2/s^2) is GGL90 sub-grid turbulent kinetic energy 30 | - "PAR" () 31 | - "Euphotic Depth" Depth (m) where light is 1% of the surface values 32 | 33 | **Missing Variables** 34 | 35 | The following variables were discussed as part of our master list and are not currently in the netcdf file. We are hoping to rectify that soon. 36 | 37 | - PAR (Photosynthetically Active Radiation) 38 | - Ekman pumping 39 | - Kd 40 | - Euphotic Depth 41 | 42 | 43 | **References:** 44 | 45 | Forget, G., J.-M. Campin, P. Heimbach, C. N. Hill, R. M. Ponte, and C. Wunsch, 2015: ECCO version 4: an integrated framework for non-linear inverse modeling and global ocean state estimation. Geoscientific Model Development, 8, 3071-3104, or [this URL](http://www.geosci-model-dev.net/8/3071/2015/) 46 | 47 | Dutkiewicz, S., A.E. Hickman, O. Jahn, W.W. Gregg, C.B. Mouw, and M.J. Follows, 2015: Capturing optically important constituents and properties in a marine biogeochemical and ecosystem model. Biogeoscience, 12, 4447-4481, or [this URL](https://www.biogeosciences.net/12/4447/2015/) 48 | 49 | Ward, B. A., Dutkiewicz, S., Jahn, O., and Follows, M. J., 2012: 50 | A size structured food-web model for the global ocean, Limnol. 51 | Oceanogr., 57, 1877–1891, or [this URL](https://aslopubs.onlinelibrary.wiley.com/doi/abs/10.4319/lo.2012.57.6.1877) 52 | 53 | **README File Revision History:** 54 | 55 | - `2020/01/22 [Chris Follett]` create README file 56 | 57 | - `2020/01/22 [Chris Follett]` edited README file 58 | - 59 | - `2020/02/06 [Chris Follett]` edited README file 60 | -------------------------------------------------------------------------------- /DataSet From DARWIN/test.jl: -------------------------------------------------------------------------------- 1 | 2 | using Plots, Distributions, NetCDF, NCDatasets, Interpolations, Roots 3 | 4 | name="C:\\Users\\folle\\Documents\\CBIOMES\\interp" 5 | 6 | bdepth=ncread("BottomDepth.nc","Bottom Depth") 7 | PAR=ncread(name*"\\IrradianceReflectance\\PAR.0001.nc","PAR"); 8 | dept=ncread(name*"\\IrradianceReflectance\\PAR.0001.nc","dep"); 9 | s1, s2, s3, s4 = size(PAR,1), size(PAR,2), size(PAR,3), size(PAR,4) 10 | PARs=PAR[:,:,1,:] 11 | Eudepth=zeros(size(bdepth)) 12 | tmp=PAR 13 | #tmp=Array{Float64,4}(undef,s1,s2,s3,s4) 14 | for n in collect(1:s3) 15 | tmp[:,:,n,:]=tmp[:,:,n,:]./PARs 16 | end 17 | export bdepth, tmp, dept, Eudepth 18 | for n in 1:720 19 | for m in 1:360 20 | for o in 1:12 21 | #export n, m, o 22 | #The negative in the tmp variable is to make the PAR strictly increasing 23 | if ~(bdepth[n,m,o]==0) 24 | bd=bdepth[n,m,o] 25 | if minimum(tmp[n,m,dept.=0) 36 | # # println(t) 37 | # # println(size(dept.2 | `10.1029/2006GL027086` 65 | EKE | `OSCAR`1 | `10.5067/OSCAR-03D01` 66 | bathymetry | `NOAA ETOPO1` | `10.7289/V5C8276M` 67 | Rrs412 | `ESA OC-CCI L4` | `10.5285/9C334FBE6D424A708CF3C4CF0C6A53F5` 68 | Rrs443 | `ESA OC-CCI L4` | `10.5285/9C334FBE6D424A708CF3C4CF0C6A53F5` 69 | Rrs490 | `ESA OC-CCI L4` | `10.5285/9C334FBE6D424A708CF3C4CF0C6A53F5` 70 | Rrs510 | `ESA OC-CCI L4` | `10.5285/9C334FBE6D424A708CF3C4CF0C6A53F5` 71 | Rrs555 | `ESA OC-CCI L4` | `10.5285/9C334FBE6D424A708CF3C4CF0C6A53F5` 72 | Rrs670 | `ESA OC-CCI L4` | `10.5285/9C334FBE6D424A708CF3C4CF0C6A53F5` 73 | ---|---|--- 74 | 75 | 1 Calculated from geostrophic velocities 76 | 2 Blended Sea Winds from [URL](https://www.ncdc.noaa.gov/data-access/marineocean-data/blended-global/blended-sea-winds) 77 | 78 | ### Model Monthly Climatologies (`v0.2.6 alpha`) 79 | 80 | These were downloaded from the source listed below and regridded using the [gcmfaces](http://gcmfaces.readthedocs.io/en/latest/) toolbox plus recipes from [OceanColorData.jl](https://gaelforget.github.io/OceanColorData.jl/dev/) [(these notebooks)](https://github.com/gaelforget/MarineEcosystemNotebooks) and those included here in `DataSet From DARWIN/`. 81 | 82 | 83 | 84 | Resolution |Gridded | Pandas/hdf5 | Comma separated 85 | ---|---|---|--- 86 | 1/2° | [Download cdf](https://rsg.pml.ac.uk/shared_files/brj/CBIOMES_ecoregions/ver_0_2_6/gridded_darwin_montly_clim_360_720_ver_0_2_6.nc) | [Download hdf](https://rsg.pml.ac.uk/shared_files/brj/CBIOMES_ecoregions/ver_0_2_6/tabulated_darwin_montly_clim_360_720_ver_0_2_6.h5) | [Download csv](https://rsg.pml.ac.uk/shared_files/brj/CBIOMES_ecoregions/ver_0_2_6/tabulated_darwin_montly_clim_360_720_ver_0_2_6.csv) 87 | 1°| |[Download hdf](https://rsg.pml.ac.uk/shared_files/brj/CBIOMES_ecoregions/ver_0_2_6/tabulated_darwin_montly_clim_180_360_ver_0_2_6.h5) | [Download csv](https://rsg.pml.ac.uk/shared_files/brj/CBIOMES_ecoregions/ver_0_2_6/tabulated_darwin_montly_clim_180_360_ver_0_2_6.csv) 88 | 2°| |[Download hdf](https://rsg.pml.ac.uk/shared_files/brj/CBIOMES_ecoregions/ver_0_2_6/tabulated_darwin_montly_clim_090_180_ver_0_2_6.h5) | [Download csv](https://rsg.pml.ac.uk/shared_files/brj/CBIOMES_ecoregions/ver_0_2_6/tabulated_darwin_montly_clim_090_180_ver_0_2_6.csv) 89 | 4°| | [Download hdf](https://rsg.pml.ac.uk/shared_files/brj/CBIOMES_ecoregions/ver_0_2_6/tabulated_darwin_montly_clim_045_090_ver_0_2_6.h5) | [Download csv](https://rsg.pml.ac.uk/shared_files/brj/CBIOMES_ecoregions/ver_0_2_6/tabulated_darwin_montly_clim_045_090_ver_0_2_6.csv) 90 | 91 | Rrs values have been fixed. 92 | 93 | **Source:** [DOI](10.5281/zenodo.2653669), [URL](http://engaging-opendap.mit.edu:8080/thredds/dodsC/las/id-fba1de9aef/), [Documentation](https://cbiomes.readthedocs.io/) 94 | 95 | ### Standard Classification Estimates 96 | 97 | [Download cdf](https://rsg.pml.ac.uk/shared_files/brj/CBIOMES_ecoregions/ver_0_2/gridded_geospatial_regions_360_720_ver_0_2.nc) 98 | 99 | There are still some issues with the hdf and csv files. 100 | 108 | *Included Parameters:* Longhurst, optical\_water\_classes 109 | -------------------------------------------------------------------------------- /cnh/histo/README.md: -------------------------------------------------------------------------------- 1 | # Histogram plotting 2 | 3 | Code to plot histograms of variable distributions from model and obs side by side 4 | to examine how similar distributions are for all time or month by month. 5 | -------------------------------------------------------------------------------- /cnh/histo/fixdarwinlongitudes.py: -------------------------------------------------------------------------------- 1 | # Fix longitudes from Darwin netCDF 2 | # for some reasons these are offset and everything east of prime meridian is zero 3 | # Only fix for month zero! Longitudes don't change by month. 4 | darDS.Londim.values 5 | lons=darDS.Londim.values-180 6 | np.shape(lons) 7 | ny=np.size(darDS.Longitude[0,:,0]) 8 | for j in range(ny): 9 | darDS.Longitude[0,j,:]=lons 10 | 11 | ( geoDS.bathymetry[0,:,:].where( geoDS.lat>22 ).where( geoDS.lon>-90 ).where( geoDS.lon<0 ) ).values 12 | -------------------------------------------------------------------------------- /cnh/histo/makebathymasks.py: -------------------------------------------------------------------------------- 1 | # Make some masks for "open ocean" (depth > dmin) 2 | dMin=500. 3 | 4 | phi=darDS['Bottom Depth'][1,:,:].values 5 | omskDar=np.where(phi>dMin,1,np.nan) 6 | x1=darDS['Bottom Depth'][1,:,:] 7 | x1.values=x1.values*omskDar 8 | xr.plot.imshow(x1) 9 | plt.show() 10 | 11 | phi=geoDS.bathymetry[1,:,:].values 12 | omskGeo=np.where(phi>dMin,1,np.nan) 13 | x1=geoDS.bathymetry[1,:,:] 14 | x1.values=x1.values*omskGeo 15 | xr.plot.imshow(x1) 16 | plt.show() 17 | -------------------------------------------------------------------------------- /cnh/histo/makechlmask.py: -------------------------------------------------------------------------------- 1 | # Make mask for very high Chl values in Satellite based estimates for open-ocean (depth > dmin ) 2 | chlMax=1 3 | 4 | phi=geoDS.Chl[:,:,:].values 5 | with np.errstate(invalid='ignore'): 6 | chlmskGeo=np.where( phi22 ,1,np.nan) \ 12 | * np.where(darDS.Latitude[0,:,:].values <65 ,1,np.nan) \ 13 | * np.where(darDS.Longitude[0,:,:].values>-90,1,np.nan) \ 14 | * np.where(darDS.Longitude[0,:,:].values< 0,1,np.nan) 15 | 16 | regmskGeo=( geoDS.bathymetry[0,:,:] \ 17 | .where( geoDS.lat>22 ) \ 18 | .where( geoDS.lat<65 ) \ 19 | .where( geoDS.lon>-90 ) \ 20 | .where( geoDS.lon<0 ) \ 21 | ).values 22 | regmskGeo=np.where(~np.isnan(regmskGeo),1,np.nan) 23 | mskname='natl' 24 | -------------------------------------------------------------------------------- /cnh/histo/oc-hist-plot.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | # In[18]: 5 | 6 | 7 | # docker run -P -d --rm -i -t -v `pwd`:/home/jovyan/host jupyter/datascience-notebook 8 | # -or- 9 | # curl https://repo.continuum.io/miniconda/Miniconda3-latest-MacOSX-x86_64.sh > Miniconda3-latest-MacOSX-x86_64.sh' 10 | # chmod +x Miniconda3-latest-MacOSX-x86_64.sh 11 | # ./Miniconda3-latest-MacOSX-x86_64.sh -b -p `pwd`/miniconda3 12 | # export PATH="`pwd`/miniconda3/bin:$PATH" 13 | # conda create -n ocean-clustering -c conda-forge python=3.7 14 | # 15 | # . miniconda3/etc/profile.d/conda.sh 16 | # conda activate ocean-clustering 17 | # 18 | # 19 | # conda install netCDF4 20 | # conda install numpy 21 | # conda install xarray 22 | # conda install cartopy 23 | 24 | import xarray as xr 25 | import matplotlib.pyplot as plt 26 | import numpy as np 27 | import cartopy.crs as ccrs 28 | 29 | 30 | # In[19]: 31 | 32 | 33 | geoF='gridded_geospatial_montly_clim_360_720_ver_0_2.nc' 34 | darF='gridded_darwin_montly_clim_360_720_ver_0_2.nc' 35 | geoDS = xr.open_dataset(geoF) 36 | darDS = xr.open_dataset(darF) 37 | 38 | # Make signs on bathymetry consistent 39 | x1=geoDS.bathymetry[:,:,:] 40 | x1.values=x1.values*-1. 41 | geoDS.bathymetry[:,:,:]=x1 42 | 43 | # Set number of histogram bins 44 | nbin=50 45 | 46 | 47 | # In[20]: 48 | 49 | 50 | # Histogram plot 51 | def mkhplot(f1,f2,fld,mno): 52 | fig=plt.figure(figsize=(10,10)) 53 | 54 | ax1 = plt.subplot(12,2,(1,7) ) 55 | if type(mno) == int: 56 | ax1.set_title('Dar-%s, month=%d'%(fld,mno)) 57 | if type(mno) == range: 58 | ax1.set_title('Dar-%s, month=%s'%(fld,'all')) 59 | fval=np.ravel( f1 ) 60 | fval=fval[~np.isnan(fval)] 61 | fvavg=np.nanmean(fval) 62 | fvstd=np.nanstd(fval) 63 | fvmin=np.nanmin(fval) 64 | fvmax=np.nanmax(fval) 65 | fvmed=np.nanmedian(fval) 66 | ax1.hist(fval,nbin) 67 | 68 | ax1s = plt.subplot(12,2,11 ) 69 | ax1s.set_axis_off() 70 | ax1s.text(0,0 ,'mean=%f'%(fvavg)) 71 | ax1s.text(0,0.25,' std=%f'%(fvstd)) 72 | ax1s.text(0,0.5 ,' max=%f'%(fvmax)) 73 | ax1s.text(0,0.75,' min=%f'%(fvmin)) 74 | ax1s.text(0,1.0 ,' med=%f'%(fvmed)) 75 | 76 | ax2 = plt.subplot(12,2,(2,8) ) 77 | if type(mno) == int: 78 | ax2.set_title('Geo-%s, month=%d'%(fld,mno)) 79 | if type(mno) == range: 80 | ax2.set_title('Geo-%s, month=%s'%(fld,'all')) 81 | fval=np.ravel( f2 ) 82 | fval=fval[~np.isnan(fval)] 83 | fvavg=np.nanmean(fval) 84 | fvstd=np.nanstd(fval) 85 | fvmin=np.nanmin(fval) 86 | fvmax=np.nanmax(fval) 87 | fvmed=np.nanmedian(fval) 88 | ax2.hist(np.ravel( fval ),nbin ) 89 | 90 | ax2s = plt.subplot(12,2,12 ) 91 | ax2s.set_axis_off() 92 | ax2s.text(0,0 ,'mean=%f'%(fvavg)) 93 | ax2s.text(0,0.25,' std=%f'%(fvstd)) 94 | ax2s.text(0,0.5 ,' max=%f'%(fvmax)) 95 | ax2s.text(0,0.75,' min=%f'%(fvmin)) 96 | ax2s.text(0,1.0 ,' med=%f'%(fvmed)) 97 | 98 | if type(mno) == int: 99 | pname='h_%s_m_%d.png'%(fld,mno) 100 | if type(mno) == range: 101 | pname='h_%s_m_%s.png'%(fld,'all') 102 | 103 | plt.savefig(pname) 104 | 105 | plt.show() 106 | 107 | 108 | # In[21]: 109 | 110 | 111 | # Lat-lon map plot 112 | def mkxyplot(x1,x2,fld,mno): 113 | 114 | fig=plt.figure(figsize=(20,10)) 115 | 116 | ax=plt.subplot(121) 117 | xr.plot.imshow(x1) 118 | ax.set_title('Dar-%s, month=%d'%(fld,mno)) 119 | 120 | ax=plt.subplot(122) 121 | xr.plot.imshow(x2) 122 | ax.set_title('Geo-%s, month=%d'%(fld,mno)) 123 | 124 | if type(mno) == int: 125 | pname='xy_%s_m_%d.png'%(fld,mno) 126 | if type(mno) == range: 127 | pname='xy_%s_m_%s.png'%(fld,'all') 128 | 129 | plt.savefig(pname) 130 | plt.show() 131 | 132 | 133 | # In[22]: 134 | 135 | 136 | # Check bathymetry 137 | fld='Depth' 138 | x1=darDS['Bottom Depth'][1,:,:] 139 | x2=geoDS.bathymetry[1,:,:] 140 | f1=x1.values 141 | f1=f1[np.where(f1!=0)] 142 | f2=x2.values 143 | f2=f2[np.where(f2!=-0.)] 144 | mkhplot(f1,f2,fld,1) 145 | mkxyplot(x1,x2,fld,1) 146 | 147 | 148 | # In[23]: 149 | 150 | 151 | # Fix longitudes from Darwin netCDF 152 | # for some reasons these are offset and everything east of prime meridian is zero 153 | # Only fix for month zero! Longitudes don't change by month. 154 | darDS.Londim.values 155 | lons=darDS.Londim.values-180 156 | np.shape(lons) 157 | ny=np.size(darDS.Longitude[0,:,0]) 158 | for j in range(ny): 159 | darDS.Longitude[0,j,:]=lons 160 | 161 | ( geoDS.bathymetry[0,:,:].where( geoDS.lat>22 ).where( geoDS.lon>-90 ).where( geoDS.lon<0 ) ).values 162 | 163 | 164 | # In[24]: 165 | 166 | 167 | # Make some masks for "open ocean" (depth > dmin) 168 | dMin=500. 169 | 170 | phi=darDS['Bottom Depth'][1,:,:].values 171 | omskDar=np.where(phi>dMin,1,np.nan) 172 | x1=darDS['Bottom Depth'][1,:,:] 173 | x1.values=x1.values*omskDar 174 | xr.plot.imshow(x1) 175 | plt.show() 176 | 177 | phi=geoDS.bathymetry[1,:,:].values 178 | omskGeo=np.where(phi>dMin,1,np.nan) 179 | x1=geoDS.bathymetry[1,:,:] 180 | x1.values=x1.values*omskDar 181 | xr.plot.imshow(x1) 182 | plt.show() 183 | 184 | # Add a region mask (custmize as needed to Longhurst, basins etc..) 185 | 186 | # No mask 187 | regmskDar=np.ones(np.shape(omskDar) ); 188 | regmskGeo=np.ones(np.shape(omskGeo) ); 189 | mskname='none' 190 | 191 | # Example mask - North Atlantic 192 | natlmask=0 193 | if natlmask == 1: 194 | regmskDar= np.where(darDS.Latitude[0,:,:].values >22 ,1,np.nan) * np.where(darDS.Latitude[0,:,:].values <65 ,1,np.nan) * np.where(darDS.Longitude[0,:,:].values>-90,1,np.nan) * np.where(darDS.Longitude[0,:,:].values< 0,1,np.nan) 195 | 196 | regmskGeo=( geoDS.bathymetry[0,:,:] .where( geoDS.lat>22 ) .where( geoDS.lat<65 ) .where( geoDS.lon>-90 ) .where( geoDS.lon<0 ) ).values 197 | regmskGeo=np.where(~np.isnan(regmskGeo),1,np.nan) 198 | mskname='natl' 199 | 200 | 201 | # In[25]: 202 | 203 | 204 | # Make mask for very high Chl values in Satellite based estimates for open-ocean (depth > dmin ) 205 | chlMax=1 206 | 207 | phi=geoDS.Chl[:,:,:].values 208 | with np.errstate(invalid='ignore'): 209 | chlmskGeo=np.where( phidcCap ,dcCap,phi) 304 | x1.values=phi 305 | 306 | f1=x1.values 307 | f2=x2.values 308 | mkhplot(f1,f2,fld,mno) 309 | mkxyplot(x1,x2,fld,mno) 310 | 311 | 312 | # In[31]: 313 | 314 | 315 | nms=[412,443,490,510,555,670] 316 | 317 | for nm in nms: 318 | fld='R%d_mask=%s'%(nm,mskname) 319 | 320 | x1=darDS['Rirr%d'%(nm)][mno,:,:] 321 | x1.values=x1.values*omskDar*regmskDar 322 | 323 | x2=geoDS['Rrs%d'%(nm)][mno,:,:] 324 | # Mask points with very high irradiance 325 | # Rhigh=100000000 326 | # with np.errstate(invalid='ignore'): 327 | # x2.values=np.where(x2.values<=Rhigh,x2.values,np.nan) 328 | x2.values=x2.values*omskGeo*regmskGeo 329 | 330 | f1=x1.values 331 | f2=x2.values 332 | mkhplot(f1,f2,fld,mno) 333 | mkxyplot(x1,x2,fld,mno) 334 | 335 | 336 | # In[32]: 337 | 338 | 339 | fld='Euphotic Depth_mask=%s'%(mskname) 340 | 341 | x1=darDS['Euphotic Depth'][mno,:,:] 342 | x1.values=x1.values*omskDar*regmskDar 343 | x2=geoDS.euphotic_depth[mno,:,:] 344 | x2.values=x2.values*omskGeo*regmskGeo 345 | 346 | f1=x1.values 347 | f2=x2.values 348 | mkhplot(f1,f2,fld,mno) 349 | mkxyplot(x1,x2,fld,mno) 350 | 351 | 352 | # In[33]: 353 | 354 | 355 | fld='Wind-speed_mask=%s'%(mskname) 356 | 357 | x1=darDS['Wind Speed'][mno,:,:] 358 | x1.values=x1.values*omskDar*regmskDar 359 | 360 | 361 | x2=geoDS.wind[mno,:,:] 362 | # Mask the few very high wind speed points 363 | whigh=12 364 | with np.errstate(invalid='ignore'): 365 | x2.values=np.where(x2.values<=whigh,x2.values,np.nan) 366 | x2.values=x2.values*omskGeo*regmskGeo 367 | 368 | 369 | f1=x1.values 370 | f2=x2.values 371 | # f2=f2[np.where(f2<50.0)] 372 | mkhplot(f1,f2,fld,mno) 373 | mkxyplot(x1,x2,fld,mno) 374 | 375 | 376 | # In[34]: 377 | 378 | 379 | fld='KE_mask=%s'%(mskname) 380 | 381 | x1=darDS['TKE'][mno,:,:] 382 | x1.values=x1.values*omskDar*regmskDar 383 | 384 | x2=darDS['TKE'][mno,:,:] 385 | x2.values=x2.values*omskGeo*regmskGeo 386 | 387 | 388 | 389 | f1=x1.values 390 | f2=x2.values 391 | 392 | # f2=f2[np.where(f2<50.0)] 393 | mkhplot(f1,f2,fld,mno) 394 | mkxyplot(x1,x2,fld,mno) 395 | 396 | 397 | # In[ ]: 398 | 399 | 400 | 401 | 402 | -------------------------------------------------------------------------------- /cnh/histo/oc-histo-plot.py: -------------------------------------------------------------------------------- 1 | # 2 | # Plot some histograms for fields in https://github.com/brorfred/ocean_clustering 3 | # 4 | # curl https://rsg.pml.ac.uk/shared_files/brj/CBIOMES_ecoregions/ver_0_2/gridded_geospatial_montly_clim_360_720_ver_0_2.nc > gridded_geospatial_montly_clim_360_720_ver_0_2.nc 5 | # curl https://rsg.pml.ac.uk/shared_files/brj/CBIOMES_ecoregions/ver_0_2/gridded_darwin_montly_clim_360_720_ver_0_2.nc > gridded_darwin_montly_clim_360_720_ver_0_2.nc 6 | # docker run -P -d --rm -i -t -v `pwd`:/home/jovyan/host jupyter/datascience-notebook 7 | # -or- 8 | # curl https://repo.continuum.io/miniconda/Miniconda3-latest-MacOSX-x86_64.sh > Miniconda3-latest-MacOSX-x86_64.sh' 9 | # chmod +x Miniconda3-latest-MacOSX-x86_64.sh 10 | # ./Miniconda3-latest-MacOSX-x86_64.sh -b -p `pwd`/miniconda3 11 | # export PATH="`pwd`/miniconda3/bin:$PATH" 12 | # conda create -n ocean-clustering -c conda-forge python=3.7 13 | # 14 | # . miniconda3/etc/profile.d/conda.sh 15 | # conda activate ocean-clustering 16 | # 17 | # conda install netCDF4 18 | # conda install numpy 19 | # conda install xarray 20 | # conda install cartopy 21 | # 22 | # python oc-histo-plot.py 23 | # produces .png plots for each compared field 24 | 25 | import xarray as xr 26 | import matplotlib.pyplot as plt 27 | import numpy as np 28 | import cartopy.crs as ccrs 29 | 30 | 31 | geoF='gridded_geospatial_montly_clim_360_720_ver_0_2.nc' 32 | darF='gridded_darwin_montly_clim_360_720_ver_0_2.nc' 33 | geoDS = xr.open_dataset(geoF) 34 | darDS = xr.open_dataset(darF) 35 | 36 | def mkplot(f1,f2,fld,mno): 37 | fig=plt.figure(figsize=(10,10)) 38 | 39 | ax1 = plt.subplot(12,2,(1,7) ) 40 | if type(mno) == int: 41 | ax1.set_title('Dar-%s, month=%d'%(fld,mno)) 42 | if type(mno) == range: 43 | ax1.set_title('Dar-%s, month=%s'%(fld,'all')) 44 | fval=np.ravel( f1 ) 45 | fvavg=np.nanmean(fval) 46 | fvstd=np.nanstd(fval) 47 | fvmin=np.nanmin(fval) 48 | fvmax=np.nanmax(fval) 49 | ax1.hist(fval,nbin) 50 | 51 | ax1s = plt.subplot(12,2,11 ) 52 | ax1s.set_axis_off() 53 | ax1s.text(0,0 ,'mean=%f'%(fvavg)) 54 | ax1s.text(0,0.25,' std=%f'%(fvstd)) 55 | ax1s.text(0,0.5 ,' max=%f'%(fvmax)) 56 | ax1s.text(0,0.75,' min=%f'%(fvmin)) 57 | 58 | ax2 = plt.subplot(12,2,(2,8) ) 59 | if type(mno) == int: 60 | ax2.set_title('Geo-%s, month=%d'%(fld,mno)) 61 | if type(mno) == range: 62 | ax2.set_title('Geo-%s, month=%s'%(fld,'all')) 63 | fval=np.ravel( f2 ) 64 | fvavg=np.nanmean(fval) 65 | fvstd=np.nanstd(fval) 66 | fvmin=np.nanmin(fval) 67 | fvmax=np.nanmax(fval) 68 | ax2.hist(np.ravel( fval ),nbin ) 69 | 70 | ax2s = plt.subplot(12,2,12 ) 71 | ax2s.set_axis_off() 72 | ax2s.text(0,0 ,'mean=%f'%(fvavg)) 73 | ax2s.text(0,0.25,' std=%f'%(fvstd)) 74 | ax2s.text(0,0.5 ,' max=%f'%(fvmax)) 75 | ax2s.text(0,0.75,' min=%f'%(fvmin)) 76 | 77 | 78 | 79 | if type(mno) == int: 80 | pname='f_%s_m_%d.png'%(fld,mno) 81 | if type(mno) == range: 82 | pname='f_%s_m_%s.png'%(fld,'all') 83 | 84 | plt.savefig(pname) 85 | 86 | mno=range(0,12,1);nbin=50 87 | 88 | fld='SST' 89 | f1=darDS.THETA[mno,:,:].values 90 | f2=geoDS.SST[mno,:,:].values 91 | mkplot(f1,f2,fld,mno) 92 | 93 | fld='Chl' 94 | f1=darDS.Chl[mno,:,:].values 95 | f2=geoDS.Chl[mno,:,:].values*0.01 96 | mkplot(f1,f2,fld,mno) 97 | 98 | fld='PAR' 99 | f1=darDS.PAR[mno,:,:].values 100 | f2=geoDS.PAR[mno,:,:].values*20. 101 | mkplot(f1,f2,fld,mno) 102 | 103 | fld='Depth' 104 | f1=darDS['Bottom Depth'][mno,:,:].values 105 | f1=f1[np.where(f1!=0)] 106 | f2=geoDS.bathymetry[mno,:,:].values*-1. 107 | f2=f2[np.where(f2!=-0.)] 108 | mkplot(f1,f2,fld,mno) 109 | 110 | fld='MLD' 111 | f1=darDS['MXLDEPTH'][mno,:,:].values 112 | f2=geoDS.mld[mno,:,:].values 113 | mkplot(f1,f2,fld,mno) 114 | 115 | fld='R412' 116 | f1=darDS['Rirr412'][mno,:,:].values 117 | f2=geoDS.Rrs412[mno,:,:].values 118 | f2=f2[np.where(f2<=0.12)] 119 | mkplot(f1,f2,fld,mno) 120 | 121 | fld='R443' 122 | f1=darDS['Rirr443'][mno,:,:].values 123 | f2=geoDS.Rrs443[mno,:,:].values 124 | f2=f2[np.where(f2<=0.12)] 125 | mkplot(f1,f2,fld,mno) 126 | 127 | fld='R490' 128 | f1=darDS['Rirr490'][mno,:,:].values 129 | f2=geoDS.Rrs490[mno,:,:].values 130 | f2=f2[np.where(f2<=0.12)] 131 | mkplot(f1,f2,fld,mno) 132 | 133 | fld='R510' 134 | f1=darDS['Rirr510'][mno,:,:].values 135 | f2=geoDS.Rrs510[mno,:,:].values 136 | f2=f2[np.where(f2<=0.12)] 137 | mkplot(f1,f2,fld,mno) 138 | 139 | fld='R555' 140 | f1=darDS['Rirr555'][mno,:,:].values 141 | f2=geoDS.Rrs555[mno,:,:].values 142 | f2=f2[np.where(f2<=0.12)] 143 | mkplot(f1,f2,fld,mno) 144 | 145 | fld='R670' 146 | f1=darDS['Rirr670'][mno,:,:].values 147 | f2=geoDS.Rrs670[mno,:,:].values 148 | f2=f2[np.where(f2<=0.12)] 149 | mkplot(f1,f2,fld,mno) 150 | 151 | fld='Euphotic Depth' 152 | f1=darDS['Euphotic Depth'][mno,:,:].values 153 | f2=geoDS.euphotic_depth[mno,:,:].values 154 | mkplot(f1,f2,fld,mno) 155 | 156 | fld='Wind speed' 157 | f1=darDS['Wind Speed'][mno,:,:].values 158 | f2=geoDS.wind[mno,:,:].values 159 | # f2=f2[np.where(f2<50.0)] 160 | mkplot(f1,f2,fld,mno) 161 | 162 | fld='KE' 163 | f1=darDS['TKE'][mno,:,:].values 164 | f2=geoDS.EKE[mno,:,:].values 165 | # f2=f2[np.where(f2<50.0)] 166 | mkplot(f1,f2,fld,mno) 167 | -------------------------------------------------------------------------------- /cnh/histo/plotbathy.py: -------------------------------------------------------------------------------- 1 | # Check bathymetry 2 | fld='Depth' 3 | x1=darDS['Bottom Depth'][1,:,:] 4 | x2=geoDS.bathymetry[1,:,:] 5 | f1=x1.values 6 | f1=f1[np.where(f1!=0)] 7 | f2=x2.values 8 | f2=f2[np.where(f2!=-0.)] 9 | mkhplot(f1,f2,fld,1) 10 | mkxyplot(x1,x2,fld,1) 11 | -------------------------------------------------------------------------------- /cnh/histo/plotrrs.py: -------------------------------------------------------------------------------- 1 | nms=[412,443,490,510,555,670] 2 | nms=[443] 3 | 4 | for nm in nms: 5 | fld='R%d_mask=%s'%(nm,mskname) 6 | 7 | x1=darDS['Rirr%d'%(nm)][mno,:,:] 8 | x1.values=x1.values*omskDar*regmskDar 9 | # RRS=(0.52*R/Q)/(1-1.7*R/Q) 10 | R=x1.values; Q=3. 11 | RRS=(0.52*R/Q)/(1-1.7*R/Q) 12 | # RRS=x1.values 13 | x1.values=RRS 14 | 15 | x2=geoDS['Rrs%d'%(nm)][mno,:,:] 16 | # Mask points with very high irradiance 17 | # Rhigh=100000000 18 | # with np.errstate(invalid='ignore'): 19 | # x2.values=np.where(x2.values<=Rhigh,x2.values,np.nan) 20 | x2.values=x2.values*omskGeo*regmskGeo 21 | 22 | f1=x1.values 23 | f2=x2.values 24 | mkhplot(f1,f2,fld,mno) 25 | mkxyplot(x1,x2,fld,mno) 26 | 27 | 28 | -------------------------------------------------------------------------------- /cnh/histo/plotutils.py: -------------------------------------------------------------------------------- 1 | # Histogram plot 2 | def mkhplot(f1,f2,fld,mno): 3 | fig=plt.figure(figsize=(10,10)) 4 | 5 | ax1 = plt.subplot(12,2,(1,7) ) 6 | if type(mno) == int: 7 | ax1.set_title('Dar-%s, month=%d'%(fld,mno)) 8 | if type(mno) == range: 9 | ax1.set_title('Dar-%s, month=%s'%(fld,'all')) 10 | fval=np.ravel( f1 ) 11 | fval=fval[~np.isnan(fval)] 12 | fvavg=np.nanmean(fval) 13 | fvstd=np.nanstd(fval) 14 | fvmin=np.nanmin(fval) 15 | fvmax=np.nanmax(fval) 16 | fvmed=np.nanmedian(fval) 17 | ax1.hist(fval,nbin) 18 | 19 | ax1s = plt.subplot(12,2,11 ) 20 | ax1s.set_axis_off() 21 | ax1s.text(0,0 ,'mean=%f'%(fvavg)) 22 | ax1s.text(0,0.25,' std=%f'%(fvstd)) 23 | ax1s.text(0,0.5 ,' max=%f'%(fvmax)) 24 | ax1s.text(0,0.75,' min=%f'%(fvmin)) 25 | ax1s.text(0,1.0 ,' med=%f'%(fvmed)) 26 | 27 | ax2 = plt.subplot(12,2,(2,8) ) 28 | if type(mno) == int: 29 | ax2.set_title('Geo-%s, month=%d'%(fld,mno)) 30 | if type(mno) == range: 31 | ax2.set_title('Geo-%s, month=%s'%(fld,'all')) 32 | fval=np.ravel( f2 ) 33 | fval=fval[~np.isnan(fval)] 34 | fvavg=np.nanmean(fval) 35 | fvstd=np.nanstd(fval) 36 | fvmin=np.nanmin(fval) 37 | fvmax=np.nanmax(fval) 38 | fvmed=np.nanmedian(fval) 39 | ax2.hist(np.ravel( fval ),nbin ) 40 | 41 | ax2s = plt.subplot(12,2,12 ) 42 | ax2s.set_axis_off() 43 | ax2s.text(0,0 ,'mean=%f'%(fvavg)) 44 | ax2s.text(0,0.25,' std=%f'%(fvstd)) 45 | ax2s.text(0,0.5 ,' max=%f'%(fvmax)) 46 | ax2s.text(0,0.75,' min=%f'%(fvmin)) 47 | ax2s.text(0,1.0 ,' med=%f'%(fvmed)) 48 | 49 | if type(mno) == int: 50 | pname='h_%s_m_%d.png'%(fld,mno) 51 | if type(mno) == range: 52 | pname='h_%s_m_%s.png'%(fld,'all') 53 | 54 | plt.savefig(pname) 55 | 56 | plt.show() 57 | 58 | # Lat-lon map plot 59 | def mkxyplot(x1,x2,fld,mno): 60 | 61 | fig=plt.figure(figsize=(20,10)) 62 | 63 | ax=plt.subplot(121) 64 | xr.plot.imshow(x1) 65 | ax.set_title('Dar-%s, month=%d'%(fld,mno)) 66 | 67 | ax=plt.subplot(122) 68 | xr.plot.imshow(x2) 69 | ax.set_title('Geo-%s, month=%d'%(fld,mno)) 70 | 71 | if type(mno) == int: 72 | pname='xy_%s_m_%d.png'%(fld,mno) 73 | if type(mno) == range: 74 | pname='xy_%s_m_%s.png'%(fld,'all') 75 | 76 | plt.savefig(pname) 77 | plt.show() 78 | 79 | -------------------------------------------------------------------------------- /cnh/histo/rrs-hist-plot.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | # In[18]: 5 | 6 | 7 | # docker run -P -d --rm -i -t -v `pwd`:/home/jovyan/host jupyter/datascience-notebook 8 | # -or- 9 | # curl https://repo.continuum.io/miniconda/Miniconda3-latest-MacOSX-x86_64.sh > Miniconda3-latest-MacOSX-x86_64.sh' 10 | # chmod +x Miniconda3-latest-MacOSX-x86_64.sh 11 | # ./Miniconda3-latest-MacOSX-x86_64.sh -b -p `pwd`/miniconda3 12 | # export PATH="`pwd`/miniconda3/bin:$PATH" 13 | # conda create -n ocean-clustering -c conda-forge python=3.7 14 | # 15 | # . miniconda3/etc/profile.d/conda.sh 16 | # conda activate ocean-clustering 17 | # 18 | # 19 | # conda install netCDF4 20 | # conda install numpy 21 | # conda install xarray 22 | # conda install cartopy 23 | 24 | import xarray as xr 25 | import matplotlib.pyplot as plt 26 | import numpy as np 27 | import cartopy.crs as ccrs 28 | 29 | 30 | # In[19]: 31 | 32 | 33 | geoF='gridded_geospatial_montly_clim_360_720_ver_0_2.nc' 34 | darF='gridded_darwin_montly_clim_360_720_ver_0_2.nc' 35 | geoDS = xr.open_dataset(geoF) 36 | darDS = xr.open_dataset(darF) 37 | 38 | # Make signs on bathymetry consistent 39 | x1=geoDS.bathymetry[:,:,:] 40 | x1.values=x1.values*-1. 41 | geoDS.bathymetry[:,:,:]=x1 42 | 43 | # Set number of histogram bins 44 | nbin=50 45 | 46 | 47 | # In[20]: 48 | 49 | exec(open("plotutils.py").read()) 50 | exec(open("fixdarwinlongitudes.py").read()) 51 | exec(open("makebathymasks.py").read()) 52 | exec(open("makeregmask.py").read()) 53 | exec(open("makechlmask.py").read()) 54 | 55 | # exec(open("plotbathy.py").read()) 56 | # OK now lets plot some fields for some month 57 | mno=0; 58 | 59 | exec(open("plotrrs.py").read()) 60 | 61 | exit() 62 | 63 | 64 | fld='SST_mask=%s'%(mskname) 65 | x1=darDS.THETA[mno,:,:] 66 | x1.values=x1.values*omskDar*regmskDar 67 | 68 | x2=geoDS.SST[mno,:,:] 69 | x2.values=x2.values*omskGeo*regmskGeo 70 | 71 | f1=x1.values 72 | f2=x2.values 73 | mkhplot(f1,f2,fld,mno) 74 | mkxyplot(x1,x2,fld,mno) 75 | 76 | 77 | # In[28]: 78 | 79 | 80 | fld='Chl_mask=%s'%(mskname) 81 | x1=darDS.Chl[mno,:,:] 82 | # Model data has some epsilon negative values, set these to zero 83 | # (amongst other things they cause xarray imshow to choose a dumb "divergent" color scale) 84 | phi=x1.values 85 | with np.errstate(invalid='ignore'): 86 | phi=np.where( phi<=0 ,0,phi) 87 | x1.values=phi 88 | # Mask to open ocean and region mask 89 | x1.values=x1.values*omskDar*regmskDar 90 | 91 | x2=geoDS.Chl[mno,:,:] 92 | # Obs data has a few very high values even in open ocean, so mask these and mask shallow ocean 93 | x2.values=x2.values*chlmskGeo[mno,:,:] 94 | x2.values=x2.values*omskGeo*regmskGeo 95 | 96 | f1=x1.values 97 | f2=x2.values 98 | 99 | mkhplot(f1,f2,fld,mno) 100 | mkxyplot(x1,x2,fld,mno) 101 | 102 | 103 | # In[29]: 104 | 105 | 106 | fld='PAR_mask=%s'%(mskname) 107 | x1=darDS.PAR[mno,:,:] 108 | # Get rid of points where PAR is exactly 0. 109 | phi=x1.values 110 | with np.errstate(invalid='ignore'): 111 | phi=np.where( phi==0 ,np.nan,phi) 112 | x1.values=phi 113 | x1.values=x1.values*omskDar*regmskDar 114 | f1=x1.values*omskDar 115 | 116 | x2=geoDS.PAR[mno,:,:] 117 | x2.values=x2.values*20.*omskGeo*regmskGeo 118 | f2=x2.values 119 | 120 | mkhplot(f1,f2,fld,mno) 121 | mkxyplot(x1,x2,fld,mno) 122 | 123 | 124 | # In[30]: 125 | 126 | 127 | fld='MLD_mask=%s'%(mskname) 128 | 129 | x1=darDS['MXLDEPTH'][mno,:,:] 130 | x1.values=x1.values*omskDar*regmskDar 131 | 132 | x2=geoDS.mld[mno,:,:] 133 | x2.values=x2.values*omskGeo*regmskGeo 134 | 135 | f1=x1.values 136 | f2=x2.values 137 | mkhplot(f1,f2,fld,mno) 138 | mkxyplot(x1,x2,fld,mno) 139 | 140 | # Now remake plots, with Dariwn deep convection sites clamped to <400m 141 | dcCap=400 142 | fld='MLD-cap=%d'%(dcCap) 143 | phi=x1.values 144 | with np.errstate(invalid='ignore'): 145 | phi=np.where( phi>dcCap ,dcCap,phi) 146 | x1.values=phi 147 | 148 | f1=x1.values 149 | f2=x2.values 150 | mkhplot(f1,f2,fld,mno) 151 | mkxyplot(x1,x2,fld,mno) 152 | 153 | 154 | # In[31]: 155 | 156 | 157 | nms=[412,443,490,510,555,670] 158 | 159 | for nm in nms: 160 | fld='R%d_mask=%s'%(nm,mskname) 161 | 162 | x1=darDS['Rirr%d'%(nm)][mno,:,:] 163 | x1.values=x1.values*omskDar*regmskDar 164 | 165 | x2=geoDS['Rrs%d'%(nm)][mno,:,:] 166 | # Mask points with very high irradiance 167 | # Rhigh=100000000 168 | # with np.errstate(invalid='ignore'): 169 | # x2.values=np.where(x2.values<=Rhigh,x2.values,np.nan) 170 | x2.values=x2.values*omskGeo*regmskGeo 171 | 172 | f1=x1.values 173 | f2=x2.values 174 | mkhplot(f1,f2,fld,mno) 175 | mkxyplot(x1,x2,fld,mno) 176 | 177 | 178 | # In[32]: 179 | 180 | 181 | fld='Euphotic Depth_mask=%s'%(mskname) 182 | 183 | x1=darDS['Euphotic Depth'][mno,:,:] 184 | x1.values=x1.values*omskDar*regmskDar 185 | x2=geoDS.euphotic_depth[mno,:,:] 186 | x2.values=x2.values*omskGeo*regmskGeo 187 | 188 | f1=x1.values 189 | f2=x2.values 190 | mkhplot(f1,f2,fld,mno) 191 | mkxyplot(x1,x2,fld,mno) 192 | 193 | 194 | # In[33]: 195 | 196 | 197 | fld='Wind-speed_mask=%s'%(mskname) 198 | 199 | x1=darDS['Wind Speed'][mno,:,:] 200 | x1.values=x1.values*omskDar*regmskDar 201 | 202 | 203 | x2=geoDS.wind[mno,:,:] 204 | # Mask the few very high wind speed points 205 | whigh=12 206 | with np.errstate(invalid='ignore'): 207 | x2.values=np.where(x2.values<=whigh,x2.values,np.nan) 208 | x2.values=x2.values*omskGeo*regmskGeo 209 | 210 | 211 | f1=x1.values 212 | f2=x2.values 213 | # f2=f2[np.where(f2<50.0)] 214 | mkhplot(f1,f2,fld,mno) 215 | mkxyplot(x1,x2,fld,mno) 216 | 217 | 218 | # In[34]: 219 | 220 | 221 | fld='KE_mask=%s'%(mskname) 222 | 223 | x1=darDS['TKE'][mno,:,:] 224 | x1.values=x1.values*omskDar*regmskDar 225 | 226 | x2=darDS['TKE'][mno,:,:] 227 | x2.values=x2.values*omskGeo*regmskGeo 228 | 229 | 230 | 231 | f1=x1.values 232 | f2=x2.values 233 | 234 | # f2=f2[np.where(f2<50.0)] 235 | mkhplot(f1,f2,fld,mno) 236 | mkxyplot(x1,x2,fld,mno) 237 | 238 | 239 | # In[ ]: 240 | 241 | 242 | 243 | 244 | --------------------------------------------------------------------------------