Skip to content

Instantly share code, notes, and snippets.

@previtus
previtus / calc_ime.py
Created March 14, 2024 20:38
snippet about IME calculation (source - https://github.com/nasa/EMIT-Data-Resources )
def calc_ime(plume_da):
molar_volume = 22.4 # L/mol at STP
molar_mass_ch4 = 0.01604 #kg/mol
kg = plume_da * (1/1e6) * (60*60) * (1000) * (1/molar_volume) * molar_mass_ch4
ime = np.nansum(kg)
return ime
@previtus
previtus / data_module.py
Created July 19, 2023 12:37
Example of remote sensing dataloaders for pytorch lightning
import os
import pytorch_lightning as pl
from typing import Optional, Tuple, List
import kornia.augmentation as K
from torch.utils.data import DataLoader, WeightedRandomSampler
from starcop.data import dataset
import pandas as pd
from . import feature_extration
import rasterio.windows
@previtus
previtus / same_location_as_source_from_target.py
Created May 8, 2023 14:55
Load the same data from a target tif using the location from a source one ...
# more in https://github.com/spaceml-org/georeader/blob/main/notebooks/reading_overlapping_sentinel2_aviris.ipynb
from georeader.rasterio_reader import RasterioReader
from georeader import read
def same_location_as_source_from_target(source_tif, target_tif, show=False):
src_reader = RasterioReader(source_tif)
src_reader_in_memory = src_reader.load()
target_reader = RasterioReader(target_tif)
@previtus
previtus / EMIT wavelenghts and band widths.py
Created April 12, 2023 13:19
EMIT wavelenghts and band widths
# from an example file with a plume event
# EMIT_L1B_RAD_001_20220823T074504_2223505_021.nc
EMIT_wavelenghts = ['381.00558', '388.4092', '395.81583', '403.2254', '410.638', '418.0536', '425.47214', '432.8927', '440.31726', '447.7428', '455.17035', '462.59888', '470.0304', '477.46292', '484.89743', '492.33292', '499.77142', '507.2099', '514.6504', '522.0909', '529.5333', '536.9768', '544.42126', '551.8667', '559.3142', '566.7616', '574.20905', '581.6585', '589.108', '596.55835', '604.0098', '611.4622', '618.9146', '626.36804', '633.8215', '641.2759', '648.7303', '656.1857', '663.6411', '671.09753', '678.5539', '686.0103', '693.4677', '700.9251', '708.38354', '715.84094', '723.2993', '730.7587', '738.2171', '745.6765', '753.1359', '760.5963', '768.0557', '775.5161', '782.97754', '790.4379', '797.89935', '805.36176', '812.8232', '820.2846', '827.746', '835.2074', '842.66986', '850.1313', '857.5937', '865.0551', '872.5176', '879.98004', '887.44147', '894.90393', '902.3664', '909.82886', '917.2913', '924.7538
@previtus
previtus / practical_colab_starter_ht22.ipynb
Last active February 2, 2022 18:52
practical_colab_starter_HT22.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@previtus
previtus / HowTo_RealTimeMusicGen.txt
Last active July 25, 2021 12:49
Bash command to train and run music_gen_interaction_RTML demo!
The run.sh bash file should do everything for you, you just need to have an audio sample (in wav format) and the Nvidia docker installed (https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html#docker)
Download the run.sh command and give it executible rights:
chmod +x run.sh
Then simply run
./run.sh sample.wav 16
This will train a model for 16 epochs and then run an interactive real-time handler with it.
@previtus
previtus / load celeb a 32x32 dataset.py
Created April 5, 2021 22:15
celeb a dataset at 32x32 resolution
from PIL import Image
from torchvision import datasets, transforms
import torch
import torch.utils.data as data
import urllib.request
import scipy.io
import os
import imageio
import numpy as np
from os import listdir
@previtus
previtus / miwae_simplified.py
Last active March 30, 2021 19:56
VAE experiments
# Based on implementations
# - vae core https://github.com/pytorch/examples/blob/master/vae/main.py
# - miwae https://github.com/yoonholee/pytorch-vae
# - notes on VAE from the article at https://iopscience.iop.org/article/10.3847/PSJ/ab9a52 (but can be taken from elsewhere too)
from __future__ import print_function
import argparse
import torch
import torch.utils.data
from torch import nn, optim
# https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_gui/py_trackbar/py_trackbar.html#trackbar
import cv2
import numpy as np
class GUIHandler(object):
def onChangeSend(self,x):
self.A = cv2.getTrackbarPos('A', self.window_name)
@previtus
previtus / Mock Settings.py
Last active February 20, 2021 19:24
Mock Settings
# v1
import mock
settings = mock.Mock()
settings.foo = 42
# v2
# works even when checking for non-existing entries...