10000 Add retrieval function for NASA MERRA2 reanalysis data by AdamRJensen · Pull Request #1274 · pvlib/pvlib-python · GitHub
[go: up one dir, main page]

Skip to content

Add retrieval function for NASA MERRA2 reanalysis data #1274

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

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add read_merra2 and variable_map
  • Loading branch information
AdamRJensen committed Aug 8, 2021
commit 2a25d8253673f3cda21cfe887572f68c5c50b1aa
48 changes: 45 additions & 3 deletions pvlib/iotools/merra2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,24 @@

import xarray as xr # Make funky import
from pydap.cas.urs import setup_session

import os

MERRA2_VARIABLE_MAP = {
# Variables from the 'M2T1NXRAD' dataset
# Hourly,Time-Averaged,Single-Level,Assimilation,Radiation Diagnostics
'ALBEDO': 'albedo',
#'surface_incoming_shortwave_flux': ,
#'surface_incoming_shortwave_flux_assuming_clear_sky': ,
#'surface_net_downward_longwave_flux': ,
'SWGDN': 'ghi',
'SWTDN': '_extra',
'PS': 'pressure',
'T2M': 'temp_air',
'T2MDEW': 'temp_dew',

}

# goldsmr4 contains the single-level 2D MERRA-2 data files
MERRA2_BASE_URL = 'https://goldsmr4.gesdisc.eosdis.nasa.gov/dods'


Expand Down Expand Up @@ -36,6 +53,16 @@ def get_merra2(latitude, longitude, start, end, dataset, variables, username,
In order to obtain MERRA2 data, it is necessary to registre for an
Earthdata account and link it to the GES DISC as described in [2]_.

MERRA-2 contains 14 single-level 2D datasets with an hourly resolution. The
most important ones are 'M2T1NXAER' which contains aerosol data, 'M2T1NXRAD'
which contains radiation related parameters, and 'M2T1NXSLV' which contains
general variables (e.g., temperature and wind speed).

Warning
-------
Known error in calculation of radiation, hence it is strongly adviced that
radiation from MERRA-2 should not be used. Users interested in radiation
from reanalysis datasets are referred to pvlib.iotools.get_era5.

See Also
--------
Expand All @@ -61,10 +88,25 @@ def get_merra2(latitude, longitude, start, end, dataset, variables, username,
'times': slice(start.strftime('%Y-%m-%d'), end.strftime('%Y-%m-%d')),
})

data = ds[[variables]].to_dataframe()
data = ds[variables].to_dataframe()

metadata = ds.attrs # Gives overall metadata but not variable stuff

metadata = {}
if local_path is not None:
ds.to_netcdf(os.path.join(local_path, metadata['Filename']))

return data, metadata


# Shoudl read_merra2 use open_mfdataset?
def read_merra2(filenames, latitude, longitude, variables, map_variables=True):
"""Reading a MERRA-2 file into a pandas dataframe.

"""
ds = xr.open_dataset(filenames).sel(lat=latitude, lon=longitude,
method='nearest')

data = ds[variables].to_dataframe().drop(columns=['lon', 'lat'])
metadata = ds.attrs # Gives overall metadata but not variable stuff

return data, metadata
0