Skip to content

Commit

Permalink
Merge pull request #2 from alekfal/development
Browse files Browse the repository at this point in the history
Major updates for #1
  • Loading branch information
alekfal authored Nov 7, 2023
2 parents b72eee3 + 2295c35 commit 1b8234f
Show file tree
Hide file tree
Showing 39 changed files with 1,070 additions and 458 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# This workflow will upload a Python Package using Twine when a release is created
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: upload PyPI

on:
release:
types: [published]

permissions:
contents: read

jobs:
deploy:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.9"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
48 changes: 48 additions & 0 deletions .github/workflows/python_package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: build

on:
push:
branches: [ "master", "development" ]
pull_request:
branches: [ "master", "development" ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
pip install -e.[dev]
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
working-directory: tests/
run: |
if [ ${{ github.event_name }} == 'push' ]; then
pytest --cov --cov-report=term --cov-report=xml
else
pytest
fi
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
18 changes: 18 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: 2

build:
os: "ubuntu-22.04"
tools:
python: "3.9"
apt_packages:
- python3-dev
jobs:
post_create_environment:
- pip install .

sphinx:
configuration: docs/conf.py

python:
install:
- requirements: docs/requirements-docs.txt
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include README.md
include requirements.txt
97 changes: 36 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,80 +1,55 @@
# NASAMeteoDataTool
# pynasapower
![nasa](https://user-images.githubusercontent.com/18232521/75673566-eb882880-5c8b-11ea-9a65-995f94b876bf.png)

Download Meteorological Data from NASA POWER restful API (https://power.larc.nasa.gov/)
[![Build Status](https://github.com/alekfal/pynasapower/actions/workflows/python-package.yml/badge.svg?branch=master)](https://github.com/alekfal/pynasapower/actions)
[![Code coverage](https://codecov.io/gh/alekfal/pynasapower/branch/master/graph/badge.svg)](https://codecov.io/gh/alekfal/pynasapower)
[![Supported Python versions](https://img.shields.io/pypi/pyversions/pynasapower.svg?style=flat-square)](https://pypi.org/project/pynasapower/)
[![Overall downloads](https://pepy.tech/badge/pynasapower)](https://pepy.tech/project/pynasapower)
[![Last month downloads](https://pepy.tech/badge/pynasapower/month)](https://pepy.tech/project/pynasapower)

The NASA POWER database is a global database of daily meteorological data
designed for agrometeorological applications and more. The spatial
resolution of the database is 0.25x0.25 degrees. Data are retrieced from in-situ observations in combination with satellite
data. The meteorological data is updated with a delay of about 3 months.
For more information on the NASA POWER database see the documentation
at: https://power.larc.nasa.gov/
Download meteorological data from NASA POWER restful API (https://power.larc.nasa.gov/) using pynasapower API client.

### Input parameters
The NASA POWER database is a global database of daily meteorological data designed for agrometeorological applications and more.
Data are retrieced from in-situ observations in combination with satellite data. The meteorological data is updated with a delay of about 3 months. For more information on the NASA POWER database see the documentation at: https://power.larc.nasa.gov/

### Installation from source

| Name | Description |
|------------------|---------------------------------------------------------------------------------------------------------------------------------------------|
| ```latitude``` | Latitude (```float```) |
| ```longitude``` | Longitude (```float```) |
| ```start_date``` | Start date (```datetime.date```) |
| ```end_date``` | End date (```datetime.date```) |
| ```to_PCSE``` | If true (```bool```) the tool will write the results in a format compatible to PCSE. In other case data will be written as in the dataframe.|
| ```to_file``` | Save to file if true (```bool - Optional, default = False```) |
| ```filename``` | Name of the new file (```string - Optional, default = meteorological_data.xls```) |

### The NASAPowerMeteorologicalData class attributes

| Name | Description |
|-----------------------|--------------------------------------------------------------------------------|
| ```data``` | All the downloaded data in pandas dataframe (```pandas.dataframe```) |
| ```description``` | A brief description of the downloaded data |
| ```elevation``` | Elevation in meters (m) |
| ```latitude``` | Latitude |
| ```longitude``` | Longitude |
| ```angstormA``` | Angstrom A value |
| ```angstormB``` | Angstrom B value |
| ```angstormB``` | Angstrom B value |
| ```power_variables``` | A list with the variables to download (from NASA) |
```bash
git clone https://github.com/alekfal/pynasapower.git
cd pynasapower/
pip install .
```

### Installation
### Instalation from PyPI

```bash
git clone https://github.com/alekfal/NASAMeteoDataTool.git
cd NASAMeteoDataTool/
pip install .
pip install pynasapower
```

### Examples

Download Meteorological data
Download meteorological data for a point in Athens, Greece and save result in `*.csv` format.

```python
import datetime as dt
from pyNASAPower import NASAPowerMeteorologicalData

# Latitude, Longitude for Athens, Greece
latitude = 37.983810
longitude = 23.727539

# Dates for downloading meteorological data in format (y, m, d)
start_date = dt.date(2017, 1, 1)
end_date = dt.date(2017, 12, 31)

# Download data
meteo = NASAPowerMeteorologicalData(latitude, longitude, start_date, end_date, to_PCSE = False, to_file = True, filename = 'meteorological_data.xls')

# Or PCSE format
meteo = NASAPowerMeteorologicalData(latitude, longitude, start_date, end_date, to_PCSE = True, to_file = True, filename = 'PCSE_meteorological_data.xls')
from pynasapower.get_data import query_power
from pynasapower.geometry import point, bbox
import datetime

# Run for point in Athens and save the result in csv format
gpoint = point(23.727539, 37.983810, "EPSG:4326")
start = datetime.date(2022, 1, 1)
end = datetime.date(2022, 2, 1)
data = query_power(gpoint, start, end, "./data", True, "ag", [], "daily", "point", "csv")
```

#### Results

1. Option to_PCSE = False (meteorological_data.xls):

![meteo](https://user-images.githubusercontent.com/18232521/94548147-f70af480-0258-11eb-885d-0fab180c700b.png)
Download meteorological data for a polygon in Athens, Greece and save result in `*.csv` format.

```python
# Run for small bbox in Athens and save the result in csv format
gbbox = bbox(23.727539, 26.73, 37.983810, 40.99, "EPSG:4326")
start = datetime.date(2022, 1, 1)
end = datetime.date(2022, 2, 1)
data = query_power(gpoint, start, end, "./data", True, "ag", [], "daily", "regional", "csv")
```

2. Option to_PCSE = True (PCSE_meteorological_data.xls):

![PCSE](https://user-images.githubusercontent.com/18232521/94549025-400f7880-025a-11eb-923f-535d27dcc4f4.png)
Read more about the software in readthedocs.
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
40 changes: 40 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Build ```pynasapower``` documentation

## Installing requirements
```bash
pip install .[docs]
```
or

```bash
pip install -r ./docs/requirements-docs.txt
```

## Quickstart with ```sphinx``` (Already implemented in this repository)

Start by moving in ```docs``` folder. If the current path is in
main folder run:

```bash
cd docs/
```

then inside the ```docs/``` folder run:

```bash
sphinx-quickstart
```

and start configuring the project.

## Automatic docstring documentation with ```sphinx-apidoc```

```bash
sphinx-apidoc ../pynasapower/ -o .
```

## Build ```HTML``` pages

```bash
make html
```
41 changes: 41 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
import os
import sys
import sphinx_rtd_theme

sys.path.insert(0, os.path.abspath('..'))

project = 'pynasapower'
copyright = '2023, Alekos Falagas'
author = 'Alekos Falagas'
release = '0.0.1a0'

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = [
'sphinx.ext.duration',
'sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'sphinx.ext.napoleon',
'sphinx.ext.todo',
'myst_parser',
'sphinxemoji.sphinxemoji',
]


templates_path = ['_templates']
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']



# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
html_theme = 'sphinx_rtd_theme'
html_static_path = ['_static']
27 changes: 27 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.. pynasapower documentation master file, created by
sphinx-quickstart on Tue Nov 7 12:33:32 2023.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to pynasapower's documentation!
=======================================

Download meteorological data from NASA POWER restful API (https://power.larc.nasa.gov/) using pynasapower API client.

The NASA POWER database is a global database of daily meteorological data designed for agrometeorological applications and more.
Data are retrieced from in-situ observations in combination with satellite data. The meteorological data is updated with a delay of about 3 months. For more information on the NASA POWER database see the documentation at: https://power.larc.nasa.gov/

.. toctree::
:maxdepth: 4
:caption: Contents:

installation
quickstart
modules

Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
19 changes: 19 additions & 0 deletions docs/installation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Installation
============

Installation using pip from GIT
-------------------------------

Use ``git`` command to get ``pynasapower`` package and then ``pip`` package manager to install the module.

.. code-block:: bash
git clone https://github.com/alekfal/pynasapower.git && cd pynasapower/
pip install .
Installation using pip from PyPI
--------------------------------

.. code-block:: bash
pip install pynasapower
Loading

0 comments on commit 1b8234f

Please sign in to comment.