Skip to content
Extraits de code Groupes Projets
Valider 24f473c3 rédigé par Pierre-Yves Barriat's avatar Pierre-Yves Barriat
Parcourir les fichiers

Move personal python

parent 61d24e40
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Affichage de
avec 1605 ajouts et 0 suppression
......@@ -11,6 +11,8 @@ learning-vscode/VSCode_WSL.html
learning-vscode/VSCode_Ubuntu.html
learning-markdown/MarkDown.html
learning-markdown/TODO_makdown.md
learning-python/Python.html
learning-python/sandbox.txt
# ---> VisualStudioCode
.settings
......
Ce diff est replié.
Fichier ajouté
# learning-python
This is the repository for the training Python
You can find the slides [here](./Python.pdf).
Presentation is [here](https://www.elic.ucl.ac.be/users/pbarriat/slides/Python.html)
learning-python/assets/Figure_1.png

18,9 ko

learning-python/assets/Figure_2.png

33,4 ko

import matplotlib.pyplot as plt
import numpy as np
plt.style.use("seaborn")
x = np.linspace(0, 2*np.pi, 100)
sin = np.sin(x)
cos = np.cos(x)
plt.plot(x, sin, "C0--", label="sin(x)")
plt.plot(x, cos, "C1:", label="cos(x)")
pi_multiples = np.array([0, 0.5, 1, 1.5, 2]) * np.pi
sin_points = np.sin(pi_multiples)
cos_points = np.cos(pi_multiples)
plt.plot(pi_multiples, sin_points, "C0o")
plt.plot(pi_multiples, cos_points, "C1o")
plt.title("Trigonometric functions")
plt.xlabel("x (radians)")
plt.xticks(np.linspace(0, 2*np.pi, 5))
plt.legend()
plt.axis("scaled")
plt.show()
learning-python/assets/Figure_3.png

96,4 ko

#
# Input data
#
# We are going to use a netCDF file for testing the following code.
# The test file islocated in a dedicated online repository:
# https://nextcloud.cism.ucl.ac.be/s/H7XFSi8J4E8dnRK
#
# Download the netCDF prmsl.2000.nc :
# a classic (regular grid) pressure file
#
from netCDF4 import Dataset
import numpy as np
import cartopy.crs as ccrs
import cartopy.feature as cfeature
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
from cartopy.util import add_cyclic_point
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
my_example_nc_file = 'prmsl.2000.nc'
fh = Dataset(my_example_nc_file, mode='r')
lons = fh.variables['lon'][:]
lats = fh.variables['lat'][:]
times = fh.variables['time'][:]
times_unit = fh.variables['time'].units
var = fh.variables['prmsl']
var_units = fh.variables['prmsl'].units
#fig = plt.subplots(figsize=(8, 6), dpi=102)
plt.axis('off')
ax = plt.axes(projection=ccrs.Robinson(central_longitude=10.0))
ax.coastlines()
# Plot Data
data = np.squeeze(var[1,:,:])
#cs = ax.pcolormesh(lons, lats, data, transform=ccrs.PlateCarree(), shading='auto')
lon = np.arange(0, 360, 2)
data, lon = add_cyclic_point(data, coord=lon)
cs = ax.contourf(lon, lats, data, transform=ccrs.PlateCarree(), transform_first=False)
# Add Grid Lines
gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True, linewidth=0.5, color="grey")
gl.xlocator = mticker.FixedLocator(np.arange(-170,191,36))
gl.ylocator = mticker.FixedLocator(np.arange(-90,90,15))
gl.rotate_labels = False
gl.top_labels = False
gl.xformatter = LONGITUDE_FORMATTER
gl.yformatter = LATITUDE_FORMATTER
# Add Colorbar
cbar = plt.colorbar(cs,orientation="horizontal")
cbar.set_label(var_units)
# Add Title
plt.title('Daily Pressure at Mean Sea Level')
plt.show()
learning-python/assets/Figure_4.png

97,1 ko

#
# Input data
#
# We are going to use a netCDF file for testing the following code.
# The test file islocated in a dedicated online repository:
# https://nextcloud.cism.ucl.ac.be/s/H7XFSi8J4E8dnRK
#
# Download the netCDF prmsl.2000.nc :
# a classic (regular grid) pressure file
#
from netCDF4 import Dataset
import numpy as np
import cartopy.crs as ccrs
import cartopy.feature as cfeature
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
from cartopy.util import add_cyclic_point
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
import matplotlib.path as mpath
my_example_nc_file = 'prmsl.2000.nc'
fh = Dataset(my_example_nc_file, mode='r')
lons = fh.variables['lon'][:]
lats = fh.variables['lat'][:]
times = fh.variables['time'][:]
times_unit = fh.variables['time'].units
var = fh.variables['prmsl']
var_units = fh.variables['prmsl'].units
#------------------------------------------------------------
# Compute a circle in axes coordinates,
# which we can use as a boundary for the map.
# https://scitools.org.uk/cartopy/docs/latest/gallery/lines_and_polygons/always_circular_stereo.html
theta = np.linspace(0, 2*np.pi, 100)
center, radius = [0.5, 0.5], 0.5
verts = np.vstack([np.sin(theta), np.cos(theta)]).T
circle = mpath.Path(verts * radius + center)
fig = plt.subplots(figsize=(6, 6), dpi=102)
plt.axis('off')
ax = plt.axes(projection=ccrs.Orthographic(central_longitude=0.0, central_latitude=90.0))
xlims = [-180,180]
ylims = [50,90]
ax.set_extent(xlims+ylims, crs=ccrs.PlateCarree())
ax.set_boundary(circle, transform=ax.transAxes)
ax.stock_img()
ax.coastlines("110m", linewidth=0.5, color="black")
# Plot Data
data = np.squeeze(var[1,:,:])
#cs = ax.pcolormesh(lons, lats, data, transform=ccrs.PlateCarree(), shading='auto')
lon = np.arange(0, 360, 2)
data, lon = add_cyclic_point(data, coord=lon)
cs = ax.contourf(lon, lats, data, transform=ccrs.PlateCarree(), transform_first=False)
# Doing the gridlines we want
gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True, linewidth=0.5, color="grey")
gl.xformatter = LONGITUDE_FORMATTER
gl.yformatter = LATITUDE_FORMATTER
gl.xlocator = mticker.FixedLocator(np.arange(-180,181,18))
gl.ylocator = mticker.FixedLocator(np.arange(-90,91,10))
# Add Colorbar
cbar = plt.colorbar(cs,orientation="horizontal")
cbar.set_label(var_units)
# Add Title
plt.title('Daily Pressure at Mean Sea Level')
plt.show()
learning-python/assets/back.png

62 ko

learning-python/assets/garde.png

44,7 ko

const { deflateSync } = require('zlib')
const krokiLangs = [
'actdiag',
'blockdiag',
'bpmn',
'bytefield',
'c4plantuml',
'ditaa',
'dot',
'erd',
'excalidraw',
'graphviz',
'mermaid',
'nomnoml',
'nwdiag',
'packetdiag',
'pikchr',
'plantuml',
'rackdiag',
'seqdiag',
'svgbob',
'umlet',
'vega',
'vegalite',
'wavedrom',
]
const entrypoint = 'https://kroki.io/'
const marpKrokiPlugin = (md) => {
const { fence } = md.renderer.rules
md.renderer.rules.fence = (tokens, idx, options, env, self) => {
const info = md.utils.unescapeAll(tokens[idx].info).trim()
if (info) {
const [lang] = info.split(/(\s+)/g)
if (krokiLangs.includes(lang)) {
const data = deflateSync(tokens[idx].content).toString('base64url')
// <marp-auto-scaling> is working only with Marp Core v3
return `<p><marp-auto-scaling data-downscale-only><img src="${entrypoint}${lang}/svg/${data}"/></marp-auto-scaling></p>`
}
}
return fence.call(self, tokens, idx, options, env, self)
}
}
module.exports = marpKrokiPlugin
const marpKrokiPlugin = require('./kroki-plugin')
module.exports = {
engine: ({ marp }) => marp.use(marpKrokiPlugin)
}
Fichier ajouté
<?xml version="1.0" encoding="utf-8"?><!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
<svg width="800px" height="800px" viewBox="0 0 64 64" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M31.885 16c-8.124 0-7.617 3.523-7.617 3.523l.01 3.65h7.752v1.095H21.197S16 23.678 16 31.876c0 8.196 4.537 7.906 4.537 7.906h2.708v-3.804s-.146-4.537 4.465-4.537h7.688s4.32.07 4.32-4.175v-7.019S40.374 16 31.885 16zm-4.275 2.454c.771 0 1.395.624 1.395 1.395s-.624 1.395-1.395 1.395a1.393 1.393 0 0 1-1.395-1.395c0-.771.624-1.395 1.395-1.395z" fill="url(#a)"/><path d="M32.115 47.833c8.124 0 7.617-3.523 7.617-3.523l-.01-3.65H31.97v-1.095h10.832S48 40.155 48 31.958c0-8.197-4.537-7.906-4.537-7.906h-2.708v3.803s.146 4.537-4.465 4.537h-7.688s-4.32-.07-4.32 4.175v7.019s-.656 4.247 7.833 4.247zm4.275-2.454a1.393 1.393 0 0 1-1.395-1.395c0-.77.624-1.394 1.395-1.394s1.395.623 1.395 1.394c0 .772-.624 1.395-1.395 1.395z" fill="url(#b)"/><defs><linearGradient id="a" x1="19.075" y1="18.782" x2="34.898" y2="34.658" gradientUnits="userSpaceOnUse"><stop stop-color="#387EB8"/><stop offset="1" stop-color="#366994"/></linearGradient><linearGradient id="b" x1="28.809" y1="28.882" x2="45.803" y2="45.163" gradientUnits="userSpaceOnUse"><stop stop-color="#FFE052"/><stop offset="1" stop-color="#FFC331"/></linearGradient></defs></svg>
\ No newline at end of file
learning-python/assets/python_logo.png

16 ko

/* @theme tum */
@import 'default';
section {
/*background-color: #fff;
color: #000;
background-image: url('images/TUM_Logo_blau_rgb_s.svg');
background-repeat: no-repeat;
background-position: right 40px top 40px;
background-size: 8%;*/
}
section.lead {
/*background-image: url('images/TUM_Uhrenturm.png');
background-position: right;
background-size: 45%;*/
}
section h1,
section h2 {
color: #1f315c;
}
section a {
color: #5fb2e6;
}
section footer,
section::after {
color: #9cb7d4;
}
section.invert {
background-color: #003359;
color: #fff;
/*background-image: url('images/TUM_Logo_weiss_rgb_s.svg');*/
}
section.lead.invert {
/*background-image: url('images/TUM_Uhrenturm_w.png');*/
}
section.invert h1,
section.invert footer,
section.invert::after {
color: #fff;
}
section.invert a {
color: #e37222;
}
/* Add "Page" prefix and total page number */
section::after {
content: attr(data-marpit-pagination) ' / ' attr(data-marpit-pagination-total);
}
#!/bin/bash
#
# PY Barriat, September 2024
#
# Download and install marp (MarkDown slides extension) from here:
# https://github.com/marp-team/marp-cli/releases
#
# Install npm (needed for mermaid: nice extension to make diagramm)
# npm i
# sudo apt install npm
#
rm -f ./Python.pdf ./Python.html
npx marp --allow-local-files --theme ./assets/tum.css -c ./assets/marp.config.js ./Python.md -o Python.pdf
npx marp --template bespoke --bespoke.progress --allow-local-files --theme ./assets/tum.css -c ./assets/marp.config.js Python.md -o Python.html
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter