Skip to content
Snippets Groups Projects
Commit 3528735a authored by Marco Kulüke's avatar Marco Kulüke
Browse files

formating in black style, add dependencies to .yml file

parent 415e3f10
No related branches found
No related tags found
No related merge requests found
name: tutorials-and-use-cases
name: /work/bk1088/k204228/kernels/test_env
channels:
- anaconda
- conda-forge
......@@ -7,12 +7,16 @@ dependencies:
- _libgcc_mutex=0.1=main
- aiohttp=3.6.2=py38h516909a_0
- appdirs=1.4.3=py_1
- argon2-cffi=20.1.0=py38h7b6447c_1
- asciitree=0.3.3=py_2
- async-timeout=3.0.1=py_1000
- async_generator=1.10=py_0
- attrs=20.2.0=pyh9f0ad1d_0
- backcall=0.2.0=py_0
- black=20.8b1=py_1
- bleach=3.2.1=py_0
- bokeh=2.2.1=py38h32f6830_0
- branca=0.4.1=py_0
- brotlipy=0.7.0=py38h1e0a361_1000
- bzip2=1.0.8=h516909a_3
- c-ares=1.16.1=h516909a_3
......@@ -32,27 +36,36 @@ dependencies:
- dask-core=2.26.0=py_0
- dataclasses=0.7=py38_0
- decorator=4.4.2=py_0
- defusedxml=0.6.0=py_0
- distributed=2.26.0=py38h32f6830_0
- entrypoints=0.3=py38h32f6830_1001
- fastprogress=1.0.0=py_0
- folium=0.11.0=py_0
- freetype=2.10.2=he06d7ca_0
- fsspec=0.8.2=py_0
- geographiclib=1.50=py_0
- geopy=2.0.0=pyh9f0ad1d_0
- geos=3.8.0=he6710b0_0
- hdf4=4.2.13=hf30be14_1003
- hdf5=1.10.6=nompi_h3c11f04_101
- heapdict=1.0.1=py_0
- idna=2.10=pyh9f0ad1d_0
- importlib-metadata=1.7.0=py38_0
- importlib_metadata=1.7.0=0
- iniconfig=1.0.1=py_0
- intake=0.6.0=py_0
- intake-esm=2020.8.15=py_0
- ipykernel=5.3.4=py38h5ca1d4c_0
- ipython=7.18.1=py38h5ca1d4c_0
- ipython_genutils=0.2.0=py38_0
- ipywidgets=7.5.1=py_1
- jedi=0.17.2=py38_0
- jinja2=2.11.2=pyh9f0ad1d_0
- jpeg=9d=h516909a_0
- jsonschema=3.2.0=py38_1
- jupyter_client=6.1.6=py_0
- jupyter_core=4.6.3=py38_0
- jupyterlab_pygments=0.1.2=py_0
- kiwisolver=1.2.0=py38hbf85e49_0
- krb5=1.17.1=hfafb76e_3
- lcms2=2.11=hbd6801e_0
......@@ -80,13 +93,19 @@ dependencies:
- markupsafe=1.1.1=py38h1e0a361_1
- matplotlib=3.3.2=0
- matplotlib-base=3.3.2=py38h91b0d89_0
- mistune=0.8.4=py38h7b6447c_1000
- more-itertools=8.5.0=py_0
- msgpack-python=1.0.0=py38hbf85e49_1
- multidict=4.7.5=py38h1e0a361_1
- mypy_extensions=0.4.3=py38h32f6830_1
- nb_black=1.0.7=py_0
- nbclient=0.5.0=py_0
- nbconvert=6.0.6=py38_0
- nbformat=5.0.7=py_0
- ncurses=6.2=he6710b0_1
- nest-asyncio=1.4.1=py_0
- netcdf4=1.5.4=nompi_py38hec8b9af_102
- notebook=6.1.4=py38_0
- numcodecs=0.7.1=py38h950e882_0
- numpy=1.19.1=py38hbc27379_2
- olefile=0.46=py_0
......@@ -94,6 +113,8 @@ dependencies:
- owslib=0.20.0=py_0
- packaging=20.4=pyh9f0ad1d_0
- pandas=1.1.2=py38h950e882_0
- pandoc=2.10.1=0
- pandocfilters=1.4.2=py38_1
- parso=0.7.0=py_0
- partd=1.1.0=py_0
- pathspec=0.8.0=pyh9f0ad1d_0
......@@ -103,6 +124,7 @@ dependencies:
- pip=20.2.2=py38_0
- pluggy=0.13.1=py38_0
- proj=6.2.1=haa6030c_0
- prometheus_client=0.8.0=py_0
- prompt-toolkit=3.0.7=py_0
- psutil=5.7.2=py38h1e0a361_0
- ptyprocess=0.6.0=py38_0
......@@ -114,6 +136,7 @@ dependencies:
- pyopenssl=19.1.0=py_1
- pyparsing=2.4.7=pyh9f0ad1d_0
- pyproj=2.6.1.post1=py38hd003209_1
- pyrsistent=0.17.3=py38h7b6447c_0
- pyshp=2.1.2=py_0
- pysocks=1.7.1=py38h32f6830_1
- pytest=6.0.1=py38_0
......@@ -129,12 +152,15 @@ dependencies:
- requests=2.24.0=pyh9f0ad1d_0
- scipy=1.5.2=py38h8c5af15_0
- seaborn=0.11.0=py_0
- send2trash=1.5.0=py38_0
- setuptools=49.6.0=py38_0
- shapely=1.7.1=py38h98ec03d_0
- six=1.15.0=py_0
- sortedcontainers=2.2.2=pyh9f0ad1d_0
- sqlite=3.33.0=h62c20be_0
- tblib=1.6.0=py_0
- terminado=0.8.3=py38_0
- testpath=0.4.4=py_0
- tk=8.6.10=hbc83047_0
- toml=0.10.1=py_0
- toolz=0.10.0=py_0
......@@ -144,7 +170,9 @@ dependencies:
- typing_extensions=3.7.4.2=py_0
- urllib3=1.25.10=py_0
- wcwidth=0.2.5=py_0
- webencodings=0.5.1=py38_1
- wheel=0.35.1=py_0
- widgetsnbextension=3.5.1=py38_0
- xarray=0.16.0=py_0
- xz=5.2.5=h7b6447c_0
- yaml=0.2.5=h516909a_0
......@@ -152,9 +180,10 @@ dependencies:
- zarr=2.4.0=py_0
- zeromq=4.3.2=he6710b0_3
- zict=2.0.0=py_0
- zipp=3.1.0=py_0
- zlib=1.2.11=h7b6447c_3
- zstd=1.4.5=h6597ccf_2
- pip:
- fasteners==0.15
- monotonic==1.5
prefix: tutorial-and-use-cases
prefix: /work/bk1088/k204228/kernels/test_env
%% Cell type:markdown id: tags:
# Count Annual Summer Days for a particular Location
%% Cell type:markdown id: tags:
TBD:
- choose year by drop-down menu and select correspondig dataset
- future:
- compare two places
- choose different index
%% Cell type:code id: tags:
``` python
# get formating done automatically according to style `black`
%load_ext lab_black
```
%% Cell type:code id: tags:
``` python
import intake
import requests
import folium
import xarray as xr
import matplotlib
from IPython.display import display
from ipywidgets import widgets
from geopy.geocoders import Nominatim
import numpy as np
```
%% Cell type:markdown id: tags:
## Choose Location
If ambiguous the more likely location will be chosen
%% Cell type:code id: tags:
``` python
place = widgets.Text()
display(place)
```
%% Output
%% Cell type:markdown id: tags:
Find Place by using GeoPy
%% Cell type:code id: tags:
``` python
geolocator = Nominatim(user_agent="any_agent")
location = geolocator.geocode(place.value)
print(location.address)
print((location.latitude, location.longitude))
#print(location.raw)
# print(location.raw)
```
%% Cell type:markdown id: tags:
## Draw Map
%% Cell type:code id: tags:
``` python
m = folium.Map(location=[location.latitude, location.longitude])
tooltip = location.latitude, location.longitude
folium.Marker([location.latitude, location.longitude], tooltip=tooltip).add_to(m)
m
```
%% Cell type:markdown id: tags:
## Choose Year
## Choose Year you want the number of summer days
%% Cell type:code id: tags:
``` python
x = range(1850, 2020) # TBD: needs to be historical time frame
x = range(1850, 2020) # TBD: needs to be historical time frame
year = widgets.Dropdown(
options=x,
description='Select year: ',
description="Select year: ",
disabled=False,
)
year
```
%% Cell type:code id: tags:
``` python
year.value
```
%% Cell type:markdown id: tags:
## Load Intake Catalogue
The catalog files are uploaded to the cloud. There is a gsv.gz file and a json file under
https://swiftbrowser.dkrz.de/public/dkrz_a44962e3ba914c309a7421573a6949a6/intake-esm/
We load the catalog descriptor with intake:
%% Cell type:code id: tags:
``` python
col_url = "https://swift.dkrz.de/v1/dkrz_a44962e3ba914c309a7421573a6949a6/intake-esm/mistral-cmip6.json"
# col_url = "https://swift.dkrz.de/v1/dkrz_a44962e3ba914c309a7421573a6949a6/intake-esm/mistral-cmip6.json"
# or
col_url = "/work/ik1017/Catalogs/mistral-cmip6.json"
col = intake.open_esm_datastore(col_url)
```
%% Cell type:markdown id: tags:
Let's see what is in the intake catalog. The underlying data base is given as a panda dataframe which we can access with 'col.df'. col.df.head() shows us the first rows of the table:
%% Cell type:code id: tags:
``` python
col.df.head()
```
%% Cell type:markdown id: tags:
## Browse Intake Catalogue and open Variable
%% Cell type:code id: tags:
``` python
query = dict(
source_id = 'MPI-ESM1-2-HR',
source_id="MPI-ESM1-2-LR",
variable_id="tasmax",
table_id="day",
experiment_id=["historical"])
experiment_id=["historical"],
)
cat = col.search(**query)
```
%% Cell type:markdown id: tags:
show query
%% Cell type:code id: tags:
``` python
cat.df
```
%% Cell type:code id: tags:
``` python
ds_tasmax = xr.open_dataset(cat.df['path'][0]) # TBD: open data set of selected year
cat.df["path"][0]
```
%% Cell type:markdown id: tags:
ds_tasmax['tasmax']
open data set
%% Cell type:code id: tags:
``` python
ds_tasmax = xr.open_dataset(cat.df["path"][0]) # TBD: open data set of selected year
ds_tasmax["tasmax"]
```
%% Cell type:markdown id: tags:
## Compare Model Grid Cell with chosen Location
%% Cell type:code id: tags:
``` python
# Find nearest model coordinate
# First, find the index of the grid point nearest a specific lat/lon.
abslat = np.abs(ds_tasmax['lat']-location.latitude)
abslon = np.abs(ds_tasmax['lon']-location.longitude)
abslat = np.abs(ds_tasmax["lat"] - location.latitude)
abslon = np.abs(ds_tasmax["lon"] - location.longitude)
c = np.maximum(abslon, abslat)
([xloc], [yloc]) = np.where(c == np.min(c))
# Now I can use that index location to get the values at the x/y diminsion
tas_max_hamburg = ds_tasmax['tasmax'][0, yloc, xloc] -273.15
```
%% Cell type:code id: tags:
%% Cell type:markdown id: tags:
``` python
```
Draw Map
%% Cell type:code id: tags:
``` python
m = folium.Map(location=[location.latitude, location.longitude], zoom_start=8)
tooltip = location.latitude, location.longitude
folium.Marker([ds_tasmax['lat'][yloc], ds_tasmax['lon'][xloc]], tooltip=tooltip, popup='Model Grid Cell Center').add_to(m)
folium.Marker([location.latitude, location.longitude], tooltip=tooltip, popup='Location selected by User').add_to(m)
folium.Marker(
[ds_tasmax["lat"][yloc], ds_tasmax["lon"][xloc]],
tooltip=tooltip,
popup="Model Grid Cell Center",
).add_to(m)
folium.Marker(
[location.latitude, location.longitude],
tooltip=tooltip,
popup="Location selected by User",
).add_to(m)
# Define rectangle
rect_lat1 = (ds_tasmax['lat'][yloc -1] +ds_tasmax['lat'][yloc])/2
rect_lon1 = (ds_tasmax['lon'][xloc -1] +ds_tasmax['lon'][xloc])/2
rect_lat2 = (ds_tasmax['lat'][yloc +1] +ds_tasmax['lat'][yloc])/2
rect_lon2 = (ds_tasmax['lon'][xloc +1] +ds_tasmax['lon'][xloc])/2
rect_lat1 = (ds_tasmax["lat"][yloc - 1] + ds_tasmax["lat"][yloc]) / 2
rect_lon1 = (ds_tasmax["lon"][xloc - 1] + ds_tasmax["lon"][xloc]) / 2
rect_lat2 = (ds_tasmax["lat"][yloc + 1] + ds_tasmax["lat"][yloc]) / 2
rect_lon2 = (ds_tasmax["lon"][xloc + 1] + ds_tasmax["lon"][xloc]) / 2
#
folium.Rectangle(bounds=[[rect_lat1,rect_lon1], [rect_lat2,rect_lon2]], color='#ff7800', fill=True, fill_color='#ffff00', fill_opacity=0.2).add_to(m)
folium.Rectangle(
bounds=[[rect_lat1, rect_lon1], [rect_lat2, rect_lon2]],
color="#ff7800",
fill=True,
fill_color="#ffff00",
fill_opacity=0.2,
).add_to(m)
m
```
%% Cell type:markdown id: tags:
## Draw Temperature Time Series and count Summer days
%% Cell type:code id: tags:
``` python
# Now I can use that index location to get the values at the lat/lon location
tas_max_hamburg = ds_tasmax["tasmax"][:, yloc, xloc] - 273.15
tas_max_hamburg = ds_tasmax['tasmax'][:, yloc, xloc] -273.15
matplotlib.pyplot.plot(tas_max_hamburg)
```
%% Cell type:code id: tags:
``` python
tas_max_hamburg[tas_max_hamburg > 25]
```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment