Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
coding the days away

Sergio Lucero sergiolucero

💭
coding the days away
View GitHub Profile
@sergiolucero
sergiolucero / dcm_plotter
Last active Aug 9, 2022
view dcm folder
View dcm_plotter
import pydicom as dicom
import matplotlib.pylab as plt
import glob
fig=plt.figure(figsize=(20,12));rows=2;cols=2;axes=[]
for a, file in zip(range(rows*cols),glob.glob('*.dcm')):
axes.append( fig.add_subplot(rows, cols, a+1) )
axes[-1].set_title(file)
axes[-1].axis('off')
plt.imshow(dicom.dcmread(file).pixel_array)
@sergiolucero
sergiolucero / pdf_merger.py
Created Jul 24, 2022
concatenate and merge a list of PDF files
View pdf_merger.py
import glob
from PyPDF2 import PdfFileMerger
merger = PdfFileMerger()
for fn in glob.glob('*.pdf'):
merger.append(fn)
merger.write('result.pdf')
merger.close()
View movie_maker.py
import glob
import cv2
images = glob.glob('Plot*.png')
print('nImages:', len(images))
height, width, layers = cv2.imread(images[0]).shape
video = cv2.VideoWriter('video.avi', 0, 1, (width,height))
for image in images:
View ec2_diagram.py
from diagrams import Diagram, Cluster
from diagrams.aws.compute import EC2
from diagrams.aws.network import ELB
from diagrams.aws.network import Route53
from diagrams.onprem.database import PostgreSQL # Would typically use RDS from aws.database
from diagrams.onprem.inmemory import Redis # Would typically use ElastiCache from aws.database
with Diagram("Simple Website Diagram", direction='LR') as diag: # It's LR by default, but you have a few options with the orientation
dns = Route53("dns")
load_balancer = ELB("Load Balancer")
@sergiolucero
sergiolucero / bicicletas.py
Last active Jun 22, 2022
descarga revistas La Bicicleta
View bicicletas.py
import wget, fitz, glob
import requests, time
from bs4 import BeautifulSoup
url='http://www.memoriachilena.gob.cl/602/w3-article-100795.html#documentos'
bs = BeautifulSoup(requests.get(url).text, 'lxml')
links = [link['href'] for link in bs.find_all('a')
if '.pdf' in link.get('href','')]
print(len(links))
@sergiolucero
sergiolucero / calidad_del_aire_CQP.py
Created Jun 9, 2022
aire región Concón-Quintero-Puchuncaví
View calidad_del_aire_CQP.py
import openaq
import pandas as pd
api = openaq.OpenAQ() # fuente: www.openaq.org
cdf = api.cities(country='CL', df=True)
cdf = cdf[cdf.city.isin(['Quintero','Concón','Puchuncaví'])]
xdf = pd.concat([api.measurements(city=city, df=True, limit=1000)
for city in cdf.city])
View mapeo_aguas.py
import geopandas as gp
import time
hdf=gp.read_file('Humedales', encoding='utf-8')
hdf.region.value_counts()
hdf.cut_reg.value_counts()
#hdf.set_crs(epsg=4326, inplace=True)
#hdf=hdf.to_crs(epsg=4326) # doesn not work for every region!
@sergiolucero
sergiolucero / pecos
Created May 1, 2022
idioma chileno según Pecos Paul Kele
View pecos
import tts
imagen = read('github/pecos.png')
texto = tts(imagen)
@sergiolucero
sergiolucero / videomapper.py
Created Apr 6, 2022
make video from pictures
View videomapper.py
import cv2, glob
import numpy as np
fourcc = cv2.VideoWriter_fourcc(*'mp4v') # choose codec according to needed format
video = cv2.VideoWriter('video.avi', fourcc, 1, (width, height))
for fn in glob.glob('*.png'):
img = cv2.imread(fn)
video.write(img)
@sergiolucero
sergiolucero / diagram.py
Last active Mar 18, 2022
diagrams in pure Python
View diagram.py
from diagrams import Diagram, Cluster
from diagrams.aws.compute import EC2
from diagrams.aws.network import ELB
with Diagram("Simple Website Diagram", direction='TB') as diag:
API = ELB("API")
piton = ELB("Python")
with Cluster("Webserver Cluster"):
svc_group = [EC2("Spotify"),EC2("Shazam!"),EC2("YouTube"),EC2("REWIND!")]
API >> piton >> svc_group