Skip to content

Commit

Permalink
use entrypoints instead of .py scripts for the command line (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
gillins authored Mar 12, 2024
1 parent 866ee42 commit be0a39d
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 10 deletions.
5 changes: 5 additions & 0 deletions INSTALL.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@

WARNING: To install python-fmask it is strongly recommended to use the conda forge
pre-built binaries. Only install from source if you absolutely must.


To install python-fmask from the source code bundle, use the following commands

First unpack the bundle. For the tar.gz file, this would be
Expand Down
2 changes: 2 additions & 0 deletions bin/fmask_sentinel2Stacked.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

from fmask.cmdline import sentinel2Stacked
import warnings
warnings.warn("Future versions of fmask may remove the .py extension from this script name", DeprecationWarning)

if __name__ == '__main__':
sentinel2Stacked.mainRoutine()
Expand Down
2 changes: 2 additions & 0 deletions bin/fmask_sentinel2makeAnglesImage.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

from fmask.cmdline import sentinel2makeAnglesImage
import warnings
warnings.warn("Future versions of fmask may remove the .py extension from this script name", DeprecationWarning)

if __name__ == "__main__":
sentinel2makeAnglesImage.mainRoutine()
Expand Down
2 changes: 2 additions & 0 deletions bin/fmask_usgsLandsatMakeAnglesImage.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

from fmask.cmdline import usgsLandsatMakeAnglesImage
import warnings
warnings.warn("Future versions of fmask may remove the .py extension from this script name", DeprecationWarning)

if __name__ == "__main__":
usgsLandsatMakeAnglesImage.mainRoutine()
2 changes: 2 additions & 0 deletions bin/fmask_usgsLandsatSaturationMask.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

from fmask.cmdline import usgsLandsatSaturationMask
import warnings
warnings.warn("Future versions of fmask may remove the .py extension from this script name", DeprecationWarning)

if __name__ == '__main__':
usgsLandsatSaturationMask.mainRoutine()
Expand Down
4 changes: 3 additions & 1 deletion bin/fmask_usgsLandsatStacked.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

from fmask.cmdline import usgsLandsatStacked

import warnings
warnings.warn("Future versions of fmask may remove the .py extension from this script name", DeprecationWarning)

if __name__ == '__main__':
usgsLandsatStacked.mainRoutine()

2 changes: 2 additions & 0 deletions bin/fmask_usgsLandsatTOA.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

from fmask.cmdline import usgsLandsatTOA
import warnings
warnings.warn("Future versions of fmask may remove the .py extension from this script name", DeprecationWarning)

if __name__ == '__main__':
usgsLandsatTOA.mainRoutine()
Expand Down
12 changes: 5 additions & 7 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ The command line scripts supplied can process an untarred USGS Landsat scene.
Here is an example of how to do this. This command will take a given scene directory,
find the right images, and create an output file called cloud.img::

fmask_usgsLandsatStacked.py -o cloud.img --scenedir LC08_L1TP_150033_20150413_20170410_01_T1
fmask_usgsLandsatStacked -o cloud.img --scenedir LC08_L1TP_150033_20150413_20170410_01_T1

If the thermal band is empty (for Landsat-8 with the SSM anomaly, after 2015-11-01) then it
is ignored gracefully.
Expand All @@ -125,13 +125,13 @@ slower, and is unlikely to be any more accurate.
This command will take a given .SAFE directory, find the right images, and create an
output file called cloud.img::

fmask_sentinel2Stacked.py -o cloud.img --safedir S2B_MSIL1C_20180918T235239_N0206_R130_T56JNQ_20180919T011001.SAFE
fmask_sentinel2Stacked -o cloud.img --safedir S2B_MSIL1C_20180918T235239_N0206_R130_T56JNQ_20180919T011001.SAFE

When working with the old ESA zipfile format, which packed multiple tiles into a single SAFE-format
zipfile, this approach will not work, as it won't know which tile to process. So, instead, use
the option to specify the granule directory, as follows::

fmask_sentinel2Stacked.py -o cloud.img --granuledir S2A_OPER_PRD_MSIL1C_PDMC_20160111T072442_R030_V20160111T000425_20160111T000425.SAFE/GRANULE/S2A_OPER_MSI_L1C_TL_SGS__20160111T051031_A002887_T56JNQ_N02.01
fmask_sentinel2Stacked -o cloud.img --granuledir S2A_OPER_PRD_MSIL1C_PDMC_20160111T072442_R030_V20160111T000425_20160111T000425.SAFE/GRANULE/S2A_OPER_MSI_L1C_TL_SGS__20160111T051031_A002887_T56JNQ_N02.01

This would also work on a new-format directory, but specifying the top .SAFE directory is easier.

Expand All @@ -155,13 +155,11 @@ Get the source as a bundle from `GitHub <https://github.com/ubarsc/python-fmask/
Release notes for each version can be read in :doc:`releasenotes`. To install from source,
read the INSTALL.txt file included inside the source bundle.

Pre-built binary `Conda <http://conda.pydata.org/miniconda.html#miniconda>`_ packages are available
Pre-built binary `Conda <https://github.com/conda-forge/miniforge>`_ packages are available
under the 'conda-forge' channel. Once you have installed
`Conda <http://conda.pydata.org/miniconda.html#miniconda>`_, run the following commands on the
`Conda <https://github.com/conda-forge/miniforge>`_, run the following commands on the
command line to install python-fmask: ::

conda config --add channels conda-forge
conda config --set channel_priority strict
conda create -n myenv python-fmask
conda activate myenv

Expand Down
6 changes: 4 additions & 2 deletions fmask/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
from rios import applier
from . import fmaskerrors

gdal.UseExceptions()

FMASK_LANDSAT47 = 0
"Landsat 4 to 7"
FMASK_LANDSAT8 = 1
Expand Down Expand Up @@ -436,7 +438,7 @@ def setTOAReflectanceFile(self, toaRefFile):
This should have numbers which are reflectance * 1000
Use the :func:`fmask.landsatTOA.makeTOAReflectance` function to create
this file from raw Landsat radiance (or the fmask_usgsLandsatTOA.py
this file from raw Landsat radiance (or the fmask_usgsLandsatTOA
command line program supplied with fmask).
It is assumed that any values that are nulls in the original radiance
Expand Down Expand Up @@ -686,7 +688,7 @@ def __init__(self, solarZenithFilename, solarZenithBand, solarAzimuthFilename,
self.viewZenithData = None
self.viewAzimuthData = None

# This default value matches the file produced by fmask_usgsLandsatMakeAnglesImage.py
# This default value matches the file produced by fmask_usgsLandsatMakeAnglesImage
self.scaleToRadians = 0.01

@staticmethod
Expand Down
1 change: 1 addition & 0 deletions fmask/fmask.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
from . import zerocheck

numpy.seterr(all='raise')
gdal.UseExceptions()

# Bands in the saturation mask, if supplied
SATURATION_BLUE = 0
Expand Down
2 changes: 2 additions & 0 deletions fmask/landsatTOA.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
from rios import applier, cuiprogress, fileinfo
from . import config

gdal.UseExceptions()

# Derived by Pete Bunting from 6S
LANDSAT8_ESUN = [1876.61, 1970.03, 1848.9, 1571.3, 967.66, 245.73, 82.03, 361.72]
# From Chander, G., Markham, B.L., Helder, D.L. (2008)
Expand Down
2 changes: 2 additions & 0 deletions fmask/landsatangles.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
from rios import applier
from rios import fileinfo

osr.UseExceptions()


def findImgCorners(img, imgInfo):
"""
Expand Down
2 changes: 2 additions & 0 deletions fmask/sen2meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

from . import fmaskerrors

osr.UseExceptions()


class Sen2TileMeta(object):
"""
Expand Down
9 changes: 9 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@
author='Neil Flood',
author_email='n.flood@uq.edu.au',
scripts=scriptList,
entry_points={
'console_scripts': [
'fmask_sentinel2makeAnglesImage = fmask.cmdline.sentinel2makeAnglesImage:mainRoutine',
'fmask_sentinel2Stacked = fmask.cmdline.sentinel2Stacked:mainRoutine',
'fmask_usgsLandsatMakeAnglesImage = fmask.cmdline.usgsLandsatMakeAnglesImage:mainRoutine',
'fmask_usgsLandsatSaturationMask = fmask.cmdline.usgsLandsatSaturationMask:mainRoutine',
'fmask_usgsLandsatStacked = fmask.cmdline.usgsLandsatStacked:mainRoutine',
'fmask_usgsLandsatTOA = fmask.cmdline.usgsLandsatTOA:mainRoutine'
]},
packages=['fmask', 'fmask/cmdline'],
ext_package='fmask',
ext_modules=extensionsList,
Expand Down

0 comments on commit be0a39d

Please sign in to comment.