دانلود فایل های MODIS با استفاده از PyModis
Summarize this content to 400 words in Persian Lang برای دانلود مستقیم فایلهای MODIS از NASA Earthdata، از کتابخانه PyModis استفاده میکنیم که به ما امکان میدهد کل فرآیند را در پایتون، از دانلود تا تجزیه و تحلیل دادهها، مدیریت کنیم. می توانید PyModis را در اینجا پیدا کنید:
https://github.com/lucadelu/pyModis/
اگر قبلاً یک حساب ناسا Earthdata ندارید، لطفاً ابتدا در آدرس زیر ثبت نام کنید:
https://urs.earthdata.nasa.gov/
نصب کتابخانه های مورد نیاز
ما با راه اندازی یک محیط مجازی Anaconda و نصب کتابخانه های لازم شروع می کنیم.
conda install -c conda-forge pymodis
conda install -c conda-forge libgdal
وقتی PyModis را با conda نصب می کنیم، GDAL باید به طور خودکار به عنوان یک وابستگی درج شود. با این حال، اگر GDAL وجود نداشته باشد، می توانیم آن را به صورت دستی نصب کنیم. اگر پشتیبانی HDF4 نیز مورد نیاز باشد، نصب libgdal هرگونه خطای مرتبط را برطرف میکند، مانند:
warnings.warn(“GDAL installation has no support for HDF4, please update GDAL”, ImportError)
استفاده از کلاس downmodis در PyModis
کلاس downmodis از PyModis ما را قادر می سازد فایل های MODIS را دانلود کنیم. در اینجا یک مرور مختصر از آرگومان های آن، با گزیده ای جزئی از کد منبع آورده شده است:
# This code is part of the PyModis library by Luca Delucchi and Logan C Byers,
# licensed under the GNU General Public License v2.0.
class downModis:
“””A class to download MODIS data from NASA FTP or HTTP repositories
:param str destinationFolder: where the files will be stored
:param str password: the password required by NASA authentication system
:param str user: the user namerequired by NASA authentication system
:param str url: the base url from where to download the MODIS data,
it can be FTP or HTTP but it has to start with
‘ftp://’ or ‘http://’ or ‘https://’
:param str path: the directory where the data that you want to
download are stored on the FTP server. For HTTP
requests, this is the part of the url between the ‘url’
parameter and the ‘product’ parameter.
:param str product: the code of the product to download, the code
should be idential to the one of the url
:param str tiles: a set of tiles to be downloaded, None == all tiles.
This can be passed as a string of tileIDs separated
by commas, or as a list of individual tileIDs
:param str today: the day to start downloading; in order to pass a
date different from today use the format YYYY-MM-DD
:param str enddate: the day to end downloading; in order to pass a
date use the format YYYY-MM-DD. This day must be
before the ‘today’ parameter. Downloading happens
in reverse order (currently)
:param int delta: timelag i.e. the number of days starting from
today backwards. Will be overwritten if
‘enddate’ is specifed during instantiation
:param bool jpeg: set to True if you want to download the JPG overview
file in addition to the HDF
:param bool debug: set to True if you want to obtain debug information
:param int timeout: Timeout value for HTTP server (seconds)
:param bool checkgdal: variable to set the GDAL check
“””
def __init__(self, destinationFolder, password=None, user=None, token=None,
url=”https://e4ftl01.cr.usgs.gov”, tiles=None, path=”MOLT”,
product=”MOD11A1.006″, today=None, enddate=None, delta=10,
jpg=False, debug=False, timeout=30, checkgdal=True):
ما میتوانیم با استفاده از نام کاربری و رمز عبور یا توکن احراز هویت کنیم. برای استفاده از یک توکن، یکی را ایجاد کنید.
برای جزئیات، نگاه کنید به:
https://urs.earthdata.nasa.gov/documentation/for_users/user_token
پیدا کردن دایرکتوری صحیح
دسترسی به URL پیشفرض، https://e4ftl01.cr.usgs.gov، ساختار دایرکتوری را مانند زیر نشان میدهد:
ASTT/
COMMUNITY/
ECOSTRESS/
MEASURES/
MOLA/
MOLT/
MOTA/
VIIRS/
به عنوان مثال، اگر به دنبال دانلود فایل های MYD11A2 هستید، آنها در آن ذخیره می شوند
https://e4ftl01.cr.usgs.gov/MOLA/MYD11A2.061
برای دانلود فایل های خاص، باید آنها را در این ساختار قرار دهیم. به عنوان مثال، فایل های MYD11A2 در ذخیره می شوند MOLA دایرکتوری ما می توانیم به آنها دسترسی پیدا کنیم:
https://e4ftl01.cr.usgs.gov/MOLA/MYD11A2.061
MOLA/
├── MYD09A1.061/
│ ├── 2002.07.04/
│ ├── 2002.07.12/
│ └── …
├── …
├── MYD11A2.061/
│ ├── 2002.07.04/
│ ├── 2002.07.12/
│ └── …
└── …
برای تعیین مکان در PyModis، مسیر و آرگومان های محصول را تنظیم می کنیم.
برای MYD11A2.061، ما تنظیم کردیم:
path: “MOLA”
product: “MYD11A2.061” (که در آن نسخه 0.061 است)
کد مثال
مثال زیر فایلهای MYD11A2.061 را برای کاشی h29v06 بین 01-01-2024 و 2024-10-15 دانلود میکند.
from pymodis import downmodis
# Define parameters
destination_folder = “downloads”
tiles = “h29v06”
path = “MOLA”
product = “MYD11A2.061”
today = “2024-01-01”
enddate = “2024-10-15″
# Initialize downloader
modis_downloader = downmodis.downModis(
destinationFolder=destination_folder,
password=”your password”,
user=”your username”,
tiles=tiles,
path=path,
product=product,
today=today,
enddate=enddate,
)
# Connect and download files
modis_downloader.connect()
modis_downloader.downloadsAllDay()
این اسکریپت فایل های مورد نظر را مستقیماً در پوشه مشخص شده احراز هویت و دانلود می کند. پارامترها را در صورت نیاز برای سایر محصولات MODIS یا بازههای زمانی تنظیم کنید.
برای دانلود مستقیم فایلهای MODIS از NASA Earthdata، از کتابخانه PyModis استفاده میکنیم که به ما امکان میدهد کل فرآیند را در پایتون، از دانلود تا تجزیه و تحلیل دادهها، مدیریت کنیم. می توانید PyModis را در اینجا پیدا کنید:
https://github.com/lucadelu/pyModis/
اگر قبلاً یک حساب ناسا Earthdata ندارید، لطفاً ابتدا در آدرس زیر ثبت نام کنید:
https://urs.earthdata.nasa.gov/
نصب کتابخانه های مورد نیاز
ما با راه اندازی یک محیط مجازی Anaconda و نصب کتابخانه های لازم شروع می کنیم.
conda install -c conda-forge pymodis
conda install -c conda-forge libgdal
وقتی PyModis را با conda نصب می کنیم، GDAL باید به طور خودکار به عنوان یک وابستگی درج شود. با این حال، اگر GDAL وجود نداشته باشد، می توانیم آن را به صورت دستی نصب کنیم. اگر پشتیبانی HDF4 نیز مورد نیاز باشد، نصب libgdal هرگونه خطای مرتبط را برطرف میکند، مانند:
warnings.warn("GDAL installation has no support for HDF4, please update GDAL", ImportError)
استفاده از کلاس downmodis در PyModis
کلاس downmodis از PyModis ما را قادر می سازد فایل های MODIS را دانلود کنیم. در اینجا یک مرور مختصر از آرگومان های آن، با گزیده ای جزئی از کد منبع آورده شده است:
# This code is part of the PyModis library by Luca Delucchi and Logan C Byers,
# licensed under the GNU General Public License v2.0.
class downModis:
"""A class to download MODIS data from NASA FTP or HTTP repositories
:param str destinationFolder: where the files will be stored
:param str password: the password required by NASA authentication system
:param str user: the user namerequired by NASA authentication system
:param str url: the base url from where to download the MODIS data,
it can be FTP or HTTP but it has to start with
'ftp://' or 'http://' or 'https://'
:param str path: the directory where the data that you want to
download are stored on the FTP server. For HTTP
requests, this is the part of the url between the 'url'
parameter and the 'product' parameter.
:param str product: the code of the product to download, the code
should be idential to the one of the url
:param str tiles: a set of tiles to be downloaded, None == all tiles.
This can be passed as a string of tileIDs separated
by commas, or as a list of individual tileIDs
:param str today: the day to start downloading; in order to pass a
date different from today use the format YYYY-MM-DD
:param str enddate: the day to end downloading; in order to pass a
date use the format YYYY-MM-DD. This day must be
before the 'today' parameter. Downloading happens
in reverse order (currently)
:param int delta: timelag i.e. the number of days starting from
today backwards. Will be overwritten if
'enddate' is specifed during instantiation
:param bool jpeg: set to True if you want to download the JPG overview
file in addition to the HDF
:param bool debug: set to True if you want to obtain debug information
:param int timeout: Timeout value for HTTP server (seconds)
:param bool checkgdal: variable to set the GDAL check
"""
def __init__(self, destinationFolder, password=None, user=None, token=None,
url="https://e4ftl01.cr.usgs.gov", tiles=None, path="MOLT",
product="MOD11A1.006", today=None, enddate=None, delta=10,
jpg=False, debug=False, timeout=30, checkgdal=True):
ما میتوانیم با استفاده از نام کاربری و رمز عبور یا توکن احراز هویت کنیم. برای استفاده از یک توکن، یکی را ایجاد کنید.
برای جزئیات، نگاه کنید به:
https://urs.earthdata.nasa.gov/documentation/for_users/user_token
پیدا کردن دایرکتوری صحیح
دسترسی به URL پیشفرض، https://e4ftl01.cr.usgs.gov، ساختار دایرکتوری را مانند زیر نشان میدهد:
ASTT/
COMMUNITY/
ECOSTRESS/
MEASURES/
MOLA/
MOLT/
MOTA/
VIIRS/
به عنوان مثال، اگر به دنبال دانلود فایل های MYD11A2 هستید، آنها در آن ذخیره می شوند
https://e4ftl01.cr.usgs.gov/MOLA/MYD11A2.061
برای دانلود فایل های خاص، باید آنها را در این ساختار قرار دهیم. به عنوان مثال، فایل های MYD11A2 در ذخیره می شوند MOLA
دایرکتوری ما می توانیم به آنها دسترسی پیدا کنیم:
https://e4ftl01.cr.usgs.gov/MOLA/MYD11A2.061
MOLA/
├── MYD09A1.061/
│ ├── 2002.07.04/
│ ├── 2002.07.12/
│ └── ...
├── ...
├── MYD11A2.061/
│ ├── 2002.07.04/
│ ├── 2002.07.12/
│ └── ...
└── ...
برای تعیین مکان در PyModis، مسیر و آرگومان های محصول را تنظیم می کنیم.
برای MYD11A2.061، ما تنظیم کردیم:
path
: "MOLA"
product
: "MYD11A2.061"
(که در آن نسخه 0.061 است)
کد مثال
مثال زیر فایلهای MYD11A2.061 را برای کاشی h29v06 بین 01-01-2024 و 2024-10-15 دانلود میکند.
from pymodis import downmodis
# Define parameters
destination_folder = "downloads"
tiles = "h29v06"
path = "MOLA"
product = "MYD11A2.061"
today = "2024-01-01"
enddate = "2024-10-15"
# Initialize downloader
modis_downloader = downmodis.downModis(
destinationFolder=destination_folder,
password="your password",
user="your username",
tiles=tiles,
path=path,
product=product,
today=today,
enddate=enddate,
)
# Connect and download files
modis_downloader.connect()
modis_downloader.downloadsAllDay()
این اسکریپت فایل های مورد نظر را مستقیماً در پوشه مشخص شده احراز هویت و دانلود می کند. پارامترها را در صورت نیاز برای سایر محصولات MODIS یا بازههای زمانی تنظیم کنید.