Open salvafern opened 3 months ago
New iteration on 2024-08-27. Some of the issues seem solved, thanks @wstolte !
$ ncdump -h foo.nc
netcdf foo {
dimensions:
lon = 4361 ;
lat = 4209 ;
aphiaid = 4 ;
string80 = 80 ;
variables:
double lon(lon) ;
lon:units = "degrees_east" ;
lon:standard_name = "longitude" ;
lon:long_name = "Longitude" ;
double lat(lat) ;
lat:units = "degrees_north" ;
lat:standard_name = "latitude" ;
lat:long_name = "Latitude" ;
int aphiaid(aphiaid) ;
aphiaid:long_name = "Life Science Identifier - World Register of Marine Species" ;
char taxon_name(aphiaid, string80) ;
taxon_name:standard_name = "biological_taxon_name" ;
taxon_name:long_name = "Scientific name of the taxa" ;
char taxon_lsid(aphiaid, string80) ;
taxon_lsid:standard_name = "biological_taxon_lsid" ;
taxon_lsid:long_name = "Life Science Identifier - World Register of Marine Species" ;
char crs ;
crs:long_name = "Coordinate Reference System" ;
crs:geographic_crs_name = "WGS 84" ;
crs:grid_mapping_name = "latitude_longitude" ;
crs:reference_ellipsoid_name = "WGS 84" ;
crs:horizontal_datum_name = "WGS 84" ;
crs:prime_meridian_name = "Greenwich" ;
crs:longitude_of_prime_meridian = 0. ;
crs:semi_major_axis = 6378137. ;
crs:semi_minor_axis = 6356752.31424518 ;
crs:inverse_flattening = 298.257223563 ;
crs:spatial_ref = "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AXIS[\"Latitude\",NORTH],AXIS[\"Longitude\",EAST],AUTHORITY[\"EPSG\",\"4326\"]]" ;
crs:GeoTransform = "-180 0.08333333333333333 0 90 0 -0.08333333333333333 " ;
double habitat_suitability(aphiaid, lat, lon) ;
habitat_suitability:_FillValue = -99999. ;
habitat_suitability:long_name = "Modelled habitat suitability for a species." ;
}
Indeed I can see that the data is not correctly plot (this case in panoply)
I have faced this before and fixed by changing the order of the data, not the latitude/longitude. Lat and Lon must be in ascendent order. You read the data as a matrix and via transpose t()
or changing order apply(x, 1, rev)
you can rotate the data. I have tried quickly but don't have time now to continue, but the solution must be something similar.
library(terra)
array <- terra::rast("foo.nc") |>
terra::as.array()
matrix <- array[, , 1] |>
terra::as.matrix()
dim(matrix)
# Transpose dimensions
matrix <- t(matrix)
# dim(matrix)
# Reverse order of lon
matrix <- apply(matrix, 1, rev)
# dim(matrix)
# Traspose one more time
matrix <- t(matrix)
raster <- terra::rast(matrix)
crs(raster) <- "+proj=lcc +lat_1=48 +lat_2=33 +lon_0=-100 +ellps=WGS84"
plot(raster)
One more version sent on 2024-08-27. Product looking good!
ncdump -h foo.nc
netcdf foo {
dimensions:
lon = 4361 ;
lat = 4209 ;
aphiaid = 4 ;
string80 = 80 ;
variables:
double lon(lon) ;
lon:units = "degrees_east" ;
lon:standard_name = "longitude" ;
lon:long_name = "Longitude" ;
double lat(lat) ;
lat:units = "degrees_north" ;
lat:standard_name = "latitude" ;
lat:long_name = "Latitude" ;
int aphiaid(aphiaid) ;
aphiaid:long_name = "Life Science Identifier - World Register of Marine Species" ;
char taxon_name(aphiaid, string80) ;
taxon_name:standard_name = "biological_taxon_name" ;
taxon_name:long_name = "Scientific name of the taxa" ;
char taxon_lsid(aphiaid, string80) ;
taxon_lsid:standard_name = "biological_taxon_lsid" ;
taxon_lsid:long_name = "Life Science Identifier - World Register of Marine Species" ;
char crs ;
crs:long_name = "Coordinate Reference System" ;
crs:geographic_crs_name = "WGS 84" ;
crs:grid_mapping_name = "latitude_longitude" ;
crs:reference_ellipsoid_name = "WGS 84" ;
crs:horizontal_datum_name = "WGS 84" ;
crs:prime_meridian_name = "Greenwich" ;
crs:longitude_of_prime_meridian = 0. ;
crs:semi_major_axis = 6378137. ;
crs:semi_minor_axis = 6356752.31424518 ;
crs:inverse_flattening = 298.257223563 ;
crs:spatial_ref = "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AXIS[\"Latitude\",NORTH],AXIS[\"Longitude\",EAST],AUTHORITY[\"EPSG\",\"4326\"]]" ;
crs:GeoTransform = "-180 0.08333333333333333 0 90 0 -0.08333333333333333 " ;
double habitat_suitability(aphiaid, lat, lon) ;
habitat_suitability:_FillValue = -99999. ;
habitat_suitability:long_name = "Modelled habitat suitability for a species." ;
}
There are only some details to be tackled:
taxon_lsid
is the same as taxon_name
, could you make taxon_lsid
be "urn:lsid:marinespecies.org:taxname:" + aphiaid?
$ ncdump -v taxon_lsid foo.nc
taxon_lsid =
"Sabellaria spinulosa",
"Lanice conchilega",
"Modiolus modiolus",
"Ostrea edulis" ;
* Could you rename the long_name attribute of "habitat_suitability" to "Probability of occurrence of biological entity specified elsewhere per unit area of the bed"
* Could you rename the variable "habitat_suitability" to "probability_of_occurrence"?
* Could you add the attribute "units" = "level" to the variable "aphiaid"?
* Could you fill the global attributes?
Thanks. Rethinking, I am not sure whether "probability_of_occurrence" is correct. It is not based on occurence alone, but it is using environmental information to find other areas (where they are not found at the moment) where they might be able to grow/live. Is it possible to stick to "habitat suitability"?
Apologies for the belated answer. Yes you can stick to "habitat_suitability".
As I mentioned in the last call, we will have to come up with standardized names for the variables we create. We will have to define both terms. I will need your feedback (and from the other partners) then, but for now we can put a pin on it.
Hi @wstolte,
Here some issues Im finding in the file with the final product. Writing here for documentation. Notice how the values of the variables present some aberrations.
e.g. I would not expect such high max and low min values of latitude, longitude or habitat suitability.
Longitude, latitude and aphiaid must be in ascendant order. Longitude must not have duplicated values.
The aphiaIDs in the file do not exist. The taxon_name and taxon_lsid seem corrupt.
Could you have a look? Maybe something went wrong when creating the file?
Created on 2024-08-09 with reprex v2.1.0
Session info
``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.3.3 (2024-02-29) #> os Ubuntu 22.04.4 LTS #> system x86_64, linux-gnu #> ui X11 #> language (EN) #> collate en_US.UTF-8 #> ctype en_US.UTF-8 #> tz Europe/Brussels #> date 2024-08-09 #> pandoc 3.1.1 @ /usr/lib/rstudio/resources/app/bin/quarto/bin/tools/ (via rmarkdown) #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source #> cli 3.6.2 2023-12-11 [1] CRAN (R 4.3.2) #> digest 0.6.33 2023-07-07 [1] CRAN (R 4.3.2) #> dplyr * 1.1.4 2023-11-17 [1] CRAN (R 4.3.2) #> evaluate 0.23 2023-11-01 [1] CRAN (R 4.3.2) #> fansi 1.0.6 2023-12-08 [1] CRAN (R 4.3.2) #> fastmap 1.1.1 2023-02-24 [1] CRAN (R 4.3.2) #> fs 1.6.3 2023-07-20 [1] CRAN (R 4.3.2) #> generics 0.1.3 2022-07-05 [1] CRAN (R 4.3.2) #> glue 1.7.0 2024-01-09 [1] CRAN (R 4.3.2) #> htmltools 0.5.7 2023-11-03 [1] CRAN (R 4.3.2) #> knitr 1.45 2023-10-30 [1] CRAN (R 4.3.2) #> lifecycle 1.0.4 2023-11-07 [1] CRAN (R 4.3.2) #> magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.3.2) #> ncdf4 * 1.22 2023-11-28 [1] CRAN (R 4.3.2) #> pillar 1.9.0 2023-03-22 [1] CRAN (R 4.3.2) #> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.3.2) #> purrr 1.0.2 2023-08-10 [1] CRAN (R 4.3.2) #> R.cache 0.16.0 2022-07-21 [1] CRAN (R 4.3.2) #> R.methodsS3 1.8.2 2022-06-13 [1] CRAN (R 4.3.2) #> R.oo 1.26.0 2024-01-24 [1] CRAN (R 4.3.2) #> R.utils 2.12.3 2023-11-18 [1] CRAN (R 4.3.2) #> R6 2.5.1 2021-08-19 [1] CRAN (R 4.3.2) #> reprex 2.1.0 2024-01-11 [1] CRAN (R 4.3.2) #> rlang 1.1.3 2024-01-10 [1] CRAN (R 4.3.2) #> rmarkdown 2.26 2024-03-05 [1] CRAN (R 4.3.3) #> rstudioapi 0.16.0 2024-03-24 [1] CRAN (R 4.3.3) #> sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.3.2) #> styler 1.10.2 2023-08-29 [1] CRAN (R 4.3.2) #> tibble 3.2.1 2023-03-20 [1] CRAN (R 4.3.2) #> tidyselect 1.2.1 2024-03-11 [1] CRAN (R 4.3.3) #> utf8 1.2.4 2023-10-22 [1] CRAN (R 4.3.2) #> vctrs 0.6.5 2023-12-01 [1] CRAN (R 4.3.2) #> withr 3.0.0 2024-01-16 [1] CRAN (R 4.3.2) #> xfun 0.43 2024-03-25 [1] CRAN (R 4.3.3) #> yaml 2.3.8 2023-12-11 [1] CRAN (R 4.3.2) #> #> [1] /home/localadmin/R/x86_64-pc-linux-gnu-library/4.3 #> [2] /usr/local/lib/R/site-library #> [3] /usr/lib/R/site-library #> [4] /usr/lib/R/library #> #> ────────────────────────────────────────────────────────────────────────────── ```