Commit ad2b1e4a919d6940956eb4c6a217302322ff3b8e
1 parent
bde102eb
Exists in
master
Example for Date()
Showing
3 changed files
with
40 additions
and
21 deletions
Show diff stats
src/guitastro/dates.py
... | ... | @@ -1136,12 +1136,25 @@ class Date(GuitastroTools): |
1136 | 1136 | |
1137 | 1137 | if __name__ == "__main__": |
1138 | 1138 | |
1139 | - example = 1 | |
1139 | + default = 1 | |
1140 | + example = input(f"Select the example (0 to 1) ({default}) ") | |
1141 | + try: | |
1142 | + example = int(example) | |
1143 | + except: | |
1144 | + example = default | |
1140 | 1145 | print("Example = {}".format(example)) |
1141 | 1146 | |
1142 | - if example == 1: | |
1147 | + if example == 0: | |
1143 | 1148 | """ |
1144 | - Difference coord angles | |
1149 | + Get current julian day | |
1145 | 1150 | """ |
1146 | 1151 | d = Date("now") |
1147 | 1152 | print(f"Now: {d.iso()} JD={d.jd()}") |
1153 | + | |
1154 | + if example == 1: | |
1155 | + """ | |
1156 | + Get ISO from julian day | |
1157 | + """ | |
1158 | + d = Date(2456789.3456) | |
1159 | + print(f"Now: {d.iso()} JD={d.jd()}") | |
1160 | + | ... | ... |
src/guitastro/ephemeris.py
... | ... | @@ -1193,7 +1193,7 @@ class Ephemeris(EphemerisException, GuitastroTools): |
1193 | 1193 | relative_humidity = rel_humidity |
1194 | 1194 | obswl = wavelength_nm * u.nm |
1195 | 1195 | fn = FileNames() |
1196 | - fn.longitude(self.home.longitude) | |
1196 | + fn.longitude = self.home.longitude | |
1197 | 1197 | # --- compute jd1, jd2 the limits of dates to compute the ephemeris |
1198 | 1198 | if nsec == 86400: |
1199 | 1199 | # - we compute ephemeris for all the night | ... | ... |
src/guitastro/filenames.py
... | ... | @@ -161,7 +161,7 @@ class FileNames(FileNamesException, GuitastroTools): |
161 | 161 | :: |
162 | 162 | |
163 | 163 | fn = FileNames() |
164 | - fn.longitude(-90) | |
164 | + fn.longitude = -90 | |
165 | 165 | night = "20230506" |
166 | 166 | jd1, jd2 = fn.night2date(night) |
167 | 167 | |
... | ... | @@ -174,12 +174,12 @@ class FileNames(FileNamesException, GuitastroTools): |
174 | 174 | the method date2night() returns a string corresponding to the night |
175 | 175 | directory according an input date (i.e. DATE-OBS). The method date2night() |
176 | 176 | consider a night as from noon to noon. To do that, before using date2night() |
177 | - you must specify the longitude of the observatory with the method longitude(). | |
177 | + you must specify the longitude of the observatory with the attribute longitude. | |
178 | 178 | |
179 | 179 | :: |
180 | 180 | |
181 | 181 | fn = FileNames() |
182 | - fn.longitude(-90) | |
182 | + fn.longitude = -90 | |
183 | 183 | date = "2023-06-12T23:02:45" |
184 | 184 | night = fn.date2night(date) |
185 | 185 | |
... | ... | @@ -350,6 +350,7 @@ class FileNames(FileNamesException, GuitastroTools): |
350 | 350 | # --- naming_rule |
351 | 351 | if len(args) > 0 : |
352 | 352 | self.naming(args[0]) |
353 | + self.longitude = 0 | |
353 | 354 | |
354 | 355 | def __repr__(self): |
355 | 356 | return str(self) |
... | ... | @@ -368,7 +369,10 @@ class FileNames(FileNamesException, GuitastroTools): |
368 | 369 | msg += f"\nExtension: {self.extension}" |
369 | 370 | return msg |
370 | 371 | |
371 | - def longitude(self, longiau_deg:float): | |
372 | + def _get_longitude(self): | |
373 | + return self._longiau_deg | |
374 | + | |
375 | + def _set_longitude(self, longiau_deg:float): | |
372 | 376 | """ Set the longitude of the observation siteobs. |
373 | 377 | |
374 | 378 | This method is useful for the method get_night(). |
... | ... | @@ -380,11 +384,13 @@ class FileNames(FileNamesException, GuitastroTools): |
380 | 384 | :: |
381 | 385 | |
382 | 386 | ima1 = Ima() |
383 | - ima1.longitude(2.3456) | |
387 | + ima1.longitude = 2.3456 | |
384 | 388 | |
385 | 389 | """ |
386 | 390 | self._longiau_deg = longiau_deg |
387 | 391 | |
392 | + longitude = property(_get_longitude, _set_longitude) | |
393 | + | |
388 | 394 | # ============================================= |
389 | 395 | # Print filters |
390 | 396 | # ============================================= |
... | ... | @@ -2351,7 +2357,7 @@ class FileNames(FileNamesException, GuitastroTools): |
2351 | 2357 | |
2352 | 2358 | fn = FileNames() |
2353 | 2359 | fn.pathing("YYYY/MM/DD") |
2354 | - fn.longitude(45.678) | |
2360 | + fn.longitude = 45.678 | |
2355 | 2361 | param = {} |
2356 | 2362 | param['date'] = "2021-10-26T13:45:23" |
2357 | 2363 | param['night'] = True |
... | ... | @@ -2507,7 +2513,7 @@ class FileNames(FileNamesException, GuitastroTools): |
2507 | 2513 | |
2508 | 2514 | fn = FileNames() |
2509 | 2515 | fn.pathnaming("PyROS.img.1") |
2510 | - fn.longitude(45.678) | |
2516 | + fn.longitude = 45.678 | |
2511 | 2517 | date = "2021-10-26T13:45:23" |
2512 | 2518 | fnd = fn.naming_date(date) |
2513 | 2519 | pparam = {} |
... | ... | @@ -2645,7 +2651,7 @@ class FileNames(FileNamesException, GuitastroTools): |
2645 | 2651 | def date2night(self, date: str="now", sampling: int=0)->str: |
2646 | 2652 | """Get the current night identifier as a string of 8 characters: YYYYMMDD. |
2647 | 2653 | |
2648 | - The night identifier changes at local noon. So it uses the longitude defined in longitude() method. | |
2654 | + The night identifier changes at local noon. So it uses the longitude defined in longitude attribute. | |
2649 | 2655 | |
2650 | 2656 | Args: |
2651 | 2657 | date: Input date to compute the night identifier. Defaut value is "now". |
... | ... | @@ -2705,7 +2711,7 @@ class FileNames(FileNamesException, GuitastroTools): |
2705 | 2711 | def night2date(self, night: str="now")->str: |
2706 | 2712 | """Get the current julian day limits from a night identifier as a string of 8 characters: YYYYMMDD. |
2707 | 2713 | |
2708 | - The night identifier changes at local noon. So it uses the longitude defined in longitude() method. | |
2714 | + The night identifier changes at local noon. So it uses the longitude defined in longitude attribute. | |
2709 | 2715 | |
2710 | 2716 | Args: |
2711 | 2717 | date: The night identifier string YYYYMMDD or a date (default is "now"). |
... | ... | @@ -2995,7 +3001,7 @@ class FileNames(FileNamesException, GuitastroTools): |
2995 | 3001 | :: |
2996 | 3002 | |
2997 | 3003 | fn = FileNames() |
2998 | - fn.longitude(165.85944) | |
3004 | + fn.longitude = 165.85944 | |
2999 | 3005 | fn.fcontext_create("my_context", "Test") |
3000 | 3006 | fn.fcontext = "my_context" |
3001 | 3007 | fn.rootdir = "/tmp" |
... | ... | @@ -3896,7 +3902,7 @@ if __name__ == "__main__": |
3896 | 3902 | fn = FileNames() |
3897 | 3903 | fn.pathing("YYYY/MM/DD") |
3898 | 3904 | params = fn.pathing_get("/tmp/2023/01/04") |
3899 | - fn.longitude(45.678) | |
3905 | + fn.longitude = 45.678 | |
3900 | 3906 | param = {} |
3901 | 3907 | param['date'] = params['date'] |
3902 | 3908 | param['night'] = False |
... | ... | @@ -3906,7 +3912,7 @@ if __name__ == "__main__": |
3906 | 3912 | |
3907 | 3913 | fn = FileNames() |
3908 | 3914 | fn.pathing("YYYY/YYYYMMDD") |
3909 | - fn.longitude(45.678) | |
3915 | + fn.longitude = 45.678 | |
3910 | 3916 | param = {} |
3911 | 3917 | param['date'] = "2021-10-26T13:45:23" |
3912 | 3918 | param['night'] = True |
... | ... | @@ -3917,7 +3923,7 @@ if __name__ == "__main__": |
3917 | 3923 | """ |
3918 | 3924 | fn = FileNames() |
3919 | 3925 | fn.pathnaming("PyROS.img.1") |
3920 | - fn.longitude(45.678) | |
3926 | + fn.longitude = 45.678 | |
3921 | 3927 | date = "2021-10-26T13:45:23" |
3922 | 3928 | fnd = fn.naming_date(date) |
3923 | 3929 | pparam = {} |
... | ... | @@ -3941,7 +3947,7 @@ if __name__ == "__main__": |
3941 | 3947 | """ |
3942 | 3948 | fn = FileNames() |
3943 | 3949 | fn.naming("T1M.1") |
3944 | - fn.longitude(45.678) | |
3950 | + fn.longitude = 45.678 | |
3945 | 3951 | date = "2021-10-26T13:45:23" |
3946 | 3952 | fnd = fn.naming_date(date) |
3947 | 3953 | fparam = {} |
... | ... | @@ -3974,7 +3980,7 @@ if __name__ == "__main__": |
3974 | 3980 | """ |
3975 | 3981 | fn = FileNames() |
3976 | 3982 | longitude= -90 |
3977 | - fn.longitude(longitude) | |
3983 | + fn.longitude = longitude | |
3978 | 3984 | print(f"longitude = {longitude}") |
3979 | 3985 | # --- Define a date of the observation |
3980 | 3986 | date = "2023-03-20T17:00:00" |
... | ... | @@ -3993,7 +3999,7 @@ if __name__ == "__main__": |
3993 | 3999 | Get path from name |
3994 | 4000 | """ |
3995 | 4001 | fn = FileNames() |
3996 | - fn.longitude(45.678) | |
4002 | + fn.longitude = 45.678 | |
3997 | 4003 | fn.fcontext = "image_raw" |
3998 | 4004 | fn.pathnaming("PyROS.img.1") |
3999 | 4005 | fn.rootdir = "/tmp" |
... | ... | @@ -4055,7 +4061,7 @@ if __name__ == "__main__": |
4055 | 4061 | Manage many contexts for PyROS |
4056 | 4062 | """ |
4057 | 4063 | fn = FileNames() |
4058 | - fn.longitude(165.85944) | |
4064 | + fn.longitude = 165.85944 | |
4059 | 4065 | |
4060 | 4066 | # --- Create a file context for L0 images |
4061 | 4067 | fn.fcontext_create("pyros_img_L0", "Images L0A") | ... | ... |