lasp-curryer


Namelasp-curryer JSON
Version 0.1.0 PyPI version JSON
download
home_pageNone
SummaryLASP SPICE extentions and geospatial data product generation tools.
upload_time2024-11-14 17:30:27
maintainerNone
docs_urlNone
authorBrandon Stone
requires_python<4,>=3.9
licenseMIT
keywords lasp sdp
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Curryer

A library for SPICE extensions and geospatial data product generation.

* Github: https://github.com/lasp/curryer
* PyPi: https://pypi.org/project/lasp-curryer/

## Core Features
* Extensions and wrappers for SPICE routines and common data patterns.
* Automation of SPICE kernel creation from JSON definition files and modern data
file formats and third-party data structures.
* Level-1 geospatial data processing routines (e.g., geolocation).


## Install
```shell
pip install lasp-curryer
```

### Data / Binary Files
_NOTE: Data files and precompiled binaries are not currently automated and thus
require manual downloading. This will be addressed in the next major release._

Download from the Curryer repo:
* `data/generic` - Generic spice kernels (e.g., leapsecond kernel)
  * Download 
* `data/<misssion>` - Mission specific kernels and/or kernel definitions.
* `data/gmted` - Digital Elevation Model (DEMs) with global coverage at
15-arc-second.
  * Alternatively, use the script [download_dem.py](bin/download_dem.py) to
download different types and/or resolutions from the USGS.

Define the top-level directory using the environment variable `CURRYER_DATA_DIR`
or pass the path to routines which require data files.

Download Third-party Files:
* SPICE Utilities: https://naif.jpl.nasa.gov/naif/utilities.html
  * At minimum: `mkspk`, `msopck`, `brief`, `ckbreif`
* SPICE Generic Kernels (large):
  * [de430.bsp](https://naif.jpl.nasa.gov/pub/naif/generic_kernels/spk/planets/de430.bsp),
place in `data/generic`.
  * PyProj Data:
    * Data directory: `import pyproj; print(pyproj.datadir.get_user_data_dir())`
    * [EGM96 TIFF](https://cdn.proj.org/us_nga_egm96_15.tif)


## Examples

### SPICE Extensions
Time conversion:
```python
from curryer import spicetime

print(spicetime.adapt(0, from_='ugps', to='iso'))
# 1980-01-06 00:00:00.000000

print(spicetime.adapt('2024-11-13', 'iso'))
# 1415491218000000

print(spicetime.adapt(1415491218000000, to='et'))
# 784728069.1827033

import numpy as np

print(repr(spicetime.adapt(np.arange(4) * 60e6 + 1415491218000000, to='dt64')))
# array(['2024-11-13T00:00:00.000000', '2024-11-13T00:01:00.000000',
#        '2024-11-13T00:02:00.000000', '2024-11-13T00:03:00.000000'],
#       dtype='datetime64[us]')
```

Abstractions:
```python
from curryer import spicierpy

spicierpy.ext.infer_ids('ISS', 25544, from_norad=True)
# {'mission': 'ISS',
#  'spacecraft': -125544,
#  'clock': -125544,
#  'ephemeris': -125544,
#  'attitude': -125544000,
#  'instruments': {}}

earth = spicierpy.obj.Body('Earth')
print(earth, earth.id)
# Body(EARTH) 399

import curryer

mkrn = curryer.meta.MetaKernel.from_json(
    'data/tsis1/tsis_v01.kernels.tm.json', sds_dir='data/generic', relative=True
)
print(mkrn)
# MetaKernel(Spacecraft(ISS_SC), Body(ISS_ELC3), Body(ISS_EXPA35), Body(TSIS_TADS),
#   Body(TSIS_AZEL), Body(TSIS_TIM), Body(TSIS_TIM_GLINT))

with spicierpy.ext.load_kernel([mkrn.sds_kernels, mkrn.mission_kernels]):
    print(spicierpy.ext.instrument_boresight('TSIS_TIM'))
# [0. 0. 1.]

mkrn = curryer.meta.MetaKernel.from_json(
    'tests/data/clarreo/cprs_v01.kernels.tm.json', sds_dir='data/generic', relative=True
)
print(mkrn)
# MetaKernel(Spacecraft(ISS_SC), Body(CPRS_BASE), Body(CPRS_PEDE),
#   Body(CPRS_AZ), Body(CPRS_YOKE), Body(CPRS_EL), Body(CPRS_HYSICS))

with spicierpy.ext.load_kernel([mkrn.sds_kernels, mkrn.mission_kernels]):
    print(curryer.compute.spatial.pixel_vectors('CPRS_HYSICS'))
# (480,
#  array([[ 0.00173869, -0.08715574,  0.99619318],
#         [ 0.0017315 , -0.08679351,  0.99622482],
#         [ 0.00172431, -0.08643127,  0.99625632],
#         ...,
#         [-0.00171712,  0.08606901,  0.9962877 ],
#         [-0.00172431,  0.08643127,  0.99625632],
#         [-0.0017315 ,  0.08679351,  0.99622482]]))
```


### SPICE Kernel Creation
Create CLARREO Dynamic Kernels:
````python
import curryer

meta_kernel = 'tests/data/clarreo/cprs_v01.kernels.tm.json'
generic_dir = 'data/generic'
kernel_configs = [
    'data/clarreo/iss_sc_v01.ephemeris.spk.json',
    'data/clarreo/iss_sc_v01.attitude.ck.json',
    'data/clarreo/cprs_az_v01.attitude.ck.json',
    'data/clarreo/cprs_el_v01.attitude.ck.json',
]
output_dir = '/tmp'
input_file_or_obj = 'tests/data/demo/cprs_geolocation_tlm_20230101_20240430.nc'

# Load meta kernel details. Includes existing static kernels.
mkrn = curryer.meta.MetaKernel.from_json(meta_kernel, relative=True, sds_dir=generic_dir)

# Create the dynamic kernels from the JSONs alone. Note that they
# contain the reference to the input_data netcdf4 file to read.
generated_kernels = []
creator = curryer.kernels.create.KernelCreator(overwrite=False, append=False)

# Generate the kernels from the config and input data (file or object).
for kernel_config in kernel_configs:
    generated_kernels.append(creator.write_from_json(
        kernel_config, output_kernel=output_dir, input_data=input_file_or_obj,
    ))

````


### Level-1 Geospatial Processing
Geolocate CLARREO HYSICS Instrument:
```python
import pandas as pd
import curryer

meta_kernel = 'tests/data/clarreo/cprs_v01.kernels.tm.json'
generic_dir = 'data/generic'

time_range = ('2023-01-01', '2023-01-01T00:05:00')
ugps_times = curryer.spicetime.adapt(pd.date_range(*time_range, freq='67ms', inclusive='left'), 'iso')

# Load meta kernel details. Includes existing static kernels.
mkrn = curryer.meta.MetaKernel.from_json(meta_kernel, relative=True, sds_dir=generic_dir)

# Geolocate all the individual pixels and create the L1A data product!
with curryer.spicierpy.ext.load_kernel([mkrn.sds_kernels, mkrn.mission_kernels]):
    geoloc_inst = curryer.compute.spatial.Geolocate('CPRS_HYSICS')
    l1a_dataset = geoloc_inst(ugps_times)
    l1a_dataset.to_netcdf('cprs_geolocation_l1a_20230101.nc')

```
_Assumes dynamic kernels have been created and their file names defined within
the metakernel JSON file._


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "lasp-curryer",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4,>=3.9",
    "maintainer_email": null,
    "keywords": "LASP, SDP",
    "author": "Brandon Stone",
    "author_email": "brandon.h.stone@colorado.edu",
    "download_url": "https://files.pythonhosted.org/packages/61/ff/7022f32e3d97f6f30c35be342d2f7fa2878336136a70f329e9197490f44f/lasp_curryer-0.1.0.tar.gz",
    "platform": null,
    "description": "# Curryer\n\nA library for SPICE extensions and geospatial data product generation.\n\n* Github: https://github.com/lasp/curryer\n* PyPi: https://pypi.org/project/lasp-curryer/\n\n## Core Features\n* Extensions and wrappers for SPICE routines and common data patterns.\n* Automation of SPICE kernel creation from JSON definition files and modern data\nfile formats and third-party data structures.\n* Level-1 geospatial data processing routines (e.g., geolocation).\n\n\n## Install\n```shell\npip install lasp-curryer\n```\n\n### Data / Binary Files\n_NOTE: Data files and precompiled binaries are not currently automated and thus\nrequire manual downloading. This will be addressed in the next major release._\n\nDownload from the Curryer repo:\n* `data/generic` - Generic spice kernels (e.g., leapsecond kernel)\n  * Download \n* `data/<misssion>` - Mission specific kernels and/or kernel definitions.\n* `data/gmted` - Digital Elevation Model (DEMs) with global coverage at\n15-arc-second.\n  * Alternatively, use the script [download_dem.py](bin/download_dem.py) to\ndownload different types and/or resolutions from the USGS.\n\nDefine the top-level directory using the environment variable `CURRYER_DATA_DIR`\nor pass the path to routines which require data files.\n\nDownload Third-party Files:\n* SPICE Utilities: https://naif.jpl.nasa.gov/naif/utilities.html\n  * At minimum: `mkspk`, `msopck`, `brief`, `ckbreif`\n* SPICE Generic Kernels (large):\n  * [de430.bsp](https://naif.jpl.nasa.gov/pub/naif/generic_kernels/spk/planets/de430.bsp),\nplace in `data/generic`.\n  * PyProj Data:\n    * Data directory: `import pyproj; print(pyproj.datadir.get_user_data_dir())`\n    * [EGM96 TIFF](https://cdn.proj.org/us_nga_egm96_15.tif)\n\n\n## Examples\n\n### SPICE Extensions\nTime conversion:\n```python\nfrom curryer import spicetime\n\nprint(spicetime.adapt(0, from_='ugps', to='iso'))\n# 1980-01-06 00:00:00.000000\n\nprint(spicetime.adapt('2024-11-13', 'iso'))\n# 1415491218000000\n\nprint(spicetime.adapt(1415491218000000, to='et'))\n# 784728069.1827033\n\nimport numpy as np\n\nprint(repr(spicetime.adapt(np.arange(4) * 60e6 + 1415491218000000, to='dt64')))\n# array(['2024-11-13T00:00:00.000000', '2024-11-13T00:01:00.000000',\n#        '2024-11-13T00:02:00.000000', '2024-11-13T00:03:00.000000'],\n#       dtype='datetime64[us]')\n```\n\nAbstractions:\n```python\nfrom curryer import spicierpy\n\nspicierpy.ext.infer_ids('ISS', 25544, from_norad=True)\n# {'mission': 'ISS',\n#  'spacecraft': -125544,\n#  'clock': -125544,\n#  'ephemeris': -125544,\n#  'attitude': -125544000,\n#  'instruments': {}}\n\nearth = spicierpy.obj.Body('Earth')\nprint(earth, earth.id)\n# Body(EARTH) 399\n\nimport curryer\n\nmkrn = curryer.meta.MetaKernel.from_json(\n    'data/tsis1/tsis_v01.kernels.tm.json', sds_dir='data/generic', relative=True\n)\nprint(mkrn)\n# MetaKernel(Spacecraft(ISS_SC), Body(ISS_ELC3), Body(ISS_EXPA35), Body(TSIS_TADS),\n#   Body(TSIS_AZEL), Body(TSIS_TIM), Body(TSIS_TIM_GLINT))\n\nwith spicierpy.ext.load_kernel([mkrn.sds_kernels, mkrn.mission_kernels]):\n    print(spicierpy.ext.instrument_boresight('TSIS_TIM'))\n# [0. 0. 1.]\n\nmkrn = curryer.meta.MetaKernel.from_json(\n    'tests/data/clarreo/cprs_v01.kernels.tm.json', sds_dir='data/generic', relative=True\n)\nprint(mkrn)\n# MetaKernel(Spacecraft(ISS_SC), Body(CPRS_BASE), Body(CPRS_PEDE),\n#   Body(CPRS_AZ), Body(CPRS_YOKE), Body(CPRS_EL), Body(CPRS_HYSICS))\n\nwith spicierpy.ext.load_kernel([mkrn.sds_kernels, mkrn.mission_kernels]):\n    print(curryer.compute.spatial.pixel_vectors('CPRS_HYSICS'))\n# (480,\n#  array([[ 0.00173869, -0.08715574,  0.99619318],\n#         [ 0.0017315 , -0.08679351,  0.99622482],\n#         [ 0.00172431, -0.08643127,  0.99625632],\n#         ...,\n#         [-0.00171712,  0.08606901,  0.9962877 ],\n#         [-0.00172431,  0.08643127,  0.99625632],\n#         [-0.0017315 ,  0.08679351,  0.99622482]]))\n```\n\n\n### SPICE Kernel Creation\nCreate CLARREO Dynamic Kernels:\n````python\nimport curryer\n\nmeta_kernel = 'tests/data/clarreo/cprs_v01.kernels.tm.json'\ngeneric_dir = 'data/generic'\nkernel_configs = [\n    'data/clarreo/iss_sc_v01.ephemeris.spk.json',\n    'data/clarreo/iss_sc_v01.attitude.ck.json',\n    'data/clarreo/cprs_az_v01.attitude.ck.json',\n    'data/clarreo/cprs_el_v01.attitude.ck.json',\n]\noutput_dir = '/tmp'\ninput_file_or_obj = 'tests/data/demo/cprs_geolocation_tlm_20230101_20240430.nc'\n\n# Load meta kernel details. Includes existing static kernels.\nmkrn = curryer.meta.MetaKernel.from_json(meta_kernel, relative=True, sds_dir=generic_dir)\n\n# Create the dynamic kernels from the JSONs alone. Note that they\n# contain the reference to the input_data netcdf4 file to read.\ngenerated_kernels = []\ncreator = curryer.kernels.create.KernelCreator(overwrite=False, append=False)\n\n# Generate the kernels from the config and input data (file or object).\nfor kernel_config in kernel_configs:\n    generated_kernels.append(creator.write_from_json(\n        kernel_config, output_kernel=output_dir, input_data=input_file_or_obj,\n    ))\n\n````\n\n\n### Level-1 Geospatial Processing\nGeolocate CLARREO HYSICS Instrument:\n```python\nimport pandas as pd\nimport curryer\n\nmeta_kernel = 'tests/data/clarreo/cprs_v01.kernels.tm.json'\ngeneric_dir = 'data/generic'\n\ntime_range = ('2023-01-01', '2023-01-01T00:05:00')\nugps_times = curryer.spicetime.adapt(pd.date_range(*time_range, freq='67ms', inclusive='left'), 'iso')\n\n# Load meta kernel details. Includes existing static kernels.\nmkrn = curryer.meta.MetaKernel.from_json(meta_kernel, relative=True, sds_dir=generic_dir)\n\n# Geolocate all the individual pixels and create the L1A data product!\nwith curryer.spicierpy.ext.load_kernel([mkrn.sds_kernels, mkrn.mission_kernels]):\n    geoloc_inst = curryer.compute.spatial.Geolocate('CPRS_HYSICS')\n    l1a_dataset = geoloc_inst(ugps_times)\n    l1a_dataset.to_netcdf('cprs_geolocation_l1a_20230101.nc')\n\n```\n_Assumes dynamic kernels have been created and their file names defined within\nthe metakernel JSON file._\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "LASP SPICE extentions and geospatial data product generation tools.",
    "version": "0.1.0",
    "project_urls": null,
    "split_keywords": [
        "lasp",
        " sdp"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "61ff7022f32e3d97f6f30c35be342d2f7fa2878336136a70f329e9197490f44f",
                "md5": "b6fcc8fe8b900a37559cd99a5c225216",
                "sha256": "9a8a7335742746abc1660eb1e59c5bdb876d4e4e10f4bb79c3ab5cf87d26f43e"
            },
            "downloads": -1,
            "filename": "lasp_curryer-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "b6fcc8fe8b900a37559cd99a5c225216",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4,>=3.9",
            "size": 83948,
            "upload_time": "2024-11-14T17:30:27",
            "upload_time_iso_8601": "2024-11-14T17:30:27.065873Z",
            "url": "https://files.pythonhosted.org/packages/61/ff/7022f32e3d97f6f30c35be342d2f7fa2878336136a70f329e9197490f44f/lasp_curryer-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-14 17:30:27",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "lasp-curryer"
}
        
Elapsed time: 0.31406s