# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # Final Micro Project

# The time has come to apply what you have learned throughout the course by doing a mini project. 

# You have two options now.
#
# 1. Choose from our list of projects
#     - [Meteorite Landings](#Meteorite-Landings)
#     - [Significant Earthquakes](#Significant-Earthquakes)
#     - [World Ocean Atlas](#World-Ocean-Atlas)
#     - [Arctic Sea Ice](#Arctic-Sea-Ice)
#     - [Other](#Other-Data)
#
# 2. Use your own data
#
#     - If you find our ideas terrible or you are eager to start using Python in your work, you can use your own data.
#     - The only requirement is that data should be in a format that we have used in this course, preferably **CSV/ASCII** or **netCDF** file.
#     - We might not be very helpful, but at least we can help you get started and/or point you to a relevant resource.

# ## Meteorite Landings

# NASA has a great [archive of open data](https://data.nasa.gov/browse) that you can use to master your data analysis skills. Moreover, there is even a small Python library to fetch some of the datasets: [pyNASA](https://bmtgoncalves.github.io/pyNASA/).

# For example, Meteorite Landings dataset can be either downloaded manually from https://data.nasa.gov/Space-Science/Meteorite-Landings/gh4g-9sfh or fetched as a `pandas.DataFrame` using `pyNASA.meteorite()` method. Some further ideas:
# * `pandas` package will be most useful to read in the data, as well as analyse them
# * Use `cartopy` to plot the data using longitude and latitude columns
# * Use scatter plot to show meteorites' mass in colour
# * Create a histogram of earthquakes magnitude

# ## Significant Earthquakes

# US Geological Survey (USGS) provides various [earthquakes data](https://earthquake.usgs.gov/data/data.php#eq) on a global scale. Its Earthquake Catalog contains earthquake source parameters (e.g. hypocenters, magnitudes, phase picks and amplitudes) and other products (e.g. moment tensor solutions, macroseismic information, tectonic summaries, maps) produced by contributing seismic networks.

# If you follow this [link](http://earthquake.usgs.gov/earthquakes/search/), you can search throught the catalog and filter data by the magnitude, time and geographic region. In the `data/` folder, we provide an [example dataset](../data/earthquakes_2015_2016_gt45.csv) of earthquakes with magnitude >4.5 that occurred around the world throughout the last year.

# So if you want to build your project on these data, some possible ideas are:
# * `pandas` package will be most useful to read in the data, as well as analyse them
# * Use `cartopy` to plot the data using longitude and latitude columns
# * Explore `pandas`' `groupby()` method, which you can use to aggregate data by time or other parameter
# * Create a histogram of earthquakes magnitude

# To get you started, we provided the minimal code to load the data.

# +
# import pandas as pd
# df = pd.read_csv('../data/earthquakes_2015_2016_gt45.csv', parse_dates = ['time',], index_col='time')
# df.head()
# -

# ## World Ocean Atlas

# NOAA's [World Ocean Atlas](https://www.nodc.noaa.gov/OC5/WOA09/netcdf_data.html) (WOA) provides open-access gridded data of temperature, salinity and other ocean parameters.  
# It is a set of objectively analyzed climatological fields at standard depth levels for annual, seasonal, and monthly compositing periods. It also includes associated statistical fields of observed oceanographic profile data.

# WOA is available over a variety of resolutions (5$^\circ$, 1$^\circ$ or 1/4$^\circ$grid). It is also available in different data formats.  
# If you choose to analyse these data, we suggest that you follow these initial steps:
#
# * download 5$^\circ$ data of temperature and oxygen, in NetCDF format. 
# * plot the sea surface data (or depth of choice) on a global map 
#     * do not use jet/rainbow colormap!
# * calculate an average depth profile and plot it beside the map
#
# Bonus step: 
# * Rather than creating two sections of code for each variable, can you create a function that will produce plots for either the temperature or oxygen variables?  

# +
# Hint: 
# To download temperature data into xarray, you can use the following e.g. 
# WOA_temp = xr.open_dataset('https://data.nodc.noaa.gov/thredds/dodsC/ncei/woa/temperature/decav/5deg/woa18_decav_t00_5d.nc', decode_times=False)
# decode_times=False is needed when xarray cannot process dates on import (you will see an error if use without). 
# To access oxygen, you can use the following URL:
# https://data.nodc.noaa.gov/thredds/dodsC/ncei/woa/oxygen/all/1.00/woa18_all_o00_01.nc


# -

# ## Arctic Sea Ice

# ### Data
# * In this project you are offered to use NOAA/NSIDC Climate Data Record of Passive Microwave Sea Ice Concentration.
# * In the `../data/` directory, there are 2 netCDF files `seaice_conc_monthly*` that correspond to September 1991 ([original FTP link](ftp://sidads.colorado.edu/pub/DATASETS/NOAA/G02202_v2/north/monthly/seaice_conc_monthly_nh_f08_199109_v02r00.nc)) and September 2012 ([original FTP link](ftp://sidads.colorado.edu/pub/DATASETS/NOAA/G02202_v2/north/monthly/seaice_conc_monthly_nh_f17_201209_v02r00.nc)).
# * If you want to download data for other months, visit the [NSIDC's data portal](https://nsidc.org/data/search/#keywords=sea+ice/sortKeys=score,,desc/facetFilters=%257B%257D/pageNumber=1/itemsPerPage=25).

# ### Ideas for the project
# * Plot one of the time slices on a map with North Polar Stereographic projection
# * Create a figure with 3 subplots
# * Plot the 1991 sea ice concentration in the 1st subplot, 2012 sea ice in the 2nd, and the difference in the 3rd.

# ### Getting started

# For this project, we recommend that you:
# * use `xarray` for opening and reading the netCDF files
# * may use `xarray.open_mf_dataset()` to load both files at once
# * use `cartopy` for creating a plot with a correct map projection
# * use appropriate colormaps for the sea ice concentration and difference

# To get started, copy the following cell into your **Project** notebook.

# +
# import cartopy.crs as ccrs
# import matplotlib.pyplot as plt
# import xarray as xr

# +
# ds = xr.open_mfdataset('../data/seaice_conc_monthly_*.nc')
## or
# ds1 = xr.open_dataset('../data/seaice_conc_monthly_nh_f08_199109_v02r00.nc')
# ds2 = xr.open_dataset('../data/seaice_conc_monthly_nh_f17_201209_v02r00.nc')

# +
## Extract longitude and latitude values, then the sea ice concentration itself

# +
## Code for creating a map
# fig = plt.figure()
# ax = fig.add_subplot(111, projection=ccrs.???(central_longitude=0))
# ax.coastlines(resolution='110m', linewidth=0.5)

# ax.gridlines()
# ax.set_extent([-180, 180, 40, 90], crs=ccrs.PlateCarree())
# -

# ## Other Data

# * In the `../data/` directory, there are several files that haven't been used in the course:
#     - `met_brw_insitu_1_obop_hour_2015.txt` with accompanying `met_brw_readme.txt` - hourly meteorological observations in Barrow, Alaska (BRW)
#     - `plot_extent_n_v2.csv` - daily total sea ice extent in the Arctic
#     - `north_sea_data.csv` - ship observations from several cruises in the North Sea (data provided by <NAME>)
# * You can use any of them: open, plot, calculate statistics, etc.

# ### Advanced: geospatial data on Amazon

# * Amazon Web Services (AWS) host a number of open datasets of geospatial data: satellite, radar, DEM, weather forecast data, etc.: https://aws.amazon.com/earth/
# * You can try to use the AWS API to download data and plot it with cartopy.

StarcoderdataJupyterScriptsDedupFiltered