Skip to content

Commit

Permalink
planetMagFields integration
Browse files Browse the repository at this point in the history
Integrate planetMagFields and require scipy
  • Loading branch information
astroDimitrios committed Aug 26, 2021
1 parent 749f029 commit ac58ab0
Show file tree
Hide file tree
Showing 19 changed files with 2,328 additions and 15 deletions.
5 changes: 4 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
include src/astroedu/interactives/*
include src/astroedu/datasets/*
include src/astroedu/datasets/*

include src/astroedu/planetmagfields/*
include src/astroedu/planetmagfields/data/*
37 changes: 26 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,21 @@
</center>

[![PyPI version](https://badge.fury.io/py/astroedu.svg)](https://badge.fury.io/py/astroedu)
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.0-4baaaa.svg)](code_of_conduct.md)
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.0-4baaaa.svg)](code_of_conduct.md) **Alpha**

This package is in alpha.
A package containing small interactives, datasets, functions etc for teaching astronomy.

Contributors:

- Dimitrios Theodorakis
- Ankit Barik, planetMagFields module, [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.4706157.svg)](https://doi.org/10.5281/zenodo.4706157), [github.com/AnkitBarik/planetMagFields](github.com/AnkitBarik/planetMagFields)

## Installation

To install **astroedu** run
```
>>> pip install astroedu
```
then run
```
>>> astroedu build
```
which creates the configuration file **config.ini**.

**config.ini** stores the location of your documents folder.
This is where an astroedu folder for interactive activites will me made. (not yet implemented)

## Current Functionality

Expand Down Expand Up @@ -120,4 +117,22 @@ The class has built in methods. For instance to calculate the tides on the Earth
>>> forces = earth.tides(moon, step=0.25, scale=5.972*10**24)
```
Documentation coming soon.
More methods will be added at a later date including calculating gravitational potentials and plotting tides & potentials.
More methods will be added at a later date including calculating gravitational potentials and plotting tides & potentials.

## Submodules

### planetMagFields

planetMagFields by Ankit Barik.
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.4706157.svg)](https://doi.org/10.5281/zenodo.4706157), [github.com/AnkitBarik/planetMagFields](github.com/AnkitBarik/planetMagFields)

See Ankit's GitHub for usage. Note: cartopy is required for some plots which requires these non-python packages to be installed, [GEOS](https://trac.osgeo.org/geos/) and [PROJ](https://proj.org/). Some functions also require other libraries, see Ankit's GitHub for more info.

Since the dataset location is defined relative to the astroedu install there is no need to specify a datDir for instance:

```
>>> from astroedu.planetmagfields import *
>>> p = planet(name='jupiter')
>>> # not p = planet(name='jupiter',datDir='planetmagfields/data/')
>>> p.plot(r=0.85,proj='Mollweide')
```
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[metadata]
# replace with your username:
name = astroedu
version = 0.3.0a1
version = 0.4.0a0
author = Dimitrios Theodorakis
author_email = astrodimitrios@gmail.com
description = A python package for astronomy educators
Expand All @@ -25,6 +25,7 @@ python_requires = >=3.7
include_package_data = True
install_requires =
numpy >= 1.20.0
scipy >= 1.6.0
matplotlib >= 3.3.0
pandas >= 1.1
jupyterlab >= 3.0.0
Expand Down
60 changes: 58 additions & 2 deletions src/astroedu/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from astroedu.__build__ import get_astroedu_path
from astroedu.__build__ import build_path_config

commands = ['build', 'interactive']
commands = ['build', 'interactive', 'magfield']
astroedu_path = get_astroedu_path()
config_file_name = '/config.ini'
config_file_path = astroedu_path + config_file_name
Expand Down Expand Up @@ -46,6 +46,60 @@ def _load_interactive(*args):
print(f'Loading interactive {interactive_name}!')
subprocess.run(run_interactive)

def _planetmagfield_quick(*args):
''' Utility function to make wuick plots using planetMagFields
See https://zenodo.org/record/5140421#.YSdp7t_TUuU
'''
levels=20
cmap='RdBu_r'
proj = 'Mollweide'
r = 1

import numpy as np

if len(args) > 4:
raise ValueError("Too many arguments, exiting ...\n")
elif len(args) == 4:
planet = str(args[1]).lower()
r = np.float32(args[2])
proj = str(args[3])
elif len(args) == 3:
planet = str(args[1]).lower()
try:
r = np.float32(args[2])
except:
proj = str(args[2])
elif len(args) == 2:
if args[2] == '--help':
print('planetMagFields\nSubmodule by Ankit Barik - 10.5281/zenodo.5140421\nUsage see - github.com/AnkitBarik/planetMagFields')
else:
print("Radius not specified, using surface\n")
planet = str(args[1]).lower()
else:
print("Planet or radius not specified, plotting for Earth's surface\n")
planet="earth"
r=1.

import matplotlib.pyplot as plt
from astroedu.planetmagfields.libbfield import getBr, plotAllFields, plotMagField

if planet == 'all':
with files('astroedu.planetmagfields').joinpath('data/') as p:
plotAllFields(datDir=p,r=r,levels=levels,cmap=cmap,proj=proj)
plt.tight_layout()
plt.subplots_adjust(top=0.895,
bottom=0.035,
left=0.023,
right=0.976,
hspace=0.38,
wspace=0.109)
else:
with files('astroedu.planetmagfields').joinpath('data/') as p:
plotMagField(planet=planet,r=r,datDir=p,levels=levels,cmap=cmap,proj=proj)
plt.tight_layout()

plt.show()

def startup(*args):
''' Startup function called by Fire cli function main()
Expand All @@ -67,7 +121,7 @@ def startup(*args):
'''
if not args:
raise ValueError('No arguments passed to astroedu call.')
command = args[0]
command = args[0].lower()
if command not in commands:
raise ValueError('Command not recognised.')
elif command == 'build':
Expand All @@ -76,6 +130,8 @@ def startup(*args):
raise ValueError(f'No arguments passed to {command}')
elif command == 'interactive':
_load_interactive(*args)
elif command == 'magfield':
_planetmagfield_quick(*args)

if __name__ == '__main__':
fire.Fire(startup)
Loading

0 comments on commit ac58ab0

Please sign in to comment.