Skip to content

Instantly share code, notes, and snippets.

@nilsleh
nilsleh / area_example.py
Last active March 5, 2022 08:33
Compare the area of a coordinate polygon with the returned image from STAC
import matplotlib.pyplot as plt
import numpy as np
import planetary_computer as pc
import stackstac
from pystac_client import Client
import shapely.geometry
import fiona.transform
polygon = {
@nilsleh
nilsleh / retrieve_large_area.py
Created March 28, 2022 19:19
Split large area into smaller manageable polygons to download via Planetary Computer
import json
import os
import matplotlib.pyplot as plt
import numpy as np
import planetary_computer as pc
import rasterio
import stackstac
from pystac_client import Client
from shapely.geometry import mapping, shape
import numpy as np
import torch
import torch.nn as nn
from functorch import vmap, jacrev, make_functional_with_buffers
batch_size = 2
in_channels = 5
out_channels = 20
feature_shape = 8
feature = torch.rand(batch_size, in_channels, feature_shape, feature_shape)
@nilsleh
nilsleh / darts_load_checkpoint.py
Last active May 8, 2024 20:41
Exploring saving and loading checkpoint
import numpy as np
import pandas as pd
from tqdm import tqdm_notebook as tqdm
import matplotlib.pyplot as plt
from darts import TimeSeries, concatenate
from darts.dataprocessing.transformers import Scaler
from darts.models import TFTModel
from darts.metrics import mape
import numpy as np
import pandas as pd
from darts import TimeSeries
from darts.dataprocessing.transformers import Scaler
from darts.models import TFTModel
from darts.datasets import AirPassengersDataset
from darts.utils.timeseries_generation import datetime_attribute_timeseries
from darts.utils.likelihood_models import QuantileRegression
import pytorch_lightning as pl
import torch
import timm
from torchgeo.datasets import EuroSAT
import numpy as np
from sklearn.linear_model import LogisticRegression
from torch.utils.data import DataLoader
import torch
from tqdm import tqdm
@nilsleh
nilsleh / 1d regression_swag.ipynb
Last active February 26, 2023 16:34
SWAG 1D Regression example
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@nilsleh
nilsleh / retrieve_milestone_contributors.py
Created November 10, 2023 13:18
Retrieve the contributors from a milestone
import requests
# Set up authentication with your PAT
headers = {
'Authorization': 'Bearer YOUR_ACCESS_TOKEN'
}
# Define the repository information
repo_owner = 'repo_owner'
repo_name = 'repo_name'
@nilsleh
nilsleh / raps.py
Last active January 11, 2024 15:06
Compare RAPS implementations
import os
from typing import Sequence
import matplotlib.pyplot as plt
import numpy as np
import torch
import torch.backends.cudnn as cudnn
from lightning import Trainer
from lightning.pytorch import seed_everything
from orig_conformal import ConformalModel
@nilsleh
nilsleh / ocean_bench_datamodule.py
Last active January 16, 2024 15:44
Ocean Bench Lightning Datamodule
"""Ocean Bench Datamodules."""
import itertools
import os
from collections import namedtuple
from typing import Any
import hydra
import numpy as np
import ocn_tools._src.geoprocessing.gridding as obgrid