Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/devcontainer #4

Merged
merged 2 commits into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/python
{
"name": "Python 3",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/python:0-3.11",
"features": {
"ghcr.io/devcontainers/features/common-utils:2": {},
"ghcr.io/devcontainers-contrib/features/black:2": {},
"ghcr.io/devcontainers-contrib/features/isort:2": {},
"ghcr.io/devcontainers-contrib/features/pre-commit:2": {},
"ghcr.io/devcontainers-contrib/features/zsh-plugins:0": {},
"ghcr.io/dhoeric/features/act:1": {},
"ghcr.io/stuartleeks/dev-container-features/shell-history:0": {},
"ghcr.io/guiyomh/features/vim:0": {}
},

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "pip3 install --user -r requirements.txt",
"postCreateCommand": "./.devcontainer/postCreateCommand.sh",
"customizations": {
"vscode": {
"extensions": [
"alefragnani.Bookmarks",
"eamodio.gitlens",
"oderwat.indent-rainbow"
]
}
}

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
25 changes: 25 additions & 0 deletions .devcontainer/postCreateCommand.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Instala o CfitsIO (fpack e funpack) e as dependencias python
sudo apt-get update && sudo apt-get install -y libcfitsio-bin --no-install-recommends \
&& sudo rm -rf /var/lib/apt/lists/* \
&& sudo apt-get purge -y \
&& pip install --upgrade pip && pip install --user -r requirements.txt


# Exemplo de Instalação de pacotes: https://www.ianlewis.org/en/creating-smaller-docker-images
# # for redis-sentinel see: http://redis.io/topics/sentinel
# ENV REDIS_VERSION 3.0.5
# ENV REDIS_DOWNLOAD_URL http://download.redis.io/releases/redis-3.0.5.tar.gz
# ENV REDIS_DOWNLOAD_SHA1 ad3ee178c42bfcfd310c72bbddffbbe35db9b4a6
# RUN buildDeps='gcc libc6-dev make' \
# && set -x \
# && apt-get update && apt-get install -y $buildDeps --no-install-recommends \
# && rm -rf /var/lib/apt/lists/* \
# && mkdir -p /usr/src/redis \
# && curl -sSL "$REDIS_DOWNLOAD_URL" -o redis.tar.gz \
# && echo "$REDIS_DOWNLOAD_SHA1 *redis.tar.gz" | sha1sum -c - \
# && tar -xzf redis.tar.gz -C /usr/src/redis --strip-components=1 \
# && rm redis.tar.gz \
# && make -C /usr/src/redis \
# && make -C /usr/src/redis install \
# && rm -r /usr/src/redis \
# && apt-get purge -y --auto-remove $buildDeps
42 changes: 40 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,39 @@
# cutout
# LIneA Cutout Service

[Requisitos](docs/definicao_requisitos/Requisitos.md)

Tiles do DES para teste: [Sample Tiles](https://scienceserver.linea.org.br/data/cutout_des_sample_tiles.tar.gz)

## Desenvolvimento

Este repositóro está configurado com devcontainer podendo ser utilizado com vscode + extensão devcontainer.

quando utilizado com devcontainer todas as dependencias e extensões já estão configuradas.

Clone do repositório

```bash
git clone https://github.com/linea-it/cutout.git
```

Acesse a pasta e abra com vscode

```bash
cd cutout && code .
```

Na primeira execução a extensão devcontainer vai perguntar se deseja fazer o build do container, aceite fazer o build ou aperte F1 e execute o comando `Rebuild and open in container` o vscode vai criar o container e abrir o repositório dentro dele.

Estando dentro do container é necessário fazer o download dos dados que serão usados para teste.
acesse a pasta /workspaces/cutout/tiles e execute o script `download_sample_tiles.sh`

Este script vai fazer o download de algumas imagens do DES e descompactar no diretório tiles.

com as imagens baixadas e descompactadas o ambiente está pronto.

Execute o script de teste `cutout.py` na raiz do repositório `/workspaces/cutout`
Os cutouts gerados ficam na pasta tiles.


---
# Cutout
Expand Down Expand Up @@ -29,14 +64,17 @@ DES0224-0958.

Use the __[desportal](https://desportal2.cosmology.illinois.edu/)__ to download full FITS image of tiles.

[Install Funpack](https://command-not-found.com/funpack)
Extract the *.fits.fz files to *.fits files using __[FITSIO](https://heasarc.gsfc.nasa.gov/fitsio/)__ and command:

`funpack tile_name.fits.fz`

`for z in *.fits.fz; do funpack "$z"; done`

and store the FITS files in folder called 'tiles'.

After that, run the code:

`python cutout.py`

The cutouts will be produced in the same folder of the project.
The cutouts will be produced in the same folder of the tiles.
9 changes: 6 additions & 3 deletions cutout.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
write_cutout_file,
cutout_verts,
tiles_from_cat)
import os

# Reading input data
RA, DEC, size = np.loadtxt('coords.dat', usecols=(0, 1, 2), unpack=True)
band, request = np.loadtxt(
'coords.dat', usecols=(3, 4), dtype=str, unpack=True)

# Set the path where the FITS files are stored
path_to_fits = '/home/adriano/cutout/tiles'
path_to_fits = 'tiles'

# Calculates the cutout's vertices to access tiles
verts = cutout_verts(RA, DEC, size)
Expand All @@ -28,7 +29,8 @@
RA[i], DEC[i], size[i], tiles[i], band[i], path_to_fits)
filename = '{:.5f}_{:.5f}_{}.fits'.format(
round(RA[i], 5), round(DEC[i], 5), band[i])
write_cutout_file(data, wcs_, filename)
filepath = os.path.join(path_to_fits, filename)
write_cutout_file(data, wcs_, filepath)
elif request[i] == 'PNG':
data_g, wcs_g = get_fits_data(
RA[i], DEC[i], size[i], tiles[i], band[i][0], path_to_fits)
Expand All @@ -38,4 +40,5 @@
RA[i], DEC[i], size[i], tiles[i], band[i][2], path_to_fits)
filename = '{:.5f}_{:.5f}_{}.png'.format(
round(RA[i], 5), round(DEC[i], 5), band[i])
cutout_lupton(data_g, data_r, data_i, 0.05, 10, 0.5, filename)
filepath = os.path.join(path_to_fits, filename)
cutout_lupton(data_g, data_r, data_i, 0.05, 10, 0.5, filepath)
14 changes: 14 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
astropy==5.2.1
contourpy==1.0.7
cycler==0.11.0
fonttools==4.39.0
kiwisolver==1.4.4
matplotlib==3.7.1
numpy==1.24.2
packaging==23.0
Pillow==9.4.0
pyerfa==2.0.0.1
pyparsing==3.0.9
python-dateutil==2.8.2
PyYAML==6.0
six==1.16.0
1 change: 1 addition & 0 deletions tiles/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.*
Empty file added tiles/README.md
Empty file.
7 changes: 7 additions & 0 deletions tiles/download_sample_tiles.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# curl -sSL "https://scienceserver.linea.org.br/data/cutout_des_sample_tiles.tar.gz" -o cutout_des_sample_tiles.tar.gz \
wget "https://scienceserver.linea.org.br/data/cutout_des_sample_tiles.tar.gz" -o cutout_des_sample_tiles.tar.gz \
&& tar -xzf cutout_des_sample_tiles.tar.gz \
&& for z in *.fits.fz; do funpack "$z"; done \
&& rm *.fits.fz \
&& rm cutout_des_sample_tiles.tar.gz \
&& ls -ltr