Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Easily exported coastwide grid #48

Open
ecophilina opened this issue Feb 20, 2024 · 18 comments
Open

Easily exported coastwide grid #48

ecophilina opened this issue Feb 20, 2024 · 18 comments

Comments

@ecophilina
Copy link

It would be nice, if this package had an easily exported coastwide mapping and prediction grid.
Ideally, it could include mean bottom depth.
Unless depth is already included in this package in a way that makes it easy to add it to the grid/any set of coordinates.

@nickcfisch
Copy link

I second this

@ecophilina
Copy link
Author

To add more specifics to this request, in addition to use as a prediction grid, I want to be able to filter the environmental variables in pacea to be just those areas with the depths occupied by a species in question.
So, what I'm looking for is a standardized coastwide grid that contains average bottom depth for each cell in addition to any of the rest of the pacea variables.
In the past I have used the package marmap to get a depth raster as here:
https://github.com/ecophilina/ye-wcvi/blob/main/analysis/00-make-grid.Rmd#L416C1-L552C1

@andrew-edwards
Copy link
Member

In PBSdata there is bctopo.rda which could be useful. As noted in #8.

@andrew-edwards
Copy link
Member

andrew-edwards commented Apr 24, 2024

I cleaned out some old unused grids.

So I think the grid26 object is what you want for the grid. It's already an object in the package, though we missed documenting it but will do in #56. Note this grid is used for mapping (converting) the BCCM outputs, but not for the OISST which retains it's original 1/4deg x 1/4deg grid.

> grid26
Simple feature collection with 41293 features and 0 fields
Geometry type: POLYGON
Dimension:     XY
Bounding box:  xmin: 164671.6 ymin: 163875 xmax: 1097612 ymax: 1103653
Projected CRS: NAD83 / BC Albers
First 10 features:
                                x
1  POLYGON ((963612.5 309653.1...
2  POLYGON ((963612.5 311653.1...
3  POLYGON ((965612.5 311653.1...
4  POLYGON ((967612.5 311653.1...
5  POLYGON ((963612.5 313653.1...
6  POLYGON ((965612.5 313653.1...
7  POLYGON ((967612.5 313653.1...
8  POLYGON ((969612.5 313653.1...
9  POLYGON ((963612.5 315653.1...
10 POLYGON ((965612.5 315653.1...
> class(grid26)
[1] "sf"         "data.frame"
> 

@travistai2 - this is what they should use yes?

Then, for depth, I think the steps are:

  • get some existing depth data, first try bctopo.rda from PBSdata, @haighr yes?
  • map that onto grid26 and save as a new object
  • document it
  • make a new vignette

@andrew-edwards
Copy link
Member

andrew-edwards commented Apr 24, 2024

Update: I looked into bctopo from PBSdata/PBSmapping. That was taken from a 1997 paper, and reformatted for PBSmapping. Would be better to use something more recent and that hasn't already been reformatted:

  • look at marmap package, as suggested by @ecophilina to get depth layers.

@andrew-edwards
Copy link
Member

grid26 is now documented - can be used as a 'standard' grid. Getting depth info next week.

@seananderson
Copy link
Member

marmap is convenient, but I believe we have a high resolution depth layer available through our spatial data hub that may be superior.

@andrew-edwards
Copy link
Member

From Cole Fields:
The data I usually recommend is listed in the open maps pdf report from my email. Here is the direct link: Canada west coast topo-bathymetric digital elevation model - Open Government Portal. It was generated by NRCan and is a mosaic of many data sources, including the MSEA one I mentioned. There are some other datasets in the pdf, and you could contact CHS as well if those don’t suit your needs.

@andrew-edwards
Copy link
Member

@KLFlynn and I looked at the data in the above comment. 7Gb, but does not go far enough out to see, just off the coast of Haida Gwaii.
Kelsey going to look (end of next week) at GEBCO, to which CHS contribute. Is ~450m resolution, which should be good. https://www.gebco.net/data_and_products/gridded_bathymetry_data/#global

@andrew-edwards
Copy link
Member

Kelsey has been working on this and has the dpeth values mapped to the grid. She just wants to double check some things, and then I can incorporate it into the package. So there will be mean, min and max depth for each grid cell.
We will get it included by lunchtime on Monday.

@travistai2
Copy link
Contributor

Amazing! Great work!

@andrew-edwards
Copy link
Member

Okay, new data object grid26_depth which is the same geometry as grid26 but also with columns mean_depth, min_depth, and max_depth in m , which are self-explanatory. Note for now these are negative values (i.e. depth of 1000 m is -1000 m), but we will likely change to be positive downwards, which is more logical for our purposes. Haven't done that yet as there are some values along that are positive (above sea level) that we haven't dug into yet (but Kelsey checked and there were all coastal).

I wrote a bit of a help file, but nothing extensive, and no vignette yet. So it's currently on branch dev-andy, so to install I think you need (but I haven't tested it)

remotes::install_github("pbs-assess/pacea",
                                       ref = "dev-andy")

Also, look in https://github.com/pbs-assess/pacea/blob/dev-andy/data-raw/depth/depth.R for sample plotting code, though I put a quick one in ?grid26_depth .

Big thanks to @KLFlynn for doing the extraction and dealing with all the projection complications.

The code in the above file can also be used to get depths for other areas also.

This should be useful enough for now. We'll have to also:

  • finish up the help file
  • write a vignette
  • update README and package authorship, and prob version number (time for 1.1.0!).

@ecophilina - hope this is good enough for now.
@travistai2 - this all sounds good yes? We kept it as a separate object (grid26_depth) instead of just adding to grid26 because doing the latter would mess up some plotting functions (and more) and not be back compatible. Objects aren't big so that's fine.

@travistai2
Copy link
Contributor

Just had a look through the object. Interesting that there are coastal values with positive depth values (indicating land). Some of those cells also have a range of only positive values (min to max depth are above sea level). Unsure of why that would be, even in the coastal areas. The BCCM data were used to create a polygon mask layer to then mask our grid (grid26) and only retain cells within the polygon, but I could imagine that there were some cells that barely overlapped the masked boundary (a tiny corner of the cell falling within the polygon mask layer) and perhaps those cells don't have ocean depth values from the bathymetry layer that you used.

Also, when converting depth values to positive, the max and min values should probably be switched - max depth = deeper (larger) values. Currently, the max_depth values represent shallower depths.

@ecophilina
Copy link
Author

Looks like it'll work for my immediate needs! Thanks! For now I will be excluding all grid cells with any positive values.
In the past when I have generated a depth values for a grid, I exclude everything with positive values first and calculate the proportion of the cell with water (assuming everything <0 at least sometimes has water covering it) and my mean, min, max depths from only those areas with negative values.

@andrew-edwards
Copy link
Member

Sounds good. Thanks Travis, yes good point about max and min, I hadn't really looked at the numbers. Will leave for now but we can easily switch before other people start using it.

@andrew-edwards
Copy link
Member

Now in the main branch (kind of by accident). Not had time for a vignette yet.

@andrew-edwards
Copy link
Member

  • The larger grid used for BCCM _full is contained in the geometry for each variables, not sure if need an extra grid variable.
  • But should do depth values, so repeat Kelsey's approach and save a _full_depth object.

@andrew-edwards
Copy link
Member

Related:

  • add confirmation that bccm_full and hotssea grids overlap, based on data-raw/hotssea/test-hotssea-bccm-full-overlap.R, but using new variables in package. Likely add to bccm_full vignette.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants