plotastrodata 1.8.16__tar.gz → 1.8.17__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. {plotastrodata-1.8.16/plotastrodata.egg-info → plotastrodata-1.8.17}/PKG-INFO +1 -1
  2. {plotastrodata-1.8.16 → plotastrodata-1.8.17}/plotastrodata/__init__.py +1 -1
  3. {plotastrodata-1.8.16 → plotastrodata-1.8.17}/plotastrodata/plot_utils.py +89 -71
  4. {plotastrodata-1.8.16 → plotastrodata-1.8.17/plotastrodata.egg-info}/PKG-INFO +1 -1
  5. {plotastrodata-1.8.16 → plotastrodata-1.8.17}/LICENSE +0 -0
  6. {plotastrodata-1.8.16 → plotastrodata-1.8.17}/MANIFEST.in +0 -0
  7. {plotastrodata-1.8.16 → plotastrodata-1.8.17}/README.md +0 -0
  8. {plotastrodata-1.8.16 → plotastrodata-1.8.17}/plotastrodata/analysis_utils.py +0 -0
  9. {plotastrodata-1.8.16 → plotastrodata-1.8.17}/plotastrodata/const_utils.py +0 -0
  10. {plotastrodata-1.8.16 → plotastrodata-1.8.17}/plotastrodata/coord_utils.py +0 -0
  11. {plotastrodata-1.8.16 → plotastrodata-1.8.17}/plotastrodata/ext_utils.py +0 -0
  12. {plotastrodata-1.8.16 → plotastrodata-1.8.17}/plotastrodata/fft_utils.py +0 -0
  13. {plotastrodata-1.8.16 → plotastrodata-1.8.17}/plotastrodata/fits_utils.py +0 -0
  14. {plotastrodata-1.8.16 → plotastrodata-1.8.17}/plotastrodata/fitting_utils.py +0 -0
  15. {plotastrodata-1.8.16 → plotastrodata-1.8.17}/plotastrodata/los_utils.py +0 -0
  16. {plotastrodata-1.8.16 → plotastrodata-1.8.17}/plotastrodata/matrix_utils.py +0 -0
  17. {plotastrodata-1.8.16 → plotastrodata-1.8.17}/plotastrodata/noise_utils.py +0 -0
  18. {plotastrodata-1.8.16 → plotastrodata-1.8.17}/plotastrodata/other_utils.py +0 -0
  19. {plotastrodata-1.8.16 → plotastrodata-1.8.17}/plotastrodata.egg-info/SOURCES.txt +0 -0
  20. {plotastrodata-1.8.16 → plotastrodata-1.8.17}/plotastrodata.egg-info/dependency_links.txt +0 -0
  21. {plotastrodata-1.8.16 → plotastrodata-1.8.17}/plotastrodata.egg-info/not-zip-safe +0 -0
  22. {plotastrodata-1.8.16 → plotastrodata-1.8.17}/plotastrodata.egg-info/requires.txt +0 -0
  23. {plotastrodata-1.8.16 → plotastrodata-1.8.17}/plotastrodata.egg-info/top_level.txt +0 -0
  24. {plotastrodata-1.8.16 → plotastrodata-1.8.17}/setup.cfg +0 -0
  25. {plotastrodata-1.8.16 → plotastrodata-1.8.17}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: plotastrodata
3
- Version: 1.8.16
3
+ Version: 1.8.17
4
4
  Summary: plotastrodata is a tool for astronomers to create figures from FITS files and perform fundamental data analyses with ease.
5
5
  Home-page: https://github.com/yusukeaso-astron/plotastrodata
6
6
  Download-URL: https://github.com/yusukeaso-astron/plotastrodata
@@ -1,4 +1,4 @@
1
1
  import warnings
2
2
 
3
3
  warnings.simplefilter('ignore', FutureWarning)
4
- __version__ = '1.8.16'
4
+ __version__ = '1.8.17'
@@ -99,6 +99,39 @@ def logcbticks(vmin: float = 1e-3, vmax: float = 1e3
99
99
  return ticks[cond], ticklabels[cond]
100
100
 
101
101
 
102
+ def _get_sec(coord: str, mode: str) -> str:
103
+ i_axis = 0 if mode == 'ra' else 1
104
+ return coord.split(' ')[i_axis].split('m')[1].strip('s')
105
+
106
+
107
+ def _get_min(coord: str, mode: str) -> str:
108
+ i_axis = 0 if mode == 'ra' else 1
109
+ s = 'h' if mode == 'ra' else 'd'
110
+ return coord.split(' ')[i_axis].split(s)[1].split('m')[0]
111
+
112
+
113
+ def _get_hmdm(coord: str, mode: str) -> str:
114
+ i_axis = 0 if mode == 'ra' else 1
115
+ return coord.split(' ')[i_axis].split('m')[0] + 'm'
116
+
117
+
118
+ def _get_gridwidth(mode: str, rmax: float) -> tuple[float, int]:
119
+ # 10^1.5 / 15 ~ 2 grids for R.A.
120
+ # 10^0.5 ~ 3 grids for Dec.
121
+ scale = 1.5 if mode == 'ra' else 0.5
122
+ log2r = np.log10(2. * rmax)
123
+ x = log2r - scale
124
+ order = np.floor(x)
125
+ frac = x - order
126
+ if frac <= 0.33:
127
+ base = 1
128
+ elif frac <= 0.68:
129
+ base = 2
130
+ else:
131
+ base = 5
132
+ return base * 10**order, int(order)
133
+
134
+
102
135
  @dataclass
103
136
  class Stretcher():
104
137
  """Arguments and methods related to the stretch in PlotAstroData.add_color() and add_rgb().
@@ -1057,86 +1090,71 @@ class PlotAstroData(AstroFrame):
1057
1090
  center = '00h00m00s 00d00m00s'
1058
1091
  if len(csplit := center.split()) == 3:
1059
1092
  center = f'{csplit[1]} {csplit[2]}'
1060
-
1061
- def get_sec(x, i):
1062
- return x.split(' ')[i].split('m')[1].strip('s')
1063
-
1064
- def get_min(x, i):
1065
- s = 'h' if i == 0 else 'd'
1066
- return x.split(' ')[i].split(s)[1].split('m')[0]
1067
-
1068
- def get_hmdm(x, i):
1069
- return x.split(' ')[i].split('m')[0] + 'm'
1070
-
1071
- on_min_scale = self.rmax >= 60.0
1072
- if on_min_scale:
1073
- ra_s = np.floor(float(get_sec(center, 0)) / 5) * 5
1093
+ if on_min_scale := (self.rmax >= 60.0):
1094
+ # On a 5-second grid.
1095
+ ra_s = np.floor(float(_get_sec(center, 0)) / 5) * 5
1074
1096
  dec_s = 0.0
1075
- ra = get_hmdm(center, 0) + f'{ra_s:.1f}s'
1076
- dec = get_hmdm(center, 1) + f'{dec_s:.1f}s'
1097
+ ra = _get_hmdm(center, 'ra') + f'{ra_s:.1f}s'
1098
+ dec = _get_hmdm(center, 'dec') + f'{dec_s:.1f}s'
1077
1099
  center = f'{ra} {dec}'
1078
1100
 
1079
- dec = np.radians(coord2xy(center)[1])
1080
- log2r = np.log10(2. * self.rmax)
1081
- n = np.array([-3, -2, -1, 0, 1, 2, 3])
1082
-
1083
- def makegrid(second, mode):
1084
- second = float(second)
1085
- is_dec = mode == 'dec'
1086
- scale = 0.5 if is_dec else 1.5
1087
- factor = 1 if is_dec else 15 * np.cos(dec)
1088
- no_sec = on_min_scale and is_dec
1089
- if no_sec:
1090
- unit = r'$^{\prime}$' if is_dec else r'$^\mathrm{m}$'
1091
- else:
1092
- unit = r'$^{\prime\prime}$' if is_dec else r'$^\mathrm{s}$'
1093
- unit = r'.$\hspace{-0.4}$' + unit
1094
- dorder = log2r - scale - (order := np.floor(log2r - scale))
1095
- if 0.00 < dorder <= 0.33:
1096
- g = 1
1097
- elif 0.33 < dorder <= 0.68:
1098
- g = 2
1099
- elif 0.68 < dorder <= 1.00:
1100
- g = 5
1101
- g *= 10**order
1102
- decimals = max(-int(order), -1)
1103
- rounded = round(second, decimals)
1104
- lastdigit = round(rounded // 10**(-decimals-1) % 100 / 10) % 10
1105
- rounded -= lastdigit * 10**(-decimals) % g
1106
- ticks = (n*g - second + rounded) * factor
1107
- ticksminor = np.linspace(ticks[0], ticks[-1], 6*nticksminor + 1)
1108
- decimals = max(decimals, 0)
1109
- decimals = f'{decimals:d}'
1101
+ def get_tickvalues(ticks: np.ndarray, mode: str, no_sec: bool
1102
+ ) -> np.ndarray:
1103
+ xy = [np.zeros_like(ticks), ticks / 3600.]
1110
1104
  if mode == 'ra':
1111
- xy, i = [ticks / 3600., ticks * 0], 0
1112
- else:
1113
- xy, i = [ticks * 0, ticks / 3600.], 1
1105
+ xy.reverse()
1114
1106
  tickvalues = xy2coord(xy, center)
1115
- _get = get_min if no_sec else get_sec
1116
- tickvalues = np.array([float(_get(t, i)) for t in tickvalues])
1117
- tickvalues = np.divmod(tickvalues + 1e-7, 1)
1118
- tickvalues = (tickvalues[0] % 60, tickvalues[1])
1119
- ticklabels = [f'{int(i):02d}{unit}' + f'{j:.{decimals}f}'[2:]
1120
- for i, j in zip(*tickvalues)]
1107
+ getter = _get_min if no_sec else _get_sec
1108
+ tickvalues = [getter(t, mode) for t in tickvalues] # str
1109
+ tickvalues = np.array(tickvalues, dtype=float)
1110
+ # 7-digit precision for practical use.
1111
+ tickvalues = np.round(tickvalues, 7)
1112
+ return tickvalues
1113
+
1114
+ units = {'ra': {'h': r'$^\mathrm{h}$',
1115
+ 'm': r'$^\mathrm{m}$',
1116
+ 's': r'.$\hspace{-0.4}^\mathrm{s}$'},
1117
+ 'dec': {'d': r'$^{\circ}$',
1118
+ 'm': r'$^{\prime}$',
1119
+ 's': r'.$\hspace{-0.4}^{\prime\prime}$'}}
1120
+ cos_dec = np.cos(np.radians(coord2xy(center)[1]))
1121
+ intgrid = np.array([-3, -2, -1, 0, 1, 2, 3])
1122
+ i_mid = (len(intgrid) - 1) // 2
1123
+
1124
+ def makegrid(mode: str):
1125
+ second = float(_get_sec(center, mode))
1126
+ no_sec = on_min_scale and (mode == 'dec')
1127
+ # gridwidth is a float like 2 x 10^order (arcsec).
1128
+ gridwidth, order = _get_gridwidth(mode, self.rmax)
1129
+ # ndigits = -1 is the largest case for 10", 20", ...
1130
+ decimals = str(max(-order, 0))
1131
+ rounded = round(second, ndigits=max(-order, -1))
1132
+ # Get a grid point closest to the input second.
1133
+ rounded = round(rounded / gridwidth) * gridwidth
1134
+ factor = 15 * cos_dec if mode == 'ra' else 1
1135
+ ticks = (intgrid * gridwidth - second + rounded) * factor
1136
+ ticksminor = np.linspace(ticks[0], ticks[-1], 6*nticksminor + 1)
1137
+ tickvalues = get_tickvalues(ticks, mode, no_sec)
1138
+ whole, frac = np.divmod(tickvalues, 1)
1139
+ u = units[mode]['m' if no_sec else 's']
1140
+ ticklabels = [f'{int(i):02d}{u}' + f'{j:.{decimals}f}'[2:]
1141
+ for i, j in zip(whole % 60, frac)]
1121
1142
  return ticks, ticksminor, ticklabels
1122
1143
 
1123
- ra_s = get_sec(center, 0)
1124
- dec_s = get_sec(center, 1)
1125
- xticks, xticksminor, xticklabels = makegrid(ra_s, 'ra')
1126
- yticks, yticksminor, yticklabels = makegrid(dec_s, 'dec')
1127
- ra_hm = get_hmdm(xy2coord([xticks[3] / 3600., 0], center), 0)
1128
- dec_dm = get_hmdm(xy2coord([0, yticks[3] / 3600.], center), 1)
1144
+ xticks, xticksminor, xticklabels = makegrid('ra')
1145
+ yticks, yticksminor, yticklabels = makegrid('dec')
1146
+ ra_hm = _get_hmdm(xy2coord([xticks[i_mid] / 3600., 0], center), 'ra')
1147
+ dec_dm = _get_hmdm(xy2coord([0, yticks[i_mid] / 3600.], center), 'dec')
1129
1148
  if on_min_scale:
1130
1149
  dec_dm = dec_dm.split('d')[0] + 'd'
1131
- trans = {'h': r'$^\mathrm{h}$', 'm': r'$^\mathrm{m}$'}
1132
- ra_hm = ra_hm.translate(str.maketrans(trans))
1133
- trans = {'d': r'$^{\circ}$', 'm': r'$^{\prime}$'}
1134
- dec_dm = dec_dm.translate(str.maketrans(trans))
1135
- xticklabels[3] = ra_hm + xticklabels[3]
1136
- yticklabels[3] = dec_dm + '\n' + yticklabels[3]
1137
- pa2 = PlotAxes2D(True, None, 'linear', 'linear', self.Xlim, self.Ylim,
1138
- xlabel, ylabel, xticks, yticks, xticklabels,
1139
- yticklabels, xticksminor, yticksminor, grid)
1150
+ ra_hm = ra_hm.translate(str.maketrans(units['ra']))
1151
+ dec_dm = dec_dm.translate(str.maketrans(units['dec']))
1152
+ xticklabels[i_mid] = ra_hm + xticklabels[i_mid]
1153
+ yticklabels[i_mid] = dec_dm + '\n' + yticklabels[i_mid]
1154
+ pa2 = PlotAxes2D(True, None, 'linear', 'linear',
1155
+ self.Xlim, self.Ylim, xlabel, ylabel,
1156
+ xticks, yticks, xticklabels, yticklabels,
1157
+ xticksminor, yticksminor, grid)
1140
1158
  self._set_axis_shared(pa2=pa2, title=title)
1141
1159
 
1142
1160
  def savefig(self, filename: str | None = None,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: plotastrodata
3
- Version: 1.8.16
3
+ Version: 1.8.17
4
4
  Summary: plotastrodata is a tool for astronomers to create figures from FITS files and perform fundamental data analyses with ease.
5
5
  Home-page: https://github.com/yusukeaso-astron/plotastrodata
6
6
  Download-URL: https://github.com/yusukeaso-astron/plotastrodata
File without changes
File without changes
File without changes
File without changes