GPlates / gplately

GPlately is a Python package to interrogate tectonic plate reconstructions.
https://gplates.github.io/gplately/
GNU General Public License v2.0
55 stars 12 forks source link

06-Rasters etopo #233

Closed saraemp closed 1 month ago

saraemp commented 1 month ago

This issue is for the following instructions:

Alternatively, you can import a local netcdf file using by passing the filename to gplately.grids.Raster or gplately.grids.read_netcdf_grid

The links are broken (404) and once you run the following to make it work gplately.grids.read_netcdf_grid(raster_manager.get_raster("ETOPO1_grd")) you get a message that says: "The local file(s) is/are still good. Will not download again at this moment."

But doesn't tell you that you have run the following

from plate_model_manager import PlateModelManager, PresentDayRasterManager

Initialize the raster manager and load the ETOPO1 grid data

raster_manager = PresentDayRasterManager() etopo = gplately.grids.read_netcdf_grid(raster_manager.get_raster("ETOPO1_grd"))

Extract the rows and columns of the etopo.data array

etopo = etopo.data[::]

Define the latitude and longitude ranges

lat_start, lat_end = -90, 90 lon_start, lon_end = -180, 180

Create latitude and longitude arrays

latitudes = np.linspace(lat_start, lat_end, etopo.shape[0])

longitudes = np.linspace(lon_start, lon_end, etopo.shape[1])

plt.imshow(etopo, extent=[lon_start, lon_end, lat_start, lat_end], origin='lower', norm=divnorm, cmap=terrain_map)

michaelchin commented 1 month ago

The code snippet below is working for me. Would you like to try it?

import gplately
from plate_model_manager import PlateModelManager, PresentDayRasterManager
import numpy as np
import matplotlib
import matplotlib.pyplot as plt

#Initialize the raster manager and load the ETOPO1 grid data
raster_manager = PresentDayRasterManager()
etopo = gplately.grids.read_netcdf_grid(raster_manager.get_raster("ETOPO1_grd"))

#Extract the rows and columns of the etopo.data array
etopo = etopo.data[::]

#Define the latitude and longitude ranges
lat_start, lat_end = -90, 90
lon_start, lon_end = -180, 180

# Create latitude and longitude arrays
latitudes = np.linspace(lat_start, lat_end, etopo.shape[0])
longitudes = np.linspace(lon_start, lon_end, etopo.shape[1])
divnorm = matplotlib.colors.TwoSlopeNorm(vmin=-500., vcenter=0, vmax=4000)
plt.imshow(etopo, extent=[lon_start, lon_end, lat_start, lat_end], origin='lower', norm=divnorm, cmap='terrain')
michaelchin commented 1 month ago

here is the image I plotted with the above code snippet.

Screenshot 2024-07-18 at 5 37 06 PM
saraemp commented 1 month ago

Hi Michael, yes we both ended up writing the same that code snippet. That snippet is not currently on the 06-Rasters. I wrote it because the links for the current instructions are broken. https://github.com/GPlates/gplately/blob/master/Notebooks/06-Rasters.ipynb

My point was that at the moment this is the only thing that the notebook says: Screenshot 2024-07-18 at 18 31 07

Once I figured out that this is the command I had to run gplately.grids.read_netcdf_grid(raster_manager.get_raster("ETOPO1_grd")) I got a message saying: "The local file(s) is/are still good. Will not download again at this moment."

But I wasn't sure what to do next and so that's why I am shared the code snipped I wrote so we both ended up writing the same code ;)

michaelchin commented 1 month ago

The message "The local file(s) is/are still good. Will not download again at this moment." means GPlately had already downloaded the raster file before and there is a copy in your local cache. So GPlately will not download it again and just use the local copy.

Alternatively, you can import a local netcdf file using by passing the filename to gplately.grids.Raster or gplately.grids.read_netcdf_grid

This means that you may use a local file directly instead of asking GPlately to download the file from Internet. For example, if you have a file on local computer and its path is "present-day-rasters/etopo1_grd/ETOPO1_Ice_g_gmt4.grd", you can just use gplately.grids.read_netcdf_grid("present-day-rasters/etopo1_grd/ETOPO1_Ice_g_gmt4.grd") instead of gplately.grids.read_netcdf_grid(raster_manager.get_raster("ETOPO1_grd"))

It seems to me that you are doing things correctly. I don't really see a problem here.

michaelchin commented 1 month ago

Hi @saraemp,

I am not sure what I can do for this issue.

Do you want me to add "from plate_model_manager import PlateModelManager, PresentDayRasterManager" to code cell 7?

Screenshot 2024-07-23 at 7 39 35 PM

The import actually has been done in code cell 1. It is not necessary to import it again.

Screenshot 2024-07-23 at 7 36 35 PM

You need to run the code cells from top to bottom in order. Some code cells rely on the output of previous code cells to work.