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

Tutorial 4 - Geophysics (Seismology): Add JN #8

Merged
merged 75 commits into from
Dec 4, 2024
Merged

Conversation

yvonnefroehlich
Copy link
Member

@yvonnefroehlich yvonnefroehlich commented Nov 9, 2024

This PR adds the Jupyter notebook for Tutorial 4 - Geophysics (Seismology).

Content:

Feel free to fill the subsections with suggestions for code and docs🙂.

Preview:

Fixes: #6

@yvonnefroehlich yvonnefroehlich changed the title WIP: Add JN for tutorial 4 Geophysics (Seismology) WIP: Tutorial 4 - Geophysics (Seismology): Add JN Nov 9, 2024
@jhtong33
Copy link
Collaborator

Hi @yvonnefroehlich
do we use grdproject or project ?
Since grdproject is specified for a region rather than individual point-to-point.

see also: https://www.pygmt.org/v0.13.0/gallery/images/cross_section.html#sphx-glr-gallery-images-cross-section-py

@yvonnefroehlich
Copy link
Member Author

Hi @yvonnefroehlich do we use grdproject or project ? Since grdproject is specified for a region rather than individual point-to-point.

see also: https://www.pygmt.org/v0.13.0/gallery/images/cross_section.html#sphx-glr-gallery-images-cross-section-py

Yep, I am sorry, I mean project I mistyped this 🙁.

Copy link
Member Author

@yvonnefroehlich yvonnefroehlich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot, @jhtong33 , for getting started here 👍!

I made a few updates:

  • I prefer to use the Scientific colour maps by F. Crameri, i.e., for topography, "oleron".
  • I reduced the resolution of the image showing within the Jupyter notebook to keep the file size smaller.
  • I figured out that list input is supported for the center and endpoint parameters of project.
  • Fix typo grdproject to project.
  • So minor code style improvements.
  • I think we should be consistent and use either single (') or double (") quotation marks; I prefer double quotation marks.

@jhtong33
Copy link
Collaborator

Thanks a lot, @jhtong33 , for getting started here 👍!

I made a few updates:

  • I prefer to use the Scientific colour maps by F. Crameri, i.e., for topography, "oleron".
  • I reduced the resolution of the image showing within the Jupyter notebook to keep the file size smaller.
  • I figured out that list input is supported for the center and endpoint parameters of project.
  • Fix typo grdproject to project.
  • So minor code style improvements.
  • I think we should be consistent and use either single (') or double (") quotation marks; I prefer double quotation marks.

Great! Thanks for your updates.
I used a remote dataset to convert data into a .txt file, which I then provided as input materials for pygmt.xyz2grd.

@jhtong33
Copy link
Collaborator

Hi @yvonnefroehlich
I have one idea that plotting beachballs for magnitude >6 events to make the tutorial more comprehensive.
However, If time make it challenging to cover all details within a 45-minute session, it would be great to focus on one significant event as an example.

see also: https://www.isc.ac.uk/cgi-bin/web-db-run?request=COMPREHENSIVE&out_format=CATCSV&searchshape=RECT&bot_lat=-40&top_lat=0&left_lon=-90&right_lon=-60&ctr_lat=&ctr_lon=&radius=&max_dist_units=deg&srn=&grn=&start_year=2022&start_month=1&start_day=01&start_time=00%3A00%3A00&end_year=2023&end_month=1&end_day=01&end_time=00%3A00%3A00&min_dep=&max_dep=&min_mag=6&max_mag=&req_mag_type=MW&req_mag_agcy=&include_links=on

@yvonnefroehlich
Copy link
Member Author

Hm. But for me, this approach does not work in the expected way. Actually, this reminds me a bit of ObsPy where users actively need to copy the Stream object, before applying any processing steps in case they want to keep their raw data in the initial variable unchanged (https://docs.obspy.org/packages/autogen/obspy.core.stream.Stream.copy.html).

I misunderstood your meaning previously. I also encounter same condition in Jupyter lab. In obspy, they use copy.deepcopy(self). I tried to use same way to solve this issue, but the result is same.

This seem to be more complicated to implemente, please see GenericMappingTools/pygmt#3645 (comment) for details.

@yvonnefroehlich
Copy link
Member Author

Are there any major review requests on this tutorial 🙂? Otherwise, I feel we can move on and merge this tutorial in the current state and, if needed, open separat PRs for minor corrections and improvements.

@Esteban82
Copy link
Member

I have two observations only:

  1. The first row of the seismicity_2022.csv file is: time,lon,lat,depth,mag. With GMT, it is good to add a # to the beginning of the line so that it is automatically identified as a header. I suspect that with PyGMT this is not necessary. is it true?
  2. It would be possible to add a shading effect to the topographic map of South America. The idea would be to show that with GMT you can make very good maps simply.
    Then, during the workshop it might be better to say that one removes the shading effect to make the processing faster.

@yvonnefroehlich
Copy link
Member Author

  1. The first row of the seismicity_2022.csv file is: time,lon,lat,depth,mag. With GMT, it is good to add a # to the beginning of the line so that it is automatically identified as a header. I suspect that with PyGMT this is not necessary. is it true?

In this tutorial, we read the CSV file via pandas into a DataFrame. The first line is by default considered as the header line and used for the column names. Later, these column names can be used to access the single columns. pandas does not require a # to indicate a header line, but would include the # into the first column name 😬:

                            #time      lon      lat    depth  mag
0     2022-12-31T23:04:12.784000Z -69.6800 -16.5378  196.743  4.9
1     2022-12-31T12:47:57.842000Z -71.5625 -32.2686   48.300  4.5
2     2022-12-31T03:31:43.830000Z -68.8969 -23.1036   96.224  5.1
3     2022-12-31T00:43:57.999000Z -77.7617  -1.7451  182.543  4.3
4     2022-12-30T22:35:25.866000Z -67.1397 -24.0267  232.941  4.5
                          ...      ...      ...      ...  ...

Thus, I prefer to leave this file as is.

@yvonnefroehlich
Copy link
Member Author

  1. It would be possible to add a shading effect to the topographic map of South America. The idea would be to show that with GMT you can make very good maps simply.
    Then, during the workshop it might be better to say that one removes the shading effect to make the processing faster.

Hm. You mean something simliar as Max does in the Xarray tutorial in the section "Processing raster data" (https://github.com/GenericMappingTools/agu24workshop/blob/add-xarray-tutorial/book/tut03_spec_xarray.ipynb) using grdgradient? Maybe we can include this in the section "Additional comments" as the tutorial is already a bit longer?

@Esteban82
Copy link
Member

Hm. You mean something simliar as Max does in the Xarray tutorial in the section "Processing raster data" (https://github.com/GenericMappingTools/agu24workshop/blob/add-xarray-tutorial/book/tut03_spec_xarray.ipynb) using grdgradient? Maybe we can include this in the section "Additional comments" as the tutorial is already a bit longer?

My idea is just to make the maps look better. I don't think it's necessary to explain anything. So, I think you can add something like shading="+a" in the code so the map looks better.

@yvonnefroehlich
Copy link
Member Author

Hm. You mean something simliar as Max does in the Xarray tutorial in the section "Processing raster data" (https://github.com/GenericMappingTools/agu24workshop/blob/add-xarray-tutorial/book/tut03_spec_xarray.ipynb) using grdgradient? Maybe we can include this in the section "Additional comments" as the tutorial is already a bit longer?

My idea is just to make the maps look better. I don't think it's necessary to explain anything. So, I think you can add something like shading="+a" in the code so the map looks better.

Ah, I first thought about grdgradient but applying the illumination directly via grdimage sounds good to me. Made an update in commit a3ded9d.

"3. `annotation`: Annotate contour levels.\n",
"4. `limit`: Draw contours below low or above high, e.g., [-4000, 0] means drawing contour lines below sea level and above -4000 m.\n",
"\n",
"Before we plot the grid as contour lines, we plot the grid with color-coding using [`pygmt.Figure.grdimage`](https://www.pygmt.org/v0.13.0/api/generated/pygmt.Figure.grdimage.html). Via the `shading` parameter, we can apply an illumination to the grid or image, which can help to create visually appealing maps. By passing the argument **+a**, we use an azimuth of -45 degrees. Run the next code cell twice, first without and second with illumination, to see the difference. For more a complicated illumination, please refer to [`pygmt.grdgradient`](https://www.pygmt.org/v0.13.0/api/generated/pygmt.grdgradient.html), which was already introduced in Tutorial 3."
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering if and how it is possible to add links to the other Jupyter notebooks or scripts (if this is possible, maybe we can also do this in a common PR).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I fully understand your point. Are you suggesting that this information could be linked to the current gallery?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm. What do you mean with "current gallery"?

We partly mention other tutorials, which is good. I feel it would be nice to directly insert the link. But we have the URL from GitHub (https://github.com/GenericMappingTools/agu24workshop/blob/main/book/tut0XYZ.ipynb) as well as the one from the Jupyter book (https://www.generic-mapping-tools.org/agu24workshop/XYZ.html). So depending on which website people are, the link does lead them to another "base" website. As the Jupyter book website is the "official" website for this workshop and GitHub is more for development, maybe using the URL to the Jupyter book website makes more sense here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I understand what you mean.

As the Jupyter book website is the "official" website for this workshop and GitHub is more for development, maybe using the URL to the Jupyter book website makes more sense here?

YES. Providing the URL to the Jupyter Book website will make it more convenient and readable.

Copy link
Member

@weiji14 weiji14 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonderful, thanks @yvonnefroehlich and @jhtong33 for working on this! Sorry for leaving this last, Seismology isn't my area of expertise, so I was hoping someone would jump in to review, but I trust that this is ok. Personally, I would have preferred it if the .txt and .csv file were not in the repository since they are big files, but hopefully everyone has good internet connection during the workshop 😆

I've got some minor suggestions below, which either of you can apply, and then I will try to merge this by tomorrow. After this, we can work on polishing all of the notebooks to have a consistent header, title and such.

@jhtong33
Copy link
Collaborator

jhtong33 commented Dec 3, 2024

Personally, I would have preferred it if the .txt and .csv file were not in the repository since they are big files, but hopefully everyone has good internet connection during the workshop 😆

If needed, I can adjust the period of the earthquake catalog, which might reduce the file size. (current size: 63 kb)

@yvonnefroehlich
Copy link
Member Author

yvonnefroehlich commented Dec 3, 2024

Wonderful, thanks @yvonnefroehlich and @jhtong33 for working on this! Sorry for leaving this last, Seismology isn't my area of expertise, so I was hoping someone would jump in to review, but I trust that this is ok.

Now worries @weiji14, @Esteban82 made already some helpful suggestions! And somethings it's actually also good to have a review from another field and also good to a have native-speaking person reading through the documentation.

Personally, I would have preferred it if the .txt and .csv file were not in the repository since they are big files, but hopefully everyone has good internet connection during the workshop 😆

Yeah! Also was thinking about what is better: people download the data during the tutorials or we provide data files within the repo, when creating the pands / geopandas tutorial. Downloading the data directly underlines that PyGMT integrates smoothly in the complete analysis workflow, and we keep the repo size small. Regarding a stable internet connection, I feel (hope) this should work (I have never been to AGU or any other big conference yet, but a working (acceptable fast) internet connection is essential for a nicely running conference) .

Regarding the elevation data: The "normal" way doing this would be to simply download the built-in GMT remote dataset for the Earth relief into a xarray.DataArray and using it for the further processing and analysis. However, in this tutorial, we like to show how people can convert any specific grid which is provided as xyz columns into a [Py]GMT-ready grid. Thus, the elevation data was written to a txt file with xyz columns, and in the tutorial we convert it back to a [Py]GMT-ready grid via xyz2grd.

Regarding the seismicity data: ObsPy is required to request and download this data. If we include this part within the tutorial, ObsPy will become a dependency, which people need to install. This was probably the reason why Jing-Hui downloaded the data externally and wrote it to a CSV file for usage in the tutorial (reading via pandas).

I've got some minor suggestions below, which either of you can apply, and then I will try to merge this by tomorrow. After this, we can work on polishing all of the notebooks to have a consistent header, title and such.

Sounds good!

@jhtong33
Copy link
Collaborator

jhtong33 commented Dec 3, 2024

Regarding the elevation data: The "normal" way doing this would be to simply download the built-in GMT remote dataset for the Earth relief into a xarray.DataArray and using it for the further processing and analysis. However, in this tutorial, we like to show how people can convert any specific grid which is provided as xyz columns into a [Py]GMT-ready grid. Thus, the elevation data was written to a txt file with xyz columns, and in the tutorial we convert it back to a [Py]GMT-ready grid via xyz2grd.

Yvonne mentioned a critical point: many current datasets (e.g., crustal thickness and seismic tomography) are available only as xyz columns rather than pre-processed GMT grids. If beginners fail to correctly convert xyz data into a grid, using grdimage will not produce accurate results. That’s why providing the xyz file is essential.

Regarding the seismicity data: ObsPy is required to request and download this data. If we include this part within the tutorial, ObsPy will become a dependency, which people need to install. This was probably the reason why Jin-Hui downloaded the data externally and wrote it to a CSV file for usage in the tutorial (reading via pandas).

If including Obspy, installing and downloading IRIS dataset more relies on internet.
I can mitigate this by reducing the file size, perhaps by limiting the earthquake data to a shorter time period.

@weiji14
Copy link
Member

weiji14 commented Dec 3, 2024

Regarding the elevation data: The "normal" way doing this would be to simply download the built-in GMT remote dataset for the Earth relief into a xarray.DataArray and using it for the further processing and analysis. However, in this tutorial, we like to show how people can convert any specific grid which is provided as xyz columns into a [Py]GMT-ready grid. Thus, the elevation data was written to a txt file with xyz columns, and in the tutorial we convert it back to a [Py]GMT-ready grid via xyz2grd.

Yvonne mentioned a critical point: many current datasets (e.g., crustal thickness and seismic tomography) are available only as xyz columns rather than pre-processed GMT grids. If beginners fail to correctly convert xyz data into a grid, using grdimage will not produce accurate results. That’s why providing the xyz file is essential.

Ah I see, then teaching xyz2grd would make sense here. Thanks for the extra context, this is why having people working in the same field makes sense 😉

Regarding the seismicity data: ObsPy is required to request and download this data. If we include this part within the tutorial, ObsPy will become a dependency, which people need to install. This was probably the reason why Jin-Hui downloaded the data externally and wrote it to a CSV file for usage in the tutorial (reading via pandas).

If including Obspy, installing and downloading IRIS dataset more relies on internet. I can mitigate this by reducing the file size, perhaps by limiting the earthquake data to a shorter time period.

The earthquake data in CSV format is actually not too big (64KB before, now 29KB). It's more the south_america_topography_05m.txt file that's a little large (5.0MB) 🙂, but I think it's ok to just keep it in the repository for now instead of changing the workflow. Also ok with having ObsPy included in the dependency list, but that can be done in a follow-up PR (only if there's time, otherwise the PR is ok as is).

@jhtong33, I'll leave this up for a few more hours in case there's any small changes you still want to make, and will merge once you hit approve (or by the end of my work day in ~7 hours).

@weiji14 weiji14 merged commit e87bf44 into main Dec 4, 2024
1 check passed
@weiji14 weiji14 deleted the add-jn-geo-seis branch December 4, 2024 01:26
@weiji14
Copy link
Member

weiji14 commented Dec 4, 2024

@yvonnefroehlich yvonnefroehlich removed the needs review Review of this PR is welcome label Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tutorial 4 - Geophysics (Seismology): Ideas and basic concept
4 participants