跳转到主要内容

哈勃空间望远镜观测校准数据管道

项目描述

哈勃空间望远镜观测校准数据管道

Powered by Astropy Badge

许可证

本项目的版权属于STScI,并受BSD 3-Clause许可证的条款约束。本软件包基于Astropy软件包模板,该模板也受BSD 3-clause许可证的约束。有关更多信息,请参阅许可证文件夹。

贡献

我们欢迎贡献!caldp是开源的,建立在开源之上,我们希望您能加入我们的社区。

冒充综合症免责声明:我们想要您的帮助。不,真的。

您脑海中可能有一个小声音在告诉您,您还没有准备好成为开源贡献者;您的技能还不够好,无法做出贡献。您能为这样一个项目提供什么帮助呢?

我们向您保证——您脑海中的那个小声音是错误的。如果您能写代码,您就可以向开源项目贡献代码。向开源项目贡献是一种提升编程技能的绝佳方式。编写完美的代码不是衡量优秀开发者的标准(这会排除我们所有人!);尝试创造东西,犯错误,并从错误中学习。这是我们所有人进步的方式,我们很高兴帮助他人学习。

成为开源贡献者不仅意味着写代码。您可以通过编写文档、测试或甚至对项目(包括贡献过程)提供反馈来提供帮助。这些贡献中的一些可能对整个项目最有价值,因为您以全新的视角来看待项目,因此您可以看到资深贡献者已经忽略的错误和假设。

注意:此免责声明最初由Adrienne LowePyCon演讲编写,并由caldp根据其用于MetPy项目的README文件中的使用情况进行修改。

CALDP概述

CALDP用于将基本HST校准程序(例如calacs.e)与输入数据、输出数据和校准参考文件(CRDS)集成。最终,

CALDP以类似于归档管道的方式对HST数据进行端到端校准,包括生成预览图像。

CALDP主要是一个Python包,包含一些可安装的脚本,但也包括构建包含所有必需内容的Docker容器的基础设施,以完全校准原始HST数据以产生类似管道的产品。

CALDP有两种基本运行方式

  1. CALDP可以在conda环境中本地运行。

  2. CALDP可以在Docker容器中运行。

在Docker容器中运行CALDP的一种变体是

3. 在AWS计算集群上运行任意数量的CALDP容器,从Astroquery拉取输入,并将输出写入AWS S3存储。这可以极大地加速大型处理运行。

本地CALDP

CALDP的核心逻辑在caldp Python包的process和create_preview模块中实现。CALDP还包括方便的脚本,以便更容易地配置和调用这些模块。由于它主要是Python,因此只要安装了先决条件,就可以在容器外运行CALDP。

本地安装

完整安装

警告:默认情况下,此安装方法将完全替换$HOME/miniconda3中您已安装的任何内容,除非您提供额外的参数。

以下命令将安装

  1. Miniconda

  2. HSTCAL的稳定版本

  3. Fitscut

  4. 您复制的任何CALDP版本,或者签出的版本

以下方括号[]中指定的参数是可选的,但必须按顺序指定,例如,要更改CONDA_DIR,必须明确指定所有四个参数。

git clone https://github.com/spacetelescope/caldp.git
cd caldp
scripts/caldp-install-all   [HSTCAL]  [PY_VER]  [CONDA_ENV]  [CONDA_DIR]

参数

默认值

描述

HSTCAL

稳定

基本校准软件包的版本,通常是稳定最新版本。

PY_VER

3.6.10

CALDP conda环境的Python版本。

CONDA_ENV

caldp_stable

要创建的conda环境

CONDA_DIR

${HOME}/miniconda3

Miniconda安装的位置。

逐步安装

本节将完整安装分解为不同的功能步骤,以便您可以根据需要省略步骤或进行自定义,例如,如果您已经安装了miniconda3,只想添加到其中。

0.检出源代码
 git clone https://github.com/spacetelescope/caldp.git
cd caldp
1.安装基本conda环境
scripts/caldp-install-conda  [CONDA_DIR]
source ~/.bashrc
2.使用管道包列表安装基本CAL代码
scripts/caldp-install-cal  [HSTCAL]  [PY_VER]  [CONDA_ENV]  [CONDA_DIR]
source $CONDA_DIR/etc/profile.d/conda.sh
conda activate [CONDA_ENV]
3.安装fitscut以进行图像预览
scripts/caldp-install-fitscut   ${CONDA_DIR}/envs/${CONDA_ENV}
4.安装CALDP及其直接依赖项
pip install .[dev,test]

在进行CALDP开发时,您可以当然只迭代更改、重新安装和测试CALDP本身。

本地运行

运行CALDP的抽象命令是

caldp-process   <ipppssoot>   [<input_path>]  [<output_path>]   [<config>]
参数定义

参数

默认值

描述

ipppssoot

不适用

HST数据集标识符,您必须始终指定此参数

input_path

文件:

可以是file:<相对路径>或astroquery:或(可能很快是s3://input-bucket/subdirs…)

output_path

文件:

可以是file:<相对路径>或s3://output-bucket/subdirs…

config

caldp-config-onsite

可以是caldp-config-offsite、caldp-config-onsite、caldp-config-aws、<custom>

本地运行时,CALDP的文件路径与正常工作一样,只是它们使用类似于URI的表示法指定,以file:开头。绝对路径在这里有效。

示例本地命令

以下是一些运行CALDP本地的参数示例,包括不同的输入和输出模式。caldp-process默认配置为使用本地文件运行。

# All file access defaults to current working directory. Inputs must pre-exist.
# Inputs: Finds raw files matching j8cb010b0 in current working directory
# Outputs: Puts output product trees under current working directory as data and messages subdirectories.
# CRDS configuration: VPN configuration, no CRDS server required, /grp/crds/cache must be visible.
# Scratch files: Extra processing artifacts appear in the current working directory. Export CALDP_HOME to move them somewhere else.

caldp-process j8cb010b0

# ----------------------------------------------------------------------------------------
# File access in subdirectories, inputs must pre-exist.
# Inputs: Finds raw files matching j8cb010b0 in subdirectory j8cb010b0_inputs.
# Outputs: Copies output product tree under subdirectory j8cb010b0_outputs.
# CRDS configuration: VPN configuration, no CRDS server required, /grp/crds/cache must be visible.
# Scratch files: Extra processing artifacts appear in the current working directory. Export CALDP_HOME to move them somewhere else.

caldp-process j8cb010b0  file:j8cb010b0_inputs  file:j8cb010b0_outputs


# ----------------------------------------------------------------------------------------
# Download inputs from astroquery as neeed
# Inputs: Downloads raw files matching j8cb010b0 from astroquery to current working directory / CALDP_HOME.
# Outputs: Copies output product tree under subdirectory j8cb010b0_outputs.
# CRDS configuration: VPN configuration, no CRDS server required, /grp/crds/cache must be visible.
# Scratch files: Extra processing artifacts appear in the current working directory. Export CALDP_HOME to move them somewhere else.

caldp-process j8cb010b0  astroquery:   file:j8cb010b0_outputs


# ----------------------------------------------------------------------------------------
# Download inputs from astroquery, upload outputs to S3, current AWS Batch configuration minus Docker.
# Inputs: Downloads raw files matching j8cb010b0 from astroquery to current working directory / CALDP_HOME.
# Outputs: Copies output product tree to AWS S3 storage bucket, AWS credentials and permission required.
# CRDS configuration: VPN configuration, no CRDS server required, /grp/crds/cache must be visible.
# Scratch files: Extra processing artifacts appear in the current working directory. Export CALDP_HOME to move them somewhere else.

caldp-process j8cb010b0  astroquery:  s3://calcloud-hst-pipeline-outputs

Docker CALDP

虽然CALDP是一个原生可安装的Python包,但其根源在于作为Docker容器,用于在AWS Batch上执行HST校准。随后,CALDP得到了增强,可以通过使用本地文件系统中的输入和输出而不是像Astroquery和AWS S3存储这样的云资源来运行。与原生运行的主要区别在于,您必须将部分本地文件系统挂载到容器内部,以便尽可能自然地传递文件。默认情况下,您的当前工作目录变为$HOME (/home/developer)

Docker构建

如果您想将CALDP作为容器运行,那么安装它的等效操作是构建或拉取容器(例如,从AWS弹性容器注册表ECR)。本节将介绍构建自己的CALDP镜像。为了完成本节的个人使用,您只需要本地安装Docker,提供的脚本会更容易地为您运行。本节不涉及一般使用Docker,或托管您自己的镜像在Docker Hub或AWS弹性容器注册表(ECR)上,您可以在那里将其提供给其他人。

  1. 将此存储库克隆到本地目录,并进入该目录。

1. 编辑scripts/caldp-image-config以设置您的Docker存储库和默认标签。除非您准备推送镜像,否则可以为您的存储库使用任何名称。在熟悉脚本并准备好修改或改进它们之前,请将默认标签保留为“latest”。

git clone https://github.com:/spacetelescope/caldp.git
cd caldp
  1. 配置和构建

    编辑scripts/caldp-image-config以设置当前构建的Docker镜像配置变量。这包括您想要构建和/或推送的存储库和镜像标签。使用vim编辑scripts/caldp-image-config,并根据需要自定义。

    使用pip install .将CALDP原生安装以获取便利脚本和配置。

    此脚本执行docker build以创建具有您配置的镜像caldp-image-build。

在此阶段,如果您愿意,可以继续运行您的镜像。

3.(可选)当您准备好与他人分享您的镜像并完成相应的Docker Hub或ECR设置时,您可以从您的shell登录,然后

caldp-image-push

这将推送您的镜像到存储库并标记您配置的上述内容。

Docker运行

以下命令配置CALDP以在本地容器中运行。它的优点是整个HST校准环境都包含在容器中,因此除了设置Docker之外没有其他初步设置步骤。相同的容器可以在本地或AWS Batch等管道集群系统上运行。

caldp-docker-run-pipeline  <ipppssoot>  [<input_path>]  [<output_path>]   [<caldp_process_config>]

它应该与上面原生CALDP部分中显示的caldp-process命令非常相似,因为它确实是。主要的区别在于绝对原生路径不起作用。

注意:指定给caldp-docker-run-pipeline的配置文件用于配置处理,而不是选择镜像。caldp-docker-run-pipeline自动使用caldp-image-config来选择要运行的镜像。

示例Docker命令(本地文件系统)

以下是一些在Docker中运行CALDP的参数示例,不同输入和输出模式。caldp-process默认配置为使用本地文件。

# All file access defaults to current working directory. Inputs must pre-exist.
# Inputs: Finds raw files matching j8cb010b0 in current working directory
# Outputs: Puts output product trees under current working directory as data and messages subdirectories.
# CRDS configuration: Remote configuration, server https://hst-crds.stsci.edu must be up, files downloaded to crds_cache.
# Scratch files: Extra processing artifacts appear in the current working directory. Export CALDP_HOME to move them somewhere else.

caldp-docker-run-pipeline j8cb010b0

# ----------------------------------------------------------------------------------------
# File access in subdirectories, inputs must pre-exist.
# Inputs: Finds raw files matching j8cb010b0 in subdirectory j8cb010b0_inputs.
# Outputs: Copies output product tree under subdirectory j8cb010b0_outputs.
# CRDS configuration: Remote configuration, server https://hst-crds.stsci.edu must be up, files downloaded to crds_cache.
# Scratch files: Extra processing artifacts appear in the current working directory. Export CALDP_HOME to move them somewhere else.

caldp-docker-run-pipeline j8cb010b0  file:j8cb010b0_inputs  file:j8cb010b0_outputs


# ----------------------------------------------------------------------------------------
# Download inputs from astroquery as neeed
# Inputs: Downloads raw files matching j8cb010b0 from astroquery to current working directory / CALDP_HOME.
# Outputs: Copies output product tree under subdirectory j8cb010b0_outputs.
# CRDS configuration: Remote configuration, server https://hst-crds.stsci.edu must be up, files downloaded to crds_cache.
# Scratch files: Extra processing artifacts appear in the current working directory. Export CALDP_HOME to move them somewhere else.

caldp-docker-run-pipeline j8cb010b0  astroquery:   file:j8cb010b0_outputs


# ----------------------------------------------------------------------------------------
# Download inputs from astroquery, upload outputs to S3, current AWS Batch configuration minus Docker.
# Inputs: Downloads raw files matching j8cb010b0 from astroquery to current working directory / CALDP_HOME.
# CRDS configuration: Remote configuration, server https://hst-crds.stsci.edu must be up, files downloaded to crds_cache.
# Scratch files: Extra processing artifacts appear in the current working directory. Export CALDP_HOME to move them somewhere else.

caldp-docker-run-pipeline j8cb010b0  astroquery:  s3://calcloud-hst-pipeline-outputs/batch-22

配置Docker后,caldp-docker-run-pipeline将运行caldp-process在Docker容器内,使用命令行上给出的参数。虽然文件路径相对于您的本地文件系统定义,但在Docker容器中,它们将按名义解释为相对于/home/developer。由于CALDP_HOME目录已挂载到Docker中,需要处理数据集的文件将反映回Docker容器到CALDP_HOME,默认为您的当前工作目录。

注意:运行上述最终的云-like配置不会产生与AWS Batch处理完全相同的结果,因为它只处理单个数据集,并且跳过了通常由操作数据集列表的批触发器lambda执行的批跟踪和组织操作。

示例Docker命令(AWS Batch)

以下是在AWS Batch上运行CALDP所使用的调用序列。此命令在AWS Batch作业定义中指定,用于运行所有排队作业。调用序列在最外层的包装脚本中使用了更多自定义的输入参数,仅指定S3输出存储桶和数据集名称。

caldp-process-aws  <s3_output_path>   <ipppssoot>

内部,caldp-process-aws会自动配置并运行caldp-process

  1. astroquery:用于获取原始数据。

  2. 指定的S3输出路径,通常包括一个批处理“子目录”。

  3. 指定的数据集(ipppssoot),以定义要获取和处理的数据。

  4. 一个无服务器CRDS配置,仅依赖于S3文件。

尽管支持容器化用例,但由于AWS Batch(或等效)通常运行Docker,caldp-process-aws在独立运行时实际上是一个原生模式命令。没有与caldp-docker-run-pipeline等效的包装脚本来自动配置和运行caldp-process-aws,但由于它实际上不需要额外的文件挂载或端口,因此使用Docker运行它非常简单。

运行caldp-process-aws需要访问CRDS以及AWS S3存储上的输出存储桶,即适当的凭证和权限。

容器内的调试

有时您希望在容器环境中执行命令,而不是caldp-process。您可以使用caldp-docker-run-container运行任何命令,该命令本身被caldp-docker-run-pipeline包装。

# You can run a shell or other alternate program inside the CALDP container like this:

caldp-docker-run-container  /bin/bash  # interactive shell at /home/developer inside the container, nominally as user *developer*.

关于CALDP_HOME

CALDP_HOME环境变量定义了caldp-docker-run-pipeline将在运行的Docker容器中以$HOME的形式挂载哪个本地目录作为读写。如果没有导出,CALDP_HOME默认为运行caldp-docker-run-pipeline的目录。由于caldp-process在Docker容器内的$HOME中运行,因此在处理过程中使用的任何临时文件都会出现在外部的CALDP_HOME中。请注意,使用caldp-docker-run-pipeline不是必需的,它只是用于为本地CALDP执行建立标准Docker配置的脚本。

在容器内获取AWS凭证

在容器内启用AWS访问的一种技术是将一个.aws配置目录放在您的CALDP_HOME目录中。

由于caldp-docker-run-pipeline将在容器中以$HOME的形式挂载CALDP_HOME,AWS将它们放在它预期找到它们的位置。AWS Batch通常运行具有附加必要权限的工作节点,因此AWS Batch不需要.aws目录。

输出结构

CALDP和CALCLOUD以设计用于帮助跟踪单个数据集状态的形式输出数据。

因此,输出目录分为两个子目录

  1. messages

  2. data

CALDP和CALCLOUD之间的一个关键区别在于,前者是为处理单个数据集而设计的,而后者是为处理由CALCLOUD单独运行的多个数据集的批次而设计的。在这种情况下,通常将来自CALCLOUD的S3存储下载到本地目录的文件放置在一个“批次目录”中,而CALDP与该批次目录相对应的输出目录。CALDP输出目录中出现的相同消息和数据也会出现在同步的CALCLOUD批次目录中。

消息子目录

messages子目录用于记录单个数据集在处理、数据传输和归档过程中的状态。每个数据集都有一个同名状态文件,随着它开始或完成各种状态,状态文件会在状态目录之间移动。数据集文件可以用于记录元数据,但它的主要用途是允许简单地识别数据集状态,而无需使用数据库、队列等。只需要本地文件系统即可使用此方案跟踪状态。在云上的S3存储上使用相同方案的一个镜像,有助于指导从AWS下载文件。

<output_path>/
    messages/
        datasets-processed/
            <ipppssoots...>    # CALDP, normally running on AWS batch, leaves messages here. they're empty.
        dataset-synced/
            <ipppssoots...>    # CALCLOUD's downloader leaves messages here, normally containing abspaths of files to archive.
        dataset-archived/
            <ipppssoots...>    # The archive can acknowledge archive completion here, file contents should be preserved.

数据子目录

数据子目录与消息子目录平行,但结构不同。对于每个ipppssoot消息,都有一个数据目录和包含处理该ipppssoot输出的子目录。在当前实现中,ipppssoot消息文件为空,它通常由CALCLOUD的下载器在输出到dataset-synced时填充文件存档的路径。

<output_path>/
    data/
        <instrument>/
            <ipppssoots...>/    # one dir per ipppssoot
                science data files for one ipppssoot...
                logs/
                    log and metrics files for one ipppssoot...
                previews/
                    preview images for one ipppssoot...

配置CALDP(高级)

如前所述,3个CALDP用例中的每个都有一个不同的CRDS配置。这里描述了这种实现,以防需要编写额外的配置或添加变量。目前,与caldp-image-config不同,这些配置脚本通常不需要定制,它们可以直接使用来支持其用例。

CALDP配置脚本设置环境变量,这些变量将在caldp-process的作用域内定义。这些配置脚本与其他CALDP脚本一起安装,因此可以直接使用而无需知道它们安装的位置。配置脚本的名称作为第四个参数传递给caldp-process,该参数通常默认。

顶级脚本

配置脚本

描述

caldp-process

caldp-config-onsite

配置CRDS从中央存储器.grp/crds/cache操作。应该可扩展。

caldp-docker-run-pipeline

caldp-config-offsite

配置CRDS从CRDS服务器下载。这可能无法很好地扩展。

caldp-process-aws

caldp-config-aws

配置CRDS从无服务器依赖的S3存储操作。应该可扩展。

测试

Travis

CALDP仓库通过GitHub检查设置Travis。每次向spacetelescope/caldp提交PR时,Travis都会自动运行CALDP的CI测试。

本地测试

在推送之前在开发机器上进行测试是常见的。这可以通过安装caldp,配置环境,然后运行pytest(类似于Travis将运行的方式)来实现。

# FIRST: Setup a conda environment for CALDP as discussed above in native installs.
# Don't use the "everything install" if you have an existing conda environment you
# don't want to wipe out.   Make sure to activate it.

# THEN:  configure your environment and run pytest as Travis would:
source caldp-config-offsite
pytest caldp --cov=caldp --cov-fail-under 80  --capture=tee-sys

注意:并非所有CALDP代码和功能都经过测试,尤其是与在Docker内部和外部运行Python包相关的包装脚本。

S3 I/O

由于S3输入和输出需要AWS凭证以启用访问,以及要使用的特定对象路径,因此S3模式的测试受两个环境变量的控制,这些变量定义了S3输入和输出的位置。

export CALDP_S3_TEST_INPUTS=s3://caldp-hst-test/inputs/test-batch
export CALDP_S3_TEST_OUTPUTS=s3://caldp-hst-test/outputs/test-batch

如果定义了上述任意一个或两个变量,pytest还将执行利用S3输入或输出模式的测试。您还需要AWS凭证。目前Travis上没有测试S3。

项目详情


下载文件

下载适用于您的平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分布

caldp-0.1.0.tar.gz (57.8 kB 查看哈希)

上传时间

由以下赞助

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面