Skip to content

Functions

Download NASA POWER climate data for the points of a table.

Each point is saved as a CSV in output_folder (<identifier>.csv). A point whose CSV already has all the period requested is not downloaded again (unless overwrite=True), so an interrupted download can be run again and continues where it stopped; if the period grows (e.g. an update with a later end_date), the point is downloaded again. Busy answers of the API (429, 5xx) are retried three times.

Parameters:

Name Type Description Default
df DataFrame

Points to download, e.g. the centroids of the municipalities or AGEB.

required
lat_col str

Columns with the coordinates (decimal degrees, WGS84).

'latitude'
lon_col str

Columns with the coordinates (decimal degrees, WGS84).

'latitude'
start_date str

Period as "YYYYMMDD"; for "monthly" only the year is used.

'20150101'
end_date str

Period as "YYYYMMDD"; for "monthly" only the year is used.

'20150101'
parameters list of str

NASA POWER parameters. Temperature: T2M, T2M_MAX, T2M_MIN, T2M_RANGE, T2MDEW, T2MWET, TS; precipitation: PRECTOTCORR; humidity: RH2M, QV2M; wind: WS2M, WS10M; radiation: ALLSKY_SFC_SW_DWN; pressure: PS.

('T2M', 'T2MDEW', 'T2MWET', 'TS', 'T2M_RANGE', 'T2M_MAX', 'T2M_MIN')
temporal_resolution ('daily', 'monthly', 'climatology')
"daily"
spatial_resolution 'point'

Kept for compatibility with version 0.1; only "point" is valid (one request per latitude and longitude).

"point"
community ('RE', 'AG', 'SB')

Renewable energy, agroclimatology or sustainable buildings (units).

"RE"
processes int

Simultaneous requests (NASA asks for at most 5); 1 downloads in order. The requests run in threads, so no if __name__ == "__main__" guard is needed in scripts.

5
output_folder str

Folder for the CSV of each point.

'./nasa_power_data'
start_col str

Columns with a different period for each point.

None
end_col str

Columns with a different period for each point.

None
id_col str

Column with the identifier of each point (else idx_<row>).

None
return_consolidated bool

If True, return the data of all the points in one table; if False, the result of each download.

True
overwrite bool

Download again every point, even if its CSV already has the period.

False
verbose bool

Show the progress.

True

Returns:

Type Description
DataFrame

Columns identifier, latitude, longitude, the date (date; year and month; or period) and one column per parameter. Missing values (-999 in NASA POWER) are NaN.

Examples:

>>> import pandas as pd
>>> from climex import download_nasa_power_data
>>> pts = pd.DataFrame({"id": ["merida"], "latitude": [20.97], "longitude": [-89.62]})
>>> clima = download_nasa_power_data(pts, id_col="id", parameters=["T2M", "PRECTOTCORR"],
...                                  start_date="20240101", end_date="20241231")

Points of the municipalities of Mexico, bundled with the package.

municipalities(cve_edo=None, point='inside')

One point per municipality of Mexico (INEGI 2019), all or by state.

The table comes with the package (2,465 municipalities), so no download is needed; it is ready for :func:climex.download_nasa_power_data with id_col="CVEGEO".

Parameters:

Name Type Description Default
cve_edo (str, int or list)

State code(s) ("31", 31 or ["14", "31"]). None returns the 2,465 municipalities of the country.

None
point ('inside', 'centroid')

"inside" (default) uses a point that is always inside the municipality (its representative point); "centroid" uses the geometric centroid, which falls outside 67 curved or fragmented municipalities (see the column centroid_inside).

"inside"

Returns:

Type Description
DataFrame

CVEGEO, CVE_ENT, state, CVE_MUN, municipality, latitude, longitude (WGS84), centroid_lat, centroid_lon, centroid_inside and area_km2.

Examples:

>>> import climex
>>> yuc = climex.municipalities("31")          # the 106 municipalities of Yucatán
>>> mx = climex.municipalities()               # all the country
>>> clima = climex.download_nasa_power_data(yuc, id_col="CVEGEO",
...                                         parameters=["T2M", "PRECTOTCORR"],
...                                         start_date="20240101", end_date="20241231")

Points (inside each polygon) to download the climate of polygons.

Uses the representative point of each polygon, which is always inside it (the centroid of a curved municipality can fall outside).

Parameters:

Name Type Description Default
gdf GeoDataFrame

Polygons, e.g. rgeomex.load("AGEM_inegi19_mx", cve_edo="31").

required
id_col str

Column with the identifier of each polygon (e.g. "CVEGEO").

required

Returns:

Type Description
DataFrame

id_col, latitude and longitude (WGS84), ready for :func:climex.download_nasa_power_data.

URL of one NASA POWER request for a point.

Parameters:

Name Type Description Default
latitude float

Coordinates of the point (decimal degrees, WGS84).

required
longitude float

Coordinates of the point (decimal degrees, WGS84).

required
parameters list of str

NASA POWER parameters, e.g. ["T2M", "PRECTOTCORR"].

required
temporal_resolution ('daily', 'monthly', 'climatology')
"daily"
community ('RE', 'AG', 'SB')
"RE"
start str

Dates as "YYYYMMDD" (for "monthly" only the year is used). Not used for "climatology".

None
end str

Dates as "YYYYMMDD" (for "monthly" only the year is used). Not used for "climatology".

None

Table (one row per day, month or period) from the JSON of NASA POWER.

Read a CSV of municipal points and keep the municipalities of one state.

Parameters:

Name Type Description Default
path str

CSV with a CVEGEO column (municipality key, 5 digits).

required
state str

State code, e.g. "01" (the first two digits of CVEGEO).

required
Notes

:func:climex.municipalities gives the same points for all the municipalities of Mexico without a CSV.